From 0bf5e900d64c009e6c7d8a01e2635c428f50eb27 Mon Sep 17 00:00:00 2001 From: Kaloyan Gangov Date: Fri, 3 Nov 2023 18:14:55 +0200 Subject: [PATCH] Multihop: adds test for checking if the max_spread_bps is above --- contracts/multihop/src/tests/swap.rs | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/contracts/multihop/src/tests/swap.rs b/contracts/multihop/src/tests/swap.rs index 2534c6e01..b05323c08 100644 --- a/contracts/multihop/src/tests/swap.rs +++ b/contracts/multihop/src/tests/swap.rs @@ -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();