fuel_streams_core/blocks/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
pub mod subjects;
pub mod types;

pub use subjects::*;

use super::types::*;
use crate::{StreamEncoder, Streamable};

impl StreamEncoder for Block {}
impl Streamable for Block {
    const NAME: &'static str = "blocks";
    const WILDCARD_LIST: &'static [&'static str] = &[BlocksSubject::WILDCARD];
}

#[cfg(test)]
mod tests {
    use serde_json::{self, json};

    use super::*;

    #[tokio::test]
    async fn test_serialization() {
        let header = BlockHeader {
            application_hash: [0u8; 32].into(),
            consensus_parameters_version: 1,
            da_height: 1000,
            event_inbox_root: [1u8; 32].into(),
            id: Default::default(),
            height: 42,
            message_outbox_root: [3u8; 32].into(),
            message_receipt_count: 10,
            prev_root: [4u8; 32].into(),
            state_transition_bytecode_version: 2,
            time: FuelCoreTai64(1697398400).into(),
            transactions_count: 5,
            transactions_root: [5u8; 32].into(),
            version: BlockHeaderVersion::V1,
        };

        let block = Block {
            consensus: Consensus::default(),
            header: header.clone(),
            height: 42,
            id: Default::default(),
            transaction_ids: vec![],
            version: BlockVersion::V1,
        };

        let serialized_block =
            serde_json::to_value(&block).expect("Failed to serialize Block");

        let expected_json = json!({
            "consensus": {
                "chainConfigHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "coinsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "contractsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "messagesRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "type": "Genesis"
            },
            "header": {
                "applicationHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "consensusParametersVersion": 1,
                "daHeight": 1000,
                "eventInboxRoot": "0x0101010101010101010101010101010101010101010101010101010101010101",
                "id": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "height": 42,
                "messageOutboxRoot": "0x0303030303030303030303030303030303030303030303030303030303030303",
                "messageReceiptCount": 10,
                "prevRoot": "0x0404040404040404040404040404040404040404040404040404040404040404",
                "stateTransitionBytecodeVersion": 2,
                "time": "1697398400",
                "transactionsCount": 5,
                "transactionsRoot": "0x0505050505050505050505050505050505050505050505050505050505050505",
                "version": "V1"
            },
            "height": 42,
            "id": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "transactionIds": [],
            "version": "V1"
        });

        assert_eq!(serialized_block, expected_json);
    }
}