titanoboa
titanoboa copied to clipboard
rework environment variables API
right now chain environment variables are set using boa.env.vm.patch
, ex. boa.env.vm.patch.chain_id = 5
.
but it might be friendlier for it to be like boa.env.chain.id = 5
(which would match the vyper naming as well).
bonus points if we can figure out how to make it a context manager at the same time, ex.
with boa.env.chain.id(5):
...
# equivalent to
tmp = boa.env.chain.id
boa.env.chain.id = 5
try:
...
finally:
boa.env.chain.id = tmp
I've closed https://github.com/vyperlang/titanoboa/pull/223 because I think it's a bad idea to use the same field name as context manager and as normal variable. I suggest:
-
boa.env.chain.id
,boa.env.block.number
, etc should be normal getter/setters -
boa.env.chain.anchor_id
,boa.env.block.anchor_number
, etc should be context managers
When we are clear on the API I can implement this issue.
Now that I think about it, do we really need context managers? It's weird that if we increase the block number/timestamp the time will always go back in the past after the context. That's not useful/realistic.
I think anchoring is fine, especially for the other patchable attributes