vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
251 stars 51 forks source link

rework environment variables API #32

Open charles-cooper opened 1 year ago

charles-cooper commented 1 year ago

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
DanielSchiavini commented 5 months ago

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:

When we are clear on the API I can implement this issue.

DanielSchiavini commented 5 months ago

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.

charles-cooper commented 5 months ago

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