Skip to content

Commit

Permalink
feat: add depositContractAddress to genesis (#744)
Browse files Browse the repository at this point in the history
* feat: add depositContractAddress to genesis

* trailing commas
  • Loading branch information
Rjected authored May 13, 2024
1 parent 77458dd commit 9d3fa45
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions crates/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct Genesis {
/// The genesis block number
#[serde(default, skip_serializing_if = "Option::is_none", with = "u64_opt_via_ruint")]
pub number: Option<u64>,
/// The deposit contract address
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deposit_contract_address: Option<Address>,
}

impl Genesis {
Expand Down Expand Up @@ -934,6 +937,84 @@ mod tests {
let _genesis: Genesis = serde_json::from_str(geth_genesis).unwrap();
}

#[test]
fn parse_deposit_contract_address() {
let genesis = r#"
{
"config": {
"chainId": 1337,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"arrowGlacierBlock": 0,
"grayGlacierBlock": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"pragueTime": 1,
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true
},
"nonce": "0x0",
"timestamp": "0x0",
"extraData": "0x",
"gasLimit": "0x4c4b40",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"depositContractAddress": "0x0000000000000000000000000000000000000000"
}
"#;

let got_genesis: Genesis = serde_json::from_str(genesis).unwrap();
let expected_genesis = Genesis {
config: ChainConfig {
chain_id: 1337,
eip150_hash: Some(
hex!("0000000000000000000000000000000000000000000000000000000000000000").into(),
),
homestead_block: Some(0),
eip150_block: Some(0),
eip155_block: Some(0),
eip158_block: Some(0),
byzantium_block: Some(0),
constantinople_block: Some(0),
petersburg_block: Some(0),
istanbul_block: Some(0),
muir_glacier_block: Some(0),
berlin_block: Some(0),
london_block: Some(0),
arrow_glacier_block: Some(0),
gray_glacier_block: Some(0),
dao_fork_block: None,
dao_fork_support: false,
shanghai_time: Some(0),
cancun_time: Some(0),
prague_time: Some(1),
terminal_total_difficulty: Some(U256::ZERO),
terminal_total_difficulty_passed: true,
..Default::default()
},
nonce: 0,
timestamp: 0,
extra_data: Bytes::new(),
gas_limit: 0x4c4b40,
difficulty: U256::from(1),
deposit_contract_address: Some(Address::ZERO),
..Default::default()
};

assert_eq!(expected_genesis, got_genesis);
}

#[test]
fn parse_prague_time() {
let genesis = r#"
Expand Down Expand Up @@ -1252,6 +1333,7 @@ mod tests {
excess_blob_gas: None,
blob_gas_used: None,
number: None,
deposit_contract_address: None,
alloc: BTreeMap::from_iter(vec![
(
Address::from_str("0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6").unwrap(),
Expand Down

0 comments on commit 9d3fa45

Please sign in to comment.