Skip to content

Commit

Permalink
Fix/swap - Swap test working fine (keep-starknet-strange#637)
Browse files Browse the repository at this point in the history
* Fixed some of the swap issues

* fixed swap issue

* removed comments

* fmt check

* fmt fix

* uncommented all the tests

* tests
  • Loading branch information
Sk8erboi84 authored Mar 30, 2024
1 parent 63b22e2 commit 18dd623
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 131 deletions.
3 changes: 1 addition & 2 deletions src/market/market_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2831,8 +2831,8 @@ fn validate_market_token_balance_with_token(
.balance_of(market.market_token)
.low
.into();
'Issue here'.print();
let expected_min_balance: u256 = get_expected_min_token_balance(data_store, market, token);

assert(balance >= expected_min_balance, MarketError::INVALID_MARKET_TOKEN_BALANCE);

// funding fees can be claimed even if the collateral for positions that should pay funding fees
Expand Down Expand Up @@ -2882,7 +2882,6 @@ fn get_expected_min_token_balance(
.get_u256(keys::claimable_ui_fee_amount_key(market.market_token, token));
let affiliate_reward_amount: u256 = data_store
.get_u256(keys::affiliate_reward_key(market.market_token, token));

// funding fees are excluded from this summation as claimable funding fees
// are incremented without a corresponding decrease of the collateral of
// other positions, the collateral of other positions is decreased when
Expand Down
23 changes: 17 additions & 6 deletions tests/integration/swap_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ fn test_deposit_market_integration() {

// Set params in data_store
data_store.set_address(keys::fee_token(), market.index_token);
data_store.set_u128(keys::max_swap_path_length(), 5);
data_store.set_u256(keys::max_swap_path_length(), 5);

// Set max pool amount.
data_store
.set_u128(
.set_u256(
keys::max_pool_amount_key(market.market_token, market.long_token), 500000000000000000
);
data_store
.set_u128(
.set_u256(
keys::max_pool_amount_key(market.market_token, market.short_token), 500000000000000000
);

oracle.set_price_testing_eth(5000);
// Fill the pool.
IERC20Dispatcher { contract_address: market.long_token }.mint(market.market_token, 50000000000);
IERC20Dispatcher { contract_address: market.short_token }
Expand Down Expand Up @@ -286,8 +287,18 @@ fn test_deposit_market_integration() {
let key = order_handler.create_order(caller_address, order_params);

let got_order = data_store.get_order(key);
// data_store.set_u128(keys::pool_amount_key(market.market_token, contract_address_const::<'USDC'>()), );
// data_store.set_u128(keys::pool_amount_key(market.market_token, contract_address_const::<'ETH'>()), 1000000);

data_store
.set_u256(
keys::pool_amount_key(market.market_token, contract_address_const::<'USDC'>()),
10000000000
);
data_store
.set_u256(
keys::pool_amount_key(market.market_token, contract_address_const::<'ETH'>()),
10000000000
);

// Execute the swap order.
let signatures: Span<felt252> = array![0].span();
let set_price_params = SetPricesParams {
Expand Down Expand Up @@ -684,7 +695,7 @@ fn deploy_role_store() -> ContractAddress {
let caller_address: ContractAddress = contract_address_const::<'caller'>();
let deployed_contract_address = contract_address_const::<'role_store'>();
start_prank(deployed_contract_address, caller_address);
contract.deploy_at(@array![], deployed_contract_address).unwrap()
contract.deploy_at(@array![caller_address.into()], deployed_contract_address).unwrap()
}

fn deploy_event_emitter() -> ContractAddress {
Expand Down
245 changes: 122 additions & 123 deletions tests/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,130 +1,129 @@
// mod adl {
// mod test_adl_utils;
// }
// mod bank {
// mod test_bank;
// mod test_strict_bank;
// }
// mod callback {
// mod test_callback_utils;
// }
// mod config {
// mod test_config;
// }
// mod data {
// mod test_data_store;
// mod test_deposit_store;
// mod test_keys;
// mod test_market;
// mod test_order;
// mod test_position;
// mod test_withdrawal;
// }
// mod deposit {
// mod test_deposit_utils;
// mod test_deposit_vault;
// mod test_execute_deposit_utils;
// }
// mod event {
// mod test_adl_events_emitted;
// mod test_callback_events_emitted;
// mod test_config_events_emitted;
// mod test_gas_events_emitted;
// mod test_market_events_emitted;
// mod test_oracle_events_emitted;
// mod test_order_events_emitted;
// mod test_position_events_emitted;
// mod test_pricing_events_emitted;
// mod test_referral_events_emitted;
// mod test_swap_events_emitted;
// mod test_timelock_events_emitted;
// mod test_withdrawal_events_emitted;
// mod test_event_utils;
// }
// mod exchange {
// mod test_liquidation_handler;
// mod test_withdrawal_handler;
// mod test_deposit_handler;
// mod test_exchange_utils;
// mod test_base_order_handler;
// }
// mod feature {
// mod test_feature_utils;
// }
// mod fee {
// mod test_fee_handler;
// mod test_fee_utils;
// }
// mod market {
// mod test_market_factory;
// mod test_market_token;
// mod test_market_utils;
// }
// mod nonce {
// mod test_nonce_utils;
// }
// mod oracle {
// mod test_oracle;
// }
// mod order {
// mod test_base_order_utils;
// mod test_increase_order_utils;
// mod test_order;
// }
// mod position {
// mod test_decrease_position_utils;
// mod test_decrease_position_swap_utils;
// mod test_position_utils;
// }
// mod price {
// mod test_price;
// }
// mod pricing {
// mod test_position_pricing_utils;
// mod test_swap_pricing_utils;
// }
// mod reader {
// mod test_reader;
// }
// mod role {
// mod test_role_module;
// mod test_role_store;
// }
// mod router {
// mod test_router;
// }
// mod swap {
// mod test_swap_handler;
// }
// mod utils {
// mod test_account_utils;
// mod test_arrays;
// mod test_basic_multicall;
// mod test_calc;
// mod test_enumerable_set;
// mod test_precision;
// mod test_reentrancy_guard;
// mod test_starknet_utils;
// mod test_u128_mask;
// mod test_i128;
// mod test_serializable_dict;
// }
// mod withdrawal {
// mod test_withdrawal_vault;
// }
// mod mock {
// mod test_governable;
// mod test_referral_storage;
// }
// mod referral {
// mod test_referral_utils;
// }
// mod test_create_and_execute_swap;
mod adl {
mod test_adl_utils;
}
mod bank {
mod test_bank;
mod test_strict_bank;
}
mod callback {
mod test_callback_utils;
}
mod config {
mod test_config;
}
mod data {
mod test_data_store;
mod test_deposit_store;
mod test_keys;
mod test_market;
mod test_order;
mod test_position;
mod test_withdrawal;
}
mod deposit {
mod test_deposit_utils;
mod test_deposit_vault;
mod test_execute_deposit_utils;
}
mod event {
mod test_adl_events_emitted;
mod test_callback_events_emitted;
mod test_config_events_emitted;
mod test_gas_events_emitted;
mod test_market_events_emitted;
mod test_oracle_events_emitted;
mod test_order_events_emitted;
mod test_position_events_emitted;
mod test_pricing_events_emitted;
mod test_referral_events_emitted;
mod test_swap_events_emitted;
mod test_timelock_events_emitted;
mod test_withdrawal_events_emitted;
mod test_event_utils;
}
mod exchange {
mod test_liquidation_handler;
mod test_withdrawal_handler;
mod test_deposit_handler;
mod test_exchange_utils;
mod test_base_order_handler;
}
mod feature {
mod test_feature_utils;
}
mod fee {
mod test_fee_handler;
mod test_fee_utils;
}
mod market {
mod test_market_factory;
mod test_market_token;
mod test_market_utils;
}
mod nonce {
mod test_nonce_utils;
}
mod oracle {
mod test_oracle;
}
mod order {
mod test_base_order_utils;
mod test_increase_order_utils;
mod test_order;
}
mod position {
mod test_decrease_position_utils;
mod test_decrease_position_swap_utils;
mod test_position_utils;
}
mod price {
mod test_price;
}
mod pricing {
mod test_position_pricing_utils;
mod test_swap_pricing_utils;
}
mod reader {
mod test_reader;
}
mod role {
mod test_role_module;
mod test_role_store;
}
mod router {
mod test_router;
}
mod swap {
mod test_swap_handler;
}
mod utils {
mod test_account_utils;
mod test_arrays;
mod test_basic_multicall;
mod test_calc;
mod test_enumerable_set;
mod test_precision;
mod test_reentrancy_guard;
mod test_starknet_utils;
// mod test_u128_mask;
// mod test_i128;
mod test_serializable_dict;
}
mod withdrawal {
mod test_withdrawal_vault;
}
mod mock {
mod test_governable;
mod test_referral_storage;
}
mod referral {
mod test_referral_utils;
}

mod integration {
mod test_deposit_withdrawal;
mod test_long_integration;
mod test_short_integration;
mod test_swap_integration;
//mod swap_test;
mod swap_test;
}

0 comments on commit 18dd623

Please sign in to comment.