Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Oct 19, 2023
1 parent f0277a5 commit 5cfa24d
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 114 deletions.
18 changes: 6 additions & 12 deletions parachain/pallets/control/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ use snowbridge_core::{
AgentId,
};
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
AccountId32,
AccountId32, BuildStorage,
};
use xcm::prelude::*;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};

#[cfg(feature = "runtime-benchmarks")]
use crate::BenchmarkHelper;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Balance = u128;

Expand Down Expand Up @@ -86,10 +84,7 @@ mod pallet_xcm_origin {

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Expand All @@ -105,24 +100,23 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -209,7 +203,7 @@ impl crate::Config for Test {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext: sp_io::TestExternalities = storage.into();
ext.execute_with(|| {
System::set_block_number(1);
Expand Down
8 changes: 4 additions & 4 deletions parachain/pallets/ethereum-beacon-client/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
use super::*;

use frame_support::dispatch::DispatchError;
use snowbridge_ethereum::{Log, Receipt};
use sp_runtime::DispatchError;

impl<T: Config> Verifier for Pallet<T> {
/// Verify a message by verifying the existence of the corresponding
Expand All @@ -29,7 +29,7 @@ impl<T: Config> Verifier for Pallet<T> {
message.proof.block_hash,
err
);
return Err(err)
return Err(err);
},
};

Expand All @@ -48,7 +48,7 @@ impl<T: Config> Verifier for Pallet<T> {
message.proof.block_hash,
err
);
return Err(Error::<T>::DecodeFailed.into())
return Err(Error::<T>::DecodeFailed.into());
},
};

Expand All @@ -58,7 +58,7 @@ impl<T: Config> Verifier for Pallet<T> {
"💫 Event log not found in receipt for transaction at index {} in block {}",
message.proof.tx_index, message.proof.block_hash,
);
return Err(Error::<T>::InvalidProof.into())
return Err(Error::<T>::InvalidProof.into());
}

