From 206495eb379c8da67dba624ad729f9dcf3aa7879 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 16 Nov 2021 22:00:48 +0800 Subject: [PATCH 1/3] fmt --- orml | 2 +- .../relaychain/kusama_cross_chain_transfer.rs | 46 +++++++++++++++++++ .../src/relaychain/kusama_test_net.rs | 6 +++ runtime/karura/src/lib.rs | 3 ++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/orml b/orml index d69f226e3..631659bde 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit d69f226e332ae29b7b33d53d2f06f309d2986ea0 +Subproject commit 631659bde3f12a110d3c8b34a62bf1a18f1aabbb 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 b65d9e7cd..1f9e210c1 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -78,3 +78,49 @@ fn transfer_to_relay_chain() { ); }); } + +#[test] +fn relay_transact_to_para_call_transfer() { + env_logger::init(); + Karura::execute_with(|| { + let _ = ParaBalances::deposit_creating(&AccountId::from(ALICE), 1000 * dollar(KAR)); + }); + + let alice = Junctions::X1(Junction::AccountId32 { + network: NetworkId::Kusama, + id: ALICE, + }); + let call = Call::Balances(pallet_balances::Call::::transfer { + dest: MultiAddress::Id(AccountId::from(BOB)), + value: 500 * dollar(KAR), + }); + let assets: MultiAsset = (Parent, dollar(KSM)).into(); + + KusamaNet::execute_with(|| { + let xcm = vec![ + WithdrawAsset(assets.clone().into()), + BuyExecution { + fees: assets, + weight_limit: Limited(dollar(KSM) as u64), + }, + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: (dollar(KSM) as u64) / 10 as u64, + call: call.encode().into(), + }, + ]; + assert_ok!(RelayChainPalletXcm::send_xcm(alice, Parachain(2000).into(), Xcm(xcm),)); + }); + + Karura::execute_with(|| { + use {Event, System}; + assert_eq!(9 * dollar(KAR), ParaTokens::free_balance(KSM, &AccountId::from(ALICE))); + assert_eq!(500 * dollar(KAR), ParaBalances::free_balance(&AccountId::from(ALICE))); + assert_eq!(500 * dollar(KAR), ParaBalances::free_balance(&AccountId::from(BOB))); + System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer( + AccountId::from(ALICE), + AccountId::from(BOB), + 500 * dollar(KAR), + ))); + }); +} diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index 55c71a0e0..c44b3a939 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -53,6 +53,12 @@ decl_test_network! { } } +pub type ParaBalances = pallet_balances::Pallet; + +pub type ParaTokens = orml_tokens::Pallet; + +pub type RelayChainPalletXcm = pallet_xcm::Pallet; + fn default_parachains_host_configuration() -> HostConfiguration { HostConfiguration { validation_upgrade_frequency: 1u32, diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 044095246..d0ef7d727 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -101,6 +101,7 @@ pub use sp_runtime::BuildStorage; pub use authority::AuthorityConfigImpl; pub use constants::{fee::*, parachains, time::*}; +use orml_xcm_support::{AllowRelayedPaidExecutionFromParent, RelayChainAccountId32Aliases}; pub use primitives::{ define_combined_task, evm::EstimateResourcesRequest, task::TaskResult, AccountId, AccountIndex, Address, Amount, AuctionId, AuthoritysOriginId, Balance, BlockNumber, CurrencyId, DataProviderId, EraIndex, Hash, Moment, Nonce, @@ -1393,6 +1394,7 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + RelayChainAccountId32Aliases, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, @@ -1453,6 +1455,7 @@ pub type Barrier = ( AllowKnownQueryResponses, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, + AllowRelayedPaidExecutionFromParent, ); pub struct ToTreasury; From e653fca1d89be6b454356486c4b19474459258bb Mon Sep 17 00:00:00 2001 From: zqh Date: Fri, 19 Nov 2021 09:01:21 +0800 Subject: [PATCH 2/3] kusd and batch_call test --- orml | 2 +- .../relaychain/kusama_cross_chain_transfer.rs | 137 +++++++++++++++++- runtime/karura/src/lib.rs | 2 +- 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/orml b/orml index 631659bde..4177cd696 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 631659bde3f12a110d3c8b34a62bf1a18f1aabbb +Subproject commit 4177cd6961ff6dd0c7d80ff713ed4839b466cae8 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 1f9e210c1..cce8e780c 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -80,8 +80,7 @@ fn transfer_to_relay_chain() { } #[test] -fn relay_transact_to_para_call_transfer() { - env_logger::init(); +fn transact_transfer_call_to_para_chain_use_ksm() { Karura::execute_with(|| { let _ = ParaBalances::deposit_creating(&AccountId::from(ALICE), 1000 * dollar(KAR)); }); @@ -108,13 +107,18 @@ fn relay_transact_to_para_call_transfer() { require_weight_at_most: (dollar(KSM) as u64) / 10 as u64, call: call.encode().into(), }, + DepositAsset { + assets: All.into(), + max_assets: 1, + beneficiary: { (1, alice.clone()).into() }, + }, ]; assert_ok!(RelayChainPalletXcm::send_xcm(alice, Parachain(2000).into(), Xcm(xcm),)); }); Karura::execute_with(|| { use {Event, System}; - assert_eq!(9 * dollar(KAR), ParaTokens::free_balance(KSM, &AccountId::from(ALICE))); + assert_eq!(9983840000000, ParaTokens::free_balance(KSM, &AccountId::from(ALICE))); assert_eq!(500 * dollar(KAR), ParaBalances::free_balance(&AccountId::from(ALICE))); assert_eq!(500 * dollar(KAR), ParaBalances::free_balance(&AccountId::from(BOB))); System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer( @@ -124,3 +128,130 @@ fn relay_transact_to_para_call_transfer() { ))); }); } + +#[test] +fn transact_transfer_call_to_para_chain_use_kusd() { + Karura::execute_with(|| { + let _ = ParaBalances::deposit_creating(&AccountId::from(ALICE), 1000 * dollar(KUSD)); + assert_ok!(ParaTokens::deposit(KUSD, &AccountId::from(ALICE), 1000 * dollar(KUSD))); + }); + + let alice = Junctions::X1(Junction::AccountId32 { + network: NetworkId::Kusama, + id: ALICE, + }); + let call = Call::Balances(pallet_balances::Call::::transfer { + dest: MultiAddress::Id(AccountId::from(BOB)), + value: 500 * dollar(KUSD), + }); + let assets: MultiAsset = ( + (Parent, X2(Parachain(2000), GeneralKey(KUSD.encode()))), + 100 * dollar(KUSD), + ) + .into(); + + KusamaNet::execute_with(|| { + let xcm = vec![ + WithdrawAsset(assets.clone().into()), + BuyExecution { + fees: assets, + weight_limit: Limited(100 * dollar(KUSD) as u64), + }, + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: dollar(KUSD) as u64, + call: call.encode().into(), + }, + DepositAsset { + assets: All.into(), + max_assets: 1, + beneficiary: { (0, alice.clone()).into() }, + }, + ]; + assert_ok!(RelayChainPalletXcm::send_xcm(alice, Parachain(2000).into(), Xcm(xcm),)); + }); + + Karura::execute_with(|| { + assert_eq!(935936000000000, ParaTokens::free_balance(KUSD, &AccountId::from(ALICE))); + assert_eq!(500 * dollar(KUSD), ParaBalances::free_balance(&AccountId::from(ALICE))); + assert_eq!(500 * dollar(KUSD), ParaBalances::free_balance(&AccountId::from(BOB))); + System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer( + AccountId::from(ALICE), + AccountId::from(BOB), + 500 * dollar(KUSD), + ))); + }); +} + +#[test] +fn batch_cdall_execute_then_send_xcm_to_para_chain() { + Karura::execute_with(|| { + assert_ok!(ParaTokens::deposit(KUSD, &AccountId::from(ALICE), 2000 * dollar(KUSD))); + }); + + let alice = Junctions::X1(Junction::AccountId32 { + network: NetworkId::Kusama, + id: ALICE, + }); + let bob = X1(Junction::AccountId32 { + network: NetworkId::Kusama, + id: BOB, + }); + KusamaNet::execute_with(|| { + // current XcmExecuteFilter = Nothing cause xcm_relay_call Filtered error + let _xcm_relay_call = kusama_runtime::Call::XcmPallet(pallet_xcm::Call::::execute { + message: Box::new(xcm::VersionedXcm::from(Xcm(vec![ + WithdrawAsset((Here, 1100 * dollar(KSM)).into()), + BuyExecution { + fees: (Here, 1100 * dollar(KSM)).into(), + weight_limit: Limited(dollar(KSM) as u64), + }, + DepositAsset { + assets: All.into(), + max_assets: 1, + beneficiary: { (0, alice.clone()).into() }, + }, + ]))), + max_weight: dollar(KSM) as u64, + }); + + let xcm_para_call = kusama_runtime::Call::XcmPallet(pallet_xcm::Call::::send { + dest: Box::new(xcm::VersionedMultiLocation::from(Parachain(2000).into())), + message: Box::new(xcm::VersionedXcm::from(Xcm(vec![ + WithdrawAsset( + ( + (Parent, X2(Parachain(2000), GeneralKey(KUSD.encode()))), + 1000 * dollar(KUSD), + ) + .into(), + ), + BuyExecution { + fees: ( + (Parent, X2(Parachain(2000), GeneralKey(KUSD.encode()))), + 1000 * dollar(KUSD), + ) + .into(), + weight_limit: Limited(dollar(KUSD) as u64), + }, + DepositAsset { + assets: All.into(), + max_assets: 1, + beneficiary: { (0, bob).into() }, + }, + ]))), + }); + + assert_ok!(pallet_utility::Pallet::::batch_all( + kusama_runtime::Origin::signed(AccountId::from(ALICE)), + vec![xcm_para_call] + )); + }); + + Karura::execute_with(|| { + assert_eq!( + 1000 * dollar(KUSD), + ParaTokens::free_balance(KUSD, &AccountId::from(ALICE)) + ); + assert_eq!(999948800000000, ParaTokens::free_balance(KUSD, &AccountId::from(BOB))); + }); +} diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index d0ef7d727..2095ac468 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1692,7 +1692,7 @@ impl Convert> for CurrencyIdConvert { (parachains::bifrost::ID, parachains::bifrost::BNC_KEY) => Some(Token(BNC)), (parachains::bifrost::ID, parachains::bifrost::VSKSM_KEY) => Some(Token(VSKSM)), (id, key) if id == u32::from(ParachainInfo::get()) => { - // Karura + // KaruraParachainInfo if let Ok(currency_id) = CurrencyId::decode(&mut &*key) { // check `currency_id` is cross-chain asset match currency_id { From 708d486cd913dfc5ac6bbe1c71a6810a9179c224 Mon Sep 17 00:00:00 2001 From: zqh Date: Fri, 19 Nov 2021 09:13:32 +0800 Subject: [PATCH 3/3] tiny --- .../src/relaychain/kusama_cross_chain_transfer.rs | 4 ++-- runtime/karura/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 cce8e780c..c5728d78b 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -184,7 +184,7 @@ fn transact_transfer_call_to_para_chain_use_kusd() { } #[test] -fn batch_cdall_execute_then_send_xcm_to_para_chain() { +fn batch_call_execute_then_send_xcm_to_para_chain() { Karura::execute_with(|| { assert_ok!(ParaTokens::deposit(KUSD, &AccountId::from(ALICE), 2000 * dollar(KUSD))); }); @@ -198,7 +198,7 @@ fn batch_cdall_execute_then_send_xcm_to_para_chain() { id: BOB, }); KusamaNet::execute_with(|| { - // current XcmExecuteFilter = Nothing cause xcm_relay_call Filtered error + // current kusama runtime `XcmExecuteFilter = Nothing` cause xcm_relay_call `Filtered` error let _xcm_relay_call = kusama_runtime::Call::XcmPallet(pallet_xcm::Call::::execute { message: Box::new(xcm::VersionedXcm::from(Xcm(vec![ WithdrawAsset((Here, 1100 * dollar(KSM)).into()), diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 2095ac468..d0ef7d727 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1692,7 +1692,7 @@ impl Convert> for CurrencyIdConvert { (parachains::bifrost::ID, parachains::bifrost::BNC_KEY) => Some(Token(BNC)), (parachains::bifrost::ID, parachains::bifrost::VSKSM_KEY) => Some(Token(VSKSM)), (id, key) if id == u32::from(ParachainInfo::get()) => { - // KaruraParachainInfo + // Karura if let Ok(currency_id) = CurrencyId::decode(&mut &*key) { // check `currency_id` is cross-chain asset match currency_id {