Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: stable

# 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
4 changes: 2 additions & 2 deletions snapshots/BinPoolManagerTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"BinPoolManagerTest": "292661",
"binPoolManager initcode hash (without constructor params, as uint256)": "86819153192491064271307073571725897487337363688428763335923728549485318549268",
"testBurnNativeCurrency": "146154",
"testExtLoadPoolActiveId": "272",
"testExtLoadPoolActiveId": "2272",
"testGasBurnHalfBin": "141152",
"testGasBurnOneBin": "137621",
"testGasDonate": "114795",
"testGasGetBin": "2275",
"testGasGetBin": "16275",
"testGasMintNneBins-1": "966356",
"testGasMintNneBins-2": "329651",
"testGasMintOneBin-1": "333929",
Expand Down
65 changes: 46 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,18 +309,24 @@ 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
{
if (sender == receiver) return; // same address transfer will revert earlier

amount = bound(amount, 1, type(uint256).max);
uint256 overflowAmount = type(uint256).max - amount + 1;

Expand All @@ -325,22 +337,32 @@ 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 {
if (sender == receiver) return; // same address transfer will revert earlier

amount = bound(amount, 1, type(uint256).max);
uint256 overflowAmount = type(uint256).max - amount + 1;

Expand All @@ -351,18 +373,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);
}
}