Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Jan 25, 2024
1 parent f78e40b commit 2aab26b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
16 changes: 16 additions & 0 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions parachain/pallets/ethereum-client/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
// See README.md for instructions to generate
#![cfg_attr(not(feature = "std"), no_std)]

use crate::{CheckpointUpdate, ExecutionHeaderUpdate, Update};
use hex_literal::hex;
use primitives::{
types::deneb, updates::AncestryProof, BeaconHeader, NextSyncCommitteeUpdate, SyncAggregate,
SyncCommittee, VersionedExecutionPayloadHeader,
use snowbridge_beacon_primitives::{
types::deneb, updates::AncestryProof, BeaconHeader, ExecutionHeaderUpdate,
NextSyncCommitteeUpdate, SyncAggregate, SyncCommittee, VersionedExecutionPayloadHeader,
};
use sp_core::U256;
use sp_std::{boxed::Box, vec};

const SC_SIZE: usize = 512;
const SC_BITS_SIZE: usize = 64;
type CheckpointUpdate = snowbridge_beacon_primitives::CheckpointUpdate<SC_SIZE>;
type Update = snowbridge_beacon_primitives::Update<SC_SIZE, SC_BITS_SIZE>;

pub fn make_checkpoint() -> Box<CheckpointUpdate> {
Box::new(CheckpointUpdate {
header: BeaconHeader {
Expand Down
3 changes: 3 additions & 0 deletions parachain/runtime/test-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ snowbridge-core = { path = "../../primitives/core", default-features = false }
snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false }
snowbridge-router-primitives = { path = "../../primitives/router", default-features = false }
snowbridge-pallet-ethereum-client = { path = "../../pallets/ethereum-client", default-features = false }
snowbridge-pallet-ethereum-client-fixtures = { path = "../../pallets/ethereum-client/fixtures", default-features = false }
snowbridge-pallet-inbound-queue = { path = "../../pallets/inbound-queue", default-features = false }
snowbridge-pallet-outbound-queue = { path = "../../pallets/outbound-queue", default-features = false }
snowbridge-outbound-queue-runtime-api = { path = "../../pallets/outbound-queue/runtime-api", default-features = false }
Expand Down Expand Up @@ -140,6 +141,7 @@ std = [
"snowbridge-core/std",
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-pallet-ethereum-client/std",
"snowbridge-pallet-ethereum-client-fixtures/std",
"snowbridge-pallet-inbound-queue/std",
"snowbridge-pallet-outbound-queue/std",
"snowbridge-pallet-system/std",
Expand Down Expand Up @@ -190,6 +192,7 @@ runtime-benchmarks = [
"polkadot-runtime-common/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-pallet-ethereum-client/runtime-benchmarks",
"snowbridge-pallet-ethereum-client-fixtures/runtime-benchmarks",
"snowbridge-pallet-inbound-queue/runtime-benchmarks",
"snowbridge-pallet-outbound-queue/runtime-benchmarks",
"snowbridge-pallet-system/runtime-benchmarks",
Expand Down
25 changes: 8 additions & 17 deletions parachain/runtime/test-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>

use codec::Encode;
use snowbridge_core::RingBufferMap;
use frame_support::{assert_err, assert_ok, traits::fungible::Mutate};
pub use parachains_runtimes_test_utils::test_cases::change_storage_constant_by_governance_works;
use parachains_runtimes_test_utils::{
AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom,
};
use snowbridge_pallet_ethereum_client::ExecutionHeaderBuffer;
use sp_core::H160;
use sp_runtime::SaturatedConversion;
use xcm::{
Expand All @@ -18,6 +16,7 @@ use xcm::{
use xcm_executor::XcmExecutor;
use sp_keyring::AccountKeyring::*;
use sp_runtime::AccountId32;
use snowbridge_pallet_ethereum_client_fixtures::*;

type RuntimeHelper<Runtime, AllPalletsWithoutSystem = ()> =
parachains_runtimes_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
Expand Down Expand Up @@ -325,10 +324,10 @@ where
.with_tracing()
.build()
.execute_with(|| {
let initial_checkpoint = fixtures::make_checkpoint();
let update = fixtures::make_finalized_header_update();
let sync_committee_update = fixtures::make_sync_committee_update();
let execution_header_update = fixtures::make_execution_header_update();
let initial_checkpoint = make_checkpoint();
let update = make_finalized_header_update();
let sync_committee_update = make_sync_committee_update();
let execution_header_update = make_execution_header_update();

let alice = Alice;
let alice_account = alice.to_account_id();
Expand Down Expand Up @@ -400,10 +399,9 @@ pub fn ethereum_to_polkadot_message_extrinsics_work<Runtime>(
.with_tracing()
.build()
.execute_with(|| {
let initial_checkpoint = fixtures::make_checkpoint_for_inbound();
let sync_committee_update = fixtures::make_sync_committee_update_for_inbound();
let sync_committee_update_for_next_period = fixtures::make_sync_committee_update_for_inbound_next_period();
let execution_header_update = fixtures::make_execution_header_update_for_inbound();
let initial_checkpoint = make_checkpoint();
let sync_committee_update = make_sync_committee_update();
let execution_header_update = make_execution_header_update();

let alice = Alice;
let alice_account = alice.to_account_id();
Expand All @@ -424,20 +422,13 @@ pub fn ethereum_to_polkadot_message_extrinsics_work<Runtime>(
update: Box::new(*sync_committee_update),
}.into();

let update_sync_committee_call_for_next_period: <Runtime as pallet_utility::Config>::RuntimeCall = snowbridge_pallet_ethereum_client::Call::<Runtime>::submit {
update: Box::new(*sync_committee_update_for_next_period),
}.into();

let execution_header_call: <Runtime as pallet_utility::Config>::RuntimeCall = snowbridge_pallet_ethereum_client::Call::<Runtime>::submit_execution_header {
update: Box::new(*execution_header_update),
}.into();

let sync_committee_outcome = construct_and_apply_extrinsic(alice, update_sync_committee_call.into());
assert_ok!(sync_committee_outcome);

let sync_committee_outcome_next_period_outcome = construct_and_apply_extrinsic(alice, update_sync_committee_call_for_next_period.into());
assert_ok!(sync_committee_outcome_next_period_outcome);

let execution_header_outcome = construct_and_apply_extrinsic(alice, execution_header_call.into());
assert_ok!(execution_header_outcome);
});
Expand Down

0 comments on commit 2aab26b

Please sign in to comment.