Coverage Report

Created: 2024-05-16 12:16

/__w/smoldot/smoldot/repo/lib/src/header/tests.rs
Line
Count
Source
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 decode_rococo() {
22
1
    // Rococo block taken 2021-04-08 around 11:00 UTC.
23
1
    super::decode(
24
1
        &[
25
1
            5, 35, 55, 218, 117, 209, 29, 117, 103, 130, 55, 39, 55, 132, 95, 54, 138, 185, 89, 79,
26
1
            123, 161, 124, 51, 67, 40, 71, 126, 0, 210, 240, 78, 57, 177, 102, 97, 175, 183, 124,
27
1
            206, 195, 77, 217, 117, 83, 14, 134, 50, 246, 163, 138, 196, 199, 78, 108, 145, 187,
28
1
            240, 123, 5, 18, 219, 158, 44, 174, 132, 41, 70, 121, 181, 160, 189, 104, 253, 173,
29
1
            135, 222, 15, 45, 68, 248, 23, 46, 6, 140, 247, 18, 52, 37, 9, 32, 38, 102, 12, 190, 8,
30
1
            212, 237, 12, 6, 66, 65, 66, 69, 181, 1, 1, 0, 0, 0, 0, 253, 121, 18, 16, 0, 0, 0, 0,
31
1
            182, 14, 80, 77, 46, 39, 209, 60, 81, 14, 141, 206, 160, 50, 106, 233, 35, 123, 4, 185,
32
1
            66, 182, 193, 156, 19, 45, 137, 155, 123, 186, 11, 120, 251, 123, 81, 117, 113, 108,
33
1
            169, 115, 142, 208, 243, 50, 102, 4, 117, 254, 247, 226, 199, 113, 132, 25, 141, 90,
34
1
            247, 19, 211, 5, 152, 96, 121, 6, 40, 217, 92, 0, 33, 38, 199, 73, 36, 129, 161, 159,
35
1
            184, 208, 215, 110, 150, 127, 221, 158, 50, 102, 118, 40, 146, 24, 8, 98, 7, 56, 144,
36
1
            0, 4, 66, 69, 69, 70, 132, 3, 39, 11, 33, 224, 56, 100, 17, 18, 118, 159, 167, 103, 10,
37
1
            86, 125, 222, 20, 189, 120, 236, 48, 202, 89, 180, 71, 31, 56, 185, 23, 33, 23, 87, 5,
38
1
            66, 65, 66, 69, 1, 1, 180, 253, 231, 90, 196, 206, 208, 183, 14, 97, 124, 243, 43, 160,
39
1
            133, 94, 19, 162, 126, 19, 7, 15, 222, 73, 114, 113, 104, 78, 24, 52, 113, 47, 39, 154,
40
1
            108, 148, 28, 146, 180, 232, 199, 20, 52, 170, 93, 214, 0, 109, 168, 175, 162, 91, 234,
41
1
            195, 228, 139, 236, 170, 251, 200, 178, 123, 26, 130,
42
1
        ],
43
1
        4,
44
1
    )
45
1
    .unwrap();
46
1
}
47
48
#[test]
49
1
fn decode_polkadot() {
50
1
    // Polkadot block #512271.
51
1
    // Has a GrandPa scheduled change.
52
1
    super::decode(include_bytes!("./tests/header-polkadot-512271"), 4).unwrap();
53
1
}
54
55
#[test]
56
1
fn decode_reencode_kusama_7472481() {
57
1
    // Kusama block #7472481.
58
1
    // Make sure that it encodes back to what is was decoded.
59
1
    let expected = include_bytes!("./tests/header-kusama-7472481");
60
1
    let decoded = super::decode(expected, 4).unwrap();
61
1
    assert_eq!(decoded.scale_encoding_vec(4), expected);
62
1
}
63
64
#[test]
65
1
fn regression_2336() {
66
1
    // Regression test for https://github.com/paritytech/smoldot/issues/2336
67
1
    let _ = super::decode(
68
1
        &[
69
1
            231, 0, 0, 255, 255, 255, 255, 255, 255, 255, 229, 255, 107, 0, 2, 0, 0, 0, 0, 0, 0, 0,
70
1
            0, 0, 0, 32, 0, 0, 0, 192, 127, 64, 0, 0, 0, 0, 0, 192, 33, 255, 255, 255, 255, 255,
71
1
            255, 0, 52, 148, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 114, 98, 0, 98, 255,
72
1
            255, 255, 255, 0, 1, 0, 4, 4, 5, 4, 4, 4, 4, 4, 1, 0, 1, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4,
73
1
            53, 4, 4, 4, 4, 53, 4, 4, 97, 117, 114, 97, 1, 1, 1, 19, 19, 19, 19, 19, 19, 19, 19,
74
1
            19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
75
1
            19, 19, 19, 19, 19, 19, 19, 1, 1, 1, 1, 1, 1, 249, 254, 1, 1, 1, 3, 255, 254, 254, 1,
76
1
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
77
1
        ],
78
1
        4,
79
1
    );
80
1
}