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
Prev Previous commit
Next Next commit
Added ExpectTransactStatus check
  • Loading branch information
bkontur committed Mar 13, 2023
commit 79f9b30635efc6469a746db45e7be86aa75c1b3e
2 changes: 2 additions & 0 deletions parachains/runtimes/assets/statemine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,10 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
}),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
}),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert_eq!(ForeignAssets::asset_ids().collect::<Vec<_>>().len(), 1);
})
);
54 changes: 51 additions & 3 deletions parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use frame_support::{
weights::Weight,
};
use parachains_common::Balance;
use sp_runtime::traits::{StaticLookup, Zero};
use sp_runtime::{
traits::{StaticLookup, Zero},
DispatchError,
};
use xcm::latest::prelude::*;
use xcm_executor::{traits::Convert, XcmExecutor};

Expand Down Expand Up @@ -107,6 +110,7 @@ pub fn receive_teleported_asset_for_native_asset_works<Runtime, XcmConfig>(
}),
},
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);

let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
Expand Down Expand Up @@ -268,6 +272,7 @@ pub fn receive_teleported_asset_from_foreign_creator_works<
}),
},
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);

Expand Down Expand Up @@ -766,6 +771,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
foreign_creator_as_account_id.clone(),
existential_deposit +
asset_deposit + metadata_deposit_base +
buy_execution_fee_amount.into() +
buy_execution_fee_amount.into(),
)])
.with_tracing()
Expand All @@ -778,6 +784,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
<pallet_balances::Pallet<Runtime>>::free_balance(&foreign_creator_as_account_id),
existential_deposit +
asset_deposit + metadata_deposit_base +
buy_execution_fee_amount.into() +
buy_execution_fee_amount.into()
);
additional_checks_before();
Expand Down Expand Up @@ -833,6 +840,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
require_weight_at_most: Weight::from_parts(20_000_000_000, 6000),
call: foreign_asset_set_team.into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);

// messages with different consensus should go through the local bridge-hub
Expand Down Expand Up @@ -888,7 +896,9 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
);
assert!(
<pallet_balances::Pallet<Runtime>>::free_balance(&foreign_creator_as_account_id) <
existential_deposit + buy_execution_fee_amount.into()
existential_deposit +
buy_execution_fee_amount.into() +
buy_execution_fee_amount.into()
);
assert_metadata::<
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
Expand All @@ -906,13 +916,51 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
);
assert_noop!(
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::freeze(
RuntimeHelper::<Runtime>::origin_of(foreign_creator_as_account_id),
RuntimeHelper::<Runtime>::origin_of(foreign_creator_as_account_id.clone()),
asset_id.clone().into(),
alice_account.into()
),
pallet_assets::Error::<Runtime, ForeignAssetsPalletInstance>::NoPermission
);

// lets try create asset for different parachain(3333) (foreign_creator(2222) can create just his assets)
let foreign_asset_id_multilocation =
MultiLocation { parents: 1, interior: X2(Parachain(3333), GeneralIndex(1234567)) };
let asset_id = AssetIdConverter::convert(foreign_asset_id_multilocation).unwrap();

// prepapre data for xcm::Transact(create)
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
let foreign_asset_create = runtime_call_encode(pallet_assets::Call::<
Runtime,
ForeignAssetsPalletInstance,
>::create {
id: asset_id.clone().into(),
// admin as sovereign_account
admin: foreign_creator_as_account_id.clone().into(),
min_balance: 1.into(),
});
let xcm = Xcm(vec![
WithdrawAsset(buy_execution_fee.clone().into()),
BuyExecution { fees: buy_execution_fee.clone().into(), weight_limit: Unlimited },
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_parts(20_000_000_000, 6000),
call: foreign_asset_create.into(),
},
ExpectTransactStatus(MaybeErrorCode::from(DispatchError::BadOrigin.encode())),
]);

// messages with different consensus should go through the local bridge-hub
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);

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

additional_checks_after();
})
}
Expand Down
2 changes: 2 additions & 0 deletions parachains/runtimes/assets/westmint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
}),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
}),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert_eq!(ForeignAssets::asset_ids().collect::<Vec<_>>().len(), 1);
})
);

Expand Down