Skip to content

Commit e3bed81

Browse files
committed
randaoe blinded block
1 parent 178e55b commit e3bed81

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

beacon_node/http_api/tests/tests.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,36 @@ impl ApiTester {
745745
self
746746
}
747747

748+
pub async fn test_beacon_states_randao(self) -> Self {
749+
for state_id in self.interesting_state_ids() {
750+
let mut state_opt = state_id
751+
.state(&self.chain)
752+
.ok()
753+
.map(|(state, _execution_optimistic)| state);
754+
755+
let epoch_opt = state_opt.as_ref().map(|state| state.current_epoch());
756+
let result = self
757+
.client
758+
.get_beacon_states_randao(state_id.0, epoch_opt)
759+
.await
760+
.unwrap()
761+
.map(|res| res.data);
762+
763+
if result.is_none() && state_opt.is_none() {
764+
continue;
765+
}
766+
767+
let state = state_opt.as_mut().expect("result should be none");
768+
let randao_mix = state
769+
.get_randao_mix(state.slot().epoch(E::slots_per_epoch()))
770+
.unwrap();
771+
772+
assert_eq!(result.unwrap().randao, *randao_mix);
773+
}
774+
775+
self
776+
}
777+
748778
pub async fn test_beacon_headers_all_slots(self) -> Self {
749779
for slot in 0..CHAIN_LENGTH {
750780
let slot = Slot::from(slot);
@@ -1016,6 +1046,82 @@ impl ApiTester {
10161046
self
10171047
}
10181048

1049+
pub async fn test_beacon_blinded_blocks(self) -> Self {
1050+
for block_id in self.interesting_block_ids() {
1051+
let expected = block_id
1052+
.blinded_block(&self.chain)
1053+
.ok()
1054+
.map(|(block, _execution_optimistic)| block);
1055+
1056+
if let CoreBlockId::Slot(slot) = block_id.0 {
1057+
if expected.is_none() {
1058+
assert!(SKIPPED_SLOTS.contains(&slot.as_u64()));
1059+
} else {
1060+
assert!(!SKIPPED_SLOTS.contains(&slot.as_u64()));
1061+
}
1062+
}
1063+
1064+
// Check the JSON endpoint.
1065+
let json_result = self
1066+
.client
1067+
.get_beacon_blinded_blocks(block_id.0)
1068+
.await
1069+
.unwrap();
1070+
1071+
if let (Some(json), Some(expected)) = (&json_result, &expected) {
1072+
assert_eq!(&json.data, expected, "{:?}", block_id);
1073+
assert_eq!(
1074+
json.version,
1075+
Some(expected.fork_name(&self.chain.spec).unwrap())
1076+
);
1077+
} else {
1078+
assert_eq!(json_result, None);
1079+
assert_eq!(expected, None);
1080+
}
1081+
1082+
// Check the SSZ endpoint.
1083+
let ssz_result = self
1084+
.client
1085+
.get_beacon_blinded_blocks_ssz(block_id.0, &self.chain.spec)
1086+
.await
1087+
.unwrap();
1088+
assert_eq!(ssz_result.as_ref(), expected.as_ref(), "{:?}", block_id);
1089+
1090+
// Check that version headers are provided.
1091+
let url = self
1092+
.client
1093+
.get_beacon_blinded_blocks_path(block_id.0)
1094+
.unwrap();
1095+
1096+
let builders: Vec<fn(RequestBuilder) -> RequestBuilder> = vec![
1097+
|b| b,
1098+
|b| b.accept(Accept::Ssz),
1099+
|b| b.accept(Accept::Json),
1100+
|b| b.accept(Accept::Any),
1101+
];
1102+
1103+
for req_builder in builders {
1104+
let raw_res = self
1105+
.client
1106+
.get_response(url.clone(), req_builder)
1107+
.await
1108+
.optional()
1109+
.unwrap();
1110+
if let (Some(raw_res), Some(expected)) = (&raw_res, &expected) {
1111+
assert_eq!(
1112+
raw_res.fork_name_from_header().unwrap(),
1113+
Some(expected.fork_name(&self.chain.spec).unwrap())
1114+
);
1115+
} else {
1116+
assert!(raw_res.is_none());
1117+
assert_eq!(expected, None);
1118+
}
1119+
}
1120+
}
1121+
1122+
self
1123+
}
1124+
10191125
pub async fn test_beacon_blocks_attestations(self) -> Self {
10201126
for block_id in self.interesting_block_ids() {
10211127
let result = self
@@ -3696,6 +3802,8 @@ async fn beacon_get() {
36963802
.await
36973803
.test_beacon_states_validator_id()
36983804
.await
3805+
.test_beacon_states_randao()
3806+
.await
36993807
.test_beacon_headers_all_slots()
37003808
.await
37013809
.test_beacon_headers_all_parents()
@@ -3704,6 +3812,8 @@ async fn beacon_get() {
37043812
.await
37053813
.test_beacon_blocks()
37063814
.await
3815+
.test_beacon_blinded_blocks()
3816+
.await
37073817
.test_beacon_blocks_attestations()
37083818
.await
37093819
.test_beacon_blocks_root()

common/eth2/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl BeaconNodeHttpClient {
523523
&self,
524524
state_id: StateId,
525525
epoch: Option<Epoch>,
526-
) -> Result<ExecutionOptimisticResponse<RandaoMix>, Error> {
526+
) -> Result<Option<ExecutionOptimisticResponse<RandaoMix>>, Error> {
527527
let mut path = self.eth_path(V1)?;
528528

529529
path.path_segments_mut()
@@ -538,7 +538,7 @@ impl BeaconNodeHttpClient {
538538
.append_pair("epoch", &epoch.to_string());
539539
}
540540

541-
self.get(path).await
541+
self.get_opt(path).await
542542
}
543543

544544
/// `GET beacon/states/{state_id}/validators/{validator_id}`

0 commit comments

Comments
 (0)