-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: setup foundry test * chore: add remappings * forge install: erc4626-tests * test: add foundry fuzzing tests * fix: max uint deposit limit * fix: test strategy * fix: foundry runner * fix: clamp overflow * fix: default tests * chore: clean up linting * fix: new strategy version
- Loading branch information
1 parent
c23843d
commit c8fab70
Showing
20 changed files
with
439 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Foundry tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{github.workflow}}-${{github.ref}} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
unit: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
architecture: | ||
- "x64" | ||
python-version: | ||
- "3.10" | ||
node_version: | ||
- 16 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: ${{ matrix.architecture }} | ||
|
||
- name: Install Ape | ||
uses: ApeWorX/[email protected] | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: install vyper | ||
run: pip install git+https://github.com/vyperlang/vyper | ||
|
||
- name: Compile contracts | ||
# Compile Ape contracts to get dependencies | ||
run: ape compile --force --size | ||
|
||
- name: Install Vyper | ||
run: pip install vyper==0.3.7 | ||
|
||
- name: Use Node.js ${{ matrix.node_version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node_version }} | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Foundry tests | ||
run: forge test -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ jobs: | |
- uses: ApeWorX/[email protected] | ||
with: | ||
python-version: '3.10' | ||
ape-version-pin: "==0.7.0" | ||
|
||
- name: install vyper | ||
run: pip install git+https://github.com/vyperlang/vyper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
pyenv.cfg | ||
vyper_git_commithash.txt | ||
bin/ | ||
lib/ | ||
cache/ | ||
out/ | ||
share/ | ||
build/ | ||
include/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/erc4626-tests"] | ||
path = lib/erc4626-tests | ||
url = https://github.com/a16z/erc4626-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[profile.default] | ||
src = 'contracts' | ||
test = 'foundry_tests' | ||
out = 'out' | ||
libs = ['lib'] | ||
|
||
remappings = [ | ||
'forge-std/=lib/forge-std/src/', | ||
'erc4626-tests/=lib/erc4626-tests/', | ||
"@tokenized-strategy=contracts/.cache/tokenized-strategy/dev_302", | ||
'@openzeppelin/contracts=contracts/.cache/openzeppelin/v4.9.5/', | ||
] | ||
fs_permissions = [{ access = "read", path = "./"}] | ||
|
||
match_path = "foundry_tests/tests/*" | ||
ffi = true | ||
|
||
[fuzz] | ||
runs = 250 | ||
max_test_rejects = 1_000_000 | ||
|
||
[invariant] | ||
runs = 100 | ||
depth = 100 | ||
|
||
# See more config options https://github.com/gakonst/foundry/tree/master/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.18; | ||
|
||
import "erc4626-tests/ERC4626.test.sol"; | ||
|
||
import {Setup} from "../utils/Setup.sol"; | ||
|
||
// SEE https://github.com/a16z/erc4626-tests | ||
contract VaultERC4626StdTest is ERC4626Test, Setup { | ||
function setUp() public override(ERC4626Test, Setup) { | ||
super.setUp(); | ||
_underlying_ = address(asset); | ||
_vault_ = address(vault); | ||
_delta_ = 0; | ||
_vaultMayBeEmpty = true; | ||
_unlimitedAmount = true; | ||
} | ||
|
||
// NOTE: The following tests are relaxed to consider only smaller values (of type uint120), | ||
// since the maxWithdraw(), and maxRedeem() functions fail with large values (due to overflow). | ||
|
||
function test_maxWithdraw(Init memory init) public override { | ||
init = clamp(init, type(uint120).max); | ||
super.test_maxWithdraw(init); | ||
} | ||
|
||
function test_maxRedeem(Init memory init) public override { | ||
init = clamp(init, type(uint120).max); | ||
super.test_maxRedeem(init); | ||
} | ||
|
||
function clamp( | ||
Init memory init, | ||
uint max | ||
) internal pure returns (Init memory) { | ||
for (uint i = 0; i < N; i++) { | ||
init.share[i] = init.share[i] % max; | ||
init.asset[i] = init.asset[i] % max; | ||
} | ||
init.yield = init.yield % int(max); | ||
return init; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity 0.8.18; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract ExtendedTest is Test { | ||
// solhint-disable-next-line | ||
function assertNeq(address a, address b) internal { | ||
if (a == b) { | ||
emit log("Error: a != b not satisfied [address]"); | ||
emit log_named_address(" Expected", b); | ||
emit log_named_address(" Actual", a); | ||
fail(); | ||
} | ||
} | ||
|
||
// @dev checks whether @a is within certain percentage of @b | ||
// @a actual value | ||
// @b expected value | ||
// solhint-disable-next-line | ||
function assertRelApproxEq( | ||
uint256 a, | ||
uint256 b, | ||
uint256 maxPercentDelta | ||
) internal virtual { | ||
uint256 delta = a > b ? a - b : b - a; | ||
uint256 maxRelDelta = b / maxPercentDelta; | ||
|
||
if (delta > maxRelDelta) { | ||
emit log("Error: a ~= b not satisfied [uint]"); | ||
emit log_named_uint(" Expected", b); | ||
emit log_named_uint(" Actual", a); | ||
emit log_named_uint(" Max Delta", maxRelDelta); | ||
emit log_named_uint(" Delta", delta); | ||
fail(); | ||
} | ||
} | ||
|
||
// Can be removed once https://github.com/dapphub/ds-test/pull/25 is merged and we update submodules, but useful for now | ||
// solhint-disable-next-line | ||
function assertApproxEq( | ||
uint256 a, | ||
uint256 b, | ||
uint256 margin_of_error | ||
) internal { | ||
if (a > b) { | ||
if (a - b > margin_of_error) { | ||
emit log("Error a not equal to b"); | ||
emit log_named_uint(" Expected", b); | ||
emit log_named_uint(" Actual", a); | ||
fail(); | ||
} | ||
} else { | ||
if (b - a > margin_of_error) { | ||
emit log("Error a not equal to b"); | ||
emit log_named_uint(" Expected", b); | ||
emit log_named_uint(" Actual", a); | ||
fail(); | ||
} | ||
} | ||
} | ||
|
||
// solhint-disable-next-line | ||
function assertApproxEq( | ||
uint256 a, | ||
uint256 b, | ||
uint256 margin_of_error, | ||
string memory err | ||
) internal { | ||
if (a > b) { | ||
if (a - b > margin_of_error) { | ||
emit log_named_string("Error", err); | ||
emit log_named_uint(" Expected", b); | ||
emit log_named_uint(" Actual", a); | ||
fail(); | ||
} | ||
} else { | ||
if (b - a > margin_of_error) { | ||
emit log_named_string("Error", err); | ||
emit log_named_uint(" Expected", b); | ||
emit log_named_uint(" Actual", a); | ||
fail(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.