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: Added tests for record_transfer_in #502

Merged
4 changes: 2 additions & 2 deletions src/deposit/deposit_vault.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ mod DepositVault {
}

fn record_transfer_in(ref self: ContractState, token: ContractAddress) -> u128 {
// TODO
0
let mut state: StrictBank::ContractState = StrictBank::unsafe_new_contract_state();
IStrictBank::record_transfer_in(ref state, token)
}
}
}
59 changes: 55 additions & 4 deletions tests/deposit/test_deposit_vault.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starknet::{
ContractAddress, get_caller_address, Felt252TryIntoContractAddress, contract_address_const,
ClassHash,
};
use snforge_std::{declare, start_prank, stop_prank, ContractClassTrait};
use snforge_std::{declare, start_prank, stop_prank, start_mock_call, ContractClassTrait};
use traits::{TryInto, Into};

// Local imports.
Expand Down Expand Up @@ -89,11 +89,62 @@ fn given_receiver_is_contract_when_transfer_out_then_fails() {
teardown(data_store, deposit_vault);
}

/// TODO: implement the tests when record_transfer_in is implemented
#[test]
#[should_panic(expected: ('NOT IMPLEMENTED YET',))]
fn given_normal_conditions_when_record_transfer_in_then_works() {
assert(true == false, 'NOT IMPLEMENTED YET')
let (_, _, _, data_store, deposit_vault, erc20) = setup();

let initial_balance: u128 = u128_from_felt252(INITIAL_TOKENS_MINTED);
let tokens_received: u128 = deposit_vault.record_transfer_in(erc20.contract_address);
assert(tokens_received == initial_balance, 'should be initial balance');

teardown(data_store, deposit_vault);
}

#[test]
fn given_more_balance_when_2nd_record_transfer_in_then_works() {
let (_, _, _, data_store, deposit_vault, erc20) = setup();

let initial_balance: u128 = u128_from_felt252(INITIAL_TOKENS_MINTED);
let tokens_received: u128 = deposit_vault.record_transfer_in(erc20.contract_address);
assert(tokens_received == initial_balance, 'should be initial balance');

let tokens_transfered_in: u128 = 250;
let mock_balance_with_more_tokens: u256 = (initial_balance + tokens_transfered_in).into();
start_mock_call(erc20.contract_address, 'balance_of', mock_balance_with_more_tokens);

let tokens_received: u128 = deposit_vault.record_transfer_in(erc20.contract_address);
assert(tokens_received == tokens_transfered_in, 'incorrect received amount');

teardown(data_store, deposit_vault);
}

#[test]
#[should_panic(expected: ('u128_sub Overflow',))]
fn given_less_balance_when_2nd_record_transfer_in_then_fails() {
let (_, _, _, data_store, deposit_vault, erc20) = setup();

let initial_balance: u128 = u128_from_felt252(INITIAL_TOKENS_MINTED);
let tokens_received: u128 = deposit_vault.record_transfer_in(erc20.contract_address);
assert(tokens_received == initial_balance, 'should be initial balance');

let tokens_transfered_out: u128 = 250;
let mock_balance_with_less_tokens: u256 = (initial_balance - tokens_transfered_out).into();
start_mock_call(erc20.contract_address, 'balance_of', mock_balance_with_less_tokens);

deposit_vault.record_transfer_in(erc20.contract_address);

teardown(data_store, deposit_vault);
}

#[test]
#[should_panic(expected: ('unauthorized_access',))]
fn given_caller_is_not_controller_when_record_transfer_in_then_fails() {
let (caller_address, _, role_store, data_store, deposit_vault, erc20) = setup();

role_store.revoke_role(caller_address, role::CONTROLLER);
deposit_vault.record_transfer_in(erc20.contract_address);

teardown(data_store, deposit_vault);
}

// *********************************************************************************************
Expand Down