Skip to content

Commit

Permalink
Merge pull request #262 from lauchaves/test/test-emit-event-donation-…
Browse files Browse the repository at this point in the history
…withdraw

TEST: Add test_emit_event_donation_withdraw test
  • Loading branch information
EmmanuelAR authored Nov 23, 2024
2 parents 3d5eef6 + da61cfd commit 9eb43f3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,61 @@ fn test_update_received_donation() {
]
);
}

#[test]
#[fork("Mainnet")]
fn test_emit_event_donation_withdraw() {
let contract_address = _setup_();

let mut spy = spy_events();

let goal: u256 = 500 * ONE_E18;

let dispatcher = IFundDispatcher { contract_address };
let minter_address = contract_address_const::<StarknetConstants::STRK_TOKEN_MINTER_ADDRESS>();
let token_address = contract_address_const::<StarknetConstants::STRK_TOKEN_ADDRESS>();
let token_dispatcher = IERC20Dispatcher { contract_address: token_address };

start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_state(2);

start_cheat_caller_address(contract_address, FUND_MANAGER());
dispatcher.set_goal(goal);

start_cheat_caller_address(token_address, minter_address);
let mut calldata = array![];
calldata.append_serde(FUND_MANAGER());
calldata.append_serde(goal);
call_contract_syscall(token_address, selector!("permissioned_mint"), calldata.span()).unwrap();
stop_cheat_caller_address(token_address);

assert(token_dispatcher.balance_of(FUND_MANAGER()) == goal, 'invalid balance');

start_cheat_caller_address(token_address, FUND_MANAGER());
token_dispatcher.transfer(contract_address, goal);
stop_cheat_caller_address(token_address);

dispatcher.update_receive_donation(goal);

let current_balance = dispatcher.get_current_goal_state();

assert(dispatcher.get_state() == FundStates::CLOSED, 'state is not closed');
assert(current_balance == goal, 'goal not reached');

start_cheat_caller_address(contract_address, OWNER());

let withdrawn_amount = (goal * 95) / 100;

dispatcher.withdraw();

spy.assert_emitted(@array![
(
contract_address,
Fund::Event::DonationWithdraw(Fund::DonationWithdraw {
owner_address: OWNER(),
fund_contract_address: contract_address,
withdrawn_amount
})
)
]);
}

0 comments on commit 9eb43f3

Please sign in to comment.