From 7b7a6e30d78b755f513ea87aac186ffe97af63e9 Mon Sep 17 00:00:00 2001 From: yrong1997 Date: Sat, 9 Oct 2021 12:59:33 +0800 Subject: [PATCH] Fix integration test --- Cargo.lock | 2 +- integration-tests/Cargo.toml | 1 - integration-tests/src/integration_tests.rs | 51 ++++--------------- .../src/kusama_cross_chain_transfer.rs | 26 +++++----- integration-tests/src/kusama_test_net.rs | 9 ++-- pallets/salp/Cargo.toml | 2 +- pallets/salp/src/mock.rs | 5 +- runtime/asgard/src/lib.rs | 16 ++++-- runtime/bifrost/src/lib.rs | 23 ++++++++- runtime/common/src/lib.rs | 5 -- runtime/dev/src/lib.rs | 13 ++++- xcm-support/src/lib.rs | 4 +- 12 files changed, 78 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7d5977e73..32ef844647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -940,7 +940,7 @@ name = "bifrost-salp" version = "0.8.0" dependencies = [ "bifrost-bancor", - "bifrost-runtime-common", + "bifrost-runtime", "frame-benchmarking", "frame-support", "frame-system", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 380138ae49..b8ff8f8ae2 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -121,7 +121,6 @@ cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumul polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" } polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" } kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" } - xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", branch = "polkadot-v0.9.10" } node-service = { path = "../node/service", features = ["with-all-runtime"] } diff --git a/integration-tests/src/integration_tests.rs b/integration-tests/src/integration_tests.rs index fce6bb0878..e591b42f21 100644 --- a/integration-tests/src/integration_tests.rs +++ b/integration-tests/src/integration_tests.rs @@ -19,12 +19,8 @@ pub use codec::Encode; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use frame_support::{ - assert_noop, assert_ok, - sp_runtime::app_crypto::sp_core::keccak_256, - traits::{ - schedule::DispatchTime, Currency, GenesisBuild, OnFinalize, OnInitialize, OriginTrait, - ValidatorSet, - }, + assert_ok, + traits::{GenesisBuild, OnFinalize, OnInitialize}, weights::constants::*, }; use frame_system::RawOrigin; @@ -34,38 +30,27 @@ pub use sp_runtime::{ traits::{AccountIdConversion, BadOrigin, Convert, Zero}, DispatchError, DispatchResult, FixedPointNumber, MultiAddress, }; -use xcm::{ - opaque::v0::prelude::{BuyExecution, DepositAsset}, - v0::{ - ExecuteXcm, - Junction::{self, *}, - MultiAsset, - MultiLocation::*, - NetworkId, Outcome, Xcm, - }, -}; pub const ALICE: [u8; 32] = [0u8; 32]; pub const BOB: [u8; 32] = [1u8; 32]; #[cfg(feature = "with-asgard-runtime")] pub use asgard_imports::*; -use xcm::v0::MultiLocation; #[cfg(feature = "with-asgard-runtime")] mod asgard_imports { pub use asgard_runtime::{ - create_x2_parachain_multilocation, AccountId, Balance, Balances, BifrostCrowdloanId, - BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit, ExistentialDeposits, - NativeCurrencyId, Origin, OriginCaller, ParachainInfo, ParachainSystem, Perbill, Proxy, - RelayCurrencyId, RelaychainSovereignSubAccount, Runtime, Salp, Scheduler, Session, - SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig, + constants::currency::DOLLARS, create_x2_multilocation, AccountId, Balance, Balances, + BifrostCrowdloanId, BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit, + ExistentialDeposits, NativeCurrencyId, Origin, OriginCaller, ParachainInfo, + ParachainSystem, Perbill, Proxy, RelayCurrencyId, RelaychainSovereignSubAccount, Runtime, + Salp, Scheduler, Session, SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting, + XTokens, XcmConfig, }; - pub use bifrost_runtime_common::constants::{currency::*, time::*}; pub use frame_support::parameter_types; pub use sp_runtime::traits::AccountIdConversion; } -fn run_to_block(n: u32) { +fn _run_to_block(n: u32) { while System::block_number() < n { Scheduler::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); @@ -75,7 +60,7 @@ fn run_to_block(n: u32) { } } -fn set_relaychain_block_number(number: BlockNumber) { +fn _set_relaychain_block_number(number: BlockNumber) { ParachainSystem::on_initialize(number); let (relay_storage_root, proof) = @@ -183,21 +168,7 @@ fn parachain_subaccounts_are_unique() { .into() ); - assert_eq!(RelaychainSovereignSubAccount::get(), create_x2_parachain_multilocation(0)); - - assert_eq!( - create_x2_parachain_multilocation(0), - MultiLocation::X2( - Junction::Parent, - Junction::AccountId32 { - network: NetworkId::Any, - id: [ - 90, 83, 115, 109, 142, 150, 241, 192, 7, 207, 13, 99, 10, 207, 82, 9, 178, - 6, 17, 97, 122, 242, 60, 233, 36, 200, 226, 83, 40, 235, 93, 40 - ] - } - ) - ); + assert_eq!(RelaychainSovereignSubAccount::get(), create_x2_multilocation(0)); }); } diff --git a/integration-tests/src/kusama_cross_chain_transfer.rs b/integration-tests/src/kusama_cross_chain_transfer.rs index eb7ad7f6a1..b16d4f192f 100644 --- a/integration-tests/src/kusama_cross_chain_transfer.rs +++ b/integration-tests/src/kusama_cross_chain_transfer.rs @@ -18,27 +18,24 @@ //! Cross-chain transfer tests within Kusama network. -use bifrost_runtime_common::*; use frame_support::assert_ok; use orml_traits::MultiCurrency; -use xcm::v0::{ - Junction::{self, Parachain, Parent}, - MultiAsset::*, - MultiLocation::*, - NetworkId, -}; +use xcm::{latest::prelude::*, VersionedMultiAssets, VersionedMultiLocation}; use xcm_emulator::TestExt; use crate::{integration_tests::*, kusama_test_net::*}; #[test] fn transfer_from_relay_chain() { - Kusama::execute_with(|| { + KusamaNet::execute_with(|| { assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( kusama_runtime::Origin::signed(ALICE.into()), - X1(Parachain(2001)), - X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }), - vec![ConcreteFungible { id: Null, amount: DOLLARS }], + Box::new(VersionedMultiLocation::V1(X1(Parachain(2001)).into())), + Box::new(VersionedMultiLocation::V1( + X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }).into() + )), + Box::new(VersionedMultiAssets::V1((Here, DOLLARS).into())), + 0, 600_000_000 )); }); @@ -58,12 +55,15 @@ fn transfer_to_relay_chain() { Origin::signed(ALICE.into()), RelayCurrencyId::get(), DOLLARS, - X2(Parent, Junction::AccountId32 { id: BOB, network: NetworkId::Any }), + Box::new(MultiLocation::new( + 1, + X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }) + )), 3_000_000_000 )); }); - Kusama::execute_with(|| { + KusamaNet::execute_with(|| { assert_eq!(kusama_runtime::Balances::free_balance(&AccountId::from(BOB)), 999_920_000_005); }); } diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index 9174958e72..6ad73d5442 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -28,7 +28,7 @@ use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain use crate::integration_tests::*; decl_test_relay_chain! { - pub struct Kusama { + pub struct KusamaNet { Runtime = kusama_runtime::Runtime, XcmConfig = kusama_runtime::XcmConfig, new_ext = kusama_ext(), @@ -45,7 +45,7 @@ decl_test_parachain! { decl_test_network! { pub struct TestNet { - relay_chain = Kusama, + relay_chain = KusamaNet, parachains = vec![ (2001, Bifrost), ], @@ -69,7 +69,6 @@ fn default_parachains_host_configuration() -> HostConfiguration { ump_service_total_weight: 4 * 1_000_000_000, max_upward_message_size: 1024 * 1024, max_upward_message_num_per_candidate: 5, - hrmp_open_request_ttl: 5, hrmp_sender_deposit: 0, hrmp_recipient_deposit: 0, hrmp_channel_max_capacity: 8, @@ -97,8 +96,8 @@ pub fn kusama_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ - (AccountId::from(ALICE), 1000 * DOLLARS), - (ParaId::from(2001).into_account(), 1000 * DOLLARS), + (AccountId::from(ALICE), 2002 * DOLLARS), + (ParaId::from(2001).into_account(), 2 * DOLLARS), ], } .assimilate_storage(&mut t) diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index 39e99c9ff4..fb0cf977ef 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -34,7 +34,7 @@ orml-tokens = "0.4.1-dev" orml-currencies = "0.4.1-dev" pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10" } bifrost-bancor = { path = "../../pallets/bancor" } -bifrost-runtime-common = { package = "bifrost-runtime-common", path = "../../runtime/common" } +bifrost-runtime = { path = "../../runtime/bifrost" } [features] default = ["std"] diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index 2b245a1907..88b15d73be 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -17,8 +17,7 @@ // along with this program. If not, see . // Ensure we're `no_std` when compiling for Wasm. - -use bifrost_runtime_common::create_x2_multilocation; +use bifrost_runtime::create_x2_multilocation; use frame_support::{ construct_runtime, parameter_types, traits::{EnsureOrigin, GenesisBuild}, @@ -203,7 +202,7 @@ parameter_types! { BRUCE, CATHI ],2); - pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ALICE); + pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(0); pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; } diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 4bf8a24bd4..2401665065 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -77,7 +77,6 @@ use bifrost_flexible_fee::{ }; use bifrost_runtime_common::{ constants::parachains, - create_x2_multilocation, xcm_impl::{ BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, @@ -1152,6 +1151,16 @@ impl EnsureOrigin for EnsureConfirmAsMultiSig { } } +pub fn create_x2_multilocation(index: u16) -> MultiLocation { + MultiLocation::new( + 1, + X1(AccountId32 { + network: NetworkId::Any, + id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(), + }), + ) +} + parameter_types! { pub const MinContribution: Balance = DOLLARS / 10; pub const RemoveKeysLimit: u32 = 500; @@ -1169,15 +1178,14 @@ parameter_types! { hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"].into(), // bob hex!["90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22"].into(), // charlie ],2); - pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16)); + pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16); pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; } impl bifrost_salp::Config for Runtime { type BancorPool = Bancor; - type BifrostXcmExecutor = - BifrostXcmAdaptor, SelfParaId>; + type BifrostXcmExecutor = BifrostXcmAdaptor; type Event = Event; type LeasePeriod = LeasePeriod; type MinContribution = MinContribution; diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index e8a6b79bd2..fa89d6edac 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -70,7 +70,6 @@ use bifrost_flexible_fee::{ }; use bifrost_runtime_common::{ constants::parachains, - create_x2_multilocation, xcm_impl::{ BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, @@ -766,6 +765,16 @@ pub type Trader = ( FixedRateOfFungible, ); +pub fn create_x2_parachain_multilocation(index: u16) -> MultiLocation { + MultiLocation::new( + 1, + X1(AccountId32 { + network: NetworkId::Any, + id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(), + }), + ) +} + pub struct XcmConfig; impl Config for XcmConfig { type AssetTransactor = BifrostAssetTransactor; @@ -1062,6 +1071,16 @@ impl EnsureOrigin for EnsureConfirmAsMultiSig { } } +pub fn create_x2_multilocation(index: u16) -> MultiLocation { + MultiLocation::new( + 1, + X1(AccountId32 { + network: NetworkId::Any, + id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(), + }), + ) +} + parameter_types! { pub const MinContribution: Balance = DOLLARS / 10; pub const RemoveKeysLimit: u32 = 500; @@ -1075,7 +1094,7 @@ parameter_types! { pub ContributionWeight:XcmBaseWeight = 893125000.into(); pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub ConfirmMuitiSigAccount: AccountId = hex!["e4da05f08e89bf6c43260d96f26fffcfc7deae5b465da08669a9d008e64c2c63"].into(); - pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16)); + pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16); pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 9b54a79818..0feee55ff6 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,7 +23,6 @@ use node_primitives::{AccountId, BlockNumber}; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_core::u32_trait::{_1, _2}; use sp_runtime::{FixedPointNumber, Perquintill}; -use xcm::latest::prelude::*; pub mod constants; pub mod xcm_impl; @@ -74,7 +73,3 @@ pub type EnsureRootOrAllTechnicalCommittee = EnsureOneOf< EnsureRoot, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, >; - -pub fn create_x2_multilocation(account: AccountId) -> MultiLocation { - MultiLocation::new(1, X1(AccountId32 { network: NetworkId::Any, id: account.into() })) -} diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 6da79fb48b..30453f4758 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -84,7 +84,6 @@ use bifrost_flexible_fee::{ }; use bifrost_runtime_common::{ constants::parachains, - create_x2_multilocation, xcm_impl::{ BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, @@ -1058,6 +1057,16 @@ impl EnsureOrigin for EnsureConfirmAsMultiSig { } } +pub fn create_x2_multilocation(index: u16) -> MultiLocation { + MultiLocation::new( + 1, + X1(AccountId32 { + network: NetworkId::Any, + id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(), + }), + ) +} + parameter_types! { pub const MinContribution: Balance = 1 * DOLLARS; pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#"); @@ -1075,7 +1084,7 @@ parameter_types! { "ce6072037670ca8e974fd571eae4f215a58d0bf823b998f619c3f87a911c3541" ] .into(); - pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16)); + pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16); pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; } diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index 4000a2d1ae..e1fe757fb5 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -92,7 +92,7 @@ impl< relay: bool, nonce: u32, ) -> Result { - let SovereignAccount: AccountId = ParaId::from(SelfParaId::get()).into_account(); + let sovereign_account: AccountId = ParaId::from(SelfParaId::get()).into_account(); let asset: MultiAsset = MultiAsset { id: Concrete(MultiLocation::here()), @@ -118,7 +118,7 @@ impl< max_assets: u32::max_value(), beneficiary: X1(Junction::AccountId32 { network: NetworkId::Any, - id: SovereignAccount.into(), + id: sovereign_account.into(), }) .into(), },