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
Show file tree
Hide file tree
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
Next Next commit
Test for create and transfer TrustBackedAssets with AssetTransactor
  • Loading branch information
bkontur committed Feb 3, 2023
commit fe2d626028b46f8318e4af1a72495bf527326c59
5 changes: 5 additions & 0 deletions parachains/runtimes/assets/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl<Runtime: frame_system::Config + pallet_balances::Config + pallet_session::C
self
}

pub fn with_tracing(self) -> Self {
frame_support::sp_tracing::try_init_simple();
self
}

pub fn build(self) -> sp_io::TestExternalities
where
Runtime:
Expand Down
91 changes: 88 additions & 3 deletions parachains/runtimes/assets/westmint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ use frame_support::{
traits::PalletInfo,
weights::{Weight, WeightToFee as WeightToFeeT},
};
use parachains_common::{AccountId, AuraId};
use westmint_runtime::xcm_config::AssetFeeAsExistentialDepositMultiplierFeeCharger;
use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId};
use westmint_runtime::xcm_config::{
AssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsPalletLocation,
};
pub use westmint_runtime::{
constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit,
Runtime, SessionKeys, System,
};
use xcm::latest::prelude::*;
use xcm_executor::traits::WeightTrader;
use xcm_builder::AsPrefixedGeneralIndex;
use xcm_executor::traits::{Convert, JustTry, TransactAsset, WeightTrader};

pub const ALICE: [u8; 32] = [1u8; 32];
pub const BOB: [u8; 32] = [2u8; 32];

#[test]
fn test_asset_xcm_trader() {
Expand Down Expand Up @@ -386,3 +390,84 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
assert_eq!(Assets::total_supply(1), minimum_asset_balance);
});
}

#[test]
fn test_asset_transactor_with_trust_backed_assets_works() {
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_tracing()
.build()
.execute_with(|| {
// We need root origin to create a sufficient asset
let minimum_asset_balance = 3333333_u128;
let local_asset_id = 1;
assert_ok!(Assets::force_create(
RuntimeHelper::<Runtime>::root_origin(),
local_asset_id.into(),
AccountId::from(ALICE).into(),
true,
minimum_asset_balance
));

// We first mint enough asset for the account to exist for assets
assert_ok!(Assets::mint(
RuntimeHelper::<Runtime>::origin_of(AccountId::from(ALICE)),
local_asset_id.into(),
AccountId::from(ALICE).into(),
minimum_asset_balance * 6
));

// check Assets before
assert_eq!(
Assets::balance(local_asset_id, AccountId::from(ALICE)),
minimum_asset_balance * 6
);
assert_eq!(Assets::balance(local_asset_id, AccountId::from(BOB)), 0);

// transfer_asset (deposit/withdraw)
let origin_location = MultiLocation {
parents: 0,
interior: X1(AccountId32 { network: None, id: AccountId::from(ALICE).into() }),
};
let target_account_location = MultiLocation {
parents: 0,
interior: X1(AccountId32 { network: None, id: AccountId::from(BOB).into() }),
};

type AssetIdConverter = AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets,
JustTry,
>;
let multi_asset = MultiAsset {
id: Concrete(AssetIdConverter::reverse_ref(local_asset_id).unwrap()),
fun: Fungible(minimum_asset_balance),
};

type AssetTransactor = <XcmConfig as xcm_executor::Config>::AssetTransactor;
let _ = <AssetTransactor as TransactAsset>::transfer_asset(
&multi_asset,
&origin_location,
&target_account_location,
// We aren't able to track the XCM that initiated the fee deposit, so we create a
// fake message hash here
&XcmContext::with_message_hash([0; 32]),
)
.expect("no error");

// check Assets after
assert_eq!(
Assets::balance(local_asset_id, AccountId::from(ALICE)),
minimum_asset_balance * 5
);
assert_eq!(
Assets::balance(local_asset_id, AccountId::from(BOB)),
minimum_asset_balance
);
})
}