-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
env.timestamp
property (#368)
* feat: add timestamp to env as shortcut to patch object * docs: document `env.timestamp()` * Create test_env_timestamp.py --------- Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
- Loading branch information
1 parent
c2f9a9a
commit d20161f
Showing
3 changed files
with
46 additions
and
7 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
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 @@ | ||
import time | ||
|
||
import boa | ||
|
||
|
||
def test_env_timestamp(): | ||
assert boa.env.timestamp == boa.env.evm.patch.timestamp | ||
|
||
tmp = boa.env.timestamp | ||
with boa.env.anchor(): | ||
boa.env.timestamp += 1 | ||
# check patch is updated | ||
assert boa.env.timestamp == boa.env.evm.patch.timestamp | ||
assert tmp + 1 == boa.env.timestamp | ||
|
||
# check reset to prior value after anchor | ||
assert tmp == boa.env.timestamp | ||
# sanity check | ||
assert boa.env.timestamp == boa.env.evm.patch.timestamp | ||
|
||
|
||
def test_timestamp_correctness(): | ||
# amount of "timer slack" to allow in the CI since it may take some | ||
# time between when boa.env is initialized and when this test is run. | ||
timer_slack = 60 | ||
assert abs(boa.env.timestamp - time.time()) < timer_slack, "bad time" |