Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relay account transact #1614

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orml
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Runtime>::transfer {
dest: MultiAddress::Id(AccountId::from(BOB)),
value: 500 * dollar(KAR),
});
let assets: MultiAsset = (Parent, dollar(KSM)).into();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also support withdraw KAR for fee payment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current ParaTokens::deposit(KAR, &AccountId::from(ALICE), 2000 * dollar(KAR)) have ExistentialDeposits limitation.
so I use KUSD instead.


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),
)));
});
}
6 changes: 6 additions & 0 deletions runtime/integration-tests/src/relaychain/kusama_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ decl_test_network! {
}
}

pub type ParaBalances = pallet_balances::Pallet<Runtime>;

pub type ParaTokens = orml_tokens::Pallet<Runtime>;

pub type RelayChainPalletXcm = pallet_xcm::Pallet<kusama_runtime::Runtime>;

fn default_parachains_host_configuration() -> HostConfiguration<BlockNumber> {
HostConfiguration {
validation_upgrade_frequency: 1u32,
Expand Down
3 changes: 3 additions & 0 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1393,6 +1394,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
RelayChainAccountId32Aliases<RelayNetwork, AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down Expand Up @@ -1453,6 +1455,7 @@ pub type Barrier = (
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
AllowRelayedPaidExecutionFromParent<RelayNetwork>,
);

pub struct ToTreasury;
Expand Down