Skip to content

Commit

Permalink
add add_pool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Jun 20, 2024
1 parent f1ee589 commit d5e46fe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 57 deletions.
81 changes: 74 additions & 7 deletions pallets/liquidity-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -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()));

Expand All @@ -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")));
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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::<Runtime>::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::<Runtime>::PoolNotFound
);
})
}
}
}

#[test]
fn receiving_output_message() {
System::externalities().execute_with(|| {
Expand Down
50 changes: 0 additions & 50 deletions runtime/integration-tests/src/generic/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,56 +699,6 @@ mod add_allow_upgrade {

use super::*;

#[test_runtimes([development])]
fn add_pool<T: Runtime + FudgeSupport>() {
let mut env = FudgeEnv::<T>::from_parachain_storage(
Genesis::default()
.add(genesis::balances::<T>(cfg(1_000)))
.add(genesis::tokens::<T>(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::<T>::add_pool
assert_noop!(
pallet_liquidity_pools::Pallet::<T>::add_pool(
RawOrigin::Signed(Keyring::Alice.into()).into(),
pool_id,
Domain::EVM(MOONBEAM_EVM_CHAIN_ID),
),
pallet_liquidity_pools::Error::<T>::PoolNotFound
);

// Now create the pool
create_ausd_pool::<T>(pool_id);

// Verify ALICE can't call `add_pool` given she is not the `PoolAdmin`
assert_noop!(
pallet_liquidity_pools::Pallet::<T>::add_pool(
RawOrigin::Signed(Keyring::Alice.into()).into(),
pool_id,
Domain::EVM(MOONBEAM_EVM_CHAIN_ID),
),
pallet_liquidity_pools::Error::<T>::NotPoolAdmin
);

// Verify that it works if it's BOB calling it (the pool admin)
assert_ok!(pallet_liquidity_pools::Pallet::<T>::add_pool(
RawOrigin::Signed(POOL_ADMIN.into()).into(),
pool_id,
Domain::EVM(MOONBEAM_EVM_CHAIN_ID),
));
});
}

#[test_runtimes([development])]
fn add_tranche<T: Runtime + FudgeSupport>() {
let mut env = FudgeEnv::<T>::from_parachain_storage(
Expand Down

0 comments on commit d5e46fe

Please sign in to comment.