Skip to content

Commit

Permalink
fiddle
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Oct 28, 2024
1 parent a5d5a04 commit ac092d5
Showing 1 changed file with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,26 @@ pub fn ethereum_extrinsic<Runtime>(
}
.into();

let block_number = <frame_system::Pallet<Runtime>>::block_number();
let next_block_number = <frame_system::Pallet<Runtime>>::block_number()
.saturating_add(BlockNumberFor::<Runtime>::from(1u32));
// Block 1
let mut block_number = 1u32;
println!("BLOCK NUMBER {}", block_number);

// Finalized header update
let update_outcome = construct_and_apply_extrinsic(alice, update_call.into());
assert_ok!(update_outcome);
let balance_after_update =
<pallet_balances::Pallet<Runtime>>::free_balance(&alice_account.clone().into());
println!("block_number: {}", block_number);

// Finish Block 1
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number.into());
<frame_system::Pallet<Runtime>>::on_finalize(block_number.into());

// Start Block 2
block_number = 2u32;
<frame_system::Pallet<Runtime>>::set_block_number(block_number.into());
<frame_system::Pallet<Runtime>>::on_initialize(block_number.into());
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_initialize(block_number.into());
println!("BLOCK NUMBER {}", block_number);

// Invalid finalized header update
let invalid_update_outcome =
Expand All @@ -352,21 +362,17 @@ pub fn ethereum_extrinsic<Runtime>(
);
let balance_after_invalid_update =
<pallet_balances::Pallet<Runtime>>::free_balance(&alice_account.clone().into());
println!("block_number: {}", block_number);

// finish current block
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number);
<frame_system::Pallet<Runtime>>::on_finalize(block_number);
// Finish Block 2
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number.into());
<frame_system::Pallet<Runtime>>::on_finalize(block_number.into());

// start next block
<frame_system::Pallet<Runtime>>::set_block_number(next_block_number);
<frame_system::Pallet<Runtime>>::on_initialize(next_block_number);
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_initialize(next_block_number);
let block_number = <frame_system::Pallet<Runtime>>::block_number();
println!("block_number: {}", block_number);

let next_block_number = <frame_system::Pallet<Runtime>>::block_number()
.saturating_add(BlockNumberFor::<Runtime>::from(1u32));
// Start Block 3
block_number = 3u32;
<frame_system::Pallet<Runtime>>::set_block_number(block_number.into());
<frame_system::Pallet<Runtime>>::on_initialize(block_number.into());
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_initialize(block_number.into());
println!("BLOCK NUMBER {}", block_number);

// Sync committee update
let sync_committee_outcome =
Expand All @@ -375,6 +381,17 @@ pub fn ethereum_extrinsic<Runtime>(
let balance_after_sync_com_update =
<pallet_balances::Pallet<Runtime>>::free_balance(&alice_account.clone().into());

// Finish Block 3
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number.into());
<frame_system::Pallet<Runtime>>::on_finalize(block_number.into());

// Start Block 4
block_number = 4u32;
<frame_system::Pallet<Runtime>>::set_block_number(block_number.into());
<frame_system::Pallet<Runtime>>::on_initialize(block_number.into());
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_initialize(block_number.into());
println!("BLOCK NUMBER {}", block_number);

// Invalid sync committee update
let invalid_sync_committee_outcome =
construct_and_apply_extrinsic(alice, invalid_update_sync_committee_call.into());
Expand All @@ -385,6 +402,17 @@ pub fn ethereum_extrinsic<Runtime>(
let balance_after_invalid_sync_com_update =
<pallet_balances::Pallet<Runtime>>::free_balance(&alice_account.clone().into());

// Finish Block 4
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number.into());
<frame_system::Pallet<Runtime>>::on_finalize(block_number.into());

// Start Block 5
block_number = 5u32;
<frame_system::Pallet<Runtime>>::set_block_number(block_number.into());
<frame_system::Pallet<Runtime>>::on_initialize(block_number.into());
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_initialize(block_number.into());
println!("BLOCK NUMBER {}", block_number);

// Assert paid operations are charged and free operations are free
// Checkpoint is a free operation
assert!(balance_before == balance_after_checkpoint);
Expand All @@ -403,6 +431,10 @@ pub fn ethereum_extrinsic<Runtime>(
assert!(balance_after_invalid_update == balance_after_sync_com_update);
// An invalid sync committee update is paid
assert!(balance_after_sync_com_update > balance_after_invalid_sync_com_update);

// Finish Block 5
<snowbridge_pallet_ethereum_client::Pallet<Runtime>>::on_finalize(block_number.into());
<frame_system::Pallet<Runtime>>::on_finalize(block_number.into());
});
}

Expand Down

0 comments on commit ac092d5

Please sign in to comment.