titanoboa icon indicating copy to clipboard operation
titanoboa copied to clipboard

rework environment variables API

Open charles-cooper opened this issue 2 years ago • 3 comments

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

charles-cooper avatar Nov 21 '22 22:11 charles-cooper

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.

DanielSchiavini avatar Jun 03 '24 11:06 DanielSchiavini

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.

DanielSchiavini avatar Jun 03 '24 11:06 DanielSchiavini

I think anchoring is fine, especially for the other patchable attributes

charles-cooper avatar Jun 03 '24 11:06 charles-cooper