diff --git a/core/packages/test/scripts/set-env.sh b/core/packages/test/scripts/set-env.sh index 49c1df47ea..b3219617c3 100755 --- a/core/packages/test/scripts/set-env.sh +++ b/core/packages/test/scripts/set-env.sh @@ -77,10 +77,10 @@ export RANDAO_COMMIT_DELAY=3 export RANDAO_COMMIT_EXP=3 export BRIDGE_HUB_PARAID=$bridgehub_para_id -export BRIDGE_HUB_AGENT_ID="" +export BRIDGE_HUB_AGENT_ID="0x0000000000000000000000000000000000000000000000000000000000000000" export ASSET_HUB_PARAID=$statemine_para_id -export ASSET_HUB_AGENT_ID="" +export ASSET_HUB_AGENT_ID="0x0000000000000000000000000000000000000000000000000000000000000000" export DEFAULT_FEE=1 export DEFAULT_REWARD=1 diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index d630d84553..c4376af52a 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -4140,6 +4140,7 @@ version = "0.9.43" source = "git+https://github.com/paritytech/polkadot?branch=master#b6b74fdf546c14bf9ac93c03916abda9ee33a52f" dependencies = [ "environmental", + "frame-benchmarking", "frame-support", "impl-trait-for-tuples", "log", diff --git a/parachain/pallets/control/Cargo.toml b/parachain/pallets/control/Cargo.toml index e88d755376..e1e61f6825 100644 --- a/parachain/pallets/control/Cargo.toml +++ b/parachain/pallets/control/Cargo.toml @@ -31,11 +31,8 @@ xcm = { git = "https://github.com/paritytech/polkadot.git", branch = "master", d ethabi = { git = "https://github.com/Snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false } - [dev-dependencies] -xcm-builder = { git = "https://github.com/paritytech/polkadot.git", branch = "master" } - - +xcm-builder = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false } [features] default = ["std"] @@ -50,7 +47,11 @@ std = [ "sp-io/std", "sp-runtime/std", "xcm/std", + "xcm-builder/std", "ethabi/std" ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "xcm-builder/runtime-benchmarks" +] try-runtime = ["frame-support/try-runtime"] diff --git a/parachain/pallets/control/src/benchmarking.rs b/parachain/pallets/control/src/benchmarking.rs index 24d780b4dd..182965a7c2 100644 --- a/parachain/pallets/control/src/benchmarking.rs +++ b/parachain/pallets/control/src/benchmarking.rs @@ -14,13 +14,12 @@ mod benchmarks { use super::*; #[benchmark] - fn upgrade(x: Linear<0, { T::MaxUpgradeDataSize::get() }>) -> Result<(), BenchmarkError> { - let caller: T::AccountId = whitelisted_caller(); + fn upgrade(x: Linear<0, { T::MaxUpgradeDataSize::get() - 1 }>) -> Result<(), BenchmarkError> { let logic = H160::repeat_byte(1); let data: Vec = (0..x).map(|_| 1u8).collect(); #[extrinsic_call] - _(RawOrigin::Signed(caller), logic, Some(data)); + _(RawOrigin::Root, logic, Some(data)); Ok(()) } diff --git a/parachain/pallets/control/src/lib.rs b/parachain/pallets/control/src/lib.rs index 05476b41c0..e48c3237e9 100644 --- a/parachain/pallets/control/src/lib.rs +++ b/parachain/pallets/control/src/lib.rs @@ -33,7 +33,6 @@ pub mod pallet { use super::*; use frame_support::{pallet_prelude::*, traits::EnsureOrigin}; use frame_system::pallet_prelude::*; - use xcm::v3::MultiLocation; #[pallet::pallet] pub struct Pallet(_); diff --git a/parachain/pallets/control/src/mock.rs b/parachain/pallets/control/src/mock.rs index f718f0fd40..cd9e9b661a 100644 --- a/parachain/pallets/control/src/mock.rs +++ b/parachain/pallets/control/src/mock.rs @@ -8,16 +8,16 @@ use frame_support::{ use snowbridge_core::{ParaId}; use sp_core::H256; use sp_runtime::{ - BuildStorage, + AccountId32, testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; - - use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32}; +use xcm::prelude::*; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; +type AccountId = AccountId32; // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( @@ -42,7 +42,7 @@ impl frame_system::Config for Test { type BlockNumber = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = u64; + type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; type RuntimeEvent = RuntimeEvent; @@ -58,14 +58,18 @@ impl frame_system::Config for Test { type MaxConsumers = frame_support::traits::ConstU32<16>; } +parameter_types! { + pub const AnyNetwork: Option = None; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + parameter_types! { pub const OwnParaId: ParaId = ParaId::new(1013); pub const MaxUpgradeDataSize: u32 = 1024; pub const SS58Prefix: u8 = 42; } -pub type LocalOriginToLocation = SignedToAccountId32; - impl snowbridge_control::Config for Test { type RuntimeEvent = RuntimeEvent; type OwnParaId = OwnParaId; diff --git a/parachain/pallets/control/src/weights.rs b/parachain/pallets/control/src/weights.rs index 2cbf27876e..eb936dcb3b 100644 --- a/parachain/pallets/control/src/weights.rs +++ b/parachain/pallets/control/src/weights.rs @@ -41,7 +41,7 @@ pub trait WeightInfo { /// Weights for pallet_template using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - fn upgrade(data_size: u32) -> Weight { + fn upgrade(_data_size: u32) -> Weight { Weight::from_parts(9_000_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -49,7 +49,7 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - fn upgrade(data_size: u32) -> Weight { + fn upgrade(_data_size: u32) -> Weight { Weight::from_parts(9_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 394eff7744..b75d1389a7 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -6,7 +6,6 @@ use pallet_timestamp; use primitives::{Fork, ForkVersions}; use sp_core::H256; use sp_runtime::{ - BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; diff --git a/parachain/pallets/inbound-queue/src/test.rs b/parachain/pallets/inbound-queue/src/test.rs index 5573d6b05d..73d9df4bd1 100644 --- a/parachain/pallets/inbound-queue/src/test.rs +++ b/parachain/pallets/inbound-queue/src/test.rs @@ -29,7 +29,10 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub struct Test + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, @@ -167,7 +170,7 @@ pub fn new_tester(gateway: H160) -> sp_io::TestExternalities { } pub fn new_tester_with_config( - config: inbound_queue::GenesisConfig, + config: inbound_queue::GenesisConfig, ) -> sp_io::TestExternalities { let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); @@ -195,7 +198,7 @@ fn parse_dest(message: Message) -> ParaId { } // The originating channel address for the messages below -const OUTBOUND_QUEUE_ADDRESS: [u8; 20] = hex!["87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"]; +const GATEWAY_ADDRESS: [u8; 20] = hex!["87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"]; const OUTBOUND_QUEUE_EVENT_LOG: [u8; 254] = hex!( " @@ -207,7 +210,7 @@ use snowbridge_core::ParaId; #[test] fn test_submit() { - new_tester(OUTBOUND_QUEUE_ADDRESS.into()).execute_with(|| { + new_tester(GATEWAY_ADDRESS.into()).execute_with(|| { let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); @@ -238,7 +241,7 @@ fn test_submit() { } #[test] -fn test_submit_with_invalid_outbound_queue() { +fn test_submit_with_invalid_gateway() { new_tester(H160::zero()).execute_with(|| { let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); @@ -259,14 +262,14 @@ fn test_submit_with_invalid_outbound_queue() { }; assert_noop!( InboundQueue::submit(origin.clone(), message.clone()), - Error::::InvalidOutboundQueue + Error::::InvalidGateway ); }); } #[test] fn test_submit_with_invalid_nonce() { - new_tester(OUTBOUND_QUEUE_ADDRESS.into()).execute_with(|| { + new_tester(GATEWAY_ADDRESS.into()).execute_with(|| { let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); @@ -300,7 +303,7 @@ fn test_submit_with_invalid_nonce() { #[test] fn test_submit_no_funds_to_reward_relayers() { - new_tester(OUTBOUND_QUEUE_ADDRESS.into()).execute_with(|| { + new_tester(GATEWAY_ADDRESS.into()).execute_with(|| { let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); @@ -328,119 +331,29 @@ fn test_submit_no_funds_to_reward_relayers() { } #[test] -fn test_add_allow_list_without_root_yields_bad_origin() { - new_tester_with_config(Default::default()).execute_with(|| { - let contract_address = hex!("0000000000000000000000000000000000000000").into(); - let relayer: AccountId = Keyring::Bob.into(); - let origin = RuntimeOrigin::signed(relayer); - assert_noop!( - InboundQueue::add_allow_list(origin, contract_address), - sp_runtime::DispatchError::BadOrigin, - ); - }); -} - -#[test] -fn test_add_allow_list_with_root_succeeds() { +fn test_set_gateway_with_root_succeeds() { new_tester_with_config(Default::default()).execute_with(|| { let origin = RuntimeOrigin::root(); - let contract_address = hex!("0000000000000000000000000000000000000000").into(); + let default_gateway_address = hex!("0000000000000000000000000000000000000000").into(); + let gateway_address = hex!("1000000000000000000000000000000000000000").into(); - assert_eq!(>::get().len(), 0); - assert_ok!(InboundQueue::add_allow_list(origin, contract_address)); + assert_eq!(>::get(), default_gateway_address); - System::assert_last_event(RuntimeEvent::InboundQueue(crate::Event::AllowListAdded { - address: contract_address, - })); + assert_ok!(InboundQueue::set_gateway(origin, gateway_address)); - assert_eq!(>::get().len(), 1); - assert!(>::get().contains(&contract_address)); + assert_eq!(>::get(), gateway_address); }); } #[test] -fn test_add_allow_list_ignores_duplicates() { +fn test_set_gateway_without_root_yields_bad_origin() { new_tester_with_config(Default::default()).execute_with(|| { - let origin = RuntimeOrigin::root(); - let contract_address = hex!("0000000000000000000000000000000000000000").into(); - - assert_eq!(>::get().len(), 0); - assert_ok!(InboundQueue::add_allow_list(origin.clone(), contract_address)); - assert_eq!(>::get().len(), 1); - assert!(>::get().contains(&contract_address)); - assert_ok!(InboundQueue::add_allow_list(origin, contract_address)); - assert_eq!(>::get().len(), 1); - assert!(>::get().contains(&contract_address)); - }); -} - -#[test] -fn test_add_allow_list_fails_when_exceeding_bounds() { - new_tester_with_config(Default::default()).execute_with(|| { - let origin = RuntimeOrigin::root(); - let contract_address1 = hex!("0000000000000000000000000000000000000000").into(); - let contract_address2 = hex!("1000000000000000000000000000000000000000").into(); - let contract_address3 = hex!("3000000000000000000000000000000000000000").into(); - - assert_eq!(>::get().len(), 0); - - assert_ok!(InboundQueue::add_allow_list(origin.clone(), contract_address1)); - assert_eq!(>::get().len(), 1); - - assert_ok!(InboundQueue::add_allow_list(origin.clone(), contract_address2)); - assert_eq!(>::get().len(), 2); - - assert_noop!( - InboundQueue::add_allow_list(origin, contract_address3), - Error::::AllowListFull, - ); - assert_eq!(>::get().len(), 2); - }); -} - -#[test] -fn test_remove_allow_list_without_root_yields_bad_origin() { - new_tester_with_config(Default::default()).execute_with(|| { - let contract_address = hex!("0000000000000000000000000000000000000000").into(); + let gateway_address = hex!("0000000000000000000000000000000000000000").into(); let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); assert_noop!( - InboundQueue::remove_allow_list(origin, contract_address), + InboundQueue::set_gateway(origin, gateway_address), sp_runtime::DispatchError::BadOrigin, ); }); } - -#[test] -fn test_remove_allow_list_with_root_succeeds() { - new_tester_with_config(Default::default()).execute_with(|| { - let origin = RuntimeOrigin::root(); - let contract_address = hex!("0000000000000000000000000000000000000000").into(); - - assert_eq!(>::get().len(), 0); - assert_ok!(InboundQueue::add_allow_list(origin.clone(), contract_address)); - assert_eq!(>::get().len(), 1); - - assert_ok!(InboundQueue::remove_allow_list(origin, contract_address)); - System::assert_last_event(RuntimeEvent::InboundQueue(crate::Event::AllowListRemoved { - address: contract_address, - })); - - assert_eq!(>::get().len(), 0); - assert!(!>::get().contains(&contract_address)); - }); -} - -#[test] -fn test_remove_allow_list_event_not_emitted_for_none_existent_item() { - new_tester_with_config(Default::default()).execute_with(|| { - let origin = RuntimeOrigin::root(); - let contract_address = hex!("0000000000000000000000000000000000000000").into(); - - let start = System::event_count(); - assert_ok!(InboundQueue::remove_allow_list(origin, contract_address)); - let end = System::event_count(); - - assert_eq!(start, end); // No new events - }); -} diff --git a/parachain/pallets/outbound-queue/src/lib.rs b/parachain/pallets/outbound-queue/src/lib.rs index 418a9f1312..65ad14782f 100644 --- a/parachain/pallets/outbound-queue/src/lib.rs +++ b/parachain/pallets/outbound-queue/src/lib.rs @@ -23,11 +23,11 @@ use frame_support::{ use scale_info::TypeInfo; use snowbridge_core::ParaId; use sp_core::{RuntimeDebug, H256}; -use sp_runtime::traits::{Hash, BlockNumberProvider}; +use sp_runtime::traits::Hash; use sp_std::prelude::*; use snowbridge_core::{ - ContractId, OutboundMessage, OutboundQueue as OutboundQueueTrait, SubmitError, + OutboundMessage, OutboundQueue as OutboundQueueTrait, SubmitError, }; use snowbridge_outbound_queue_merkle_tree::merkle_root; diff --git a/parachain/pallets/outbound-queue/src/test.rs b/parachain/pallets/outbound-queue/src/test.rs index 8f2b871f30..8fe24413ea 100644 --- a/parachain/pallets/outbound-queue/src/test.rs +++ b/parachain/pallets/outbound-queue/src/test.rs @@ -10,7 +10,6 @@ use frame_support::{ use sp_core::H256; use sp_runtime::{ - BuildStorage, testing::Header, traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Keccak256, Verify}, BoundedVec, MultiSignature, diff --git a/parachain/primitives/router/src/outbound/mod.rs b/parachain/primitives/router/src/outbound/mod.rs index 2191f39081..50064a05a3 100644 --- a/parachain/primitives/router/src/outbound/mod.rs +++ b/parachain/primitives/router/src/outbound/mod.rs @@ -794,11 +794,11 @@ mod tests { ] .into(); let mut converter = XcmConverter::new(&message, &network, &BRIDGE_REGISTRY); - let expected_payload = Message::NativeTokens(NativeTokensMessage::Unlock { - asset: H160(token_address), - destination: H160(beneficiary_address), + let expected_payload = Message::UnlockNativeTokens { + token: H160(token_address), + recipient: H160(beneficiary_address), amount: 1000, - }); + }; let result = converter.convert(); assert_eq!(result, Ok((expected_payload, None))); } @@ -834,11 +834,11 @@ mod tests { ] .into(); let mut converter = XcmConverter::new(&message, &network, &BRIDGE_REGISTRY); - let expected_payload = Message::NativeTokens(NativeTokensMessage::Unlock { - asset: H160(token_address), - destination: H160(beneficiary_address), + let expected_payload = Message::UnlockNativeTokens { + token: H160(token_address), + recipient: H160(beneficiary_address), amount: 1000, - }); + }; let result = converter.convert(); assert_eq!(result, Ok((expected_payload, None))); }