-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: getBlockTimestamp and getBlockHeight * tests * chore: rename getBlockHeight to getBlockNumber * cargo cheats * chore: make fns safe & view * Update testdata/cheats/GetBlockTimestamp.t.sol Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> * chore: update docs * chore: cargo cheats --------- Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "./Vm.sol"; | ||
|
||
contract GetBlockTimestampTest is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function testGetTimestamp() public { | ||
uint256 timestamp = vm.getBlockTimestamp(); | ||
assertEq(timestamp, 1, "timestamp should be 1"); | ||
} | ||
|
||
function testGetTimestampWithWarp() public { | ||
assertEq(vm.getBlockTimestamp(), 1, "timestamp should be 1"); | ||
vm.warp(10); | ||
assertEq(vm.getBlockTimestamp(), 10, "warp failed"); | ||
} | ||
|
||
function testGetTimestampWithWarpFuzzed(uint128 jump) public { | ||
uint256 pre = vm.getBlockTimestamp(); | ||
vm.warp(pre + jump); | ||
assertEq(vm.getBlockTimestamp(), pre + jump, "warp failed"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,25 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "./Vm.sol"; | ||
|
||
contract GetBlockNumberTest is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function testGetBlockNumber() public { | ||
uint256 height = vm.getBlockNumber(); | ||
assertEq(height, uint256(block.number), "height should be equal to block.number"); | ||
} | ||
|
||
function testGetBlockNumberWithRoll() public { | ||
vm.roll(10); | ||
assertEq(vm.getBlockNumber(), 10, "could not get correct block height after roll"); | ||
} | ||
|
||
function testGetBlockNumberWithRollFuzzed(uint128 jump) public { | ||
uint256 pre = vm.getBlockNumber(); | ||
vm.roll(pre + jump); | ||
assertEq(vm.getBlockNumber(), pre + jump, "could not get correct block height after roll"); | ||
} | ||
} |