Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit b523bf5

Browse files
authored
Merge pull request #14 from anton-rs/rf/feat/chain-genesis-tests
feat(primitives): Chain Genesis Unit Tests
2 parents f737563 + 93cf817 commit b523bf5

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

crates/primitives/src/genesis.rs

+53
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,56 @@ pub struct ChainGenesis {
2323
/// Optional System configuration
2424
pub system_config: Option<SystemConfig>,
2525
}
26+
27+
#[cfg(test)]
28+
mod tests {
29+
use super::*;
30+
use alloy_primitives::{address, b256, uint};
31+
32+
fn ref_genesis() -> ChainGenesis {
33+
ChainGenesis {
34+
l1: BlockID {
35+
hash: b256!("438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108"),
36+
number: 17422590,
37+
},
38+
l2: BlockID {
39+
hash: b256!("dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3"),
40+
number: 105235063,
41+
},
42+
l2_time: 1686068903,
43+
extra_data: None,
44+
system_config: Some(SystemConfig {
45+
batcher_address: address!("6887246668a3b87F54DeB3b94Ba47a6f63F32985"),
46+
overhead: uint!(0xbc_U256),
47+
scalar: uint!(0xa6fe0_U256),
48+
gas_limit: 30000000,
49+
base_fee_scalar: None,
50+
blob_base_fee_scalar: None,
51+
}),
52+
}
53+
}
54+
55+
#[test]
56+
fn test_genesis_serde() {
57+
let genesis_str = r#"{
58+
"L1": {
59+
"Hash": "0x438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108",
60+
"Number": 17422590
61+
},
62+
"L2": {
63+
"Hash": "0xdbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3",
64+
"Number": 105235063
65+
},
66+
"l2_time": 1686068903,
67+
"ExtraData": null,
68+
"system_config": {
69+
"batcherAddr": "0x6887246668a3b87F54DeB3b94Ba47a6f63F32985",
70+
"overhead": "0x00000000000000000000000000000000000000000000000000000000000000bc",
71+
"scalar": "0x00000000000000000000000000000000000000000000000000000000000a6fe0",
72+
"gasLimit": 30000000
73+
}
74+
}"#;
75+
let genesis: ChainGenesis = serde_json::from_str(genesis_str).unwrap();
76+
assert_eq!(genesis, ref_genesis());
77+
}
78+
}

0 commit comments

Comments
 (0)