log::info!(
Expand Down
37 changes: 19 additions & 18 deletions parachain/pallets/ethereum-beacon-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ mod tests;
mod benchmarking;

use frame_support::{
dispatch::DispatchResult, log, pallet_prelude::OptionQuery, traits::Get, transactional,
dispatch::DispatchResult, pallet_prelude::OptionQuery, traits::Get, transactional,
};
use frame_system::ensure_signed;
use log;
use primitives::{
fast_aggregate_verify, verify_merkle_branch, verify_receipt_proof, BeaconHeader, BlsError,
CompactBeaconState, CompactExecutionHeader, ExecutionHeaderState, ForkData, ForkVersion,
Expand Down Expand Up @@ -351,9 +352,9 @@ pub mod pallet {
// committee period.
let max_latency = config::EPOCHS_PER_SYNC_COMMITTEE_PERIOD * config::SLOTS_PER_EPOCH;
ensure!(
latest_execution_state.beacon_slot == 0 ||
latest_finalized_state.slot <
latest_execution_state.beacon_slot + max_latency as u64,
latest_execution_state.beacon_slot == 0
|| latest_finalized_state.slot
< latest_execution_state.beacon_slot + max_latency as u64,
Error::<T>::ExecutionHeaderTooFarBehind
);
Ok(())
Expand All @@ -371,8 +372,8 @@ pub mod pallet {

// Verify update does not skip a sync committee period.
ensure!(
update.signature_slot > update.attested_header.slot &&
update.attested_header.slot >= update.finalized_header.slot,
update.signature_slot > update.attested_header.slot
&& update.attested_header.slot >= update.finalized_header.slot,
Error::<T>::InvalidUpdateSlot
);
// Retrieve latest finalized state.
Expand All @@ -392,12 +393,12 @@ pub mod pallet {

// Verify update is relevant.
let update_attested_period = compute_period(update.attested_header.slot);
let update_has_next_sync_committee = !<NextSyncCommittee<T>>::exists() &&
(update.next_sync_committee_update.is_some() &&
update_attested_period == store_period);
let update_has_next_sync_committee = !<NextSyncCommittee<T>>::exists()
&& (update.next_sync_committee_update.is_some()
&& update_attested_period == store_period);
ensure!(
update.attested_header.slot > latest_finalized_state.slot ||
update_has_next_sync_committee,
update.attested_header.slot > latest_finalized_state.slot
|| update_has_next_sync_committee,
Error::<T>::IrrelevantUpdate
);

Expand Down Expand Up @@ -554,9 +555,9 @@ pub mod pallet {
// Checks that we don't skip execution headers, they need to be imported sequentially.
let latest_execution_state: ExecutionHeaderState = Self::latest_execution_state();
ensure!(
latest_execution_state.block_number == 0 ||
update.execution_header.block_number ==
latest_execution_state.block_number + 1,
latest_execution_state.block_number == 0
|| update.execution_header.block_number
== latest_execution_state.block_number + 1,
Error::<T>::ExecutionHeaderSkippedBlock
);

Expand Down Expand Up @@ -600,7 +601,7 @@ pub mod pallet {
let state = <FinalizedBeaconState<T>>::get(block_root)
.ok_or(Error::<T>::ExpectedFinalizedHeaderNotStored)?;
if update.header.slot != state.slot {
return Err(Error::<T>::ExpectedFinalizedHeaderNotStored.into())
return Err(Error::<T>::ExpectedFinalizedHeaderNotStored.into());
}
},
}
Expand Down Expand Up @@ -790,13 +791,13 @@ pub mod pallet {
/// Returns the fork version based on the current epoch.
pub(super) fn select_fork_version(fork_versions: &ForkVersions, epoch: u64) -> ForkVersion {
if epoch >= fork_versions.capella.epoch {
return fork_versions.capella.version
return fork_versions.capella.version;
}
if epoch >= fork_versions.bellatrix.epoch {
return fork_versions.bellatrix.version
return fork_versions.bellatrix.version;
}
if epoch >= fork_versions.altair.epoch {
return fork_versions.altair.version
return fork_versions.altair.version;
}

fork_versions.genesis.version
Expand Down
39 changes: 13 additions & 26 deletions parachain/pallets/ethereum-beacon-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use frame_support::parameter_types;
use pallet_timestamp;
use primitives::{Fork, ForkVersions};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};

#[cfg(not(feature = "beacon-spec-mainnet"))]
pub mod minimal {
Expand All @@ -18,17 +15,13 @@ pub mod minimal {
use hex_literal::hex;
use primitives::CompactExecutionHeader;
use snowbridge_core::inbound::{Message, Proof};
use sp_runtime::BuildStorage;
use std::{fs::File, path::PathBuf};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub enum Test {
System: frame_system::{Pallet, Call, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event<T>},
Expand All @@ -48,13 +41,10 @@ pub mod minimal {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand All @@ -65,6 +55,8 @@ pub mod minimal {
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

impl pallet_timestamp::Config for Test {
Expand Down Expand Up @@ -105,9 +97,9 @@ pub mod minimal {

// Build genesis storage according to the mock runtime.
pub fn new_tester() -> sp_io::TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| Timestamp::set_timestamp(30_000));
let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000));
ext
}

Expand Down Expand Up @@ -185,15 +177,11 @@ pub mod minimal {
pub mod mainnet {
use super::*;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
use sp_runtime::BuildStorage;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub enum Test {
System: frame_system::{Pallet, Call, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event<T>},
Expand All @@ -213,13 +201,10 @@ pub mod mainnet {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand All @@ -230,6 +215,8 @@ pub mod mainnet {
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

impl pallet_timestamp::Config for Test {
Expand Down Expand Up @@ -270,9 +257,9 @@ pub mod mainnet {

// Build genesis storage according to the mock runtime.
pub fn new_tester() -> sp_io::TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| Timestamp::set_timestamp(30_000));
let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000));
ext
}
}
21 changes: 7 additions & 14 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
use super::*;

use frame_support::{
assert_noop, assert_ok,
dispatch::DispatchError,
parameter_types,
assert_noop, assert_ok, parameter_types,
traits::{ConstU64, Everything},
};
use sp_core::{H160, H256};
use sp_keyring::AccountKeyring as Keyring;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
ArithmeticError, MultiSignature,
};
Expand All @@ -24,20 +21,17 @@ use snowbridge_core::{
};
use snowbridge_ethereum::Log;
use snowbridge_router_primitives::inbound::MessageToXcm;
use sp_runtime::{BuildStorage, DispatchError};

use hex_literal::hex;
use xcm::v3::{prelude::*, MultiAssets, SendXcm};

use crate::{self as inbound_queue, envelope::Envelope, Error, Event as InboundQueueEvent};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Expand All @@ -59,13 +53,10 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
Expand All @@ -78,6 +69,8 @@ impl frame_system::Config for Test {
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -162,7 +155,7 @@ impl SendXcm for MockXcmSender {
match dest {
Some(MultiLocation { interior, .. }) => {
if let X1(Parachain(1001)) = interior {
return Err(XcmpSendError::NotApplicable)
return Err(XcmpSendError::NotApplicable);
}
Ok(((), MultiAssets::default()))
},
Expand Down Expand Up @@ -203,7 +196,7 @@ fn expect_events(e: Vec<RuntimeEvent>) {
}

pub fn new_tester() -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext: sp_io::TestExternalities = storage.into();
ext.execute_with(|| System::set_block_number(1));
ext
Expand Down
Loading

0 comments on commit 5cfa24d

Please sign in to comment.