From 3c25a51339bfda1391dd9c541a8f9e70f1187812 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Mon, 6 Jun 2022 20:57:42 +1200 Subject: [PATCH] Fix integration tests for sibling XCM transfer for karura-runtime (#2138) * Removed the integration-tests feature from karura-runtime * Added a extra metadata storage for foreign assets in Asset Registry module Modified integration tests to support sibling transfer of native assets. Removed other integration-tests feature related code * Renamed the fields in ForeignAssetExtraMetadata to better reflect their functionalities. Added unit tests and modified integration tests for the new metadata's override functions. * Fixed build issue from merge * Removed the ForeignAssetExtraMetadata Improved XCM integration test setups Rewrote and improved the sibling chain BNC token transfer * no message * Reverted more unneeded changes * Addressed some PR comments * Added one more integration test that tests sending BNC to mock bifrost 2001 chain. * Minor improvement Co-authored-by: Roy Yang Co-authored-by: Acala Benchmarking Bot --- runtime/integration-tests/Cargo.toml | 1 - runtime/integration-tests/src/dex.rs | 2 +- .../integration-tests/src/relaychain/erc20.rs | 24 +- .../relaychain/kusama_cross_chain_transfer.rs | 354 ++++++++++++------ .../src/relaychain/kusama_test_net.rs | 15 +- .../src/relaychain/polkadot_test_net.rs | 15 +- runtime/karura/Cargo.toml | 2 - .../karura/src/integration_tests_config.rs | 50 --- runtime/karura/src/lib.rs | 3 - runtime/karura/src/xcm_config.rs | 29 +- 10 files changed, 289 insertions(+), 206 deletions(-) delete mode 100644 runtime/karura/src/integration_tests_config.rs diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 189efc2841..308e31988b 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -157,7 +157,6 @@ with-mandala-runtime = [ ] with-karura-runtime = [ "karura-runtime", - "karura-runtime/integration-tests", "acala-service/with-karura-runtime", "module-relaychain/kusama" ] diff --git a/runtime/integration-tests/src/dex.rs b/runtime/integration-tests/src/dex.rs index fdc3d728b7..adde4bfd70 100644 --- a/runtime/integration-tests/src/dex.rs +++ b/runtime/integration-tests/src/dex.rs @@ -219,7 +219,7 @@ fn test_trading_pair() { assert_ok!(AssetRegistry::register_foreign_asset( Origin::root(), - Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(KAR.encode()))).into()), + Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(KAR.encode()))).into()), Box::new(AssetMetadata { name: b"Sibling Token".to_vec(), symbol: b"ST".to_vec(), diff --git a/runtime/integration-tests/src/relaychain/erc20.rs b/runtime/integration-tests/src/relaychain/erc20.rs index 445dfffd73..b05d9230ef 100644 --- a/runtime/integration-tests/src/relaychain/erc20.rs +++ b/runtime/integration-tests/src/relaychain/erc20.rs @@ -31,6 +31,9 @@ use sp_core::{H256, U256}; use std::str::FromStr; use xcm_emulator::TestExt; +pub const SIBLING_ID: u32 = 2002; +pub const KARURA_ID: u32 = 2000; + pub fn erc20_address_0() -> EvmAddress { EvmAddress::from_str("0x5e0b4bfa0b55932a3587e648c3552a6515ba56b1").unwrap() } @@ -39,6 +42,13 @@ pub fn alice_evm_addr() -> EvmAddress { EvmAddress::from_str("1000000000000000000000000000000000000001").unwrap() } +fn sibling_reserve_account() -> AccountId { + polkadot_parachain::primitives::Sibling::from(SIBLING_ID).into_account() +} +fn karura_reserve_account() -> AccountId { + polkadot_parachain::primitives::Sibling::from(KARURA_ID).into_account() +} + pub fn deploy_erc20_contracts() { let json: serde_json::Value = serde_json::from_str(include_str!("../../../../ts-tests/build/Erc20DemoContract2.json")).unwrap(); @@ -78,10 +88,6 @@ pub fn deploy_erc20_contracts() { fn erc20_transfer_between_sibling() { TestNet::reset(); - fn sibling_reserve_account() -> AccountId { - polkadot_parachain::primitives::Sibling::from(2001).into_account() - } - Sibling::execute_with(|| { let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0()); // register Karura's erc20 as foreign asset @@ -142,7 +148,7 @@ fn erc20_transfer_between_sibling() { MultiLocation::new( 1, X2( - Parachain(2001), + Parachain(SIBLING_ID), Junction::AccountId32 { network: NetworkId::Any, id: BOB.into(), @@ -244,16 +250,12 @@ fn erc20_transfer_between_sibling() { fn sibling_erc20_to_self_as_foreign_asset() { TestNet::reset(); - fn sibling_reserve_account() -> AccountId { - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } - Karura::execute_with(|| { let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0()); // register Karura's erc20 as foreign asset assert_ok!(AssetRegistry::register_foreign_asset( Origin::root(), - Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(erc20_as_foreign_asset.encode()))).into()), + Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(erc20_as_foreign_asset.encode()))).into()), Box::new(AssetMetadata { name: b"Sibling USDC".to_vec(), symbol: b"sUSDC".to_vec(), @@ -326,7 +328,7 @@ fn sibling_erc20_to_self_as_foreign_asset() { ); assert_eq!( 10_000_000_000_000, - Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &sibling_reserve_account()) + Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &karura_reserve_account()) ); }); diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index 149343c66d..d10ef44b14 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -25,21 +25,32 @@ use frame_support::assert_ok; use sp_runtime::traits::AccountIdConversion; use xcm_builder::ParentIsPreset; -use karura_runtime::parachains::bifrost::BNC_KEY; +use karura_runtime::parachains::bifrost::{BNC_KEY, ID as BIFROST_ID}; use karura_runtime::{AssetRegistry, KaruraTreasuryAccount}; use module_relaychain::RelayChainCallBuilder; use module_support::CallBuilder; use orml_traits::MultiCurrency; -use primitives::currency::AssetMetadata; +use primitives::currency::{AssetMetadata, BNC}; use xcm_emulator::TestExt; use xcm_executor::traits::Convert; +pub const KARURA_ID: u32 = 2000; +pub const MOCK_BIFROST_ID: u32 = 2001; +pub const SIBLING_ID: u32 = 2002; + +fn karura_reserve_account() -> AccountId { + polkadot_parachain::primitives::Sibling::from(KARURA_ID).into_account() +} +fn sibling_reserve_account() -> AccountId { + polkadot_parachain::primitives::Sibling::from(SIBLING_ID).into_account() +} + #[test] fn transfer_from_relay_chain() { KusamaNet::execute_with(|| { assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( kusama_runtime::Origin::signed(ALICE.into()), - Box::new(Parachain(2000).into().into()), + Box::new(Parachain(KARURA_ID).into().into()), Box::new( Junction::AccountId32 { id: BOB, @@ -94,16 +105,27 @@ fn transfer_to_relay_chain() { fn transfer_sibling_chain_asset() { TestNet::reset(); - fn karura_reserve_account() -> AccountId { - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } - Karura::execute_with(|| { assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100_000_000_000_000)); }); - Sibling::execute_with(|| { - assert_ok!(Tokens::deposit(BNC, &karura_reserve_account(), 100_000_000_000_000)); + MockBifrost::execute_with(|| { + // Register native BNC's incoming address as a foreign asset so it can handle reserve transfers + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(0, X1(GeneralKey(BNC_KEY.to_vec()))).into()), + Box::new(AssetMetadata { + name: b"Native BNC".to_vec(), + symbol: b"BNC".to_vec(), + decimals: 12, + minimal_balance: Balances::minimum_balance() / 10, // 10% + }) + )); + assert_ok!(Tokens::deposit( + CurrencyId::ForeignAsset(0), + &karura_reserve_account(), + 100_000_000_000_000 + )); }); Karura::execute_with(|| { @@ -115,7 +137,7 @@ fn transfer_sibling_chain_asset() { MultiLocation::new( 1, X2( - Parachain(2001), + Parachain(SIBLING_ID), Junction::AccountId32 { network: NetworkId::Any, id: BOB.into(), @@ -130,9 +152,25 @@ fn transfer_sibling_chain_asset() { assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000); }); + MockBifrost::execute_with(|| { + // Due to reanchoring BNC is not treated as native BNC due to the change of Multilocation + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 0); + assert_eq!(Tokens::free_balance(BNC, &sibling_reserve_account()), 0); + + // Registered Foreign asset 0 is used to handle reservation for BNC token. + // Karura -->(transfer 10_000_000_000_000)--> Sibling + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &karura_reserve_account()), + 90_000_000_000_000 + ); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &sibling_reserve_account()), + 9_999_360_000_000 + ); + }); + Sibling::execute_with(|| { - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 90_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 9_989_760_000_000); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 9_989_120_000_000); assert_ok!(XTokens::transfer( Origin::signed(BOB.into()), @@ -142,7 +180,7 @@ fn transfer_sibling_chain_asset() { MultiLocation::new( 1, X2( - Parachain(2000), + Parachain(KARURA_ID), Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into(), @@ -154,12 +192,23 @@ fn transfer_sibling_chain_asset() { 1_000_000_000, )); - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 95_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 4_989_760_000_000); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 4_989_120_000_000); + }); + + MockBifrost::execute_with(|| { + // Sibling -->(transfer 5_000_000_000_000)--> Karura + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &karura_reserve_account()), + 94_999_360_000_000 + ); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &sibling_reserve_account()), + 4_999_360_000_000 + ); }); Karura::execute_with(|| { - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 94_989_760_000_000); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 94_989_120_000_000); }); } @@ -168,7 +217,7 @@ fn transfer_from_relay_chain_deposit_to_treasury_if_below_ed() { KusamaNet::execute_with(|| { assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( kusama_runtime::Origin::signed(ALICE.into()), - Box::new(Parachain(2000).into().into()), + Box::new(Parachain(KARURA_ID).into().into()), Box::new( Junction::AccountId32 { id: BOB, @@ -216,7 +265,7 @@ fn xcm_transfer_execution_barrier_trader_works() { network: NetworkId::Any, id: ALICE.into(), }), - Parachain(2000).into(), + Parachain(KARURA_ID).into(), message )); }); @@ -298,7 +347,7 @@ fn subscribe_version_notify_works() { KusamaNet::execute_with(|| { let r = pallet_xcm::Pallet::::force_subscribe_version_notify( kusama_runtime::Origin::root(), - Box::new(Parachain(2000).into().into()), + Box::new(Parachain(KARURA_ID).into().into()), ); assert_ok!(r); }); @@ -307,7 +356,7 @@ fn subscribe_version_notify_works() { pallet_xcm::Event::SupportedVersionChanged( MultiLocation { parents: 0, - interior: X1(Parachain(2000)), + interior: X1(Parachain(KARURA_ID)), }, 2, ), @@ -338,7 +387,7 @@ fn subscribe_version_notify_works() { Karura::execute_with(|| { let r = pallet_xcm::Pallet::::force_subscribe_version_notify( Origin::root(), - Box::new((Parent, Parachain(2001)).into()), + Box::new((Parent, Parachain(SIBLING_ID)).into()), ); assert_ok!(r); }); @@ -361,78 +410,71 @@ fn subscribe_version_notify_works() { fn test_asset_registry_module() { TestNet::reset(); - fn karura_reserve_account() -> AccountId { - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } - Karura::execute_with(|| { - // register foreign asset + assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100_000_000_000_000)); + }); + + MockBifrost::execute_with(|| { + // Register native BNC's incoming address as a foreign asset so it can handle reserve transfers assert_ok!(AssetRegistry::register_foreign_asset( Origin::root(), - Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(BNC_KEY.to_vec()))).into()), + Box::new(MultiLocation::new(0, X1(GeneralKey(BNC_KEY.to_vec()))).into()), Box::new(AssetMetadata { - name: b"Sibling Token".to_vec(), - symbol: b"ST".to_vec(), + name: b"Native BNC".to_vec(), + symbol: b"BNC".to_vec(), decimals: 12, minimal_balance: Balances::minimum_balance() / 10, // 10% }) )); - - assert_eq!( - Tokens::free_balance(CurrencyId::ForeignAsset(0), &TreasuryAccount::get()), - 0 - ); + assert_ok!(Tokens::deposit( + CurrencyId::ForeignAsset(0), + &karura_reserve_account(), + 100_000_000_000_000 + )); }); Sibling::execute_with(|| { - let _ = Tokens::deposit(BNC, &AccountId::from(BOB), 100_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 0); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 100_000_000_000_000); - - assert_ok!(XTokens::transfer( - Origin::signed(BOB.into()), - BNC, - 5_000_000_000_000, - Box::new( - MultiLocation::new( - 1, - X2( - Parachain(2000), - Junction::AccountId32 { - network: NetworkId::Any, - id: ALICE.into(), - } - ) - ) - .into() - ), - 1_000_000_000, + // Register BNC as foreign asset(0) + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(1, X2(Parachain(BIFROST_ID), GeneralKey(BNC_KEY.to_vec()))).into()), + Box::new(AssetMetadata { + name: b"Bifrost BNC".to_vec(), + symbol: b"BNC".to_vec(), + decimals: 12, + minimal_balance: Balances::minimum_balance() / 10, // 10% + }) )); - - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 5_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 95_000_000_000_000); }); Karura::execute_with(|| { - assert_eq!( - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)), - 4_989_760_000_000 - ); - // ToTreasury - assert_eq!( - Tokens::free_balance(CurrencyId::ForeignAsset(0), &TreasuryAccount::get()), - 10_240_000_000 - ); + // Register BNC as foreign asset(0) + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(1, X2(Parachain(BIFROST_ID), GeneralKey(BNC_KEY.to_vec()))).into()), + Box::new(AssetMetadata { + name: b"Bifrost BNC".to_vec(), + symbol: b"BNC".to_vec(), + decimals: 12, + minimal_balance: Balances::minimum_balance() / 10, // 10% + }) + )); + + assert_ok!(Tokens::deposit( + CurrencyId::ForeignAsset(0), + &AccountId::from(ALICE), + 100_000_000_000_000 + )); assert_ok!(XTokens::transfer( Origin::signed(ALICE.into()), CurrencyId::ForeignAsset(0), - 1_000_000_000_000, + 10_000_000_000_000, Box::new( MultiLocation::new( 1, X2( - Parachain(2001), + Parachain(SIBLING_ID), Junction::AccountId32 { network: NetworkId::Any, id: BOB.into(), @@ -446,44 +488,38 @@ fn test_asset_registry_module() { assert_eq!( Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)), - 3_989_760_000_000 + 90_000_000_000_000 ); }); - Sibling::execute_with(|| { - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 4_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 95_989_760_000_000); - }); - - // remove it - Karura::execute_with(|| { - // register foreign asset - assert_ok!(AssetRegistry::update_foreign_asset( - Origin::root(), - 0, - Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(BNC_KEY.to_vec()))).into()), - Box::new(AssetMetadata { - name: b"Sibling Token".to_vec(), - symbol: b"ST".to_vec(), - decimals: 12, - minimal_balance: 0, // buy_weight 0 - }) - )); + MockBifrost::execute_with(|| { + // Registered Foreign asset 0 is used to handle reservation for BNC token. + // Karura -->(transfer 10_000_000_000_000)--> Sibling + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &karura_reserve_account()), + 90_000_000_000_000 + ); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &sibling_reserve_account()), + 9_999_360_000_000 + ); }); Sibling::execute_with(|| { - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 4_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 95_989_760_000_000); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)), + 9_989_120_000_000 + ); assert_ok!(XTokens::transfer( Origin::signed(BOB.into()), - BNC, + CurrencyId::ForeignAsset(0), 5_000_000_000_000, Box::new( MultiLocation::new( 1, X2( - Parachain(2000), + Parachain(KARURA_ID), Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into(), @@ -495,20 +531,28 @@ fn test_asset_registry_module() { 1_000_000_000, )); - assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 9_000_000_000_000); - assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 90_989_760_000_000); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)), + 4_989_120_000_000 + ); }); - Karura::execute_with(|| { + MockBifrost::execute_with(|| { + // Sibling -->(transfer 5_000_000_000_000)--> Karura assert_eq!( - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)), - 8_979_520_000_000 + Tokens::free_balance(CurrencyId::ForeignAsset(0), &karura_reserve_account()), + 94_999_360_000_000 + ); + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &sibling_reserve_account()), + 4_999_360_000_000 ); + }); - // ToTreasury + Karura::execute_with(|| { assert_eq!( - Tokens::free_balance(CurrencyId::ForeignAsset(0), &TreasuryAccount::get()), - 20_480_000_000 + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)), + 94_989_120_000_000 ); }); } @@ -658,7 +702,7 @@ fn trap_assets_larger_than_ed_works() { ]; assert_ok!(pallet_xcm::Pallet::::send_xcm( Here, - Parachain(2000).into(), + Parachain(KARURA_ID).into(), Xcm(xcm), )); }); @@ -706,7 +750,7 @@ fn trap_assets_lower_than_ed_works() { ]; assert_ok!(pallet_xcm::Pallet::::send_xcm( Here, - Parachain(2000).into(), + Parachain(KARURA_ID).into(), Xcm(xcm), )); }); @@ -737,13 +781,9 @@ fn sibling_trap_assets_works() { let mut kar_treasury_amount = 0; let (bnc_asset_amount, kar_asset_amount) = (cent(BNC) / 10, cent(KAR)); - fn sibling_account() -> AccountId { - polkadot_parachain::primitives::Sibling::from(2001).into_account() - } - Karura::execute_with(|| { - assert_ok!(Tokens::deposit(BNC, &sibling_account(), dollar(BNC))); - let _ = pallet_balances::Pallet::::deposit_creating(&sibling_account(), dollar(KAR)); + assert_ok!(Tokens::deposit(BNC, &sibling_reserve_account(), dollar(BNC))); + let _ = pallet_balances::Pallet::::deposit_creating(&sibling_reserve_account(), dollar(KAR)); kar_treasury_amount = Currencies::free_balance(KAR, &KaruraTreasuryAccount::get()); }); @@ -757,10 +797,7 @@ fn sibling_trap_assets_works() { }, WithdrawAsset( ( - ( - Parent, - X2(Parachain(2001), GeneralKey(parachains::bifrost::BNC_KEY.to_vec())), - ), + (Parent, X2(Parachain(BIFROST_ID), GeneralKey(BNC_KEY.to_vec()))), bnc_asset_amount, ) .into(), @@ -768,7 +805,7 @@ fn sibling_trap_assets_works() { ]; assert_ok!(pallet_xcm::Pallet::::send_xcm( Here, - (Parent, Parachain(2000)), + (Parent, Parachain(KARURA_ID)), Xcm(xcm), )); }); @@ -790,3 +827,90 @@ fn sibling_trap_assets_works() { ); }); } + +#[test] +fn transfer_native_chain_asset() { + TestNet::reset(); + + MockBifrost::execute_with(|| { + // Register native BNC's incoming address as a foreign asset so it can receive BNC + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(0, X1(GeneralKey(BNC_KEY.to_vec()))).into()), + Box::new(AssetMetadata { + name: b"Native BNC".to_vec(), + symbol: b"BNC".to_vec(), + decimals: 12, + minimal_balance: Balances::minimum_balance() / 10, // 10% + }) + )); + assert_ok!(Tokens::deposit( + CurrencyId::ForeignAsset(0), + &karura_reserve_account(), + 100_000_000_000_000 + )); + + assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100_000_000_000_000)); + + assert_ok!(XTokens::transfer( + Origin::signed(ALICE.into()), + BNC, + 10_000_000_000_000, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(KARURA_ID), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + 1_000_000_000, + )); + + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000); + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 10_000_000_000_000); + }); + + Karura::execute_with(|| { + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 9_989_760_000_000); + + assert_ok!(XTokens::transfer( + Origin::signed(BOB.into()), + BNC, + 5_000_000_000_000, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(MOCK_BIFROST_ID), + Junction::AccountId32 { + network: NetworkId::Any, + id: ALICE.into(), + } + ) + ) + .into() + ), + 1_000_000_000, + )); + + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 4_989_760_000_000); + }); + + MockBifrost::execute_with(|| { + // Due to the re-anchoring, BNC came back as registered ForeignAsset(0) + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000); + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 10_000_000_000_000); + + assert_eq!( + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)), + 4_999_360_000_000 + ); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000); + }); +} diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index cd067e96a0..3cd5f86530 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -47,7 +47,7 @@ decl_test_parachain! { } decl_test_parachain! { - pub struct Sibling { + pub struct MockBifrost { Runtime = Runtime, Origin = Origin, XcmpMessageHandler = karura_runtime::XcmpQueue, @@ -56,6 +56,16 @@ decl_test_parachain! { } } +decl_test_parachain! { + pub struct Sibling { + Runtime = Runtime, + Origin = Origin, + XcmpMessageHandler = karura_runtime::XcmpQueue, + DmpMessageHandler = karura_runtime::DmpQueue, + new_ext = para_ext(2002), + } +} + decl_test_parachain! { pub struct Statemine { Runtime = statemine_runtime::Runtime, @@ -72,7 +82,8 @@ decl_test_network! { parachains = vec![ (1000, Statemine), (2000, Karura), - (2001, Sibling), + (2001, MockBifrost), + (2002, Sibling), ], } } diff --git a/runtime/integration-tests/src/relaychain/polkadot_test_net.rs b/runtime/integration-tests/src/relaychain/polkadot_test_net.rs index 4d67277694..2cbbb50cf1 100644 --- a/runtime/integration-tests/src/relaychain/polkadot_test_net.rs +++ b/runtime/integration-tests/src/relaychain/polkadot_test_net.rs @@ -47,7 +47,7 @@ decl_test_parachain! { } decl_test_parachain! { - pub struct Sibling { + pub struct MockBifrost { Runtime = Runtime, Origin = Origin, XcmpMessageHandler = acala_runtime::XcmpQueue, @@ -56,12 +56,23 @@ decl_test_parachain! { } } +decl_test_parachain! { + pub struct Sibling { + Runtime = Runtime, + Origin = Origin, + XcmpMessageHandler = acala_runtime::XcmpQueue, + DmpMessageHandler = acala_runtime::DmpQueue, + new_ext = para_ext(2002), + } +} + decl_test_network! { pub struct TestNet { relay_chain = PolkadotNet, parachains = vec![ (2000, Acala), - (2001, Sibling), + (2001, MockBifrost), + (2002, Sibling), ], } } diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index 3b522136f0..626737c188 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -344,8 +344,6 @@ try-runtime = [ "module-session-manager/try-runtime", "module-honzon-bridge/try-runtime", ] - -integration-tests = [] # By default some types have documentation, `no-metadata-docs` allows to reduce the documentation # in the metadata. no-metadata-docs = ["frame-support/no-metadata-docs"] diff --git a/runtime/karura/src/integration_tests_config.rs b/runtime/karura/src/integration_tests_config.rs deleted file mode 100644 index d4b2c3d5e8..0000000000 --- a/runtime/karura/src/integration_tests_config.rs +++ /dev/null @@ -1,50 +0,0 @@ -// This file is part of Acala. - -// Copyright (C) 2020-2022 Acala Foundation. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use super::xcm_config::*; -use super::{ - constants::{fee::*, parachains}, - FixedRateOfAssetRegistry, Runtime, TransactionFeePoolTrader, -}; -use xcm::latest::prelude::*; - -parameter_types! { - pub BncPerSecondOfCanonicalLocation: (AssetId, u128) = ( - MultiLocation::new( - 0, - X1(GeneralKey(parachains::bifrost::BNC_KEY.to_vec())), - ).into(), - ksm_per_second() * 80 - ); -} - -pub type Trader = ( - TransactionFeePoolTrader, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfFungible, - FixedRateOfAssetRegistry>, - FixedRateOfAssetRegistry>, -); diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 5355fe7159..4766805fad 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -114,9 +114,6 @@ pub use xcm::latest::prelude::*; /// Import the stable_asset pallet. pub use nutsfinance_stable_asset; -#[cfg(feature = "integration-tests")] -mod integration_tests_config; - mod authority; mod benchmarking; pub mod constants; diff --git a/runtime/karura/src/xcm_config.rs b/runtime/karura/src/xcm_config.rs index f7818158ba..3583f7e64b 100644 --- a/runtime/karura/src/xcm_config.rs +++ b/runtime/karura/src/xcm_config.rs @@ -19,8 +19,9 @@ use super::{ constants::{fee::*, parachains}, AccountId, AssetIdMapping, AssetIdMaps, Balance, Call, Convert, Currencies, CurrencyId, Event, ExistentialDeposits, - GetNativeCurrencyId, KaruraTreasuryAccount, NativeTokenExistentialDeposit, Origin, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, UnknownTokens, XcmInterface, XcmpQueue, KAR, KUSD, LKSM, + FixedRateOfAssetRegistry, GetNativeCurrencyId, KaruraTreasuryAccount, NativeTokenExistentialDeposit, Origin, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, TransactionFeePoolTrader, UnknownTokens, XcmInterface, + XcmpQueue, KAR, KUSD, LKSM, }; use codec::{Decode, Encode}; pub use cumulus_primitives_core::ParaId; @@ -47,11 +48,6 @@ pub use xcm_builder::{ }; use xcm_executor::XcmExecutor; -#[cfg(not(feature = "integration-tests"))] -use super::{FixedRateOfAssetRegistry, TransactionFeePoolTrader}; -#[cfg(feature = "integration-tests")] -use crate::integration_tests_config::*; - parameter_types! { pub KsmLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; @@ -192,7 +188,6 @@ parameter_types! { pub KarPerSecondAsBased: u128 = kar_per_second(); } -#[cfg(not(feature = "integration-tests"))] pub type Trader = ( TransactionFeePoolTrader, FixedRateOfFungible, @@ -444,18 +439,14 @@ impl Convert> for CurrencyIdConvert { MultiLocation { parents: 0, interior: X1(GeneralKey(key)), - } => match &key[..] { - #[cfg(feature = "integration-tests")] - parachains::bifrost::BNC_KEY => Some(Token(BNC)), - key => { - let currency_id = CurrencyId::decode(&mut &*key).ok()?; - match currency_id { - Token(KAR) | Token(KUSD) | Token(LKSM) => Some(currency_id), - Erc20(address) if !is_system_contract(address) => Some(currency_id), - _ => None, - } + } => { + let currency_id = CurrencyId::decode(&mut &*key).ok()?; + match currency_id { + Token(KAR) | Token(KUSD) | Token(LKSM) => Some(currency_id), + Erc20(address) if !is_system_contract(address) => Some(currency_id), + _ => None, } - }, + } _ => None, } }