Skip to content

Commit

Permalink
Merge pull request #289 from ralexstokes/update-ssz
Browse files Browse the repository at this point in the history
Update ssz dep with new serde impl
  • Loading branch information
ralexstokes authored Oct 17, 2023
2 parents 4c041e2 + cfbc4d4 commit 8b62a44
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ethereum-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ec = [
]

[dependencies]
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "c00a4659b9d1980d410c487a88e983cf2506c928" }
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "20829edcaa48e5f5f39939a69928debc477be4e2" }
blst = "0.3.11"
rand = "0.8.4"
thiserror = "1.0.30"
Expand Down
65 changes: 65 additions & 0 deletions ethereum-consensus/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,68 @@ pub mod collection_over_string {
T::try_from(data).map_err(|_| serde::de::Error::custom("failure to parse collection"))
}
}

#[cfg(test)]
mod tests {
use crate::types::mainnet::SignedBeaconBlock;

const EXPECTED_SIGNED_BLOCK_STR: &str = r#"
{ "message": {
"slot": "0",
"proposer_index": "0",
"parent_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"state_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"body": {
"randao_reveal": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"eth1_data": {
"deposit_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"deposit_count": "0",
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"graffiti": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposer_slashings": [],
"attester_slashings": [],
"attestations": [],
"deposits": [],
"voluntary_exits": [],
"sync_aggregate": {
"sync_committee_bits": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"sync_committee_signature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"execution_payload": {
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000",
"state_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"receipts_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prev_randao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"block_number": "0",
"gas_limit": "0",
"gas_used": "0",
"timestamp": "0",
"extra_data": "0x",
"base_fee_per_gas": "0",
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactions": [],
"withdrawals": [],
"blob_gas_used": "0",
"excess_blob_gas": "0"
},
"bls_to_execution_changes": [],
"blob_kzg_commitments": []
}
},
"signature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }
"#;

#[test]
fn test_serde() {
let signed_block = SignedBeaconBlock::Deneb(Default::default());
let str = serde_json::to_string(&signed_block).unwrap();
let expected_str =
EXPECTED_SIGNED_BLOCK_STR.chars().filter(|c| !c.is_whitespace()).collect::<String>();
assert_eq!(str, expected_str);
let recovered_signed_block: SignedBeaconBlock = serde_json::from_str(&str).unwrap();
assert_eq!(signed_block, recovered_signed_block);
}
}

0 comments on commit 8b62a44

Please sign in to comment.