Skip to content

Commit

Permalink
pool: lints, adds comments according to PR, fixes conflicts, fixes fa…
Browse files Browse the repository at this point in the history
…iling tests
  • Loading branch information
gangov committed Feb 19, 2024
1 parent 3f132bb commit 2e2288e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions contracts/pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ impl LiquidityPoolTrait for LiquidityPool {
} else if offer_asset == config.token_b {
(pool_balance_b, pool_balance_a)
} else {
log!(&env, "Token offered to swap not found in Pool");
panic_with_error!(env, ContractError::AssetNotInPool);
};

Expand Down Expand Up @@ -627,6 +628,7 @@ impl LiquidityPoolTrait for LiquidityPool {
} else if ask_asset == config.token_a {
(pool_balance_b, pool_balance_a)
} else {
log!(&env, "Token offered to swap not found in Pool");
panic_with_error!(env, ContractError::AssetNotInPool);
};

Expand Down
12 changes: 9 additions & 3 deletions contracts/pool/src/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ fn test_v_phx_vul_021_should_panic_when_max_spread_invalid_range(max_spread: Opt
}

#[test]
#[should_panic(expected = "HostError: Error(Contract, #13)")]
#[should_panic(expected = "HostError: Error(Contract, #16)")]
fn test_v_phx_vul_017_should_panic_when_swapping_non_existing_token_in_pool() {
let env = Env::default();
env.mock_all_auths();
Expand All @@ -839,6 +839,8 @@ fn test_v_phx_vul_017_should_panic_when_swapping_non_existing_token_in_pool() {
None,
None,
None,
Address::generate(&env),
Address::generate(&env),
);
// Swap fails because we provide incorrect token as offer token.
pool.swap(
Expand All @@ -853,7 +855,7 @@ fn test_v_phx_vul_017_should_panic_when_swapping_non_existing_token_in_pool() {
}

#[test]
#[should_panic(expected = "HostError: Error(Contract, #13)")]
#[should_panic(expected = "HostError: Error(Contract, #16)")]
fn test_v_phx_vul_017_should_panic_when_simulating_swap_for_non_existing_token_in_pool() {
let env = Env::default();
env.mock_all_auths();
Expand All @@ -878,6 +880,8 @@ fn test_v_phx_vul_017_should_panic_when_simulating_swap_for_non_existing_token_i
None,
None,
None,
Address::generate(&env),
Address::generate(&env),
);
// Simulate swap fails because we provide incorrect token as offer token.
pool.simulate_swap(
Expand All @@ -889,7 +893,7 @@ fn test_v_phx_vul_017_should_panic_when_simulating_swap_for_non_existing_token_i
}

#[test]
#[should_panic(expected = "HostError: Error(Contract, #13)")]
#[should_panic(expected = "HostError: Error(Contract, #16)")]
fn test_v_phx_vul_017_should_panic_when_simulating_reverse_swap_for_non_existing_token_in_pool() {
let env = Env::default();
env.mock_all_auths();
Expand All @@ -914,6 +918,8 @@ fn test_v_phx_vul_017_should_panic_when_simulating_reverse_swap_for_non_existing
None,
None,
None,
Address::generate(&env),
Address::generate(&env),
);
// Simulate swap fails because we provide incorrect token as offer token.
pool.simulate_reverse_swap(
Expand Down

0 comments on commit 2e2288e

Please sign in to comment.