Fixed some BeaconChain Tests

This commit is contained in:
Mark Mackey 2022-11-28 16:56:54 -06:00
parent e0ea26c228
commit 36170ec428
3 changed files with 65 additions and 32 deletions

View File

@ -12,17 +12,17 @@ fn verify_execution_payload_chain<T: EthSpec>(chain: &[FullPayload<T>]) {
let mut prev_ep: Option<FullPayload<T>> = None; let mut prev_ep: Option<FullPayload<T>> = None;
for ep in chain { for ep in chain {
assert!(*ep != FullPayload::default()); assert!(!ep.is_default_with_empty_roots());
assert!(ep.block_hash() != ExecutionBlockHash::zero()); assert!(ep.block_hash() != ExecutionBlockHash::zero());
// Check against previous `ExecutionPayload`. // Check against previous `ExecutionPayload`.
if let Some(prev_ep) = prev_ep { if let Some(prev_ep) = prev_ep {
assert_eq!(prev_ep.block_hash(), ep.execution_payload.parent_hash); assert_eq!(prev_ep.block_hash(), ep.execution_payload().parent_hash());
assert_eq!( assert_eq!(
prev_ep.execution_payload.block_number + 1, prev_ep.execution_payload().block_number() + 1,
ep.execution_payload.block_number ep.execution_payload().block_number()
); );
assert!(ep.execution_payload.timestamp > prev_ep.execution_payload.timestamp); assert!(ep.execution_payload().timestamp() > prev_ep.execution_payload().timestamp());
} }
prev_ep = Some(ep.clone()); prev_ep = Some(ep.clone());
} }
@ -88,7 +88,7 @@ async fn merge_with_terminal_block_hash_override() {
if i == 0 { if i == 0 {
assert_eq!(execution_payload.block_hash(), genesis_pow_block_hash); assert_eq!(execution_payload.block_hash(), genesis_pow_block_hash);
} }
execution_payloads.push(execution_payload); execution_payloads.push(execution_payload.into());
} }
verify_execution_payload_chain(execution_payloads.as_slice()); verify_execution_payload_chain(execution_payloads.as_slice());
@ -139,9 +139,14 @@ async fn base_altair_merge_with_terminal_block_after_fork() {
let merge_head = &harness.chain.head_snapshot().beacon_block; let merge_head = &harness.chain.head_snapshot().beacon_block;
assert!(merge_head.as_merge().is_ok()); assert!(merge_head.as_merge().is_ok());
assert_eq!(merge_head.slot(), merge_fork_slot); assert_eq!(merge_head.slot(), merge_fork_slot);
assert_eq!( assert!(
*merge_head.message().body().execution_payload().unwrap(), merge_head
FullPayload::default() .message()
.body()
.execution_payload()
.unwrap()
.is_default_with_empty_roots(),
"Merge head is default payload"
); );
/* /*
@ -151,13 +156,14 @@ async fn base_altair_merge_with_terminal_block_after_fork() {
harness.extend_slots(1).await; harness.extend_slots(1).await;
let one_after_merge_head = &harness.chain.head_snapshot().beacon_block; let one_after_merge_head = &harness.chain.head_snapshot().beacon_block;
assert_eq!( assert!(
*one_after_merge_head one_after_merge_head
.message() .message()
.body() .body()
.execution_payload() .execution_payload()
.unwrap(), .unwrap()
FullPayload::default() .is_default_with_empty_roots(),
"One after merge head is default payload"
); );
assert_eq!(one_after_merge_head.slot(), merge_fork_slot + 1); assert_eq!(one_after_merge_head.slot(), merge_fork_slot + 1);
@ -184,25 +190,34 @@ async fn base_altair_merge_with_terminal_block_after_fork() {
harness.extend_slots(1).await; harness.extend_slots(1).await;
let one_after_merge_head = &harness.chain.head_snapshot().beacon_block; let one_after_merge_head = &harness.chain.head_snapshot().beacon_block;
assert_eq!( // FIXME: why is this being tested twice?
*one_after_merge_head assert!(
one_after_merge_head
.message() .message()
.body() .body()
.execution_payload() .execution_payload()
.unwrap(), .unwrap()
FullPayload::default() .is_default_with_empty_roots(),
"One after merge head is default payload"
); );
assert_eq!(one_after_merge_head.slot(), merge_fork_slot + 2); assert_eq!(one_after_merge_head.slot(), merge_fork_slot + 2);
/* /*
* Next merge block should include an exec payload. * Next merge block should include an exec payload.
*/ */
for _ in 0..4 { for _ in 0..4 {
harness.extend_slots(1).await; harness.extend_slots(1).await;
let block = &harness.chain.head_snapshot().beacon_block; let block = &harness.chain.head_snapshot().beacon_block;
execution_payloads.push(block.message().body().execution_payload().unwrap().clone()); execution_payloads.push(
block
.message()
.body()
.execution_payload()
.unwrap()
.clone()
.into(),
);
} }
verify_execution_payload_chain(execution_payloads.as_slice()); verify_execution_payload_chain(execution_payloads.as_slice());

View File

@ -12,9 +12,9 @@ use beacon_chain::{
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON, INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON,
}; };
use execution_layer::{ use execution_layer::{
json_structures::{JsonForkchoiceStateV1, JsonPayloadAttributesV1}, json_structures::{JsonForkchoiceStateV1, JsonPayloadAttributes, JsonPayloadAttributesV1},
test_utils::ExecutionBlockGenerator, test_utils::ExecutionBlockGenerator,
ExecutionLayer, ForkchoiceState, PayloadAttributes, ExecutionLayer, ForkchoiceState, PayloadAttributes, PayloadAttributesV1,
}; };
use fork_choice::{ use fork_choice::{
CountUnrealized, Error as ForkChoiceError, InvalidationOperation, PayloadVerificationStatus, CountUnrealized, Error as ForkChoiceError, InvalidationOperation, PayloadVerificationStatus,
@ -133,7 +133,10 @@ impl InvalidPayloadRig {
let attributes: JsonPayloadAttributesV1 = let attributes: JsonPayloadAttributesV1 =
serde_json::from_value(payload_param_json.clone()).unwrap(); serde_json::from_value(payload_param_json.clone()).unwrap();
(fork_choice_state.into(), attributes.into()) (
fork_choice_state.into(),
JsonPayloadAttributes::V1(attributes).into(),
)
} }
fn previous_payload_attributes(&self) -> PayloadAttributes { fn previous_payload_attributes(&self) -> PayloadAttributes {
@ -982,7 +985,7 @@ async fn payload_preparation() {
.await .await
.unwrap(); .unwrap();
let payload_attributes = PayloadAttributes { let payload_attributes = PayloadAttributes::V1(PayloadAttributesV1 {
timestamp: rig timestamp: rig
.harness .harness
.chain .chain
@ -995,7 +998,7 @@ async fn payload_preparation() {
.get_randao_mix(head.beacon_state.current_epoch()) .get_randao_mix(head.beacon_state.current_epoch())
.unwrap(), .unwrap(),
suggested_fee_recipient: fee_recipient, suggested_fee_recipient: fee_recipient,
}; });
assert_eq!(rig.previous_payload_attributes(), payload_attributes); assert_eq!(rig.previous_payload_attributes(), payload_attributes);
} }
@ -1125,7 +1128,7 @@ async fn payload_preparation_before_transition_block() {
let (fork_choice_state, payload_attributes) = rig.previous_forkchoice_update_params(); let (fork_choice_state, payload_attributes) = rig.previous_forkchoice_update_params();
let latest_block_hash = rig.latest_execution_block_hash(); let latest_block_hash = rig.latest_execution_block_hash();
assert_eq!(payload_attributes.suggested_fee_recipient, fee_recipient); assert_eq!(payload_attributes.suggested_fee_recipient(), fee_recipient);
assert_eq!(fork_choice_state.head_block_hash, latest_block_hash); assert_eq!(fork_choice_state.head_block_hash, latest_block_hash);
} }
@ -1367,18 +1370,16 @@ async fn build_optimistic_chain(
.body() .body()
.execution_payload() .execution_payload()
.unwrap() .unwrap()
.execution_payload .is_default_with_empty_roots(),
== <_>::default(),
"the block *has not* undergone the merge transition" "the block *has not* undergone the merge transition"
); );
assert!( assert!(
post_transition_block !post_transition_block
.message() .message()
.body() .body()
.execution_payload() .execution_payload()
.unwrap() .unwrap()
.execution_payload .is_default_with_empty_roots(),
!= <_>::default(),
"the block *has* undergone the merge transition" "the block *has* undergone the merge transition"
); );

View File

@ -148,8 +148,8 @@ impl<T: EthSpec> From<FullPayload<T>> for ExecutionPayload<T> {
} }
impl<'a, T: EthSpec> From<FullPayloadRef<'a, T>> for ExecutionPayload<T> { impl<'a, T: EthSpec> From<FullPayloadRef<'a, T>> for ExecutionPayload<T> {
fn from(full_payload: FullPayloadRef<'a, T>) -> Self { fn from(full_payload_ref: FullPayloadRef<'a, T>) -> Self {
match full_payload { match full_payload_ref {
FullPayloadRef::Merge(payload) => { FullPayloadRef::Merge(payload) => {
ExecutionPayload::Merge(payload.execution_payload.clone()) ExecutionPayload::Merge(payload.execution_payload.clone())
} }
@ -163,6 +163,23 @@ impl<'a, T: EthSpec> From<FullPayloadRef<'a, T>> for ExecutionPayload<T> {
} }
} }
// FIXME: can this be implemented as Deref or Clone somehow?
impl<'a, T: EthSpec> From<FullPayloadRef<'a, T>> for FullPayload<T> {
fn from(full_payload_ref: FullPayloadRef<'a, T>) -> Self {
match full_payload_ref {
FullPayloadRef::Merge(payload_ref) => {
FullPayload::Merge(payload_ref.clone())
}
FullPayloadRef::Capella(payload_ref) => {
FullPayload::Capella(payload_ref.clone())
}
FullPayloadRef::Eip4844(payload_ref) => {
FullPayload::Eip4844(payload_ref.clone())
}
}
}
}
impl<T: EthSpec> ExecPayload<T> for FullPayload<T> { impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
fn block_type() -> BlockType { fn block_type() -> BlockType {
BlockType::Full BlockType::Full