Skip to content

Commit

Permalink
XCM: add deposit error handler for multi-currency adapter. (#1756)
Browse files Browse the repository at this point in the history
* XCM: add deposit error handler for multi-currency adapter.

* Fix integration tests.
  • Loading branch information
shaunxw authored Jan 9, 2022
1 parent 1d54bdb commit dda03dc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion orml
3 changes: 2 additions & 1 deletion runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use orml_traits::{
use pallet_transaction_payment::RuntimeDispatchInfo;

pub use cumulus_primitives_core::ParaId;
pub use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
pub use polkadot_parachain::primitives::Sibling;
pub use xcm::latest::prelude::*;
Expand Down Expand Up @@ -1618,6 +1618,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter<
LocationToAccountId,
CurrencyId,
CurrencyIdConvert,
DepositToAlternative<AcalaTreasuryAccount, Currencies, CurrencyId, AccountId, Balance>,
>;

//TODO: use token registry currency type encoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,34 @@ fn transfer_to_sibling() {
});
}

#[test]
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(
Junction::AccountId32 {
id: BOB,
network: NetworkId::Any
}
.into()
.into()
),
Box::new((Here, 128_000_111).into()),
0
));
});

Karura::execute_with(|| {
assert_eq!(Tokens::free_balance(KSM, &AccountId::from(BOB)), 0);
assert_eq!(
Tokens::free_balance(KSM, &karura_runtime::KaruraTreasuryAccount::get()),
1_000_128_000_111
);
});
}

#[test]
fn xcm_transfer_execution_barrier_trader_works() {
let expect_weight_limit = 600_000_000;
Expand Down Expand Up @@ -637,7 +665,7 @@ fn trap_assets_larger_than_ed_works() {
.any(|r| matches!(r.event, Event::PolkadotXcm(pallet_xcm::Event::AssetsTrapped(_, _, _)))));

assert_eq!(
trader_weight_to_treasury,
trader_weight_to_treasury + dollar(KSM),
Currencies::free_balance(KSM, &KaruraTreasuryAccount::get())
);
assert_eq!(
Expand Down Expand Up @@ -693,7 +721,7 @@ fn trap_assets_lower_than_ed_works() {
);

assert_eq!(
ksm_asset_amount,
ksm_asset_amount + dollar(KSM),
Currencies::free_balance(KSM, &KaruraTreasuryAccount::get())
);
assert_eq!(
Expand Down
5 changes: 4 additions & 1 deletion runtime/integration-tests/src/relaychain/kusama_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ pub fn kusama_ext() -> sp_io::TestExternalities {

pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilder::default()
.balances(vec![(AccountId::from(ALICE), KSM, 10 * dollar(KSM))])
.balances(vec![
(AccountId::from(ALICE), KSM, 10 * dollar(KSM)),
(karura_runtime::KaruraTreasuryAccount::get(), KSM, dollar(KSM)),
])
.parachain_id(parachain_id)
.build()
}
3 changes: 2 additions & 1 deletion runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use orml_traits::{
use pallet_transaction_payment::RuntimeDispatchInfo;

pub use cumulus_primitives_core::ParaId;
pub use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
pub use polkadot_parachain::primitives::Sibling;
pub use xcm::latest::prelude::*;
Expand Down Expand Up @@ -1693,6 +1693,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter<
LocationToAccountId,
CurrencyId,
CurrencyIdConvert,
DepositToAlternative<KaruraTreasuryAccount, Currencies, CurrencyId, AccountId, Balance>,
>;

//TODO: use token registry currency type encoding
Expand Down
3 changes: 2 additions & 1 deletion runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

pub use cumulus_primitives_core::ParaId;
pub use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
pub use polkadot_parachain::primitives::Sibling;
pub use xcm::latest::prelude::*;
Expand Down Expand Up @@ -1720,6 +1720,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter<
LocationToAccountId,
CurrencyId,
CurrencyIdConvert,
DepositToAlternative<TreasuryAccount, Currencies, CurrencyId, AccountId, Balance>,
>;

//TODO: use token registry currency type encoding
Expand Down

0 comments on commit dda03dc

Please sign in to comment.