diff --git a/pallets/liquidity-pools/src/tests.rs b/pallets/liquidity-pools/src/tests.rs index c18cf4198c..4e4a7f2e9e 100644 --- a/pallets/liquidity-pools/src/tests.rs +++ b/pallets/liquidity-pools/src/tests.rs @@ -182,7 +182,7 @@ mod transfer { } #[test] - fn without_correct_location() { + fn with_wrong_location() { System::externalities().execute_with(|| { AssetRegistry::mock_metadata(|_| Some(transferable_metadata())); @@ -199,7 +199,7 @@ mod transfer { } #[test] - fn without_correct_domain() { + fn with_wrong_domain() { System::externalities().execute_with(|| { AssetRegistry::mock_metadata(|_| Some(wrapped_transferable_metadata())); @@ -216,7 +216,7 @@ mod transfer { } #[test] - fn without_satisfy_lp_filter() { + fn without_satisfy_filter() { System::externalities().execute_with(|| { AssetRegistry::mock_metadata(|_| Some(wrapped_transferable_metadata())); TransferFilter::mock_check(|_| Err(DispatchError::Other("Err"))); @@ -322,7 +322,7 @@ mod transfer_tranche_tokens { } #[test] - fn with_no_tranche_investor_role() { + fn with_wrong_permissions() { System::externalities().execute_with(|| { DomainAddressToAccountId::mock_convert(|_| CONTRACT_ACCOUNT_ID); Time::mock_now(|| NOW); @@ -342,7 +342,7 @@ mod transfer_tranche_tokens { } #[test] - fn without_correct_pool() { + fn with_wrong_pool() { System::externalities().execute_with(|| { DomainAddressToAccountId::mock_convert(|_| CONTRACT_ACCOUNT_ID); Time::mock_now(|| NOW); @@ -363,7 +363,7 @@ mod transfer_tranche_tokens { } #[test] - fn without_correct_tranche_id() { + fn with_wrong_tranche_id() { System::externalities().execute_with(|| { DomainAddressToAccountId::mock_convert(|_| CONTRACT_ACCOUNT_ID); Time::mock_now(|| NOW); @@ -385,7 +385,7 @@ mod transfer_tranche_tokens { } #[test] - fn without_satisfy_lp_filter() { + fn without_satisfy_filter() { System::externalities().execute_with(|| { DomainAddressToAccountId::mock_convert(|_| CONTRACT_ACCOUNT_ID); Time::mock_now(|| NOW); @@ -409,6 +409,73 @@ mod transfer_tranche_tokens { } } +mod add_pool { + use super::*; + + #[test] + fn success() { + System::externalities().execute_with(|| { + Permissions::mock_has(move |scope, who, role| { + assert_eq!(who, ALICE); + assert!(matches!(scope, PermissionScope::Pool(POOL_ID))); + assert!(matches!(role, Role::PoolRole(PoolRole::PoolAdmin))); + true + }); + Pools::mock_pool_exists(|_| true); + + Gateway::mock_submit(|sender, destination, msg| { + assert_eq!(sender, ALICE); + assert_eq!(destination, EVM_ADDRESS.domain()); + assert_eq!(msg, Message::AddPool { pool_id: POOL_ID }); + Ok(()) + }); + + assert_ok!(LiquidityPools::add_pool( + RuntimeOrigin::signed(ALICE), + POOL_ID, + EVM_ADDRESS.domain(), + )); + }) + } + + mod erroring_out_when { + use super::*; + + #[test] + fn with_wrong_pool() { + System::externalities().execute_with(|| { + Pools::mock_pool_exists(|_| true); + Permissions::mock_has(move |_, _, _| false); + + assert_noop!( + LiquidityPools::add_pool( + RuntimeOrigin::signed(ALICE), + POOL_ID, + EVM_ADDRESS.domain(), + ), + Error::::NotPoolAdmin + ); + }) + } + + #[test] + fn with_wrong_permissions() { + System::externalities().execute_with(|| { + Pools::mock_pool_exists(|_| false); + + assert_noop!( + LiquidityPools::add_pool( + RuntimeOrigin::signed(ALICE), + POOL_ID, + EVM_ADDRESS.domain(), + ), + Error::::PoolNotFound + ); + }) + } + } +} + #[test] fn receiving_output_message() { System::externalities().execute_with(|| { diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index f5d5b59018..b92197b337 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -699,56 +699,6 @@ mod add_allow_upgrade { use super::*; - #[test_runtimes([development])] - fn add_pool() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(1_000))) - .add(genesis::tokens::(vec![( - GLMR_CURRENCY_ID, - DEFAULT_BALANCE_GLMR, - )])) - .storage(), - ); - - setup_test(&mut env); - - env.parachain_state_mut(|| { - let pool_id = POOL_ID; - - // Verify that the pool must exist before we can call - // pallet_liquidity_pools::Pallet::::add_pool - assert_noop!( - pallet_liquidity_pools::Pallet::::add_pool( - RawOrigin::Signed(Keyring::Alice.into()).into(), - pool_id, - Domain::EVM(MOONBEAM_EVM_CHAIN_ID), - ), - pallet_liquidity_pools::Error::::PoolNotFound - ); - - // Now create the pool - create_ausd_pool::(pool_id); - - // Verify ALICE can't call `add_pool` given she is not the `PoolAdmin` - assert_noop!( - pallet_liquidity_pools::Pallet::::add_pool( - RawOrigin::Signed(Keyring::Alice.into()).into(), - pool_id, - Domain::EVM(MOONBEAM_EVM_CHAIN_ID), - ), - pallet_liquidity_pools::Error::::NotPoolAdmin - ); - - // Verify that it works if it's BOB calling it (the pool admin) - assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( - RawOrigin::Signed(POOL_ADMIN.into()).into(), - pool_id, - Domain::EVM(MOONBEAM_EVM_CHAIN_ID), - )); - }); - } - #[test_runtimes([development])] fn add_tranche() { let mut env = FudgeEnv::::from_parachain_storage(