-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: initialize echidna for fuzz testing (#208)
Co-authored-by: lumtis <[email protected]>
- Loading branch information
Showing
16 changed files
with
2,247 additions
and
11 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 |
---|---|---|
|
@@ -4,4 +4,5 @@ cache | |
dist | ||
node_modules | ||
typechain-types | ||
docs | ||
docs | ||
crytic-export |
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 |
---|---|---|
|
@@ -30,4 +30,6 @@ coverage.json | |
scripts/slither-results/* | ||
!scripts/slither-results/.gitkeep | ||
|
||
abi | ||
abi | ||
|
||
crytic-export |
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,6 @@ | ||
# provide solc remappings to crytic-compile | ||
cryticArgs: ['--solc-remaps', '@=node_modules/@'] | ||
testMode: "assertion" | ||
testLimit: 50000 | ||
seqLen: 10000 | ||
allContracts: false |
2 changes: 1 addition & 1 deletion
2
pkg/contracts/prototypes/evm/erc20custodynew.sol/erc20custodynew.go
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
import "../../contracts/prototypes/evm/TestERC20.sol"; | ||
import "../../contracts/prototypes/evm/ERC20CustodyNew.sol"; | ||
import "../../contracts/prototypes/evm/GatewayEVM.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract ERC20CustodyNewEchidnaTest is ERC20CustodyNew { | ||
using SafeERC20 for IERC20; | ||
|
||
TestERC20 public testERC20; | ||
address public echidnaCaller = msg.sender; | ||
|
||
GatewayEVM testGateway = new GatewayEVM(); | ||
|
||
constructor() ERC20CustodyNew(address(testGateway)) { | ||
testGateway.initialize(echidnaCaller); | ||
testERC20 = new TestERC20("test", "TEST"); | ||
testGateway.setCustody(address(this)); | ||
} | ||
|
||
function testWithdrawAndCall(address to, uint256 amount, bytes calldata data) public { | ||
// mint more than amount | ||
testERC20.mint(address(this), amount + 5); | ||
// transfer overhead to gateway | ||
testERC20.transfer(address(testGateway), 5); | ||
|
||
withdrawAndCall(address(testERC20), to, amount, data); | ||
|
||
// Assertion to ensure no ERC20 tokens are left in the gateway contract after execution | ||
assert(testERC20.balanceOf(address(gateway)) == 0); | ||
} | ||
} |
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,27 @@ | ||
import "../../contracts/prototypes/evm/GatewayEVM.sol"; | ||
import "../../contracts/prototypes/evm/TestERC20.sol"; | ||
import "../../contracts/prototypes/evm/ERC20CustodyNew.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract GatewayEVMEchidnaTest is GatewayEVM { | ||
using SafeERC20 for IERC20; | ||
|
||
TestERC20 public testERC20; | ||
address public echidnaCaller = msg.sender; | ||
|
||
constructor() { | ||
initialize(echidnaCaller); | ||
testERC20 = new TestERC20("test", "TEST"); | ||
custody = address(new ERC20CustodyNew(address(this))); | ||
} | ||
|
||
function testExecuteWithERC20(address to, uint256 amount, bytes calldata data) public { | ||
testERC20.mint(address(this), amount); | ||
|
||
executeWithERC20(address(testERC20), to, amount, data); | ||
|
||
// Assertion to ensure no ERC20 tokens are left in the contract after execution | ||
assert(testERC20.balanceOf(address(this)) == 0); | ||
} | ||
} |
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,13 @@ | ||
## Setup echidna | ||
|
||
``` | ||
brew install echidna | ||
solc-select use 0.8.7 | ||
``` | ||
|
||
## Execute contract tests | ||
|
||
``` | ||
echidna test/fuzz/ERC20CustodyNewEchidnaTest.sol --contract ERC20CustodyNewEchidnaTest --config echidna.yaml | ||
echidna test/fuzz/GatewayEVMEchidnaTest.sol --contract GatewayEVMEchidnaTest --config echidna.yaml | ||
``` |
Oops, something went wrong.