Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-471e4ac317858b3419faaee58ade30c0671021e0 # Nightly (2024-10-03)
version: v1.0.0
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open to v1.0.0 or if u guys prefer stable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use stable now ?
And test did not pass

Copy link
Copy Markdown
Contributor Author

@ChefMist ChefMist May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1.0.0 timeout in CI for test, where v1.1.0 had performance optimization. see https://github.com/foundry-rs/foundry/releases/tag/v1.1.0

from CI test log can see our test runs much faster now


# If FOUNDRY_PROFILE is removed, test will not revert if exceed contract size limit
- name: Run tests
Expand Down
5 changes: 0 additions & 5 deletions .husky/pre-commit

This file was deleted.

4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ evm_version = 'cancun'
gas_limit = "300000000"
bytecode_hash = "none"

# added due to v1.0 foundry
# ref: https://book.getfoundry.sh/guides/v1.0-migration#expect-revert-cheatcode-disabled-on-internal-calls-by-default
allow_internal_expect_revert = true

[fuzz]
runs = 5 # change this for higher number of fuzz runs locally

Expand Down
61 changes: 42 additions & 19 deletions test/VaultToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,22 @@ contract VaultTokenTest is Test {
assertEq(token.balanceOf(receiver, _toCurrency(1337)), 70);
}

function testFailMintBalanceOverflow() public {
function test_RevertWhenMintBalanceOverflow() public {
token.mint(address(0xDEAD), _toCurrency(1337), type(uint256).max);
vm.expectRevert();
token.mint(address(0xDEAD), _toCurrency(1337), 1);
}

function testFailTransferBalanceUnderflow() public {
function test_RevertWhenTransferBalanceUnderflow() public {
address sender = address(0xABCD);
address receiver = address(0xBEEF);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, _toCurrency(1337), 1);
}

function testFailTransferBalanceOverflow() public {
function test_RevertWhenTransferBalanceOverflow() public {
address sender = address(0xABCD);
address receiver = address(0xBEEF);

Expand All @@ -137,19 +139,21 @@ contract VaultTokenTest is Test {

token.mint(sender, _toCurrency(1337), 1);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, _toCurrency(1337), 1);
}

function testFailTransferFromBalanceUnderflow() public {
function test_RevertWhenTransferFromBalanceUnderflow() public {
address sender = address(0xABCD);
address receiver = address(0xBEEF);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, _toCurrency(1337), 1);
}

function testFailTransferFromBalanceOverflow() public {
function test_RevertWhenTransferFromBalanceOverflow() public {
address sender = address(0xABCD);
address receiver = address(0xBEEF);

Expand All @@ -160,16 +164,18 @@ contract VaultTokenTest is Test {

token.mint(sender, _toCurrency(1337), 1);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, _toCurrency(1337), 1);
}

function testFailTransferFromNotAuthorized() public {
function test_RevertWhenTransferFromNotAuthorized() public {
address sender = address(0xABCD);
address receiver = address(0xBEEF);

token.mint(sender, _toCurrency(1337), 100);

vm.expectRevert();
token.transferFrom(sender, receiver, _toCurrency(1337), 100);
}

Expand Down Expand Up @@ -303,16 +309,20 @@ contract VaultTokenTest is Test {
}
}

function testFailTransferBalanceUnderflow(address sender, address receiver, Currency currency, uint256 amount)
public
{
function test_RevertWhenTransferBalanceUnderflow(
address sender,
address receiver,
Currency currency,
uint256 amount
) public {
amount = bound(amount, 1, type(uint256).max);

vm.expectRevert();
vm.prank(sender);
token.transfer(receiver, currency, amount);
}

function testFailTransferBalanceOverflow(address sender, address receiver, Currency currency, uint256 amount)
function test_RevertWhenTransferBalanceOverflow(address sender, address receiver, Currency currency, uint256 amount)
public
{
amount = bound(amount, 1, type(uint256).max);
Expand All @@ -325,22 +335,30 @@ contract VaultTokenTest is Test {

token.mint(sender, currency, overflowAmount);

vm.expectRevert();
vm.prank(sender);
token.transfer(receiver, currency, overflowAmount);
}

function testFailTransferFromBalanceUnderflow(address sender, address receiver, Currency currency, uint256 amount)
public
{
function test_RevertWhenTransferFromBalanceUnderflow(
address sender,
address receiver,
Currency currency,
uint256 amount
) public {
amount = bound(amount, 1, type(uint256).max);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, currency, amount);
}

function testFailTransferFromBalanceOverflow(address sender, address receiver, Currency currency, uint256 amount)
public
{
function test_RevertWhenTransferFromBalanceOverflow(
address sender,
address receiver,
Currency currency,
uint256 amount
) public {
amount = bound(amount, 1, type(uint256).max);
uint256 overflowAmount = type(uint256).max - amount + 1;

Expand All @@ -351,18 +369,23 @@ contract VaultTokenTest is Test {

token.mint(sender, currency, overflowAmount);

vm.expectRevert();
vm.prank(sender);
token.transferFrom(sender, receiver, currency, overflowAmount);
}

function testFailTransferFromNotAuthorized(address sender, address receiver, Currency currency, uint256 amount)
public
{
function test_RevertWhenTransferFromNotAuthorized(
address sender,
address receiver,
Currency currency,
uint256 amount
) public {
amount = bound(amount, 1, type(uint256).max);
vm.assume(sender != address(this));

token.mint(sender, currency, amount);

vm.expectRevert();
token.transferFrom(sender, receiver, currency, amount);
}
}
Loading