Skip to content

Commit

Permalink
fix(beacon): update LightClientHeader fork version (#1554)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenev authored Oct 28, 2024
1 parent bf02bc3 commit 12da3d1
Show file tree
Hide file tree
Showing 33 changed files with 2,581 additions and 64 deletions.
38 changes: 37 additions & 1 deletion ethportal-api/src/types/consensus/light_client/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
consensus::header::BeaconBlockHeader,
light_client::header::LightClientHeaderDeneb,
types::consensus::{
fork::ForkName,
light_client::header::{LightClientHeaderBellatrix, LightClientHeaderCapella},
Expand Down Expand Up @@ -34,7 +35,7 @@ pub struct LightClientBootstrap {
#[superstruct(only(Capella), partial_getter(rename = "header_capella"))]
pub header: LightClientHeaderCapella,
#[superstruct(only(Deneb), partial_getter(rename = "header_deneb"))]
pub header: LightClientHeaderCapella,
pub header: LightClientHeaderDeneb,
/// Current sync committee corresponding to `header.beacon.state_root`
pub current_sync_committee: SyncCommittee,
pub current_sync_committee_branch: FixedVector<B256, CurrentSyncCommitteeProofLen>,
Expand Down Expand Up @@ -152,4 +153,39 @@ mod test {
LightClientBootstrap::from_ssz_bytes(&expected, ForkName::Capella).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn serde_light_client_bootstrap_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientBootstrap/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientBootstrapDeneb = serde_json::from_value(value.clone()).unwrap();
let serialized = serde_json::to_value(content).unwrap();
assert_eq!(serialized, value);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn ssz_light_client_bootstrap_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientBootstrap/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientBootstrapDeneb = serde_json::from_value(value).unwrap();

let compressed = std::fs::read(format!(
"../test_assets/beacon/deneb/LightClientBootstrap/ssz_random/{case}/serialized.ssz_snappy"
))
.expect("cannot find test asset");
let mut decoder = snap::raw::Decoder::new();
let expected = decoder.decompress_vec(&compressed).unwrap();
LightClientBootstrap::from_ssz_bytes(&expected, ForkName::Deneb).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}
}
36 changes: 36 additions & 0 deletions ethportal-api/src/types/consensus/light_client/finality_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,40 @@ mod test {
LightClientFinalityUpdate::from_ssz_bytes(&expected, ForkName::Capella).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn serde_light_client_finality_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientFinalityUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientFinalityUpdateDeneb =
serde_json::from_value(value.clone()).unwrap();
let serialized = serde_json::to_value(content).unwrap();
assert_eq!(serialized, value);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn ssz_light_client_finality_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientFinalityUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientFinalityUpdateDeneb = serde_json::from_value(value).unwrap();

let compressed = std::fs::read(format!(
"../test_assets/beacon/deneb/LightClientFinalityUpdate/ssz_random/{case}/serialized.ssz_snappy"
))
.expect("cannot find test asset");
let mut decoder = snap::raw::Decoder::new();
let expected = decoder.decompress_vec(&compressed).unwrap();
LightClientFinalityUpdate::from_ssz_bytes(&expected, ForkName::Deneb).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}
}
46 changes: 43 additions & 3 deletions ethportal-api/src/types/consensus/light_client/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::types::consensus::{
execution_payload::ExecutionPayloadHeaderCapella, fork::ForkName, header::BeaconBlockHeader,
use crate::{
consensus::execution_payload::ExecutionPayloadHeaderDeneb,
types::consensus::{
execution_payload::ExecutionPayloadHeaderCapella, fork::ForkName, header::BeaconBlockHeader,
},
};
use alloy::primitives::B256;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -33,8 +36,10 @@ pub type ExecutionBranchLen = U4;
#[tree_hash(enum_behaviour = "transparent")]
pub struct LightClientHeader {
pub beacon: BeaconBlockHeader,
#[superstruct(only(Capella, Deneb))]
#[superstruct(only(Capella), partial_getter(rename = "execution_capella"))]
pub execution: ExecutionPayloadHeaderCapella,
#[superstruct(only(Deneb), partial_getter(rename = "execution_deneb"))]
pub execution: ExecutionPayloadHeaderDeneb,
#[superstruct(only(Capella, Deneb))]
pub execution_branch: FixedVector<B256, ExecutionBranchLen>,
}
Expand Down Expand Up @@ -146,4 +151,39 @@ mod test {
LightClientHeader::from_ssz_bytes(&expected, ForkName::Capella).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn serde_light_client_header_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientHeader/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientHeaderDeneb = serde_json::from_value(value.clone()).unwrap();
let serialized = serde_json::to_value(content).unwrap();
assert_eq!(serialized, value);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn ssz_light_client_header_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientHeader/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientHeaderDeneb = serde_json::from_value(value).unwrap();

let compressed = std::fs::read(format!(
"../test_assets/beacon/deneb/LightClientHeader/ssz_random/{case}/serialized.ssz_snappy"
))
.expect("cannot find test asset");
let mut decoder = snap::raw::Decoder::new();
let expected = decoder.decompress_vec(&compressed).unwrap();
LightClientHeader::from_ssz_bytes(&expected, ForkName::Deneb).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,40 @@ mod test {
LightClientOptimisticUpdate::from_ssz_bytes(&expected, ForkName::Capella).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn serde_light_client_optimistic_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientOptimisticUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientOptimisticUpdateDeneb =
serde_json::from_value(value.clone()).unwrap();
let serialized = serde_json::to_value(content).unwrap();
assert_eq!(serialized, value);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn ssz_light_client_optimistic_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientOptimisticUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientOptimisticUpdateDeneb = serde_json::from_value(value).unwrap();

let compressed = std::fs::read(format!(
"../test_assets/beacon/deneb/LightClientOptimisticUpdate/ssz_random/{case}/serialized.ssz_snappy"
))
.expect("cannot find test asset");
let mut decoder = snap::raw::Decoder::new();
let expected = decoder.decompress_vec(&compressed).unwrap();
LightClientOptimisticUpdate::from_ssz_bytes(&expected, ForkName::Deneb).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}
}
35 changes: 35 additions & 0 deletions ethportal-api/src/types/consensus/light_client/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,39 @@ mod test {
LightClientUpdate::from_ssz_bytes(&expected, ForkName::Capella).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn serde_light_client_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientUpdateDeneb = serde_json::from_value(value.clone()).unwrap();
let serialized = serde_json::to_value(content).unwrap();
assert_eq!(serialized, value);
}

#[rstest]
#[case("case_0")]
#[case("case_1")]
fn ssz_light_client_update_deneb(#[case] case: &str) {
let value = std::fs::read_to_string(format!(
"../test_assets/beacon/deneb/LightClientUpdate/ssz_random/{case}/value.yaml"
))
.expect("cannot find test asset");
let value: Value = serde_yaml::from_str(&value).unwrap();
let content: LightClientUpdateDeneb = serde_json::from_value(value).unwrap();

let compressed = std::fs::read(format!(
"../test_assets/beacon/deneb/LightClientUpdate/ssz_random/{case}/serialized.ssz_snappy"
))
.expect("cannot find test asset");
let mut decoder = snap::raw::Decoder::new();
let expected = decoder.decompress_vec(&compressed).unwrap();
LightClientUpdate::from_ssz_bytes(&expected, ForkName::Deneb).unwrap();
assert_eq!(content.as_ssz_bytes(), expected);
}
}
2 changes: 1 addition & 1 deletion light-client/testdata/bootstrap.json

Large diffs are not rendered by default.

Loading

0 comments on commit 12da3d1

Please sign in to comment.