Skip to content

Commit

Permalink
Improve test widthdrawal handler (keep-starknet-strange#549)
Browse files Browse the repository at this point in the history
* improve_tests_withdrawal_handler

* improve_tests_withdrawal_handler

* improve_test_withdrawal_handler

* imporve_tests_withdrawal_handler

* improve_test_withdrawal_handler

---------

Co-authored-by: zarboq <[email protected]>
  • Loading branch information
0xTitan and zarboq authored Oct 26, 2023
1 parent 9f3d431 commit 21c7e18
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/exchange/withdrawal_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod WithdrawalHandler {

global_reentrancy_guard::non_reentrant_before(data_store); // Initiates re-entrancy

let starting_gas = starknet_utils::sn_gasleft(array![100]); // Returns 100 for now,
let starting_gas = starknet_utils::sn_gasleft(array![200]); // Returns 200 for now,
let withdrawal = data_store.get_withdrawal(key);

feature_utils::validate_feature(
Expand Down
8 changes: 5 additions & 3 deletions src/market/market_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2570,9 +2570,11 @@ fn validate_enabled_market_check(
fn validate_enabled_market(data_store: IDataStoreDispatcher, market: Market) {
assert(market.market_token != 0.try_into().unwrap(), MarketError::EMPTY_MARKET);

let is_market_disabled: bool = data_store
.get_bool(keys::is_market_disabled_key(market.market_token))
.unwrap();
let is_market_disabled: bool =
match data_store.get_bool(keys::is_market_disabled_key(market.market_token)) {
Option::Some(value) => value,
Option::None => false
};

if (is_market_disabled) {
MarketError::DISABLED_MARKET(is_market_disabled);
Expand Down
10 changes: 4 additions & 6 deletions src/withdrawal/withdrawal_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ fn create_withdrawal(
account_utils::validate_receiver(params.receiver);

let market_token_amount = withdrawal_vault.record_transfer_in(params.market);

if market_token_amount.is_zero() {
WithdrawalError::EMPTY_WITHDRAWAL_AMOUNT;
}

assert(market_token_amount.is_non_zero(), WithdrawalError::EMPTY_WITHDRAWAL_AMOUNT);
params.execution_fee = fee_token_amount.into();

market_utils::validate_enabled_market_check(data_store, params.market);
Expand Down Expand Up @@ -187,7 +183,9 @@ fn create_withdrawal(
gas_utils::validate_execution_fee(data_store, estimated_gas_limit, params.execution_fee);

let key = nonce_utils::get_next_key(data_store);

// assign generated key to withdrawal
withdrawal.key = key;
// store withdrawal
data_store.set_withdrawal(key, withdrawal);

event_emitter.emit_withdrawal_created(key, withdrawal);
Expand Down
Loading

0 comments on commit 21c7e18

Please sign in to comment.