Skip to content

Commit

Permalink
Multihop: adds test for checking if the max_spread_bps is above
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Nov 3, 2023
1 parent 607ba05 commit 0bf5e90
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions contracts/multihop/src/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,47 @@ fn swap_single_pool_no_fees() {
assert_eq!(token2.balance(&recipient), 1_000i128); // +1_000 token1
}

#[test]
#[should_panic(expected = "Pool: Assert max spread: spread exceeds maximum allowed")]
fn swap_should_fail_when_spread_exceeds_the_limit() {
let env = Env::default();
let admin = Address::random(&env);

env.mock_all_auths();
env.budget().reset_unlimited();

let token1 = deploy_and_mint_tokens(&env, &admin, 1_001_000i128);
let token2 = deploy_and_mint_tokens(&env, &admin, 1_001_000i128);

let factory_client = deploy_and_initialize_factory(&env, admin.clone());

deploy_and_initialize_lp(
&env,
&factory_client,
admin.clone(),
token1.address.clone(),
1_000_000,
token2.address.clone(),
1_000_000,
None,
);

let multihop = deploy_multihop_contract(&env, admin.clone(), &factory_client.address);
let recipient = Address::random(&env);
token1.mint(&recipient, &5_000i128); // mints 50 token0 to recipient
assert_eq!(token1.balance(&recipient), 5_000i128);
assert_eq!(token2.balance(&recipient), 0i128);

let swap1 = Swap {
offer_asset: token1.address.clone(),
ask_asset: token2.address.clone(),
};

let operations = vec![&env, swap1];

multihop.swap(&recipient, &None, &operations, &None, &Some(7_000), &1_000);
}

#[test]
fn swap_single_pool_with_fees() {
let env = Env::default();
Expand Down

0 comments on commit 0bf5e90

Please sign in to comment.