From ffb73f4a61bd0d88b879eb57404bf50e1745891e Mon Sep 17 00:00:00 2001 From: Oshioke Salaki Date: Sat, 10 Feb 2024 15:13:55 +0000 Subject: [PATCH] test: withdraw fails when there is insuffient reward tokens --- .../test_bwc_staking_contract.cairo | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/tests/bwc_staking_contract/test_bwc_staking_contract.cairo b/src/tests/bwc_staking_contract/test_bwc_staking_contract.cairo index 47c1dbe..0248723 100644 --- a/src/tests/bwc_staking_contract/test_bwc_staking_contract.cairo +++ b/src/tests/bwc_staking_contract/test_bwc_staking_contract.cairo @@ -278,7 +278,34 @@ fn test_invalid_withdraw_time() { stake_dispatcher.withdraw(5); } +#[test] +#[should_panic(expected: ('Not enough reward token to send',))] +fn test_insufficient_reward_token() { + let (staking_contract_address, bwc_contract_address, receipt_contract_address, reward_contract_address) = + deploy_contract(); + let receipt_dispatcher = IERC20Dispatcher { contract_address: receipt_contract_address }; + let stake_dispatcher = IStakeDispatcher { contract_address: staking_contract_address }; + let bwc_dispatcher = IERC20Dispatcher { contract_address: bwc_contract_address }; + let reward_dispatcher = IERC20Dispatcher { contract_address: reward_contract_address }; + + + start_prank(CheatTarget::One(bwc_contract_address), Account::admin()); + bwc_dispatcher.transfer(Account::user1(), 35); + stop_prank(CheatTarget::One(bwc_contract_address)); + start_prank(CheatTarget::One(receipt_contract_address), Account::admin()); + receipt_dispatcher.transfer(staking_contract_address, 20); + stop_prank(CheatTarget::One(receipt_contract_address)); + + start_prank(CheatTarget::One(bwc_contract_address), Account::user1()); + bwc_dispatcher.approve(staking_contract_address, 10); + stop_prank(CheatTarget::One(bwc_contract_address)); + + start_prank(CheatTarget::One(staking_contract_address), Account::user1()); + stake_dispatcher.stake(6); + start_warp(CheatTarget::One(staking_contract_address), get_block_timestamp() + 240); + stake_dispatcher.withdraw(5); +}