Skip to content

Commit

Permalink
feat: adding more checks to bToken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 22, 2024
1 parent d4ebbab commit a5c434b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/unit/BToken.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import {IERC20} from '@openzeppelin/contracts/interfaces/IERC20.sol';
import {IERC20Errors} from '@openzeppelin/contracts/interfaces/draft-IERC6093.sol';
import {Test} from 'forge-std/Test.sol';
import {MockBToken} from 'test/smock/MockBToken.sol';
Expand Down Expand Up @@ -44,6 +45,10 @@ contract BToken is Test {
}

function test_IncreaseApprovalWhenCalled() external {
// it emits Approval event
vm.expectEmit();
emit IERC20.Approval(caller, spender, 200e18);

bToken.increaseApproval(spender, 100e18);
// it increases spender approval
assertEq(bToken.allowance(caller, spender), 200e18);
Expand All @@ -69,22 +74,46 @@ contract BToken is Test {
}

function test_DecreaseApprovalWhenCalled() external {
// it emits Approval event
vm.expectEmit();
emit IERC20.Approval(caller, spender, 50e18);

bToken.decreaseApproval(spender, 50e18);
// it decreases spender approval
assertEq(bToken.allowance(caller, spender), 50e18);
}

function test__pushRevertWhen_ContractDoesNotHaveEnoughBalance() external {
// it should revert
vm.expectRevert(abi.encodeWithSelector(IERC20Errors.ERC20InsufficientBalance.selector, address(bToken), 0, 50e18));
bToken.call__push(target, 50e18);
}

function test__pushWhenCalled() external {
deal(address(bToken), address(bToken), initialBalance);
// it emits Transfer event
vm.expectEmit();
emit IERC20.Transfer(address(bToken), target, 50e18);

bToken.call__push(target, 50e18);

// it transfers tokens to recipient
assertEq(bToken.balanceOf(address(bToken)), 50e18);
assertEq(bToken.balanceOf(target), 50e18);
}

function test__pullRevertWhen_TargetDoesNotHaveEnoughBalance() external {
// it should revert
vm.expectRevert(abi.encodeWithSelector(IERC20Errors.ERC20InsufficientBalance.selector, target, 0, 50e18));
bToken.call__pull(target, 50e18);
}

function test__pullWhenCalled() external {
deal(address(bToken), address(target), initialBalance);
// it emits Transfer event
vm.expectEmit();
emit IERC20.Transfer(target, address(bToken), 50e18);

bToken.call__pull(target, 50e18);

// it transfers tokens from sender
Expand Down
8 changes: 8 additions & 0 deletions test/unit/BToken.tree
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BToken::increaseApproval
├── when spender is address zero
│ └── it should revert
└── when called
├── it emits Approval event
└── it increases spender approval

BToken::decreaseApproval
Expand All @@ -19,12 +20,19 @@ BToken::decreaseApproval
├── when decrement is bigger than current approval
│ └── it decreases spender approval to 0
└── when called
├── it emits Approval event
└── it decreases spender approval

BToken::_push
├── when contract does not have enough balance
│ └── it should revert
└── when called
├── it emits Transfer event
└── it transfers tokens to recipient

BToken::_pull
├── when target does not have enough balance
│ └── it should revert
└── when called
├── it emits Transfer event
└── it transfers tokens from sender

0 comments on commit a5c434b

Please sign in to comment.