Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Assets/ForeignAssets tests and fixes #2167

Merged
merged 41 commits into from
Mar 16, 2023
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fe2d626
Test for create and transfer `TrustBackedAssets` with AssetTransactor
bkontur Feb 3, 2023
8e3f62c
Test for transfer `local Currency` with AssetTransactor
bkontur Feb 6, 2023
766abea
Test for create foreign assets (covers foreign relaychain currency)
bkontur Feb 7, 2023
12d61db
Added `ForeignFungiblesTransactor` and test for transfer `ForeignAsse…
bkontur Feb 8, 2023
778f80f
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Feb 13, 2023
7772da9
Removed unused `pub const Local: MultiLocation`
bkontur Feb 13, 2023
40ccf5f
Changed `ParaId -> Sibling` for `SiblingParachainConvertsVia`
bkontur Feb 13, 2023
990e255
Test for create foreign assets (covers local sibling parachain assets)
bkontur Feb 13, 2023
a83d680
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Feb 23, 2023
2c11d66
Reverted stuff for ForeignCreators from different global consensus (m…
bkontur Feb 24, 2023
96379c3
Refactor `weight_limit` for `execute_xcm`
bkontur Feb 27, 2023
5bd9983
Added test for `set_metadata` by ForeignCreator with `xcm::Transact(s…
bkontur Feb 27, 2023
1fb6f90
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
bkontur Feb 28, 2023
457f87f
Renamed `receive_teleported_asset_works` -> `receive_teleported_asset…
bkontur Feb 28, 2023
7e1da40
Allow `ForeignCreators` only for sibling parachains
bkontur Feb 28, 2023
449ba70
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
bkontur Mar 3, 2023
80756d1
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 3, 2023
03915e2
Unify ReservedDmpWeight/ReservedXcmpWeight usage
bkontur Mar 3, 2023
cabf0f9
Removed hack - replaced with `MatchedConvertedConcreteId`
bkontur Mar 3, 2023
92fee37
Refactor `ForeignCreators` to assets-common
bkontur Mar 3, 2023
e7cd1f5
Add `ReceiveTeleportedAsset` test
bkontur Mar 1, 2023
2aa0c8a
Change test - `Utility::batch` -> Multiple `xcm::Transact`
bkontur Mar 6, 2023
3310cd1
Reusing the same deposits as for TrustBackedAssets
bkontur Mar 6, 2023
24d0274
missing `try_successful_origin` ?
bkontur Mar 6, 2023
afbfeb0
Finished `ForeignAssets` for westmint (converter, FungiblesApi, tests)
bkontur Mar 8, 2023
ed97007
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 8, 2023
47ba115
Refactoring tests - receive_teleported_asset_for_native_asset_works
bkontur Mar 9, 2023
0748e97
ForeignAssets for statemine + refactored `receive_teleported_asset_fr…
bkontur Mar 9, 2023
30acc18
Add `ForeignAssets` to statemine `FungiblesApi`
bkontur Mar 9, 2023
4fb2f85
Add `asset_transactor_transfer_with_local_consensus_currency_works` t…
bkontur Mar 9, 2023
2695886
Added `asset_transactor_transfer_with_trust_backed_assets_works` test
bkontur Mar 10, 2023
c181e0c
Added `asset_transactor_transfer_with_foreign_assets_works`
bkontur Mar 10, 2023
16ad4a4
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 10, 2023
913504c
Fix `missing `try_successful_origin` in implementation`
bkontur Mar 12, 2023
4245b2f
Added `create_and_manage_foreign_assets_for_local_consensus_parachain…
bkontur Mar 13, 2023
79f9b30
Added `ExpectTransactStatus` check
bkontur Mar 13, 2023
5c97727
Small rename
bkontur Mar 13, 2023
c615788
Extended `test_assets_balances_api_works` with ForeignAssets for `sta…
bkontur Mar 13, 2023
0460e76
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 15, 2023
ece1905
PR fixes
bkontur Mar 16, 2023
4b354a4
Update parachains/runtimes/assets/test-utils/src/test_cases.rs
joepetrowski Mar 16, 2023
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
Prev Previous commit
Next Next commit
Add ReceiveTeleportedAsset test
  • Loading branch information
bkontur committed Mar 6, 2023
commit e7cd1f5b7e66dec0d4ca710587ed5b3b5a4073eb
111 changes: 110 additions & 1 deletion parachains/runtimes/assets/westmint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ fn receive_teleported_asset_for_native_asset_works() {
ClearOrigin,
BuyExecution {
fees: MultiAsset {
// TODO: refactor here little bit: MultiLocation::parent()
id: Concrete(MultiLocation { parents: 1, interior: Here }),
fun: Fungible(10000000000000),
},
Expand Down Expand Up @@ -901,6 +902,8 @@ fn create_foreign_assets_for_local_consensus_parachain_assets_works() {
],
});

// TODO:: try this this with multiple Transacts with different origin_kind

// lets simulate this was triggered by relay chain from local consensus sibling parachain
let xcm = Xcm(vec![
WithdrawAsset(buy_execution_fee.clone().into()),
Expand Down Expand Up @@ -1015,4 +1018,110 @@ fn create_foreign_assets_for_local_consensus_parachain_assets_works() {
})
}

// TODO: test for ReserveAssetTeleported (IsTeleporter) - rebase + rename existing test to native
#[test]
fn receive_teleported_asset_from_foreign_creator_works() {
// foreign parachain with the same consenus currency as asset
let foreign_asset_id_multilocation =
MultiLocation { parents: 1, interior: X2(Parachain(2222), GeneralIndex(1234567)) };

// foreign creator, which can be sibling parachain to match ForeignCreators
let foreign_creator = MultiLocation { parents: 1, interior: X1(Parachain(2222)) };
let foreign_creator_as_account_id =
ForeignCreatorsSovereignAccountOf::convert(foreign_creator).expect("");

// we want to buy execution with local relay chain currency
let buy_execution_fee_amount =
WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 0));
let buy_execution_fee = MultiAsset {
id: Concrete(MultiLocation::parent()),
fun: Fungible(buy_execution_fee_amount),
};

