/__w/smoldot/smoldot/repo/lib/src/executor/host/zstd/tests.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Smoldot |
2 | | // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | #![cfg(test)] |
19 | | |
20 | | #[test] |
21 | 1 | fn basic_works() { |
22 | 1 | // Note that this example file doesn't have the zstd header. |
23 | 1 | super::zstd_decode( |
24 | 1 | &include_bytes!("./example-runtime.wasm.zstd")[..], |
25 | 1 | 10 * 1024 * 1024, |
26 | 1 | ) |
27 | 1 | .unwrap(); |
28 | 1 | } |
29 | | |
30 | | #[test] |
31 | 1 | fn limit_reached() { |
32 | 1 | // Note that this example file doesn't have the zstd header. |
33 | 1 | assert!(matches!0 ( |
34 | | super::zstd_decode( |
35 | 1 | &include_bytes!("./example-runtime.wasm.zstd")[..], |
36 | 1 | 16 * 1024 |
37 | | ), |
38 | | Err(super::Error::TooLarge) |
39 | | )); |
40 | 1 | } |
41 | | |
42 | | #[test] |
43 | 1 | fn invalid_data() { |
44 | 1 | assert!(matches!0 ( |
45 | 2.04k | super::zstd_decode(&(0..2048).map(1 |_| 0xff).collect::<Vec<_>>(), 1024 * 10241 ), |
46 | | Err(super::Error::InvalidZstd) |
47 | | )); |
48 | 1 | } |
49 | | |
50 | | #[test] |
51 | 1 | fn basic_works_with_header() { |
52 | 1 | super::zstd_decode_if_necessary( |
53 | 1 | &include_bytes!("./polkadot-runtime-v9160.wasm.zstd")[..], |
54 | 1 | 10 * 1024 * 1024, |
55 | 1 | ) |
56 | 1 | .unwrap(); |
57 | 1 | } |