-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: initialize echidna for fuzz testing #208
Changes from all commits
1f2625e
bd71007
3553a8f
791834b
c1bd47d
6aed43c
8a973c1
d562400
555ff9d
21b8ace
484096a
a0c8e5a
5b893d2
776caef
704382b
5e4766c
ce87491
049f956
278c327
9303311
cb0ca6c
b9e5bfd
9a785bc
430992a
a09cc0c
b39bc57
4ee9023
d784b8e
7e3ad3e
0b1f894
7db93dd
69d5763
022fee2
1e8af88
d94d8ff
290a84e
5817d9a
f7d18fd
51ff6a2
b857b9c
cbd7dcf
da9c0cd
6bd8c16
f2a3371
cc93e3e
5a5f76b
941949e
6275282
8c33743
fa96e30
b5a665a
badd4f8
d158c71
49223b2
4275805
caae687
0c1b370
76f284d
e62b051
b69926f
bb27a54
d80596e
e559c31
d0ad2f5
354e45a
3190026
4ec838c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ cache | |
dist | ||
node_modules | ||
typechain-types | ||
docs | ||
docs | ||
crytic-export |
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 |
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 | ||||||||||||||||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix trailing spaces and add a newline at the end of the file. There are trailing spaces on lines 4 and 5, and the file is missing a newline at the end. - testLimit: 50000
- seqLen: 10000
+ testLimit: 50000
+ seqLen: 10000
+ Committable suggestion
Suggested change
Toolsyamllint
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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); | ||
} | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Setup echidna | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify language for fenced code blocks and add a newline at the end of the file. Fenced code blocks should have a language specified, and the file should end with a newline. - ```
+ ```sh
- ```
+ ```sh
+ Also applies to: 10-10, 13-13 ToolsMarkdownlint
|
||
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 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under which circumstances is withdrawAndCall and executeWithERC20 be called from within ERC20CustodyNew? This impacts the amount of gas consumed by these functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by circumstances?
withdrawAndCall
is called by the TSS address when handling an outboundThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably will be clearer when we add access control