let target_account = AccountId::from(BOB);
let teleported_foreign_asset_amount = 10000000000000;

ExtBuilder::<Runtime>::default()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)])
.with_balances(vec![
(
foreign_creator_as_account_id.clone(),
ExistentialDeposit::get() +
AssetDeposit::get() + MetadataDepositBase::get() +
(buy_execution_fee_amount * 2),
),
(target_account.clone(), ExistentialDeposit::get()),
])
.with_tracing()
.build()
.execute_with(|| {
// checks before
assert_eq!(Balances::free_balance(&target_account), ExistentialDeposit::get());
assert_eq!(
ForeignAssets::balance(foreign_asset_id_multilocation, target_account.clone()),
0
);

// create foreign asset
let asset_minimum_asset_balance = 3333333_u128;
assert_ok!(ForeignAssets::force_create(
RuntimeHelper::<Runtime>::root_origin(),
foreign_asset_id_multilocation.clone().into(),
AccountId::from(SOME_ASSET_ADMIN).into(),
false,
asset_minimum_asset_balance
));
assert!(teleported_foreign_asset_amount > asset_minimum_asset_balance);

// prepare xcm
let xcm = Xcm(vec![
// BuyExecution with relaychain native token
WithdrawAsset(buy_execution_fee.clone().into()),
BuyExecution {
fees: MultiAsset {
id: Concrete(MultiLocation::parent()),
fun: Fungible(buy_execution_fee_amount),
},
weight_limit: Limited(Weight::from_parts(403531000, 1024)),
},
// Process teleported asset
ReceiveTeleportedAsset(MultiAssets::from(vec![MultiAsset {
id: Concrete(foreign_asset_id_multilocation),
fun: Fungible(teleported_foreign_asset_amount),
}])),
DepositAsset {
assets: Wild(AllOf {
id: Concrete(foreign_asset_id_multilocation),
fun: WildFungibility::Fungible,
}),
beneficiary: MultiLocation {
parents: 0,
interior: X1(AccountId32 {
network: None,
id: target_account.clone().into(),
}),
},
},
]);
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);

let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
foreign_creator,
xcm,
hash,
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
);
assert_eq!(outcome.ensure_complete(), Ok(()));

// checks after
assert_eq!(Balances::free_balance(&target_account), ExistentialDeposit::get());
assert_eq!(
ForeignAssets::balance(foreign_asset_id_multilocation, target_account.clone()),
teleported_foreign_asset_amount
);
})
}