Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
illustrates border condition
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Sep 2, 2024
1 parent dfee885 commit 8a27360
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ pub mod pallet {
let update_has_next_sync_committee = !<NextSyncCommittee<T>>::exists() &&
(update.next_sync_committee_update.is_some() &&
update_attested_period == store_period);

println!("update_has_next_sync_committee {}", update_has_next_sync_committee);
println!("update.attested_header.slot {}", update.attested_header.slot);
println!("latest_finalized_state.slot {}", latest_finalized_state.slot);

ensure!(
update.attested_header.slot > latest_finalized_state.slot ||
update_has_next_sync_committee,
Expand Down Expand Up @@ -457,10 +462,13 @@ pub mod pallet {
<Error<T>>::InvalidSyncCommitteeUpdate
);
<NextSyncCommittee<T>>::set(sync_committee_prepared);
println!("condition 1");
} else if update_finalized_period == store_period + 1 {
<CurrentSyncCommittee<T>>::set(<NextSyncCommittee<T>>::get());
<NextSyncCommittee<T>>::set(sync_committee_prepared);
println!("condition 2");
}
println!("SyncCommitteeUpdated at period {}", update_finalized_period);
log::info!(
target: LOG_TARGET,
"💫 SyncCommitteeUpdated at period {}.",
Expand Down
20 changes: 20 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ pub fn load_next_finalized_header_update_fixture() -> snowbridge_beacon_primitiv
load_fixture("next-finalized-header-update.json".to_string()).unwrap()
}

pub fn load_test_checkpoint_update_fixture(
) -> snowbridge_beacon_primitives::CheckpointUpdate<{ config::SYNC_COMMITTEE_SIZE }> {
load_fixture("initial-checkpoint-test.json".to_string()).unwrap()
}

pub fn load_test_sync_committee_update_fixture() -> snowbridge_beacon_primitives::Update<
{ config::SYNC_COMMITTEE_SIZE },
{ config::SYNC_COMMITTEE_BITS_SIZE },
> {
load_fixture("sync-committee-update-test.json".to_string()).unwrap()
}

pub fn load_second_test_sync_committee_update_fixture() -> snowbridge_beacon_primitives::Update<
{ config::SYNC_COMMITTEE_SIZE },
{ config::SYNC_COMMITTEE_BITS_SIZE },
> {
load_fixture("second-sync-committee-update-test.json".to_string()).unwrap()
}


pub fn get_message_verification_payload() -> (Log, Proof) {
let inbound_fixture = snowbridge_pallet_ethereum_client_fixtures::make_inbound_fixture();
(inbound_fixture.message.event_log, inbound_fixture.message.proof)
Expand Down
24 changes: 24 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,30 @@ fn duplicate_sync_committee_updates_are_not_free() {
});
}

#[test]
fn sync_committee_update_for_sync_committee_already_imported_are_not_free() {
let checkpoint = Box::new(load_test_checkpoint_update_fixture());
let sync_committee_update = Box::new(load_test_sync_committee_update_fixture());
let second_sync_committee_update = Box::new(load_second_test_sync_committee_update_fixture());

new_tester().execute_with(|| {
println!("checkpoint =============");
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint));
println!("submit 1 =============");
let result =
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), sync_committee_update.clone());
assert_ok!(result);
assert_eq!(result.unwrap().pays_fee, Pays::No);

println!("submit 2 =============");
// Check that if the same update is submitted, the update is not free.
let second_result =
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), second_sync_committee_update);
//assert_err!(second_result, Error::<Test>::IrrelevantUpdate);
assert_eq!(second_result.unwrap_err().post_info.pays_fee, Pays::Yes);
});
}

/* IMPLS */

#[test]
Expand Down

0 comments on commit 8a27360

Please sign in to comment.