Skip to content

Commit

Permalink
test: add a test for exchange_utils (#383)
Browse files Browse the repository at this point in the history
* Add tests

* Update test_exchange_utils.cairo

* Update test_exchange_utils.cairo

* Update lib.cairo

* Update test_exchange_utils.cairo

* Update test_exchange_utils.cairo

---------

Co-authored-by: sparqet <37338401+sparqet@users.noreply.github.com>
  • Loading branch information
delaaxe and sparqet authored Oct 19, 2023
1 parent 4208819 commit 6ce3682
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/exchange/test_exchange_utils.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use starknet::{
ContractAddress, get_caller_address, get_contract_address, Felt252TryIntoContractAddress,
contract_address_const
};
use starknet::info::get_block_number;
use snforge_std::{declare, start_prank, stop_prank, start_roll, ContractClassTrait};

use satoru::data::keys;
use satoru::data::data_store::{IDataStoreDispatcher, IDataStoreDispatcherTrait};
use satoru::exchange::exchange_utils::validate_request_cancellation;
use satoru::tests_lib::{setup, teardown};

#[test]
fn given_exchange_utils_when_validate_request_cancellation_then_success() {
// Setup
let (_, _, data_store) = setup();
let contract_address = contract_address_const::<0>();

// Test
let expiration_age = 5;
data_store.set_u128(keys::request_expiration_block_age(), expiration_age);

let block_number = get_block_number();

let created_at_block = block_number - 5;
validate_request_cancellation(data_store, created_at_block, 'SOME_REQUEST_TYPE');

let created_at_block = block_number - 6;
validate_request_cancellation(data_store, created_at_block, 'SOME_REQUEST_TYPE');

// Teardown
teardown(data_store.contract_address);
}

#[test]
#[should_panic(expected: ('request_not_yet_cancellable', 'SOME_REQUEST_TYPE'))]
fn given_exchange_utils_when_validate_request_cancellation_then_fails() {
// Setup
let (_, _, data_store) = setup();
let contract_address = contract_address_const::<0>();

// Test
let expiration_age = 5;
data_store.set_u128(keys::request_expiration_block_age(), expiration_age);

let block_number = get_block_number();
let created_at_block = block_number - 4;

validate_request_cancellation(data_store, created_at_block, 'SOME_REQUEST_TYPE');
}
1 change: 1 addition & 0 deletions tests/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ 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 {
Expand Down

0 comments on commit 6ce3682

Please sign in to comment.