-
Notifications
You must be signed in to change notification settings - Fork 326
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
hevm: enchanced control over blockchain context #716
Open
d-xo
wants to merge
6
commits into
master
Choose a base branch
from
control-nonce
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+306
−41
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd1ae7a
hevm: add env var to control nonce
d-xo 14ca831
nix: buildDappPackage: use real dapprc
d-xo 4f4bd40
hevm: add look and file cheatcodes
d-xo b934e8f
hevm: dev: add some new opts to ghciTest
d-xo 51fdbaa
hevm: rm address replacement cheatcode, add code replacement cheatcode
d-xo 7006ccd
hevm: don't modify vm after vmError
d-xo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,8 @@ | ||
import "ds-test/test.sol"; | ||
|
||
contract Env is DSTest { | ||
// DAPP_TEST_ORIGIN | ||
function testOrigin() public { | ||
assertEq(tx.origin, address(256)); | ||
} | ||
} |
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,72 @@ | ||
import "ds-test/test.sol"; | ||
|
||
contract Env is DSTest { | ||
uint creationGas; | ||
constructor() public { | ||
creationGas = gasleft(); | ||
} | ||
|
||
// TODO: why does this fail when address == 0? | ||
// DAPP_TEST_BALANCE | ||
function testBalance() public { | ||
assertEq(address(this).balance, 998877665544 ether); | ||
} | ||
// DAPP_TEST_ADDRESS | ||
function testAddress() public { | ||
assertEq(address(this), address(256)); | ||
} | ||
// DAPP_TEST_NONCE | ||
// we can't test the nonce directly, but can instead check the address of a newly deployed contract | ||
function testNonce() public { | ||
uint8 nonce = 100; | ||
bytes memory payload = abi.encodePacked(hex"d694", address(this), nonce); | ||
|
||
address expected = address(uint160(uint256(keccak256(payload)))); | ||
address actual = address(new Trivial()); | ||
assertEq(actual, expected); | ||
|
||
} | ||
// DAPP_TEST_CALLER | ||
function testCaller() public { | ||
assertEq(msg.sender, address(100)); | ||
} | ||
// DAPP_TEST_GAS_CREATE | ||
function testGasCreate() public { | ||
// we can't be exact since we had to spend some gas to write to storage... | ||
assertLt(creationGas, 4.20 ether); | ||
assertGt(creationGas, 4.1999999999999 ether); | ||
} | ||
// DAPP_TEST_GAS_CALL | ||
function testGasCall() public { | ||
uint gas = gasleft(); | ||
// we can't be exact since we had to spend some gas to get here... | ||
assertLt(gas, 0.69 ether); | ||
assertGt(gas, 0.689999999999999 ether); | ||
} | ||
// DAPP_TEST_COINBASE | ||
function testCoinbase() public { | ||
assertEq(block.coinbase, address(666)); | ||
} | ||
// DAPP_TEST_NUMBER | ||
function testBlockNumber() public { | ||
assertEq(block.number, 420); | ||
} | ||
// DAPP_TEST_TIMESTAMP | ||
function testTimestamp() public { | ||
assertEq(block.timestamp, 69); | ||
} | ||
// DAPP_TEST_GAS_LIMIT | ||
function testGasLimit() public { | ||
assertEq(block.gaslimit, 4206966 ether); | ||
} | ||
// DAPP_TEST_GAS_PRICE | ||
function testGasPrice() public { | ||
assertEq(tx.gasprice, 100); | ||
} | ||
// DAPP_TEST_DIFFICULTY | ||
function testDifficulty() public { | ||
assertEq(block.difficulty, 600); | ||
} | ||
} | ||
|
||
contract Trivial {} |
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 |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
## Unreleased | ||
|
||
### Added | ||
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. TODO: document new cheatcodes.... |
||
|
||
- A new configuration variable `DAPP_TEST_NONCE` has been added that allows control over the nonce of the testing contract | ||
|
||
### Changed | ||
|
||
- The configuration variable `DAPP_TEST_BALANCE_CREATE` has been renamed to `DAPP_TEST_BALANCE` | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no idea why at all, but if I construct the target contract directly with the code below in the test instead of in the constructor this test always fails (and it does so before reaching the call to the cheatcode).... 🤔
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.
Hmm, strange indeed. Does it revert or what is the error?
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.