From 535ca7490119b473ea9347bdff07d56bdd827be3 Mon Sep 17 00:00:00 2001 From: cdamian <17934949+cdamian@users.noreply.github.com> Date: Fri, 27 Oct 2023 21:05:57 +0200 Subject: [PATCH] integration-tests: Use fudge in development LP tests --- .../pallet/development/setup.rs | 4 +- .../liquidity_pools/add_allow_upgrade.rs | 310 +++++---- .../liquidity_pools/foreign_investments.rs | 596 +++++++++++------- .../development/tests/liquidity_pools/mod.rs | 2 +- .../tests/liquidity_pools/setup.rs | 98 ++- .../tests/liquidity_pools/transfers.rs | 128 ++-- .../development/tests/routers/ethereum_xcm.rs | 96 +-- .../pallet/development/transfers.rs | 213 +++++-- runtime/integration-tests/src/utils/env.rs | 216 ++++--- runtime/integration-tests/src/utils/logs.rs | 9 +- 10 files changed, 1047 insertions(+), 625 deletions(-) diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs index 4530a5807c..e5429ffcd4 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/setup.rs @@ -16,6 +16,8 @@ use cfg_types::{domain_address::Domain, tokens::CustomMetadata}; use frame_support::traits::GenesisBuild; use orml_traits::asset_registry::AssetMetadata; +use crate::utils::env::PARA_ID_SIBLING; + /// Accounts pub const ALICE: [u8; 32] = [4u8; 32]; pub const BOB: [u8; 32] = [5u8; 32]; @@ -110,7 +112,7 @@ pub fn dollar(decimals: u32) -> Balance { } pub fn moonbeam_account() -> AccountId { - parachain_account(PARA_ID_MOONBEAM) + parachain_account(PARA_ID_SIBLING) } pub fn centrifuge_account() -> AccountId { diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs index 5b3f4971b6..9b0718da0b 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/add_allow_upgrade.rs @@ -36,33 +36,51 @@ use cfg_types::{ ForeignAssetId, }, }; -use development_runtime::{ - LiquidityPools, LocationToAccountId, OrderBook, OrmlAssetRegistry, OrmlTokens, Permissions, - Runtime as DevelopmentRuntime, RuntimeOrigin, System, TreasuryAccount, XTokens, XcmTransactor, -}; +use codec::Encode; use frame_support::{assert_noop, assert_ok, traits::fungibles::Mutate}; +use fudge::primitives::{Chain, PoolState}; use orml_traits::{asset_registry::AssetMetadata, FixedConversionRateProvider, MultiCurrency}; +use polkadot_parachain::primitives::Id; use runtime_common::account_conversion::AccountConverter; use sp_runtime::{ traits::{BadOrigin, Convert, One, Zero}, - BoundedVec, DispatchError, + BoundedVec, DispatchError, Storage, +}; +use tokio::runtime::Handle; +use xcm::{ + latest::MultiLocation, + prelude::XCM_VERSION, + v3::{Junction, Junctions}, + VersionedMultiLocation, }; -use xcm::{latest::MultiLocation, VersionedMultiLocation}; use xcm_simulator::TestExt; use crate::{ + chain::{ + centrifuge::{ + LiquidityPools, LocationToAccountId, OrderBook, OrmlAssetRegistry, OrmlTokens, + Permissions, Runtime as DevelopmentRuntime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + System, TreasuryAccount, XTokens, XcmTransactor, PARA_ID, + }, + relay::{Runtime as RelayRuntime, RuntimeOrigin as RelayRuntimeOrigin}, + }, liquidity_pools::pallet::development::{ - setup::{dollar, ALICE, BOB}, + setup::dollar, test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::setup::{ asset_metadata, create_ausd_pool, create_currency_pool, enable_liquidity_pool_transferability, get_default_moonbeam_native_token_location, investments::default_tranche_id, liquidity_pools_transferable_multilocation, - setup_pre_requirements, DEFAULT_BALANCE_GLMR, DEFAULT_MOONBEAM_LOCATION, - DEFAULT_POOL_ID, DEFAULT_VALIDITY, + setup_pre_requirements, setup_test_env, DEFAULT_BALANCE_GLMR, DEFAULT_POOL_ID, + DEFAULT_SIBLING_LOCATION, DEFAULT_VALIDITY, }, }, - utils::{AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID}, + utils::{ + accounts::Keyring, + env, + env::{ChainState, EventRange, PARA_ID_SIBLING}, + genesis, AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID, + }, }; /// NOTE: We can't actually verify that the messages hits the @@ -76,17 +94,23 @@ use crate::{ /// be executed on Moonbeam. /// Verify that `LiquidityPools::add_pool` succeeds when called with all the /// necessary requirements. -#[test] -fn add_pool() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn add_pool() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; // Verify that the pool must exist before we can call LiquidityPools::add_pool assert_noop!( LiquidityPools::add_pool( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), ), @@ -99,7 +123,7 @@ fn add_pool() { // Verify ALICE can't call `add_pool` given she is not the `PoolAdmin` assert_noop!( LiquidityPools::add_pool( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), ), @@ -108,7 +132,7 @@ fn add_pool() { // Verify that it works if it's BOB calling it (the pool admin) assert_ok!(LiquidityPools::add_pool( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), )); @@ -121,13 +145,17 @@ fn add_pool() { /// heavy e2e setup to emulate. Instead, here we test that we can send the /// extrinsic and we have other unit tests verifying the encoding of the remote /// EVM call to be executed on Moonbeam. -#[test] -fn add_tranche() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); - let decimals: u8 = 15; +#[tokio::test] +async fn add_tranche() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { // Now create the pool let pool_id = DEFAULT_POOL_ID; create_ausd_pool(pool_id); @@ -137,7 +165,7 @@ fn add_tranche() { let nonexistent_tranche = [71u8; 16]; assert_noop!( LiquidityPools::add_tranche( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, nonexistent_tranche, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -149,7 +177,7 @@ fn add_tranche() { // Verify ALICE can't call `add_tranche` given she is not the `PoolAdmin` assert_noop!( LiquidityPools::add_tranche( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -160,7 +188,7 @@ fn add_tranche() { // Finally, verify we can call LiquidityPools::add_tranche successfully // when called by the PoolAdmin with the right pool + tranche id pair. assert_ok!(LiquidityPools::add_tranche( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -171,7 +199,7 @@ fn add_tranche() { orml_asset_registry::Metadata::::remove(tranche_currency_id); assert_noop!( LiquidityPools::update_tranche_token_metadata( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -181,15 +209,22 @@ fn add_tranche() { }); } -#[test] -fn update_member() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn update_member() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + env.with_mut_state(Chain::Para(PARA_ID), || { // Now create the pool let pool_id = DEFAULT_POOL_ID; + create_ausd_pool(pool_id); + let tranche_id = default_tranche_id(pool_id); // Finally, verify we can call LiquidityPools::add_tranche successfully @@ -201,7 +236,7 @@ fn update_member() { assert_ok!(Permissions::add( RuntimeOrigin::root(), Role::PoolRole(PoolRole::PoolAdmin), - ALICE.into(), + Keyring::Alice.into(), PermissionScope::Pool(pool_id), Role::PoolRole(PoolRole::InvestorAdmin), )); @@ -209,7 +244,7 @@ fn update_member() { // Verify it fails if the destination is not whitelisted yet assert_noop!( LiquidityPools::update_member( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, tranche_id, new_member.clone(), @@ -220,7 +255,7 @@ fn update_member() { // Whitelist destination as TrancheInvestor of this Pool assert_ok!(Permissions::add( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), Role::PoolRole(PoolRole::InvestorAdmin), AccountConverter::::convert( new_member.clone() @@ -243,7 +278,7 @@ fn update_member() { // Verify it now works assert_ok!(LiquidityPools::update_member( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, tranche_id, new_member, @@ -254,7 +289,7 @@ fn update_member() { // beforehand assert_noop!( LiquidityPools::update_member( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, tranche_id, DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [9; 20]), @@ -265,19 +300,26 @@ fn update_member() { }); } -#[test] -fn update_token_price() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); - let decimals: u8 = 15; +#[tokio::test] +async fn update_token_price() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let currency_id = AUSD_CURRENCY_ID; let pool_id = DEFAULT_POOL_ID; - create_ausd_pool(pool_id); + enable_liquidity_pool_transferability(currency_id); + create_ausd_pool(pool_id); + assert_ok!(LiquidityPools::update_token_price( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), currency_id, @@ -286,69 +328,79 @@ fn update_token_price() { }); } -#[test] -fn add_currency() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn add_currency() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_state(Chain::Para(PARA_ID), || { + let gateway_sender = + ::Sender::get(); let currency_id = AUSD_CURRENCY_ID; - // Enable LiquidityPools transferability enable_liquidity_pool_transferability(currency_id); assert_eq!( - OrmlTokens::free_balance( - GLMR_CURRENCY_ID, - &::Sender::get() - ), + OrmlTokens::free_balance(GLMR_CURRENCY_ID, &gateway_sender), DEFAULT_BALANCE_GLMR ); assert_ok!(LiquidityPools::add_currency( - RuntimeOrigin::signed(BOB.into()), - currency_id + RuntimeOrigin::signed(Keyring::Bob.into()), + currency_id, )); assert_eq!( - OrmlTokens::free_balance( - GLMR_CURRENCY_ID, - &::Sender::get() - ), + OrmlTokens::free_balance(GLMR_CURRENCY_ID, &gateway_sender), /// Ensure it only charged the 0.2 GLMR of fee DEFAULT_BALANCE_GLMR - dollar(18).saturating_div(5) ); - }); + }) + .unwrap(); } -#[test] -fn add_currency_should_fail() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn add_currency_should_fail() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + env.with_mut_state(Chain::Para(PARA_ID), || { assert_noop!( LiquidityPools::add_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), CurrencyId::ForeignAsset(42) ), pallet_liquidity_pools::Error::::AssetNotFound ); assert_noop!( - LiquidityPools::add_currency(RuntimeOrigin::signed(BOB.into()), CurrencyId::Native), + LiquidityPools::add_currency( + RuntimeOrigin::signed(Keyring::Bob.into()), + CurrencyId::Native + ), pallet_liquidity_pools::Error::::AssetNotFound ); assert_noop!( LiquidityPools::add_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), CurrencyId::Staking(cfg_types::tokens::StakingCurrency::BlockRewards) ), pallet_liquidity_pools::Error::::AssetNotFound ); assert_noop!( LiquidityPools::add_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), CurrencyId::Staking(cfg_types::tokens::StakingCurrency::BlockRewards) ), pallet_liquidity_pools::Error::::AssetNotFound @@ -370,7 +422,7 @@ fn add_currency_should_fail() { Some(currency_id) )); assert_noop!( - LiquidityPools::add_currency(RuntimeOrigin::signed(BOB.into()), currency_id), + LiquidityPools::add_currency(RuntimeOrigin::signed(Keyring::Bob.into()), currency_id), pallet_liquidity_pools::Error::::AssetNotLiquidityPoolsWrappedToken ); @@ -397,7 +449,7 @@ fn add_currency_should_fail() { }), )); assert_noop!( - LiquidityPools::add_currency(RuntimeOrigin::signed(BOB.into()), currency_id), + LiquidityPools::add_currency(RuntimeOrigin::signed(Keyring::Bob.into()), currency_id), pallet_liquidity_pools::Error::::AssetNotLiquidityPoolsTransferable ); @@ -419,18 +471,23 @@ fn add_currency_should_fail() { }) )); assert_noop!( - LiquidityPools::add_currency(RuntimeOrigin::signed(BOB.into()), currency_id), + LiquidityPools::add_currency(RuntimeOrigin::signed(Keyring::Bob.into()), currency_id), pallet_liquidity_pools::Error::::AssetNotLiquidityPoolsTransferable ); }); } -#[test] -fn allow_investment_currency() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn allow_investment_currency() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let currency_id = AUSD_CURRENCY_ID; let pool_id = DEFAULT_POOL_ID; let evm_chain_id: u64 = MOONBEAM_EVM_CHAIN_ID; @@ -439,6 +496,8 @@ fn allow_investment_currency() { // Create an AUSD pool create_ausd_pool(pool_id); + enable_liquidity_pool_transferability(currency_id); + // Enable LiquidityPools transferability assert_ok!(OrmlAssetRegistry::update_asset( RuntimeOrigin::root(), @@ -462,7 +521,7 @@ fn allow_investment_currency() { )); assert_ok!(LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), currency_id, @@ -470,20 +529,25 @@ fn allow_investment_currency() { }); } -#[test] -fn allow_pool_should_fail() { - TestNet::reset(); +#[tokio::test] +async fn allow_pool_should_fail() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); - Development::execute_with(|| { + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let currency_id = CurrencyId::ForeignAsset(42); let ausd_currency_id = AUSD_CURRENCY_ID; - setup_pre_requirements(); // Should fail if pool does not exist assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, // Tranche id is arbitrary in this case as pool does not exist [0u8; 16], @@ -510,10 +574,9 @@ fn allow_pool_should_fail() { create_currency_pool(pool_id, currency_id, 10_000 * dollar(12)); // Should fail if asset is not payment currency - assert!(currency_id != ausd_currency_id); assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), ausd_currency_id, @@ -532,7 +595,7 @@ fn allow_pool_should_fail() { enable_liquidity_pool_transferability(ausd_currency_id); assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), ausd_currency_id, @@ -560,7 +623,7 @@ fn allow_pool_should_fail() { )); assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), currency_id, @@ -588,7 +651,7 @@ fn allow_pool_should_fail() { )); assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), currency_id, @@ -612,7 +675,7 @@ fn allow_pool_should_fail() { )); assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, default_tranche_id(pool_id), currency_id, @@ -638,7 +701,7 @@ fn allow_pool_should_fail() { // Should fail if currency is not foreign asset assert_noop!( LiquidityPools::allow_investment_currency( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id + 1, // Tranche id is arbitrary in this case, so we don't need to check for the exact // pool_id @@ -650,16 +713,21 @@ fn allow_pool_should_fail() { }); } -#[test] -fn schedule_upgrade() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn schedule_upgrade() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { // Only Root can call `schedule_upgrade` assert_noop!( LiquidityPools::schedule_upgrade( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), MOONBEAM_EVM_CHAIN_ID, [7; 20] ), @@ -675,16 +743,21 @@ fn schedule_upgrade() { }); } -#[test] -fn cancel_upgrade_upgrade() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn cancel_upgrade_upgrade() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + env.with_mut_state(Chain::Para(PARA_ID), || { // Only Root can call `cancel_upgrade` assert_noop!( LiquidityPools::cancel_upgrade( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), MOONBEAM_EVM_CHAIN_ID, [7; 20] ), @@ -700,12 +773,17 @@ fn cancel_upgrade_upgrade() { }); } -#[test] -fn update_tranche_token_metadata() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); - let decimals: u8 = 15; +#[tokio::test] +async fn update_tranche_token_metadata() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; // NOTE: Default pool admin is BOB create_ausd_pool(pool_id); @@ -714,7 +792,7 @@ fn update_tranche_token_metadata() { let nonexistent_tranche = [71u8; 16]; assert_noop!( LiquidityPools::update_tranche_token_metadata( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, nonexistent_tranche, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -726,7 +804,7 @@ fn update_tranche_token_metadata() { // Should throw if called by anything but `PoolAdmin` assert_noop!( LiquidityPools::update_tranche_token_metadata( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -735,7 +813,7 @@ fn update_tranche_token_metadata() { ); assert_ok!(LiquidityPools::update_tranche_token_metadata( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), @@ -746,7 +824,7 @@ fn update_tranche_token_metadata() { orml_asset_registry::Metadata::::remove(tranche_currency_id); assert_noop!( LiquidityPools::update_tranche_token_metadata( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), pool_id, tranche_id, Domain::EVM(MOONBEAM_EVM_CHAIN_ID), diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs index f7ce99e4b7..ce0247150d 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/foreign_investments.rs @@ -40,11 +40,6 @@ use cfg_types::{ ForeignAssetId, }, }; -use development_runtime::{ - Balances, ForeignInvestments, Investments, LiquidityPools, LocationToAccountId, - OrmlAssetRegistry, Permissions, PoolSystem, Runtime as DevelopmentRuntime, RuntimeOrigin, - System, Tokens, -}; use frame_support::{ assert_noop, assert_ok, traits::{ @@ -52,6 +47,7 @@ use frame_support::{ Get, PalletInfo, }, }; +use fudge::primitives::Chain; use orml_traits::{asset_registry::AssetMetadata, FixedConversionRateProvider, MultiCurrency}; use pallet_foreign_investments::{ types::{InvestState, RedeemState}, @@ -64,13 +60,20 @@ use runtime_common::{ }; use sp_runtime::{ traits::{AccountIdConversion, BadOrigin, ConstU32, Convert, EnsureAdd, One, Zero}, - BoundedVec, DispatchError, FixedPointNumber, Perquintill, SaturatedConversion, WeakBoundedVec, + BoundedVec, DispatchError, FixedPointNumber, Perquintill, SaturatedConversion, Storage, + WeakBoundedVec, }; +use tokio::runtime::Handle; use xcm_simulator::TestExt; use crate::{ + chain::centrifuge::{ + Balances, ForeignInvestments, Investments, LiquidityPools, LocationToAccountId, + OrmlAssetRegistry, Permissions, PoolSystem, Runtime as DevelopmentRuntime, RuntimeOrigin, + System, Tokens, PARA_ID, + }, liquidity_pools::pallet::development::{ - setup::{dollar, ALICE, BOB}, + setup::dollar, test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::{ foreign_investments::setup::{ @@ -83,12 +86,12 @@ use crate::{ default_investment_account, default_investment_id, default_tranche_id, general_currency_index, investment_id, }, - setup_pre_requirements, LiquidityPoolMessage, DEFAULT_DOMAIN_ADDRESS_MOONBEAM, + setup_test_env, LiquidityPoolMessage, DEFAULT_DOMAIN_ADDRESS_MOONBEAM, DEFAULT_POOL_ID, DEFAULT_VALIDITY, DOMAIN_MOONBEAM, }, }, }, - utils::AUSD_CURRENCY_ID, + utils::{accounts::Keyring, env, genesis, AUSD_CURRENCY_ID}, }; mod same_currencies { @@ -96,17 +99,23 @@ mod same_currencies { use super::*; - #[test] - fn increase_invest_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn increase_invest_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -144,11 +153,17 @@ mod same_currencies { }); } - #[test] - fn decrease_invest_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn decrease_invest_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let invest_amount: u128 = 100_000_000; let decrease_amount = invest_amount / 3; @@ -156,7 +171,7 @@ mod same_currencies { let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -226,17 +241,23 @@ mod same_currencies { }); } - #[test] - fn cancel_invest_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn cancel_invest_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let invest_amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -287,7 +308,7 @@ mod same_currencies { investor: investor.clone(), investment_id: default_investment_id(), } - .into() + .into() })); // Verify investment was entirely drained from investment account @@ -323,17 +344,23 @@ mod same_currencies { }); } - #[test] - fn collect_invest_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn collect_invest_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -395,11 +422,11 @@ mod same_currencies { ); assert!(!events_since_collect.iter().any(|e| { e.event - == pallet_investments::Event::::InvestCollectedForNonClearedOrderId { + == pallet_investments::Event::::InvestCollectedForNonClearedOrderId { investment_id: default_investment_id(), who: investor.clone(), } - .into() + .into() })); // Order should not have been updated since everything is collected @@ -448,26 +475,32 @@ mod same_currencies { // Clearing of foreign InvestState should be dispatched assert!(events_since_collect.iter().any(|e| { e.event - == pallet_foreign_investments::Event::::ForeignInvestmentCleared { + == pallet_foreign_investments::Event::::ForeignInvestmentCleared { investor: investor.clone(), investment_id: default_investment_id(), } - .into() + .into() })); }); } - #[test] - fn partially_collect_investment_for_through_investments() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn partially_collect_investment_for_through_investments() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let invest_amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -516,7 +549,7 @@ mod same_currencies { // Collecting through Investments should denote amounts and transition // state assert_ok!(Investments::collect_investments_for( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), investor.clone(), default_investment_id() )); @@ -590,7 +623,7 @@ mod same_currencies { // Collect remainder through Investments assert_ok!(Investments::collect_investments_for( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), investor.clone(), default_investment_id() )); @@ -632,11 +665,11 @@ mod same_currencies { ); assert!(!System::events().iter().any(|e| { e.event - == pallet_investments::Event::::InvestCollectedForNonClearedOrderId { + == pallet_investments::Event::::InvestCollectedForNonClearedOrderId { investment_id: default_investment_id(), who: investor.clone(), } - .into() + .into() })); assert!(System::events().iter().any(|e| { e.event @@ -658,11 +691,11 @@ mod same_currencies { .iter() .filter(|e| { e.event - == pallet_foreign_investments::Event::::ForeignInvestmentCleared { - investor: investor.clone(), - investment_id: default_investment_id(), - } - .into() + == pallet_foreign_investments::Event::::ForeignInvestmentCleared { + investor: investor.clone(), + investment_id: default_investment_id(), + } + .into() }) .count(), 1 @@ -682,17 +715,23 @@ mod same_currencies { }); } - #[test] - fn increase_redeem_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn increase_redeem_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -735,11 +774,17 @@ mod same_currencies { }); } - #[test] - fn decrease_redeem_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn decrease_redeem_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let redeem_amount = 100_000_000; let decrease_amount = redeem_amount / 3; @@ -747,7 +792,7 @@ mod same_currencies { let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -802,14 +847,14 @@ mod same_currencies { // Foreign RedemptionState should be updated assert!(System::events().iter().any(|e| { e.event - == pallet_foreign_investments::Event::::ForeignRedemptionUpdated { + == pallet_foreign_investments::Event::::ForeignRedemptionUpdated { investor: investor.clone(), investment_id: default_investment_id(), state: RedeemState::Redeeming { - redeem_amount: final_amount + redeem_amount: final_amount } } - .into() + .into() })); // Order should have been updated @@ -831,17 +876,23 @@ mod same_currencies { }); } - #[test] - fn cancel_redeem_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn cancel_redeem_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let redeem_amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -901,11 +952,11 @@ mod same_currencies { // Foreign RedemptionState should be updated assert!(System::events().iter().any(|e| { e.event - == pallet_foreign_investments::Event::::ForeignRedemptionCleared { + == pallet_foreign_investments::Event::::ForeignRedemptionCleared { investor: investor.clone(), investment_id: default_investment_id(), } - .into() + .into() })); // Order should have been updated @@ -927,17 +978,23 @@ mod same_currencies { }); } - #[test] - fn fully_collect_redeem_order() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn fully_collect_redeem_order() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -1007,11 +1064,11 @@ mod same_currencies { ); assert!(!events_since_collect.iter().any(|e| { e.event - == pallet_investments::Event::::RedeemCollectedForNonClearedOrderId { + == pallet_investments::Event::::RedeemCollectedForNonClearedOrderId { investment_id: default_investment_id(), who: investor.clone(), } - .into() + .into() })); // Order should not have been updated since everything is collected @@ -1056,25 +1113,31 @@ mod same_currencies { assert!(events_since_collect.iter().any(|e| { e.event == pallet_foreign_investments::Event::::ForeignRedemptionCleared { - investor: investor.clone(), - investment_id: default_investment_id(), - } + investor: investor.clone(), + investment_id: default_investment_id(), + } .into() })); }); } - #[test] - fn partially_collect_redemption_for_through_investments() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn partially_collect_redemption_for_through_investments() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let redeem_amount = 100_000_000; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -1119,7 +1182,7 @@ mod same_currencies { // Collecting through investments should denote amounts and transition // state assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), investor.clone(), default_investment_id() )); @@ -1181,7 +1244,7 @@ mod same_currencies { // Collect remainder through Investments assert_ok!(Investments::collect_redemptions_for( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), investor.clone(), default_investment_id() )); @@ -1199,11 +1262,11 @@ mod same_currencies { )); assert!(!System::events().iter().any(|e| { e.event - == pallet_investments::Event::::RedeemCollectedForNonClearedOrderId { + == pallet_investments::Event::::RedeemCollectedForNonClearedOrderId { investment_id: default_investment_id(), who: investor.clone(), } - .into() + .into() })); assert!(System::events().iter().any(|e| { e.event @@ -1234,11 +1297,11 @@ mod same_currencies { .iter() .filter(|e| { e.event - == pallet_foreign_investments::Event::::ForeignRedemptionCleared { - investor: investor.clone(), - investment_id: default_investment_id(), - } - .into() + == pallet_foreign_investments::Event::::ForeignRedemptionCleared { + investor: investor.clone(), + investment_id: default_investment_id(), + } + .into() }) .count(), 1 @@ -1254,18 +1317,24 @@ mod same_currencies { mod decrease_should_underflow { use super::*; - #[test] - fn invest_decrease_underflow() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invest_decrease_underflow() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let invest_amount: u128 = 100_000_000; let decrease_amount = invest_amount + 1; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool(pool_id, currency_id, currency_decimals.into()); @@ -1296,18 +1365,24 @@ mod same_currencies { }); } - #[test] - fn redeem_decrease_underflow() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn redeem_decrease_underflow() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let redeem_amount: u128 = 100_000_000; let decrease_amount = redeem_amount + 1; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool(pool_id, currency_id, currency_decimals.into()); @@ -1339,17 +1414,24 @@ mod same_currencies { mod should_throw_requires_collect { use super::*; - #[test] - fn invest_requires_collect() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + + #[tokio::test] + async fn invest_requires_collect() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount: u128 = 100_000_000; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool(pool_id, currency_id, currency_decimals.into()); @@ -1407,17 +1489,23 @@ mod same_currencies { }); } - #[test] - fn redeem_requires_collect() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn redeem_requires_collect() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount: u128 = 100_000_000; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool(pool_id, currency_id, currency_decimals.into()); @@ -1486,16 +1574,22 @@ mod same_currencies { utils::USDT_CURRENCY_ID, }; - #[test] - fn invalid_invest_payment_currency() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invalid_invest_payment_currency() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let pool_currency = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1554,16 +1648,22 @@ mod same_currencies { }); } - #[test] - fn invalid_redeem_payout_currency() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invalid_redeem_payout_currency() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let pool_currency = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1626,16 +1726,22 @@ mod same_currencies { }); } - #[test] - fn invest_payment_currency_not_found() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invest_payment_currency_not_found() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let pool_currency = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1677,16 +1783,22 @@ mod same_currencies { }); } - #[test] - fn redeem_payout_currency_not_found() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn redeem_payout_currency_not_found() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::< DevelopmentRuntime, LocationToAccountId, - >::convert((DOMAIN_MOONBEAM, BOB)); + >::convert((DOMAIN_MOONBEAM, Keyring::Bob.into())); let pool_currency = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1756,16 +1868,22 @@ mod mismatching_currencies { utils::{GLMR_CURRENCY_ID, USDT_CURRENCY_ID}, }; - #[test] - fn collect_foreign_investment_for() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn collect_foreign_investment_for() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1814,7 +1932,7 @@ mod mismatching_currencies { } )); assert_ok!(Investments::collect_investments_for( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), investor.clone(), default_investment_id() )); @@ -1846,16 +1964,22 @@ mod mismatching_currencies { /// Invest in pool currency, then increase in allowed foreign currency, then /// decrease in same foreign currency multiple times. - #[test] - fn invest_increase_decrease() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invest_increase_decrease() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1919,7 +2043,7 @@ mod mismatching_currencies { invest_amount: invest_amount_pool_denominated }, } - .into() + .into() })); // Should be able to to decrease in the swapping foreign currency @@ -1944,14 +2068,14 @@ mod mismatching_currencies { ); assert!(System::events().iter().any(|e| { e.event == - pallet_foreign_investments::Event::::ForeignInvestmentUpdated - { investor: investor.clone(), - investment_id: default_investment_id(), - state: InvestState::InvestmentOngoing { - invest_amount: invest_amount_pool_denominated - }, - } - .into() + pallet_foreign_investments::Event::::ForeignInvestmentUpdated + { investor: investor.clone(), + investment_id: default_investment_id(), + state: InvestState::InvestmentOngoing { + invest_amount: invest_amount_pool_denominated + }, + } + .into() })); // Decrease partial investing amount @@ -1982,12 +2106,12 @@ mod mismatching_currencies { ); assert!(System::events().iter().any(|e| { e.event == - pallet_foreign_investments::Event::::ForeignInvestmentUpdated - { investor: investor.clone(), - investment_id: default_investment_id(), - state: expected_state.clone() - } - .into() + pallet_foreign_investments::Event::::ForeignInvestmentUpdated + { investor: investor.clone(), + investment_id: default_investment_id(), + state: expected_state.clone() + } + .into() })); /// Consume entire investing amount by sending same message @@ -2008,31 +2132,37 @@ mod mismatching_currencies { ); assert!(System::events().iter().any(|e| { e.event == - pallet_foreign_investments::Event::::ForeignInvestmentUpdated - { investor: investor.clone(), - investment_id: default_investment_id(), - state: expected_state.clone() - } - .into() + pallet_foreign_investments::Event::::ForeignInvestmentUpdated + { investor: investor.clone(), + investment_id: default_investment_id(), + state: expected_state.clone() + } + .into() })); }); } - #[test] /// Propagate swaps only via OrderBook fulfillments. /// /// Flow: Increase, fulfill, decrease, fulfill - fn invest_swaps_happy_path() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); + #[tokio::test] + async fn invest_swaps_happy_path() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); - let trader: AccountId = ALICE.into(); + let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; @@ -2175,23 +2305,28 @@ mod mismatching_currencies { }); } - #[test] /// Verify handling concurrent swap orders works if /// * Invest is swapping from pool to foreign after decreasing an /// unprocessed investment /// * Redeem is swapping from pool to foreign after collecting - fn concurrent_swap_orders_same_direction() { - TestNet::reset(); - Development::execute_with(|| { - // Increase invest setup - setup_pre_requirements(); + #[tokio::test] + async fn concurrent_swap_orders_same_direction() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); - let trader: AccountId = ALICE.into(); + let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; @@ -2425,22 +2560,27 @@ mod mismatching_currencies { }); } - #[test] /// Verify handling concurrent swap orders works if /// * Invest is swapping from foreign to pool after increasing /// * Redeem is swapping from pool to foreign after collecting - fn concurrent_swap_orders_opposite_direction() { - TestNet::reset(); - Development::execute_with(|| { - // Increase invest setup - setup_pre_requirements(); + #[tokio::test] + async fn concurrent_swap_orders_opposite_direction() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); - let trader: AccountId = ALICE.into(); + let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; @@ -2724,19 +2864,24 @@ mod mismatching_currencies { /// 2. increase invest in foreign /// 3. process invest /// 4. fulfill swap order - #[test] - fn fulfill_invest_swap_order_requires_collect() { - TestNet::reset(); - Development::execute_with(|| { - // Increase invest setup - setup_pre_requirements(); + #[tokio::test] + async fn fulfill_invest_swap_order_requires_collect() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); - let trader: AccountId = ALICE.into(); + let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; @@ -2828,19 +2973,24 @@ mod mismatching_currencies { /// 3. collect /// 4. process redemption /// 5. fulfill swap order should implicitly collect - #[test] - fn fulfill_redeem_swap_order_requires_collect() { - TestNet::reset(); - Development::execute_with(|| { - // Increase redeem setup - setup_pre_requirements(); + #[tokio::test] + async fn fulfill_redeem_swap_order_requires_collect() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let investor: AccountId = AccountConverter::::convert(( DOMAIN_MOONBEAM, - BOB, + Keyring::Bob.into(), )); - let trader: AccountId = ALICE.into(); + let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/mod.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/mod.rs index e8e509c216..1bc730757d 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/mod.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/mod.rs @@ -24,7 +24,7 @@ mod add_allow_upgrade; mod foreign_investments; -mod setup; +pub(crate) mod setup; mod transfers; #[test] diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs index 7616998a4c..0f103d7b6e 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/setup.rs @@ -31,10 +31,6 @@ use cfg_types::{ tokens::{CrossChainTransferability, CurrencyId, CustomMetadata}, }; use cumulus_primitives_core::Junction::GlobalConsensus; -use development_runtime::{ - LiquidityPools, LiquidityPoolsGateway, OrmlAssetRegistry, OrmlTokens, PoolSystem, - Runtime as DevelopmentRuntime, RuntimeOrigin, TreasuryPalletId, -}; use frame_support::{ assert_ok, traits::{ @@ -43,6 +39,7 @@ use frame_support::{ Get, PalletInfo, }, }; +use fudge::primitives::Chain; use liquidity_pools_gateway_routers::{ ethereum_xcm::EthereumXCMRouter, DomainRouter, XCMRouter, XcmDomain as GatewayXcmDomain, XcmTransactInfo, DEFAULT_PROOF_SIZE, @@ -51,6 +48,7 @@ use orml_asset_registry::{AssetMetadata, Metadata}; use orml_traits::MultiCurrency; use pallet_liquidity_pools::Message; use pallet_pool_system::tranches::{TrancheInput, TrancheType}; +use polkadot_parachain::primitives::Id; use runtime_common::{ account_conversion::AccountConverter, xcm::general_key, xcm_fees::default_per_second, }; @@ -60,18 +58,22 @@ use sp_runtime::{ BoundedVec, DispatchError, Perquintill, SaturatedConversion, WeakBoundedVec, }; use xcm::{ - latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId}, - prelude::{Parachain, X1, X2}, + prelude::{Parachain, X1, X2, X3, XCM_VERSION}, + v3::{Junction, Junction::*, Junctions, MultiLocation, NetworkId}, VersionedMultiLocation, }; use crate::{ - chain::centrifuge::development, - liquidity_pools::pallet::development::{ - setup::{dollar, ALICE, BOB, PARA_ID_MOONBEAM}, - tests::register_ausd, + chain::{ + centrifuge::{ + LiquidityPools, LiquidityPoolsGateway, OrmlAssetRegistry, OrmlTokens, PolkadotXcm, + PoolSystem, Runtime as DevelopmentRuntime, RuntimeOrigin, Tokens, TreasuryPalletId, + PARA_ID, + }, + relay::{Hrmp as RelayHrmp, RuntimeOrigin as RelayRuntimeOrigin}, }, - utils::{AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID}, + liquidity_pools::pallet::development::{setup::dollar, tests::register_ausd}, + utils::{accounts::Keyring, AUSD_CURRENCY_ID, GLMR_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID}, }; // 10 GLMR (18 decimals) @@ -84,18 +86,20 @@ pub const DEFAULT_VALIDITY: Moment = 2555583502; pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress = DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [0; 20]); pub const DEFAULT_POOL_ID: u64 = 42; -pub const DEFAULT_MOONBEAM_LOCATION: MultiLocation = MultiLocation { +pub const DEFAULT_SIBLING_LOCATION: MultiLocation = MultiLocation { parents: 1, - interior: X1(Parachain(PARA_ID_MOONBEAM)), + interior: X1(Parachain(PARA_ID_SIBLING)), }; use frame_support::weights::Weight; +use crate::utils::env::{TestEnv, PARA_ID_SIBLING}; + pub type LiquidityPoolMessage = Message; pub fn get_default_moonbeam_native_token_location() -> MultiLocation { MultiLocation { parents: 1, - interior: X2(Parachain(PARA_ID_MOONBEAM), general_key(&[0, 1])), + interior: X2(Parachain(PARA_ID_SIBLING), general_key(&[0, 1])), } } @@ -135,12 +139,27 @@ pub fn set_test_domain_router( )); } +pub fn setup_test_env(env: &mut TestEnv) { + env.with_mut_state(Chain::Para(PARA_ID), || { + setup_pre_requirements(); + }) + .unwrap(); + + env.with_mut_state(Chain::Relay, || { + setup_hrmp_channel(); + }) + .unwrap(); + + env.evolve().unwrap(); +} + /// Initializes universally required storage for liquidityPools tests: /// * Set the EthereumXCM router which in turn sets: /// * transact info and domain router for Moonbeam `MultiLocation`, /// * fee for GLMR (`GLMR_CURRENCY_ID`), /// * Register GLMR and AUSD in `OrmlAssetRegistry`, -/// * Mint 10 GLMR (`DEFAULT_BALANCE_GLMR`) for Alice, Bob and the Treasury. +/// * Mint 10 GLMR (`DEFAULT_BALANCE_GLMR`) for the LP Gateway Sender. +/// * Set the XCM version for the sibling parachain. /// /// NOTE: AUSD is the default pool currency in `create_pool`. /// Neither AUSD nor GLMR are registered as a liquidityPools-transferable @@ -149,7 +168,7 @@ pub fn setup_pre_requirements() { /// Set the EthereumXCM router necessary for Moonbeam. set_test_domain_router( MOONBEAM_EVM_CHAIN_ID, - DEFAULT_MOONBEAM_LOCATION.into(), + DEFAULT_SIBLING_LOCATION.into(), GLMR_CURRENCY_ID, ); @@ -170,22 +189,45 @@ pub fn setup_pre_requirements() { )); // Fund the gateway sender account with enough glimmer to pay for fees - OrmlTokens::deposit( + assert_ok!(Tokens::set_balance( + RuntimeOrigin::root(), + ::Sender::get().into(), GLMR_CURRENCY_ID, - &::Sender::get(), DEFAULT_BALANCE_GLMR, - ); - // TODO: Check - // // Treasury pays for `Executed*` messages - // OrmlTokens::deposit( - // GLMR_CURRENCY_ID, - // &TreasuryPalletId::get().into_account_truncating(), - // DEFAULT_BALANCE_GLMR * dollar(18), - // ); + 0, + )); // Register AUSD in the asset registry which is the default pool currency in // `create_pool` register_ausd(); + + // Set the XCM version used when sending XCM messages to sibling. + assert_ok!(PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(MultiLocation::new( + 1, + Junctions::X1(Junction::Parachain(PARA_ID_SIBLING)), + )), + XCM_VERSION, + )); +} + +/// Opens the required HRMP channel between parachain and sibling. +/// +/// NOTE - this is should be done on the relay chain. +pub fn setup_hrmp_channel() { + assert_ok!(RelayHrmp::force_open_hrmp_channel( + RelayRuntimeOrigin::root(), + Id::from(PARA_ID), + Id::from(PARA_ID_SIBLING), + 10, + 1024, + )); + + assert_ok!(RelayHrmp::force_process_hrmp_open( + RelayRuntimeOrigin::root(), + 0, + )); } /// Creates a new pool for the given id with @@ -202,8 +244,8 @@ pub fn create_ausd_pool(pool_id: u64) { /// * The given `currency` as pool currency with of `currency_decimals`. pub fn create_currency_pool(pool_id: u64, currency_id: CurrencyId, currency_decimals: Balance) { assert_ok!(PoolSystem::create( - BOB.into(), - BOB.into(), + Keyring::Bob.into(), + Keyring::Bob.into(), pool_id, vec![ TrancheInput { diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs index b03ed7ffda..e473ed362f 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/liquidity_pools/transfers.rs @@ -36,48 +36,53 @@ use cfg_types::{ ForeignAssetId, }, }; -use development_runtime::{ - LiquidityPools, LocationToAccountId, OrmlTokens, Permissions, PoolSystem, - Runtime as DevelopmentRuntime, RuntimeOrigin, System, -}; use frame_support::{assert_noop, assert_ok, dispatch::Weight, traits::fungibles::Mutate}; +use fudge::primitives::Chain; use orml_traits::{asset_registry::AssetMetadata, FixedConversionRateProvider, MultiCurrency}; use runtime_common::account_conversion::AccountConverter; use sp_runtime::{ traits::{Convert, One, Zero}, - BoundedVec, DispatchError, + BoundedVec, DispatchError, Storage, }; +use tokio::runtime::Handle; use xcm::{latest::MultiLocation, VersionedMultiLocation}; use xcm_simulator::TestExt; use crate::{ + chain::centrifuge::{ + LiquidityPools, LocationToAccountId, OrmlTokens, Permissions, PoolSystem, + Runtime as DevelopmentRuntime, RuntimeOrigin, System, PARA_ID, + }, liquidity_pools::pallet::development::{ - setup::{dollar, ALICE, BOB}, + setup::dollar, test_net::{Development, Moonbeam, RelayChain, TestNet}, tests::liquidity_pools::setup::{ asset_metadata, create_ausd_pool, create_currency_pool, enable_liquidity_pool_transferability, investments::{default_tranche_id, general_currency_index, investment_id}, - liquidity_pools_transferable_multilocation, setup_pre_requirements, - LiquidityPoolMessage, DEFAULT_BALANCE_GLMR, DEFAULT_DOMAIN_ADDRESS_MOONBEAM, - DEFAULT_POOL_ID, + liquidity_pools_transferable_multilocation, setup_test_env, LiquidityPoolMessage, + DEFAULT_BALANCE_GLMR, DEFAULT_DOMAIN_ADDRESS_MOONBEAM, DEFAULT_POOL_ID, }, }, - utils::{AUSD_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID}, + utils::{accounts::Keyring, env, genesis, AUSD_CURRENCY_ID, MOONBEAM_EVM_CHAIN_ID}, }; -#[test] -fn transfer_non_tranche_tokens_from_local() { - TestNet::reset(); - Development::execute_with(|| { - // Register GLMR and fund BOB - setup_pre_requirements(); +#[tokio::test] +async fn transfer_non_tranche_tokens_from_local() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_native_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let initial_balance = 100_000_000; let amount = initial_balance / 2; let dest_address = DEFAULT_DOMAIN_ADDRESS_MOONBEAM; let currency_id = AUSD_CURRENCY_ID; - let source_account = BOB; + let source_account = Keyring::Bob; // Mint sufficient balance assert_ok!(OrmlTokens::mint_into( @@ -167,23 +172,28 @@ fn transfer_non_tranche_tokens_from_local() { }); } -#[test] -fn transfer_non_tranche_tokens_to_local() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn transfer_non_tranche_tokens_to_local() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_native_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + env.with_mut_state(Chain::Para(PARA_ID), || { let initial_balance = DEFAULT_BALANCE_GLMR; let amount = DEFAULT_BALANCE_GLMR / 2; let dest_address = DEFAULT_DOMAIN_ADDRESS_MOONBEAM; let currency_id = AUSD_CURRENCY_ID; - let receiver: AccountId = BOB.into(); + let receiver: AccountId = Keyring::Bob.into(); // Mock incoming decrease message let msg = LiquidityPoolMessage::Transfer { currency: general_currency_index(currency_id), // sender is irrelevant for other -> local - sender: ALICE, + sender: Keyring::Alice.into(), receiver: receiver.clone().into(), amount, }; @@ -204,7 +214,7 @@ fn transfer_non_tranche_tokens_to_local() { DEFAULT_DOMAIN_ADDRESS_MOONBEAM, LiquidityPoolMessage::Transfer { currency: general_currency_index(currency_id), - sender: ALICE, + sender: Keyring::Alice.into(), receiver: receiver.into(), amount: 0, }, @@ -214,16 +224,21 @@ fn transfer_non_tranche_tokens_to_local() { }); } -#[test] -fn transfer_tranche_tokens_from_local() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn transfer_tranche_tokens_from_local() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let pool_id = DEFAULT_POOL_ID; let amount = 100_000; let dest_address: DomainAddress = DomainAddress::EVM(1284, [99; 20]); - let receiver = BOB; + let receiver = Keyring::Bob; // Create the pool create_ausd_pool(pool_id); @@ -235,7 +250,7 @@ fn transfer_tranche_tokens_from_local() { // Verify that we first need the destination address to be whitelisted assert_noop!( LiquidityPools::transfer_tranche_tokens( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), pool_id, default_tranche_id(pool_id), dest_address.clone(), @@ -305,18 +320,23 @@ fn transfer_tranche_tokens_from_local() { }); } -#[test] -fn transfer_tranche_tokens_to_local() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn transfer_tranche_tokens_to_local() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + env.with_mut_state(Chain::Para(PARA_ID), || { // Create new pool let pool_id = DEFAULT_POOL_ID; create_ausd_pool(pool_id); let amount = 100_000_000; - let receiver: AccountId = BOB.into(); + let receiver: AccountId = Keyring::Bob.into(); let sender: DomainAddress = DomainAddress::EVM(1284, [99; 20]); let sending_domain_locator = Domain::convert(DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain()); let tranche_id = default_tranche_id(pool_id); @@ -380,13 +400,19 @@ fn transfer_tranche_tokens_to_local() { }); } -#[test] /// Try to transfer tranches for non-existing pools or invalid tranche ids for /// existing pools. -fn transferring_invalid_tranche_tokens_should_fail() { - TestNet::reset(); - Development::execute_with(|| { - setup_pre_requirements(); +#[tokio::test] +async fn transferring_invalid_tranche_tokens_should_fail() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); + + env.with_mut_state(Chain::Para(PARA_ID), || { let dest_address: DomainAddress = DomainAddress::EVM(1284, [99; 20]); let valid_pool_id: u64 = 42; @@ -398,26 +424,26 @@ fn transferring_invalid_tranche_tokens_should_fail() { let invalid_tranche_id = valid_tranche_id.map(|i| i.saturating_add(1)); assert!(PoolSystem::pool(invalid_pool_id).is_none()); - // Make BOB the MembersListAdmin of both pools + // Make Keyring::Bob the MembersListAdmin of both pools assert_ok!(Permissions::add( RuntimeOrigin::root(), Role::PoolRole(PoolRole::PoolAdmin), - BOB.into(), + Keyring::Bob.into(), PermissionScope::Pool(valid_pool_id), Role::PoolRole(PoolRole::InvestorAdmin), )); assert_ok!(Permissions::add( RuntimeOrigin::root(), Role::PoolRole(PoolRole::PoolAdmin), - BOB.into(), + Keyring::Bob.into(), PermissionScope::Pool(invalid_pool_id), Role::PoolRole(PoolRole::InvestorAdmin), )); - // Give BOB investor role for (valid_pool_id, invalid_tranche_id) and + // Give Keyring::Bob investor role for (valid_pool_id, invalid_tranche_id) and // (invalid_pool_id, valid_tranche_id) assert_ok!(Permissions::add( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), Role::PoolRole(PoolRole::InvestorAdmin), AccountConverter::::convert( dest_address.clone() @@ -426,7 +452,7 @@ fn transferring_invalid_tranche_tokens_should_fail() { Role::PoolRole(PoolRole::TrancheInvestor(valid_tranche_id, valid_until)), )); assert_ok!(Permissions::add( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), Role::PoolRole(PoolRole::InvestorAdmin), AccountConverter::::convert( dest_address.clone() @@ -436,7 +462,7 @@ fn transferring_invalid_tranche_tokens_should_fail() { )); assert_noop!( LiquidityPools::transfer_tranche_tokens( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), invalid_pool_id, valid_tranche_id, dest_address.clone(), @@ -446,7 +472,7 @@ fn transferring_invalid_tranche_tokens_should_fail() { ); assert_noop!( LiquidityPools::transfer_tranche_tokens( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), valid_pool_id, invalid_tranche_id, dest_address, diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs index bdb22376b7..9ff76ced7b 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/tests/routers/ethereum_xcm.rs @@ -23,6 +23,7 @@ use cfg_types::{ tokens::{CrossChainTransferability, CurrencyId, CustomMetadata}, }; use frame_support::{assert_noop, assert_ok}; +use fudge::primitives::Chain; use hex::FromHex; use liquidity_pools_gateway_routers::{ ethereum_xcm::EthereumXCMRouter, AxelarXCMRouter, DomainRouter, EVMDomain, FeeValues, @@ -32,52 +33,65 @@ use orml_traits::{asset_registry::AssetMetadata, MultiCurrency}; use pallet_liquidity_pools::Message; use runtime_common::{xcm::general_key, xcm_fees::default_per_second}; use sp_core::{bounded::BoundedVec, H160}; +use sp_runtime::Storage; +use tokio::runtime::Handle; use xcm_simulator::TestExt; use crate::{ chain::centrifuge::{ Balance, LiquidityPoolsGateway, OrmlAssetRegistry, OrmlTokens, Runtime, RuntimeOrigin, + PARA_ID, }, liquidity_pools::pallet::development::{ - setup::{dollar, ALICE, BOB, CHARLIE, PARA_ID_MOONBEAM, TEST_DOMAIN}, + setup::{dollar, TEST_DOMAIN}, test_net::{Development, Moonbeam, RelayChain, TestNet}, - tests::routers::axelar_evm::TEST_EVM_CHAIN, + tests, + tests::{ + liquidity_pools::setup::{setup_test_env, DEFAULT_SIBLING_LOCATION}, + routers::axelar_evm::TEST_EVM_CHAIN, + }, }, - utils::accounts::Keyring, + utils::{accounts::Keyring, env, env::PARA_ID_SIBLING, genesis, GLMR_CURRENCY_ID}, }; -#[test] -fn submit_ethereum_xcm() { +#[tokio::test] +async fn submit_ethereum_xcm() { submit_test_fn(get_ethereum_xcm_router_fn()); } -#[test] -fn submit_axelar_xcm() { +#[tokio::test] +async fn submit_axelar_xcm() { submit_test_fn(get_axelar_xcm_router_fn()); } fn submit_test_fn(router_creation_fn: RouterCreationFn) { - TestNet::reset(); + let mut env = { + let mut genesis = Storage::default(); + genesis::default_native_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; + + setup_test_env(&mut env); - Development::execute_with(|| { + env.with_mut_state(Chain::Para(PARA_ID), || { setup(router_creation_fn); let msg = Message::::Transfer { currency: 0, - sender: ALICE.into(), - receiver: BOB.into(), + sender: Keyring::Alice.into(), + receiver: Keyring::Bob.into(), amount: 1_000u128, }; assert_ok!(::submit( - ALICE.into(), + Keyring::Alice.into(), TEST_DOMAIN, msg.clone(), )); assert_noop!( ::submit( - ALICE.into(), + Keyring::Alice.into(), Domain::EVM(1285), msg.clone(), ), @@ -141,65 +155,11 @@ fn get_ethereum_xcm_router_fn() -> RouterCreationFn { } fn setup(router_creation_fn: RouterCreationFn) { - let moonbeam_location = MultiLocation { - parents: 1, - interior: X1(Parachain(PARA_ID_MOONBEAM)), - }; - let moonbeam_native_token = MultiLocation { - parents: 1, - interior: X2(Parachain(PARA_ID_MOONBEAM), general_key(&[0, 1])), - }; - - /// Register Moonbeam's native token - let glmr_currency_id = CurrencyId::ForeignAsset(1); - let meta: AssetMetadata = AssetMetadata { - decimals: 18, - name: "Glimmer".into(), - symbol: "GLMR".into(), - existential_deposit: 1_000_000, - location: Some(VersionedMultiLocation::V3(moonbeam_native_token)), - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; - - let domain_router = router_creation_fn(moonbeam_location.into(), glmr_currency_id); + let domain_router = router_creation_fn(DEFAULT_SIBLING_LOCATION.into(), GLMR_CURRENCY_ID); assert_ok!(LiquidityPoolsGateway::set_domain_router( RuntimeOrigin::root(), TEST_DOMAIN, domain_router, )); - - assert_ok!(OrmlAssetRegistry::register_asset( - RuntimeOrigin::root(), - meta, - Some(glmr_currency_id) - )); - - // Fund the gateway sender account with enough glimmer to pay for fees - OrmlTokens::deposit( - glmr_currency_id, - &::Sender::get(), - 1_000_000_000_000 * dollar(18), - ); - - // We first need to register AUSD in the asset registry - let ausd_meta: AssetMetadata = AssetMetadata { - decimals: 12, - name: "Acala Dollar".into(), - symbol: "AUSD".into(), - existential_deposit: 1_000, - location: None, - additional: CustomMetadata { - transferability: CrossChainTransferability::Xcm(Default::default()), - ..CustomMetadata::default() - }, - }; - assert_ok!(OrmlAssetRegistry::register_asset( - RuntimeOrigin::root(), - ausd_meta, - Some(CurrencyId::AUSD) - )); } diff --git a/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs b/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs index beb715182e..51f6f5e103 100644 --- a/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs +++ b/runtime/integration-tests/src/liquidity_pools/pallet/development/transfers.rs @@ -27,27 +27,45 @@ use cfg_types::{ tokens::{CrossChainTransferability, CurrencyId, CustomMetadata}, xcm::XcmMetadata, }; -use development_runtime::{Balances, OrmlAssetRegistry, OrmlTokens, RuntimeOrigin, XTokens}; use frame_support::assert_ok; +use fudge::primitives::Chain; use orml_traits::{asset_registry::AssetMetadata, FixedConversionRateProvider, MultiCurrency}; +use polkadot_parachain::primitives::Id; use runtime_common::{ xcm::general_key, xcm_fees::{default_per_second, ksm_per_second}, }; -use sp_runtime::traits::BadOrigin; +use sp_runtime::{traits::BadOrigin, Storage}; +use tokio::runtime::Handle; use xcm::{ - latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId, WeightLimit}, + prelude::XCM_VERSION, + v3::{Junction, Junction::*, Junctions, Junctions::*, MultiLocation, NetworkId, WeightLimit}, VersionedMultiLocation, }; use xcm_simulator::TestExt; -use crate::liquidity_pools::pallet::{ - development::{ - setup::{centrifuge_account, cfg, moonbeam_account, ALICE, BOB, CHARLIE, PARA_ID_MOONBEAM}, - test_net::{Development, Moonbeam, RelayChain, TestNet}, - tests::register_ausd, +use crate::{ + chain::{ + centrifuge::{ + AccountId, Balances, OrmlAssetRegistry, OrmlTokens, PolkadotXcm, Runtime, + RuntimeOrigin, XTokens, PARA_ID, + }, + relay::{Hrmp as RelayHrmp, RuntimeOrigin as RelayRuntimeOrigin}, + }, + liquidity_pools::pallet::{ + development::{ + setup::{centrifuge_account, cfg, moonbeam_account}, + test_net::{Development, Moonbeam, RelayChain, TestNet}, + tests::register_ausd, + }, + xcm_metadata, + }, + utils::{ + accounts::Keyring, + env, + env::{TestEnv, PARA_ID_SIBLING}, + genesis, }, - xcm_metadata, }; /* @@ -61,12 +79,19 @@ which would go unnoticed and untreated otherwise. */ -#[test] -fn transfer_cfg_to_sibling() { - TestNet::reset(); +#[tokio::test] +async fn test_transfer_cfg_to_sibling() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_native_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; - let alice_initial_balance = cfg(10_000); - let bob_initial_balance = cfg(10_000); + transfer_cfg_to_sibling(&mut env); +} + +fn transfer_cfg_to_sibling(env: &mut TestEnv) { + let alice_initial_balance = cfg(100_000); let transfer_amount = cfg(5); let cfg_in_sibling = CurrencyId::ForeignAsset(12); @@ -79,7 +104,7 @@ fn transfer_cfg_to_sibling() { location: Some(VersionedMultiLocation::V3(MultiLocation::new( 1, X2( - Parachain(parachains::polkadot::centrifuge::ID), + Parachain(PARA_ID), general_key(parachains::polkadot::centrifuge::CFG_KEY), ), ))), @@ -89,8 +114,11 @@ fn transfer_cfg_to_sibling() { }, }; - Development::execute_with(|| { - assert_eq!(Balances::free_balance(&ALICE.into()), alice_initial_balance); + env.with_mut_state(Chain::Para(PARA_ID), || { + assert_eq!( + Balances::free_balance(&Keyring::Alice.into()), + alice_initial_balance + ); assert_eq!(Balances::free_balance(&moonbeam_account()), 0); assert_ok!(OrmlAssetRegistry::register_asset( @@ -98,10 +126,39 @@ fn transfer_cfg_to_sibling() { meta.clone(), Some(CurrencyId::Native), )); + + assert_ok!(PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(MultiLocation::new( + 1, + Junctions::X1(Junction::Parachain(PARA_ID_SIBLING)), + )), + XCM_VERSION, + )); + }); + + env.with_mut_state(Chain::Relay, || { + assert_ok!(RelayHrmp::force_open_hrmp_channel( + RelayRuntimeOrigin::root(), + Id::from(PARA_ID), + Id::from(PARA_ID_SIBLING), + 10, + 1024, + )); + + assert_ok!(RelayHrmp::force_process_hrmp_open( + RelayRuntimeOrigin::root(), + 0, + )); }); - Moonbeam::execute_with(|| { - assert_eq!(OrmlTokens::free_balance(cfg_in_sibling, &BOB.into()), 0); + env.evolve().unwrap(); + + env.with_mut_state(Chain::Para(PARA_ID_SIBLING), || { + assert_eq!( + OrmlTokens::free_balance(cfg_in_sibling, &Keyring::Bob.into()), + 0 + ); assert_ok!(OrmlAssetRegistry::register_asset( RuntimeOrigin::root(), @@ -110,30 +167,30 @@ fn transfer_cfg_to_sibling() { )); }); - Development::execute_with(|| { + env.with_mut_state(Chain::Para(PARA_ID), || { assert_ok!(XTokens::transfer( - RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(Keyring::Alice.into()), CurrencyId::Native, transfer_amount, Box::new( MultiLocation::new( 1, X2( - Parachain(PARA_ID_MOONBEAM), + Parachain(PARA_ID_SIBLING), Junction::AccountId32 { network: None, - id: BOB, - } - ) + id: Keyring::Bob.into(), + }, + ), ) .into() ), WeightLimit::Limited(8_000_000_000_000.into()), )); - // Confirm that Alice's balance is initial balance - amount transferred + // Confirm that Keyring::Alice's balance is initial balance - amount transferred assert_eq!( - Balances::free_balance(&ALICE.into()), + Balances::free_balance(&Keyring::Alice.into()), alice_initial_balance - transfer_amount ); @@ -141,55 +198,102 @@ fn transfer_cfg_to_sibling() { assert_eq!(Balances::free_balance(&moonbeam_account()), transfer_amount); }); - Moonbeam::execute_with(|| { - let current_balance = OrmlTokens::free_balance(cfg_in_sibling, &BOB.into()); + env.evolve().unwrap(); - // Verify that BOB now has (amount transferred - fee) + env.with_mut_state(Chain::Para(PARA_ID_SIBLING), || { + let current_balance = OrmlTokens::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 BOB ends up with - assert_eq!(current_balance, 4991987200000000000); + // Sanity check for the actual amount Keyring::Bob ends up with + assert_eq!(current_balance, 4992960800000000000); }); } -#[test] -fn transfer_cfg_sibling_to_centrifuge() { - TestNet::reset(); +#[tokio::test] +async fn transfer_cfg_sibling_to_centrifuge() { + let mut env = { + let mut genesis = Storage::default(); + genesis::default_native_balances::(&mut genesis); + env::test_env_with_centrifuge_storage(Handle::current(), genesis) + }; // 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(); + transfer_cfg_to_sibling(&mut env); - let alice_initial_balance = 9995000000000000000000; - let bob_initial_balance = cfg(5) - cfg_fee(); - let transfer_amount = cfg(4); + let para_to_sibling_transfer_amount = cfg(5); + + let alice_balance = cfg(100_000) - para_to_sibling_transfer_amount; + let bob_balance = para_to_sibling_transfer_amount - fee(18); + let charlie_balance = cfg(100_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); - Development::execute_with(|| { - assert_eq!(Balances::free_balance(&ALICE.into()), alice_initial_balance); + env.with_mut_state(Chain::Para(PARA_ID), || { + assert_eq!( + Balances::free_balance(&Keyring::Alice.into()), + alice_balance + ); }); - Moonbeam::execute_with(|| { + env.with_mut_state(Chain::Para(PARA_ID_SIBLING), || { assert_eq!(Balances::free_balance(¢rifuge_account()), 0); + + assert_eq!( + Balances::free_balance(&Keyring::Charlie.into()), + charlie_balance + ); + assert_eq!( - OrmlTokens::free_balance(cfg_in_sibling, &BOB.into()), - bob_initial_balance + OrmlTokens::free_balance(cfg_in_sibling, &Keyring::Bob.into()), + bob_balance ); + assert_ok!(PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(MultiLocation::new( + 1, + Junctions::X1(Junction::Parachain(PARA_ID)), + )), + XCM_VERSION, + )); + }); + + env.with_mut_state(Chain::Relay, || { + assert_ok!(RelayHrmp::force_open_hrmp_channel( + RelayRuntimeOrigin::root(), + Id::from(PARA_ID_SIBLING), + Id::from(PARA_ID), + 10, + 1024, + )); + + assert_ok!(RelayHrmp::force_process_hrmp_open( + RelayRuntimeOrigin::root(), + 0, + )); + }); + + env.evolve().unwrap(); + + env.with_mut_state(Chain::Para(PARA_ID_SIBLING), || { assert_ok!(XTokens::transfer( - RuntimeOrigin::signed(BOB.into()), + RuntimeOrigin::signed(Keyring::Bob.into()), cfg_in_sibling, - transfer_amount, + sibling_to_para_transfer_amount, Box::new( MultiLocation::new( 1, X2( - Parachain(parachains::polkadot::centrifuge::ID), + Parachain(PARA_ID), Junction::AccountId32 { network: None, - id: CHARLIE, + id: Keyring::Charlie.into(), } ) ) @@ -200,16 +304,19 @@ fn transfer_cfg_sibling_to_centrifuge() { // Confirm that Charlie's balance is initial balance - amount transferred assert_eq!( - OrmlTokens::free_balance(cfg_in_sibling, &BOB.into()), - bob_initial_balance - transfer_amount + OrmlTokens::free_balance(cfg_in_sibling, &Keyring::Bob.into()), + bob_balance - sibling_to_para_transfer_amount ); }); - Development::execute_with(|| { + env.evolve().unwrap(); + env.evolve().unwrap(); + + env.with_mut_state(Chain::Para(PARA_ID), || { // Verify that Charlie's balance equals the amount transferred - fee assert_eq!( - Balances::free_balance(&CHARLIE.into()), - transfer_amount - cfg_fee(), + Balances::free_balance(&Into::::into(Keyring::Charlie)), + charlie_balance + sibling_to_para_transfer_amount - cfg_fee(), ); }); } diff --git a/runtime/integration-tests/src/utils/env.rs b/runtime/integration-tests/src/utils/env.rs index b3cad85793..e79eb418f0 100644 --- a/runtime/integration-tests/src/utils/env.rs +++ b/runtime/integration-tests/src/utils/env.rs @@ -25,13 +25,14 @@ use fudge::{ }, primitives::{Chain, PoolState}, state::StateProvider, - ParachainBuilder, RelaychainBuilder, TWasmExecutor, + InherentBuilder, ParachainBuilder, RelaychainBuilder, TWasmExecutor, }; use lazy_static::lazy_static; //pub use macros::{assert_events, events, run}; pub use macros::*; use polkadot_core_primitives::{Block as RelayBlock, Header as RelayHeader}; use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{configuration, configuration::HostConfiguration, dmp}; use sc_executor::{WasmExecutionMethod, WasmExecutor}; use sc_service::{TFullBackend, TFullClient, TaskManager}; use sp_consensus_babe::digests::CompatibleDigestItem; @@ -436,6 +437,8 @@ pub enum EventRange { Latest, } +pub(crate) const PARA_ID_SIBLING: u32 = 2001; + #[fudge::companion] pub struct TestEnv { #[fudge::relaychain] @@ -443,6 +446,8 @@ pub struct TestEnv { #[fudge::parachain(PARA_ID)] pub centrifuge: ParachainBuilder, + #[fudge::parachain(PARA_ID_SIBLING)] + pub sibling: ParachainBuilder, nonce_manager: Arc>, pub events: Arc>, } @@ -776,11 +781,23 @@ fn test_env( ) .expect("ESSENTIAL: State provider can be created"); - // We need to HostConfiguration and use the default here. + let mut configuration = configuration::GenesisConfig::::default(); + + let mut host_config = HostConfiguration::::default(); + host_config.max_downward_message_size = 1024; + host_config.hrmp_channel_max_capacity = 100; + host_config.hrmp_channel_max_message_size = 1024; + host_config.hrmp_channel_max_total_size = 1024; + host_config.hrmp_max_parachain_outbound_channels = 10; + host_config.hrmp_max_parachain_inbound_channels = 10; + host_config.hrmp_max_message_num_per_candidate = 100; + + configuration.config = host_config; + state.insert_storage( - polkadot_runtime_parachains::configuration::GenesisConfig::::default() + configuration .build_storage() - .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), + .expect("ESSENTIAL: Host Configuration GenesisBuild must not fail at this stage."), ); state.insert_storage( @@ -788,7 +805,7 @@ fn test_env( code: RelayCode.expect("ESSENTIAL: Relay WASM is some.").to_vec(), } .build_storage::() - .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), + .expect("ESSENTIAL: Frame System GenesisBuild must not fail at this stage."), ); if let Some(storage) = relay_storage { @@ -844,95 +861,128 @@ fn test_env( .expect("ESSENTIAL: Relay chain builder can be created.") }; - // Build parachain-builder - let centrifuge = { - sp_tracing::enter_span!(sp_tracing::Level::INFO, "Centrifuge - StartUp"); - let mut state = - StateProvider::, centrifuge::Block>::empty_default( - Some(CentrifugeCode.expect("Wasm is build. Qed.")), - ) - .expect("ESSENTIAL: State provider can be created."); + let para_inherent_builder = relay.inherent_builder(ParaId::from(PARA_ID)); + let sibling_inherent_builder = relay.inherent_builder(ParaId::from(PARA_ID_SIBLING)); - state.insert_storage( - frame_system::GenesisConfig { - code: CentrifugeCode - .expect("ESSENTIAL: Centrifuge WASM is some.") - .to_vec(), - } - .build_storage::() - .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), - ); - state.insert_storage( - pallet_aura::GenesisConfig:: { - authorities: vec![AuraId::from(sp_core::sr25519::Public([0u8; 32]))], - } - .build_storage() - .expect("ESSENTIAL: GenesisBuild must not fail at this stage."), - ); + let para_builder = get_parachain_builder( + handle.clone(), + para_inherent_builder, + PARA_ID, + centrifuge_storage.clone(), + ); - if let Some(storage) = centrifuge_storage { - state.insert_storage(storage); - } + let sibling_builder = get_parachain_builder( + handle, + sibling_inherent_builder, + PARA_ID_SIBLING, + centrifuge_storage, + ); - let mut init = fudge::initiator::default(handle); - init.with_genesis(Box::new(state)); + TestEnv::new( + relay, + para_builder, + sibling_builder, + Arc::new(Mutex::new(NonceManager::new())), + Arc::new(Mutex::new(EventsStorage::new())), + ) + .expect("ESSENTIAL: Creating new TestEnv instance must not fail.") +} - let para_id = ParaId::from(PARA_ID); - let inherent_builder = relay.inherent_builder(para_id.clone()); - let instance_id = FudgeInherentTimestamp::create_instance( - std::time::Duration::from_secs(12), - Some(std::time::Duration::from_millis(START_DATE)), +fn get_parachain_builder( + handle: Handle, + inherent_builder: InherentBuilder< + TFullClient, + TFullBackend, + >, + para_id: u32, + centrifuge_storage: Option, +) -> ParachainBuilder { + sp_tracing::enter_span!(sp_tracing::Level::INFO, "Parachain - StartUp"); + + let mut state = + StateProvider::, centrifuge::Block>::empty_default(Some( + CentrifugeCode.expect("Wasm is build. Qed."), + )) + .expect("ESSENTIAL: State provider can be created."); + + state.insert_storage( + frame_system::GenesisConfig { + code: CentrifugeCode + .expect("ESSENTIAL: Centrifuge WASM is some.") + .to_vec(), + } + .build_storage::() + .expect("ESSENTIAL: Frame System GenesisBuild must not fail at this stage."), + ); + state.insert_storage( + pallet_aura::GenesisConfig:: { + authorities: vec![AuraId::from(sp_core::sr25519::Public([0u8; 32]))], + } + .build_storage() + .expect("ESSENTIAL: Pallet Aura GenesisBuild must not fail at this stage."), + ); + state.insert_storage( + >::build_storage( + ¶chain_info::GenesisConfig { + parachain_id: ParaId::from(para_id), + }, ) - .expect("ESSENTIAL: Instance ID can be created."); + .expect("ESSENTIAL: Parachain Info GenesisBuild must not fail at this stage."), + ); - let cidp = Box::new(move |_parent: H256, ()| { - let inherent_builder_clone = inherent_builder.clone(); - async move { - let timestamp = FudgeInherentTimestamp::get_instance(instance_id) - .expect("Instances is initialized"); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - timestamp.current_time(), - SlotDuration::from_millis(std::time::Duration::from_secs(12).as_millis() as u64), - ); - let inherent = inherent_builder_clone.parachain_inherent().await.unwrap(); - let relay_para_inherent = FudgeInherentParaParachain::new(inherent); - Ok((timestamp, slot, relay_para_inherent)) - } - }); - let dp = |clone_client: Arc< - sc_service::TFullClient, - >| { - Box::new(move |parent, inherents| { - let client = clone_client.clone(); + if let Some(storage) = centrifuge_storage { + state.insert_storage(storage); + } - async move { - let aura = FudgeAuraDigest::< - CentrifugeBlock, - sc_service::TFullClient, - >::new(&*client) - .expect("ESSENTIAL: Aura digest can be created."); - - let digest = aura.build_digest(parent, &inherents).await?; - Ok(digest) - } - }) - }; + let mut init = fudge::initiator::default(handle); + init.with_genesis(Box::new(state)); - ParachainBuilder::<_, _, CentrifugeCidp, CentrifugeDp>::new(init, |client| { - (cidp, dp(client)) + let para_id = ParaId::from(para_id); + let instance_id = FudgeInherentTimestamp::create_instance( + std::time::Duration::from_secs(12), + Some(std::time::Duration::from_millis(START_DATE)), + ) + .expect("ESSENTIAL: Instance ID can be created."); + + let cidp = Box::new(move |_parent: H256, ()| { + let inherent_builder_clone = inherent_builder.clone(); + async move { + let timestamp = FudgeInherentTimestamp::get_instance(instance_id) + .expect("Instances is initialized"); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + timestamp.current_time(), + SlotDuration::from_millis(std::time::Duration::from_secs(12).as_millis() as u64), + ); + let inherent = inherent_builder_clone.parachain_inherent().await.unwrap(); + let relay_para_inherent = FudgeInherentParaParachain::new(inherent); + Ok((timestamp, slot, relay_para_inherent)) + } + }); + let dp = |clone_client: Arc< + sc_service::TFullClient, + >| { + Box::new(move |parent, inherents| { + let client = clone_client.clone(); + + async move { + let aura = FudgeAuraDigest::< + CentrifugeBlock, + sc_service::TFullClient, + >::new(&*client) + .expect("ESSENTIAL: Aura digest can be created."); + + let digest = aura.build_digest(parent, &inherents).await?; + Ok(digest) + } }) - .expect("ESSENTIAL: Parachain builder can be created.") }; - TestEnv::new( - relay, - centrifuge, - Arc::new(Mutex::new(NonceManager::new())), - Arc::new(Mutex::new(EventsStorage::new())), - ) - .expect("ESSENTIAL: Creating new TestEnv instance must not fail.") + ParachainBuilder::<_, _, CentrifugeCidp, CentrifugeDp>::new(para_id, init, |client| { + (cidp, dp(client)) + }) + .expect("ESSENTIAL: Parachain builder can be created.") } /// Pass n_blocks on the parachain-side! diff --git a/runtime/integration-tests/src/utils/logs.rs b/runtime/integration-tests/src/utils/logs.rs index 16a6c2ffdc..fec9837e5a 100644 --- a/runtime/integration-tests/src/utils/logs.rs +++ b/runtime/integration-tests/src/utils/logs.rs @@ -12,12 +12,17 @@ //! Utilities to initialize logging subscriber use std::sync::atomic::{AtomicUsize, Ordering}; + +use tracing_subscriber::filter::LevelFilter; + static GLOBAL_INIT: AtomicUsize = AtomicUsize::new(UNINITIALIZED); const UNINITIALIZED: usize = 0; const INITIALIZING: usize = 1; const INITIALIZED: usize = 2; +const LOG_LEVEL: LevelFilter = LevelFilter::INFO; + pub fn init_logs() { if GLOBAL_INIT .compare_exchange( @@ -29,6 +34,8 @@ pub fn init_logs() { .is_ok() { GLOBAL_INIT.store(INITIALIZED, Ordering::SeqCst); - tracing_subscriber::fmt::init(); + tracing_subscriber::fmt::fmt() + .with_max_level(LOG_LEVEL) + .init(); } }