diff --git a/libs/types/src/tokens.rs b/libs/types/src/tokens.rs index 2d4f7e4311..aefb80a73c 100644 --- a/libs/types/src/tokens.rs +++ b/libs/types/src/tokens.rs @@ -365,7 +365,7 @@ impl CrossChainTransferability { matches!(self, Self::LiquidityPools) } - /// Fees will charged using `FixedRateOfFungible`. + /// Fees will be charged using `FixedRateOfFungible`. #[cfg(feature = "std")] pub fn xcm_default() -> Self { Self::Xcm(XcmMetadata { @@ -373,7 +373,7 @@ impl CrossChainTransferability { }) } - /// Fees will charged using `AssetRegistryTrader`. + /// Fees will be charged using `AssetRegistryTrader`. /// If value is 0, no fees will be charged. #[cfg(feature = "std")] pub fn xcm_with_fees(value: Balance) -> Self { diff --git a/runtime/integration-tests/src/generic/cases/investments.rs b/runtime/integration-tests/src/generic/cases/investments.rs index 50672efaf2..946d98a779 100644 --- a/runtime/integration-tests/src/generic/cases/investments.rs +++ b/runtime/integration-tests/src/generic/cases/investments.rs @@ -43,7 +43,7 @@ mod common { .add(genesis::balances::( T::ExistentialDeposit::get() + FOR_FEES, )) - .add(genesis::assets::(vec![&Usd6])) + .add(genesis::assets::(vec![(Usd6.id(), &Usd6.metadata())])) .add(genesis::tokens::(vec![(Usd6.id(), Usd6.ed())])) .storage(), ); diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index 255d62526d..3cb300a6f3 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -4477,199 +4477,6 @@ mod development { ); }); } - - fn transfer_cfg_to_sibling(env: &mut FudgeEnv) { - let alice_initial_balance = cfg(1_000); - let transfer_amount = cfg(5); - let cfg_in_sibling = CurrencyId::ForeignAsset(12); - - // CFG Metadata - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - general_key(parachains::polkadot::centrifuge::CFG_KEY), - ], - ))), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; - - env.parachain_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - ); - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - 0 - ); - - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(CurrencyId::Native), - )); - }); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - 0 - ); - - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta, - Some(cfg_in_sibling) - )); - }); - - env.parachain_state_mut(|| { - assert_ok!(pallet_restricted_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - CurrencyId::Native, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::SIBLING_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - }, - ], - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Keyring::Alice's balance is initial balance - amount transferred - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - transfer_amount - ); - - // Verify that the amount transferred is now part of the sibling account here - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(2)); - - env.sibling_state(|| { - let current_balance = - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()); - - // Verify that Keyring::Bob now has (amount transferred - fee) - assert_eq!(current_balance, transfer_amount - fee(18)); - - // Sanity check for the actual amount Keyring::Bob ends up with - assert_eq!(current_balance, 4993570400000000000); - }); - } - - #[test_runtimes([development])] - fn transfer_cfg_to_and_from_sibling() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(1_000))) - .storage(), - ); - - setup_test(&mut env); - - // In order to be able to transfer CFG from Moonbeam to Development, we need to - // first send CFG from Development to Moonbeam, or else it fails since it'd be - // like Moonbeam had minted CFG on their side. - transfer_cfg_to_sibling::(&mut env); - - let para_to_sibling_transfer_amount = cfg(5); - - let alice_balance = cfg(1_000) - para_to_sibling_transfer_amount; - let bob_balance = para_to_sibling_transfer_amount - fee(18); - let charlie_balance = cfg(1_000); - - let sibling_to_para_transfer_amount = cfg(4); - // Note: This asset was registered in `transfer_cfg_to_sibling` - let cfg_in_sibling = CurrencyId::ForeignAsset(12); - - env.parachain_state(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_balance - ); - }); - - env.sibling_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::PARA_ID - )), - 0 - ); - - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - bob_balance - ); - }); - - env.sibling_state_mut(|| { - assert_ok!(pallet_restricted_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Bob.into()).into(), - cfg_in_sibling, - sibling_to_para_transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Charlie.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Charlie's balance is initial balance - amount transferred - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - bob_balance - sibling_to_para_transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state(|| { - // Verify that Charlie's balance equals the amount transferred - fee - assert_eq!( - pallet_balances::Pallet::::free_balance(&Into::::into( - Keyring::Charlie - )), - charlie_balance + sibling_to_para_transfer_amount - cfg_fee(), - ); - }); - } } mod routers { @@ -5261,369 +5068,71 @@ mod altair { mod transfers { use super::*; - fn transfer_air_to_sibling(env: &mut FudgeEnv) { - let alice_initial_balance = air(10); - let transfer_amount = air(5); - let air_in_sibling = CurrencyId::ForeignAsset(12); - + fn transfer_ksm_from_relay_chain( + env: &mut FudgeEnv, + transfer_amount: Balance, + currency_id: CurrencyId, + meta: AssetMetadata, + ) { env.parachain_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - ); - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - 0 - ); - - // Register AIR as foreign asset in the sibling parachain - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - general_key(parachains::kusama::altair::AIR_KEY), - ], - ))), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; assert_ok!(orml_asset_registry::Pallet::::register_asset( ::RuntimeOrigin::root(), - meta, - Some(CurrencyId::Native) + meta.clone(), + Some(currency_id), )); - }); - env.sibling_state_mut(|| { assert_eq!( - orml_tokens::Pallet::::free_balance(air_in_sibling, &Keyring::Bob.into()), + orml_tokens::Pallet::::free_balance(currency_id, &Keyring::Bob.into()), 0 ); - - // Register AIR as foreign asset in the sibling parachain - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - general_key(parachains::kusama::altair::AIR_KEY), - ], - ))), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta, - Some(air_in_sibling) - )); }); - env.pass(Blocks::ByNumber(1)); - - env.parachain_state_mut(|| { - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - CurrencyId::Native, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::SIBLING_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); + env.relay_state_mut(|| { + assert_ok!( + pallet_balances::Pallet::>::force_set_balance( + as frame_system::Config>::RuntimeOrigin::root(), + as frame_system::Config>::Lookup::unlookup( + Keyring::Alice.id() + ), + transfer_amount * 2, + ) + ); - // Confirm that Alice's balance is initial balance - amount transferred - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - transfer_amount + assert_ok!( + pallet_xcm::Pallet::>::force_xcm_version( + as frame_system::Config>::RuntimeOrigin::root(), + Box::new(Location::new( + 0, + Junction::Parachain(T::FudgeHandle::PARA_ID), + )), + XCM_VERSION, + ) ); - // Verify that the amount transferred is now part of the sibling account here - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - transfer_amount + assert_ok!( + pallet_xcm::Pallet::>::reserve_transfer_assets( + RawOrigin::Signed(Keyring::Alice.into()).into(), + Box::new(Parachain(T::FudgeHandle::PARA_ID).into()), + Box::new( + Junction::AccountId32 { + network: None, + id: Keyring::Bob.into(), + } + .into() + ), + Box::new((Here, transfer_amount).into()), + 0 + ) ); }); env.pass(Blocks::ByNumber(2)); - env.sibling_state_mut(|| { - let current_balance = - orml_tokens::Pallet::::free_balance(air_in_sibling, &Keyring::Bob.into()); - - // Verify that Keyring::Bob now has (amount transferred - fee) - assert_eq!(current_balance, transfer_amount - fee(18)); - - // Sanity check for the actual amount Keyring::Bob ends up with - assert_eq!(current_balance, 4993570400000000000); - }); - } - - #[test_runtimes([altair])] - fn test_air_transfers_to_and_from_sibling() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(air(10))) - .storage(), - ); - - setup_xcm(&mut env); - - // In order to be able to transfer AIR from Sibling to Altair, we need to first - // send AIR from Altair to Sibling, or else it fails since it'd be like Sibling - // had minted AIR on their side. - transfer_air_to_sibling(&mut env); - - let alice_initial_balance = air(5); - let bob_initial_balance = air(5) - air_fee(); - let transfer_amount = air(1); - - // Note: This asset was registered in `transfer_air_to_sibling` - let air_in_sibling = CurrencyId::ForeignAsset(12); - - env.parachain_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - ); - }); - - env.sibling_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::PARA_ID - )), - 0 - ); - assert_eq!( - orml_tokens::Pallet::::free_balance(air_in_sibling, &Keyring::Bob.into()), - bob_initial_balance - ); - - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Bob.into()).into(), - air_in_sibling, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Alice.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Bobs's balance is initial balance - amount transferred - assert_eq!( - orml_tokens::Pallet::::free_balance(air_in_sibling, &Keyring::Bob.into()), - bob_initial_balance - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - // Verify that Keyring::Alice now has initial balance + amount transferred - fee - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance + transfer_amount - air_fee(), - ); - }); - } - - #[test_runtimes([altair])] - fn transfer_ausd_to_altair() { - let mut env = FudgeEnv::::default(); - - setup_xcm(&mut env); - - let alice_initial_balance = ausd(10); - let transfer_amount = ausd(7); - - env.sibling_state_mut(|| { - register_ausd::(); - - assert_ok!(orml_tokens::Pallet::::deposit( - AUSD_CURRENCY_ID, - &Keyring::Alice.into(), - alice_initial_balance - )); - - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - ¶chain_account(T::FudgeHandle::PARA_ID) - ), - 0 - ); - }); - - env.parachain_state_mut(|| { - register_ausd::(); - - assert_eq!( - orml_tokens::Pallet::::free_balance(AUSD_CURRENCY_ID, &Keyring::Bob.into()), - 0, - ); - }); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - &Keyring::Alice.into() - ), - ausd(10), - ); - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - AUSD_CURRENCY_ID, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - &Keyring::Alice.into() - ), - alice_initial_balance - transfer_amount - ); - - // Verify that the amount transferred is now part of the altair parachain - // account here - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - ¶chain_account(T::FudgeHandle::PARA_ID) - ), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - // Verify that Keyring::Bob now has initial balance + amount transferred - fee - assert_eq!( - orml_tokens::Pallet::::free_balance(AUSD_CURRENCY_ID, &Keyring::Bob.into()), - transfer_amount - ausd_fee() - ); - }); - } - - fn transfer_ksm_from_relay_chain( - env: &mut FudgeEnv, - transfer_amount: Balance, - currency_id: CurrencyId, - meta: AssetMetadata, - ) { - env.parachain_state_mut(|| { - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(currency_id), - )); - - assert_eq!( - orml_tokens::Pallet::::free_balance(currency_id, &Keyring::Bob.into()), - 0 - ); - }); - - env.relay_state_mut(|| { - assert_ok!( - pallet_balances::Pallet::>::force_set_balance( - as frame_system::Config>::RuntimeOrigin::root(), - as frame_system::Config>::Lookup::unlookup( - Keyring::Alice.id() - ), - transfer_amount * 2, - ) - ); - - assert_ok!( - pallet_xcm::Pallet::>::force_xcm_version( - as frame_system::Config>::RuntimeOrigin::root(), - Box::new(Location::new( - 0, - Junction::Parachain(T::FudgeHandle::PARA_ID), - )), - XCM_VERSION, - ) - ); - - assert_ok!( - pallet_xcm::Pallet::>::reserve_transfer_assets( - RawOrigin::Signed(Keyring::Alice.into()).into(), - Box::new(Parachain(T::FudgeHandle::PARA_ID).into()), - Box::new( - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - .into() - ), - Box::new((Here, transfer_amount).into()), - 0 - ) - ); - }); - - env.pass(Blocks::ByNumber(2)); - - env.parachain_state(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance(currency_id, &Keyring::Bob.into()), - 1991963000000 // Comes from `transfer_amount - fee(meta.decimals)` with noise - ); + env.parachain_state(|| { + assert_eq!( + orml_tokens::Pallet::::free_balance(currency_id, &Keyring::Bob.into()), + 1991963000000 // Comes from `transfer_amount - fee(meta.decimals)` with noise + ); }); } @@ -5686,114 +5195,6 @@ mod altair { ); }); } - - #[test_runtimes([altair])] - fn transfer_foreign_sibling_to_altair() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(air(10))) - .storage(), - ); - - setup_xcm(&mut env); - - let sibling_asset_id = CurrencyId::ForeignAsset(1); - let asset_location = Location::new( - 1, - [Parachain(T::FudgeHandle::SIBLING_ID), general_key(&[0, 1])], - ); - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(asset_location)), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(XcmMetadata { - // We specify a custom fee_per_second and verify below that this value is - // used when XCM transfer fees are charged for this token. - fee_per_second: Some(8420000000000000000), - }), - ..CustomMetadata::default() - }, - }; - let transfer_amount = foreign(1, meta.decimals); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance(sibling_asset_id, &Keyring::Bob.into()), - 0 - ); - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(CurrencyId::Native), - )); - }); - - env.parachain_state_mut(|| { - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(sibling_asset_id) - )); - }); - - env.sibling_state_mut(|| { - assert_ok!(pallet_balances::Pallet::::force_set_balance( - ::RuntimeOrigin::root(), - Keyring::Alice.to_account_id().into(), - transfer_amount * 2, - )); - - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - CurrencyId::Native, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Alice's balance is initial balance - amount transferred - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - let bob_balance = - orml_tokens::Pallet::::free_balance(sibling_asset_id, &Keyring::Bob.into()); - - // Verify that Keyring::Bob now has initial balance + amount transferred - fee - assert_eq!( - bob_balance, - transfer_amount - - calc_fee( - xcm_metadata(meta.additional.transferability) - .unwrap() - .fee_per_second - .unwrap() - ) - ); - // Sanity check to ensure the calculated is what is expected - assert_eq!(bob_balance, 993264000000000000); - }); - } } mod asset_registry { @@ -7364,292 +6765,11 @@ mod centrifuge { mod transfers { use super::*; + #[test_runtimes([centrifuge])] + fn transfer_dot_to_and_from_relay_chain() { + let mut env = FudgeEnv::::default(); - fn transfer_cfg_to_sibling(env: &mut FudgeEnv) { - let alice_initial_balance = cfg(10); - let transfer_amount = cfg(5); - let cfg_in_sibling = CurrencyId::ForeignAsset(12); - - // CFG Metadata - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - general_key(parachains::polkadot::centrifuge::CFG_KEY), - ], - ))), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; - - env.parachain_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - ); - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - 0 - ); - - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(CurrencyId::Native), - )); - }); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - 0 - ); - - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta, - Some(cfg_in_sibling) - )); - }); - - env.parachain_state_mut(|| { - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - CurrencyId::Native, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::SIBLING_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Alice's balance is initial balance - amount transferred - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - transfer_amount - ); - - // Verify that the amount transferred is now part of the sibling account here - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::SIBLING_ID - )), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(2)); - - env.sibling_state_mut(|| { - let current_balance = - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()); - - // Verify that Keyring::Bob now has (amount transferred - fee) - assert_eq!(current_balance, transfer_amount - fee(18)); - - // Sanity check for the actual amount Keyring::Bob ends up with - assert_eq!(current_balance, 4993570400000000000); - }); - } - - #[test_runtimes([centrifuge])] - fn test_cfg_transfers_to_and_from_sibling() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(10))) - .storage(), - ); - - setup_xcm(&mut env); - - // In order to be able to transfer CFG from Sibling to Centrifuge, we need to - // first send CFG from Centrifuge to Sibling, or else it fails since it'd be - // like Sibling had minted CFG on their side. - transfer_cfg_to_sibling(&mut env); - - let alice_initial_balance = cfg(5); - let bob_initial_balance = cfg(5) - cfg_fee(); - let transfer_amount = cfg(1); - // Note: This asset was registered in `transfer_cfg_to_sibling` - let cfg_in_sibling = CurrencyId::ForeignAsset(12); - - env.parachain_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance - ); - }); - - env.sibling_state_mut(|| { - assert_eq!( - pallet_balances::Pallet::::free_balance(¶chain_account( - T::FudgeHandle::PARA_ID - )), - 0 - ); - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - bob_initial_balance - ); - }); - - env.sibling_state_mut(|| { - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Bob.into()).into(), - cfg_in_sibling, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Alice.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Bobs's balance is initial balance - amount transferred - assert_eq!( - orml_tokens::Pallet::::free_balance(cfg_in_sibling, &Keyring::Bob.into()), - bob_initial_balance - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - // Verify that Keyring::Alice now has initial balance + amount transferred - fee - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - alice_initial_balance + transfer_amount - cfg_fee(), - ); - }); - } - - #[test_runtimes([centrifuge])] - fn transfer_ausd_to_centrifuge() { - let mut env = FudgeEnv::::default(); - - setup_xcm(&mut env); - - let alice_initial_balance = ausd(10); - let transfer_amount = ausd(7); - - env.sibling_state_mut(|| { - register_ausd::(); - - assert_ok!(orml_tokens::Pallet::::deposit( - AUSD_CURRENCY_ID, - &Keyring::Alice.into(), - alice_initial_balance - )); - - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - ¶chain_account(T::FudgeHandle::PARA_ID) - ), - 0 - ); - }); - - env.parachain_state_mut(|| { - register_ausd::(); - - assert_eq!( - orml_tokens::Pallet::::free_balance(AUSD_CURRENCY_ID, &Keyring::Bob.into()), - 0, - ); - }); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - &Keyring::Alice.into() - ), - ausd(10), - ); - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - AUSD_CURRENCY_ID, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - &Keyring::Alice.into() - ), - alice_initial_balance - transfer_amount - ); - - // Verify that the amount transferred is now part of the centrifuge parachain - // account here - assert_eq!( - orml_tokens::Pallet::::free_balance( - AUSD_CURRENCY_ID, - ¶chain_account(T::FudgeHandle::PARA_ID) - ), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - // Verify that Keyring::Bob now has initial balance + amount transferred - fee - assert_eq!( - orml_tokens::Pallet::::free_balance(AUSD_CURRENCY_ID, &Keyring::Bob.into()), - transfer_amount - ausd_fee() - ); - }); - } - - #[test_runtimes([centrifuge])] - fn transfer_dot_to_and_from_relay_chain() { - let mut env = FudgeEnv::::default(); - - transfer_dot_from_relay_chain(&mut env); + transfer_dot_from_relay_chain(&mut env); env.parachain_state_mut(|| { let alice_initial_dot = @@ -7695,114 +6815,5 @@ mod centrifuge { ); }); } - - #[test_runtimes([centrifuge])] - fn transfer_foreign_sibling_to_centrifuge() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(10))) - .storage(), - ); - - setup_xcm(&mut env); - - let sibling_asset_id = CurrencyId::ForeignAsset(1); - let asset_location = Location::new( - 1, - [Parachain(T::FudgeHandle::SIBLING_ID), general_key(&[0, 1])], - ); - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: BoundedVec::default(), - symbol: BoundedVec::default(), - existential_deposit: 1_000_000_000_000, - location: Some(VersionedLocation::V4(asset_location)), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(XcmMetadata { - // We specify a custom fee_per_second and verify below that this value is - // used when XCM transfer fees are charged for this token. - fee_per_second: Some(8420000000000000000), - }), - ..CustomMetadata::default() - }, - }; - let transfer_amount = foreign(1, meta.decimals); - - env.sibling_state_mut(|| { - assert_eq!( - orml_tokens::Pallet::::free_balance(sibling_asset_id, &Keyring::Bob.into()), - 0 - ); - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(CurrencyId::Native), - )); - }); - - env.parachain_state_mut(|| { - // First, register the asset in centrifuge - assert_ok!(orml_asset_registry::Pallet::::register_asset( - ::RuntimeOrigin::root(), - meta.clone(), - Some(sibling_asset_id) - )); - }); - - env.sibling_state_mut(|| { - assert_ok!(pallet_balances::Pallet::::force_set_balance( - ::RuntimeOrigin::root(), - Keyring::Alice.to_account_id().into(), - transfer_amount * 2, - )); - - assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - CurrencyId::Native, - transfer_amount, - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::PARA_ID), - Junction::AccountId32 { - network: None, - id: Keyring::Bob.into(), - } - ] - ) - .into() - ), - WeightLimit::Limited(8_000_000_000_000.into()), - )); - - // Confirm that Alice's balance is initial balance - amount transferred - assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - transfer_amount - ); - }); - - env.pass(Blocks::ByNumber(3)); - - env.parachain_state_mut(|| { - let bob_balance = - orml_tokens::Pallet::::free_balance(sibling_asset_id, &Keyring::Bob.into()); - - // Verify that Keyring::Bob now has initial balance + amount transferred - fee - assert_eq!( - bob_balance, - transfer_amount - - calc_fee( - xcm_metadata(meta.additional.transferability) - .unwrap() - .fee_per_second - .unwrap() - ) - ); - // Sanity check to ensure the calculated is what is expected - assert_eq!(bob_balance, 993264000000000000); - }); - } } } diff --git a/runtime/integration-tests/src/generic/cases/loans.rs b/runtime/integration-tests/src/generic/cases/loans.rs index e3e806ab42..4c506c77d1 100644 --- a/runtime/integration-tests/src/generic/cases/loans.rs +++ b/runtime/integration-tests/src/generic/cases/loans.rs @@ -76,7 +76,7 @@ mod common { .add(genesis::balances::( T::ExistentialDeposit::get() + FOR_FEES, )) - .add(genesis::assets::(vec![&Usd6])) + .add(genesis::assets::(vec![(Usd6.id(), &Usd6.metadata())])) .add(genesis::tokens::(vec![(Usd6.id(), Usd6.ed())])) .storage(), ); diff --git a/runtime/integration-tests/src/generic/cases/oracles.rs b/runtime/integration-tests/src/generic/cases/oracles.rs index 14124b582c..d194c50ea8 100644 --- a/runtime/integration-tests/src/generic/cases/oracles.rs +++ b/runtime/integration-tests/src/generic/cases/oracles.rs @@ -27,7 +27,7 @@ mod ratio_provider { config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, - utils::currency::{register_currency, CurrencyInfo, CONST_DEFAULT_CUSTOM}, + utils::currency::{register_currency, CurrencyInfo}, }; pub struct OtherLocal; @@ -40,7 +40,7 @@ mod ratio_provider { CustomMetadata { pool_currency: true, transferability: CrossChainTransferability::None, - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } @@ -55,7 +55,7 @@ mod ratio_provider { CustomMetadata { pool_currency: true, transferability: CrossChainTransferability::None, - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } @@ -71,7 +71,7 @@ mod ratio_provider { pool_currency: true, transferability: CrossChainTransferability::LiquidityPools, local_representation: Some(LocalAssetId(1)), - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } diff --git a/runtime/integration-tests/src/generic/cases/precompile.rs b/runtime/integration-tests/src/generic/cases/precompile.rs index 269e1a1d97..aed0baa6eb 100644 --- a/runtime/integration-tests/src/generic/cases/precompile.rs +++ b/runtime/integration-tests/src/generic/cases/precompile.rs @@ -30,7 +30,7 @@ use crate::generic::{ fn axelar_precompile_execute() { RuntimeEnv::::from_parachain_storage( Genesis::default() - .add(genesis::assets::(vec![&Usd18])) + .add(genesis::assets::([(Usd18.id(), &Usd18.metadata())])) .storage(), ) .parachain_state_mut(|| { diff --git a/runtime/integration-tests/src/generic/cases/xtransfers.rs b/runtime/integration-tests/src/generic/cases/xtransfers.rs index fb67216afe..8886640755 100644 --- a/runtime/integration-tests/src/generic/cases/xtransfers.rs +++ b/runtime/integration-tests/src/generic/cases/xtransfers.rs @@ -1,10 +1,7 @@ -use cfg_types::tokens::{CrossChainTransferability, CurrencyId, CustomMetadata}; +use cfg_types::tokens::CurrencyId; use frame_support::{assert_ok, dispatch::RawOrigin}; use orml_traits::MultiCurrency; -use staging_xcm::{ - v4::{Junction, Junction::*, Location, WeightLimit}, - VersionedLocation, -}; +use staging_xcm::v4::WeightLimit; use crate::{ generic::{ @@ -15,50 +12,70 @@ use crate::{ currency::{cfg, CurrencyInfo, CustomCurrency}, genesis, genesis::Genesis, - xcm::setup_xcm, + xcm::{account_location, setup_xcm, transferable_metadata}, }, }, utils::accounts::Keyring, }; -fn bob_in_sibling() -> Box { - Box::new( - Location::new( - 1, - [ - Parachain(T::FudgeHandle::SIBLING_ID), - Junction::from(Keyring::Bob.bytes()), - ], - ) - .into(), - ) -} +const INITIAL: u32 = 100; +const TRANSFER: u32 = 80; #[test_runtimes(all)] -fn transfer_native_tokens_to_sibling() { - let native_curr = CustomCurrency { - id: CurrencyId::Native, - decimals: 18, - location: Location::new(1, Parachain(T::FudgeHandle::PARA_ID)), - custom: CustomMetadata { - transferability: CrossChainTransferability::xcm_with_fees(0), - ..Default::default() - }, - }; +fn foreign_to_foreign_tokens() { + let curr = CustomCurrency(CurrencyId::ForeignAsset(1), transferable_metadata::(6)); + + let mut env = FudgeEnv::::from_storage( + Default::default(), + Genesis::default() + .add(genesis::tokens::([(curr.id(), curr.val(INITIAL))])) + .add(genesis::assets::([(curr.id(), &curr.metadata())])) + .storage(), + Genesis::default() + .add(genesis::assets::([(curr.id(), &curr.metadata())])) + .storage(), + ); + + setup_xcm(&mut env); + + env.parachain_state_mut(|| { + assert_ok!(orml_xtokens::Pallet::::transfer( + RawOrigin::Signed(Keyring::Alice.id()).into(), + curr.id(), + curr.val(TRANSFER), + account_location(Keyring::Bob.id(), T::FudgeHandle::SIBLING_ID), + WeightLimit::Unlimited, + )); - let xnative_curr = CustomCurrency { - id: CurrencyId::ForeignAsset(99), - ..native_curr.clone() - }; + assert_eq!( + orml_tokens::Pallet::::free_balance(curr.id(), &Keyring::Alice.id()), + curr.val(INITIAL) - curr.val(TRANSFER) + ); + }); + + env.pass(Blocks::ByNumber(2)); + + env.sibling_state_mut(|| { + assert_eq!( + orml_tokens::Pallet::::free_balance(curr.id(), &Keyring::Bob.id()), + curr.val(TRANSFER) + ); + }); +} + +#[test_runtimes(all)] +fn native_to_foreign_tokens() { + let metadata = transferable_metadata::(18); + let xnative = CustomCurrency(CurrencyId::ForeignAsset(1), metadata.clone()); let mut env = FudgeEnv::::from_storage( Default::default(), Genesis::default() - .add(genesis::balances::(cfg(100))) - .add(genesis::assets::(vec![&native_curr])) + .add(genesis::balances::(cfg(INITIAL))) + .add(genesis::assets::([(CurrencyId::Native, &metadata)])) .storage(), Genesis::default() - .add(genesis::assets::(vec![&xnative_curr])) + .add(genesis::assets::([(xnative.id(), &metadata)])) .storage(), ); @@ -66,16 +83,16 @@ fn transfer_native_tokens_to_sibling() { env.parachain_state_mut(|| { assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), + RawOrigin::Signed(Keyring::Alice.id()).into(), CurrencyId::Native, - cfg(80), - bob_in_sibling::(), + cfg(TRANSFER), + account_location(Keyring::Bob.id(), T::FudgeHandle::SIBLING_ID), WeightLimit::Unlimited, )); assert_eq!( - pallet_balances::Pallet::::free_balance(&Keyring::Alice.into()), - cfg(100) - cfg(80) + pallet_balances::Pallet::::free_balance(&Keyring::Alice.id()), + cfg(INITIAL) - cfg(TRANSFER) ); }); @@ -83,32 +100,25 @@ fn transfer_native_tokens_to_sibling() { env.sibling_state_mut(|| { assert_eq!( - orml_tokens::Pallet::::free_balance(xnative_curr.id(), &Keyring::Bob.into()), - xnative_curr.val(80) + orml_tokens::Pallet::::free_balance(xnative.id(), &Keyring::Bob.id()), + xnative.val(TRANSFER) ); }); } #[test_runtimes(all)] -fn transfer_foreign_tokens_to_sibling() { - let curr = CustomCurrency { - id: 1.into(), - decimals: 6, - location: Location::new(1, Parachain(T::FudgeHandle::PARA_ID)), - custom: CustomMetadata { - transferability: CrossChainTransferability::xcm_with_fees(0), - ..Default::default() - }, - }; +fn foreign_to_native_tokens() { + let metadata = transferable_metadata::(18); + let xnative = CustomCurrency(CurrencyId::ForeignAsset(1), metadata.clone()); let mut env = FudgeEnv::::from_storage( Default::default(), Genesis::default() - .add(genesis::tokens::(vec![(curr.id(), curr.val(100))])) - .add(genesis::assets::(vec![&curr])) + .add(genesis::tokens::([(xnative.id(), xnative.val(INITIAL))])) + .add(genesis::assets::([(xnative.id(), &metadata)])) .storage(), Genesis::default() - .add(genesis::assets::(vec![&curr])) + .add(genesis::assets::([(CurrencyId::Native, &metadata)])) .storage(), ); @@ -116,16 +126,16 @@ fn transfer_foreign_tokens_to_sibling() { env.parachain_state_mut(|| { assert_ok!(orml_xtokens::Pallet::::transfer( - RawOrigin::Signed(Keyring::Alice.into()).into(), - curr.id(), - curr.val(80), - bob_in_sibling::(), + RawOrigin::Signed(Keyring::Alice.id()).into(), + xnative.id(), + xnative.val(TRANSFER), + account_location(Keyring::Bob.id(), T::FudgeHandle::SIBLING_ID), WeightLimit::Unlimited, )); assert_eq!( - orml_tokens::Pallet::::free_balance(curr.id(), &Keyring::Alice.id()), - curr.val(100) - curr.val(80) + orml_tokens::Pallet::::free_balance(xnative.id(), &Keyring::Bob.id()), + xnative.val(INITIAL) - xnative.val(TRANSFER) ); }); @@ -133,8 +143,8 @@ fn transfer_foreign_tokens_to_sibling() { env.sibling_state_mut(|| { assert_eq!( - orml_tokens::Pallet::::free_balance(curr.id(), &Keyring::Bob.id()), - curr.val(80) + pallet_balances::Pallet::::free_balance(&Keyring::Alice.id()), + cfg(TRANSFER) ); }); } diff --git a/runtime/integration-tests/src/generic/utils/currency.rs b/runtime/integration-tests/src/generic/utils/currency.rs index ef3cf786c3..f0b6c027f7 100644 --- a/runtime/integration-tests/src/generic/utils/currency.rs +++ b/runtime/integration-tests/src/generic/utils/currency.rs @@ -1,28 +1,31 @@ //! PLEASE be as much generic as possible because no domain or use cases are //! considered at this level. -use cfg_primitives::{conversion, Balance, CFG}; -use cfg_types::tokens::{AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata}; +use cfg_primitives::{conversion, Balance}; +use cfg_types::tokens::{AssetMetadata, CurrencyId, CustomMetadata}; use frame_support::{assert_ok, traits::OriginTrait}; use sp_runtime::FixedPointNumber; -use staging_xcm::{v4::Location, VersionedLocation}; +use staging_xcm::VersionedLocation; use crate::generic::config::Runtime; -pub const fn amount6(amount: Balance) -> Balance { - amount * 10u128.pow(6) -} - -pub const fn amount12(amount: Balance) -> Balance { - amount * 10u128.pow(12) +pub fn default_metadata() -> AssetMetadata { + AssetMetadata { + decimals: 0, + name: Default::default(), + symbol: Default::default(), + existential_deposit: 0, + location: None, + additional: Default::default(), + } } -pub const fn amount18(amount: Balance) -> Balance { - amount * 10u128.pow(18) +const fn amount_pow(amount: Balance, exp: u32) -> Balance { + amount * 10u128.pow(exp) } -pub const fn cfg(amount: Balance) -> Balance { - amount * CFG +pub const fn cfg(amount: u32) -> Balance { + amount_pow(amount as Balance, 18) } pub trait CurrencyInfo { @@ -66,15 +69,6 @@ pub trait CurrencyInfo { } } -/// Matches default() but for const support -pub const CONST_DEFAULT_CUSTOM: CustomMetadata = CustomMetadata { - transferability: CrossChainTransferability::None, - mintable: false, - permissioned: false, - pool_currency: false, - local_representation: None, -}; - pub fn price_to_currency>( price: N, currency_id: impl CurrencyInfo, @@ -99,13 +93,13 @@ impl CurrencyInfo for Usd6 { fn custom(&self) -> CustomMetadata { CustomMetadata { pool_currency: true, - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } pub const fn usd6(amount: Balance) -> Balance { - amount6(amount) + amount_pow(amount, 6) } pub struct Usd12; @@ -125,13 +119,13 @@ impl CurrencyInfo for Usd12 { fn custom(&self) -> CustomMetadata { CustomMetadata { pool_currency: true, - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } pub const fn usd12(amount: Balance) -> Balance { - amount12(amount) + amount_pow(amount, 12) } pub struct Usd18; @@ -151,30 +145,24 @@ impl CurrencyInfo for Usd18 { fn custom(&self) -> CustomMetadata { CustomMetadata { pool_currency: true, - ..CONST_DEFAULT_CUSTOM + ..Default::default() } } } pub const fn usd18(amount: Balance) -> Balance { - amount18(amount) + amount_pow(amount, 18) } #[derive(Clone)] -pub struct CustomCurrency { - pub id: CurrencyId, - pub decimals: u32, - pub location: Location, - pub custom: CustomMetadata, -} - +pub struct CustomCurrency(pub CurrencyId, pub AssetMetadata); impl CurrencyInfo for CustomCurrency { fn id(&self) -> CurrencyId { - self.id + self.0 } fn decimals(&self) -> u32 { - self.decimals + self.1.decimals } fn symbol(&self) -> &'static str { @@ -182,17 +170,17 @@ impl CurrencyInfo for CustomCurrency { } fn location(&self) -> Option { - Some(VersionedLocation::V4(self.location.clone())) + self.1.location.clone() } fn custom(&self) -> CustomMetadata { - self.custom + self.1.additional } } impl CustomCurrency { - pub const fn val(&self, amount: Balance) -> Balance { - amount * 10u128.pow(self.decimals) + pub const fn val(&self, amount: u32) -> Balance { + amount_pow(amount as Balance, self.1.decimals) } } diff --git a/runtime/integration-tests/src/generic/utils/genesis.rs b/runtime/integration-tests/src/generic/utils/genesis.rs index b26691e1ef..a87b470184 100644 --- a/runtime/integration-tests/src/generic/utils/genesis.rs +++ b/runtime/integration-tests/src/generic/utils/genesis.rs @@ -2,13 +2,16 @@ //! considered at this level. use cfg_primitives::Balance; -use cfg_types::{fixed_point::Rate, tokens::CurrencyId}; +use cfg_types::{ + fixed_point::Rate, + tokens::{AssetMetadata, CurrencyId}, +}; use parity_scale_codec::Encode; use sp_core::Get; use sp_runtime::{BuildStorage, FixedPointNumber, Storage}; use crate::{ - generic::{config::Runtime, utils::currency::CurrencyInfo}, + generic::config::Runtime, utils::accounts::{default_accounts, Keyring}, }; @@ -37,7 +40,9 @@ pub fn balances(balance: Balance) -> impl BuildStorage { } } -pub fn tokens(values: Vec<(CurrencyId, Balance)>) -> impl BuildStorage { +pub fn tokens( + values: impl IntoIterator + Clone, +) -> impl BuildStorage { orml_tokens::GenesisConfig:: { balances: default_accounts() .into_iter() @@ -53,24 +58,30 @@ pub fn tokens(values: Vec<(CurrencyId, Balance)>) -> impl BuildStora } } -pub fn assets(currency_ids: Vec<&dyn CurrencyInfo>) -> impl BuildStorage { +pub fn assets<'a, T: Runtime>( + currency_ids: impl IntoIterator, +) -> impl BuildStorage { orml_asset_registry::module::GenesisConfig:: { assets: currency_ids .into_iter() - .map(|currency_id| (currency_id.id(), currency_id.metadata().encode())) + .map(|(currency_id, metadata)| (currency_id, metadata.encode())) .collect(), last_asset_id: Default::default(), // It seems deprecated } } -pub fn council_members(members: Vec) -> impl BuildStorage { +pub fn council_members( + members: impl IntoIterator, +) -> impl BuildStorage { pallet_collective::GenesisConfig:: { phantom: Default::default(), members: members.into_iter().map(|acc| acc.id()).collect(), } } -pub fn invulnerables(invulnerables: Vec) -> impl BuildStorage { +pub fn invulnerables( + invulnerables: impl IntoIterator, +) -> impl BuildStorage { pallet_collator_selection::GenesisConfig:: { invulnerables: invulnerables.into_iter().map(|acc| acc.id()).collect(), candidacy_bond: cfg_primitives::MILLI_CFG, @@ -87,7 +98,9 @@ pub fn session_keys() -> impl BuildStorage { } } -pub fn block_rewards(collators: Vec) -> impl BuildStorage { +pub fn block_rewards( + collators: impl IntoIterator, +) -> impl BuildStorage { pallet_block_rewards::GenesisConfig:: { collators: collators.into_iter().map(|acc| acc.id()).collect(), collator_reward: (1000 * cfg_primitives::CFG).into(), diff --git a/runtime/integration-tests/src/generic/utils/xcm.rs b/runtime/integration-tests/src/generic/utils/xcm.rs index 97c788071b..cc8e270f2e 100644 --- a/runtime/integration-tests/src/generic/utils/xcm.rs +++ b/runtime/integration-tests/src/generic/utils/xcm.rs @@ -1,14 +1,18 @@ +use cfg_primitives::AccountId; +use cfg_types::tokens::{AssetMetadata, CrossChainTransferability, CustomMetadata}; use frame_support::{assert_ok, traits::OriginTrait}; use polkadot_parachain_primitives::primitives::Id; use staging_xcm::{ prelude::XCM_VERSION, v4::{Junction, Location}, + VersionedLocation, }; use crate::generic::{ config::Runtime, env::{Blocks, Env}, envs::fudge_env::{handle::FudgeHandle, FudgeEnv, FudgeRelayRuntime, FudgeSupport}, + utils::currency::default_metadata, }; pub fn setup_xcm(env: &mut FudgeEnv) { @@ -67,3 +71,31 @@ pub fn setup_xcm(env: &mut FudgeEnv) { env.pass(Blocks::ByNumber(1)); } + +pub fn account_location(account_id: AccountId, para_id: u32) -> Box { + Box::new( + Location::new( + 1, + [ + Junction::Parachain(para_id), + Junction::AccountId32 { + network: None, + id: account_id.into(), + }, + ], + ) + .into(), + ) +} + +pub fn transferable_metadata(decimals: u32) -> AssetMetadata { + AssetMetadata { + decimals, + location: Some(Location::new(1, Junction::Parachain(T::FudgeHandle::PARA_ID)).into()), + additional: CustomMetadata { + transferability: CrossChainTransferability::xcm_with_fees(0), + ..Default::default() + }, + ..default_metadata() + } +} diff --git a/runtime/integration-tests/src/utils/accounts.rs b/runtime/integration-tests/src/utils/accounts.rs index 463e962f58..0b38d5f9de 100644 --- a/runtime/integration-tests/src/utils/accounts.rs +++ b/runtime/integration-tests/src/utils/accounts.rs @@ -40,10 +40,6 @@ impl Keyring { self.to_account_id() } - pub fn bytes(self) -> [u8; 32] { - self.public().0 - } - pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) }