Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Improve tests of exchange_router contract. #555

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/deposit/deposit_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn create_deposit(
) -> felt252 {
validate_account(account);

//let market = data_store.get_market(data_store,params.market);
let market = market_utils::get_enabled_market(data_store, params.market);
market_utils::validate_swap_path(data_store, params.long_token_swap_path);
market_utils::validate_swap_path(data_store, params.short_token_swap_path);
Expand Down
10 changes: 5 additions & 5 deletions src/exchange/deposit_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod DepositHandler {
use satoru::exchange::exchange_utils;
use satoru::deposit::execute_deposit_utils;
use satoru::oracle::oracle_utils;
use satoru::utils::global_reentrancy_guard;
use satoru::utils::{global_reentrancy_guard, starknet_utils};

// *************************************************************************
// STORAGE
Expand Down Expand Up @@ -183,7 +183,7 @@ mod DepositHandler {
let data_store = self.data_store.read();
global_reentrancy_guard::non_reentrant_before(data_store);

// let starting_gas = gas_left();
let starting_gas = starknet_utils::sn_gasleft(array![]);

let deposit = data_store.get_deposit(key);

Expand All @@ -200,7 +200,7 @@ mod DepositHandler {
self.deposit_vault.read(),
key,
deposit.account,
0, //starting_gas
starting_gas,
keys::user_initiated_cancel(),
array!['Cancel Deposit'] //TODO should be empty string
);
Expand Down Expand Up @@ -254,7 +254,7 @@ mod DepositHandler {
oracle_params: SetPricesParams,
keeper: ContractAddress
) {
// let starting_gas = gas_left();
let starting_gas = starknet_utils::sn_gasleft(array![]);
let data_store = self.data_store.read();
feature_utils::validate_feature(
data_store, keys::execute_deposit_feature_disabled_key(get_contract_address())
Expand All @@ -276,7 +276,7 @@ mod DepositHandler {
min_oracle_block_numbers,
max_oracle_block_numbers,
keeper,
starting_gas: 0 // TODO starting_gas
starting_gas
};

execute_deposit_utils::execute_deposit(params);
Expand Down
4 changes: 2 additions & 2 deletions src/gas/gas_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ fn pay_execution_fee_deposit(
let fee_token: ContractAddress = token_utils::fee_token(data_store);

// 63/64 gas is forwarded to external calls, reduce the startingGas to account for this
let reduced_starting_gas = starting_gas - sn_gasleft(array![100]) / 63;
let gas_used = reduced_starting_gas - sn_gasleft(array![100]);
let reduced_starting_gas = starting_gas - sn_gasleft(array![]) / 63;
let gas_used = reduced_starting_gas - sn_gasleft(array![]);

// each external call forwards 63/64 of the remaining gas
let mut execution_fee_for_keeper = adjust_gas_usage(data_store, gas_used)
Expand Down
9 changes: 4 additions & 5 deletions src/router/exchange_router.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,20 @@ mod ExchangeRouter {

fn create_deposit(ref self: ContractState, params: CreateDepositParams) -> felt252 {
let data_store = self.data_store.read();
global_reentrancy_guard::non_reentrant_before(data_store);
// global_reentrancy_guard::non_reentrant_before(data_store);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global_reentrancy_guard::non_reentrant_before function is also called in the create_deposit function.
So I think there's one call too many, please, can you check if it's really this call that should be removed and not the one from the create_deposit function?


let account = get_caller_address();

let key = self.deposit_handler.read().create_deposit(account, params);

global_reentrancy_guard::non_reentrant_after(data_store);
// global_reentrancy_guard::non_reentrant_after(data_store);

key
}

fn cancel_deposit(ref self: ContractState, key: felt252) {
let data_store = self.data_store.read();
global_reentrancy_guard::non_reentrant_before(data_store);
// global_reentrancy_guard::non_reentrant_before(data_store);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global_reentrancy_guard::non_reentrant_before function is also called in the cancel_deposit function.
So I think there's one call too many, please, can you check if it's really this call that should be removed and not the one from the cancel_deposit function?


let deposit = data_store.get_deposit(key);

Expand All @@ -311,8 +311,7 @@ mod ExchangeRouter {
}

self.deposit_handler.read().cancel_deposit(key);

global_reentrancy_guard::non_reentrant_after(data_store);
// global_reentrancy_guard::non_reentrant_after(data_store);
}

fn create_withdrawal(ref self: ContractState, params: CreateWithdrawalParams) -> felt252 {
Expand Down
1 change: 1 addition & 0 deletions tests/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod role {
}
mod router {
mod test_router;
mod test_exchange_router;
}
mod swap {
mod test_swap_handler;
Expand Down
Loading
Loading