Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(fw,tests): Transaction nonce as Iterator[int] #434

Closed
wants to merge 2 commits into from

Conversation

marioevz
Copy link
Member

@marioevz marioevz commented Feb 9, 2024

🗒️ Description

Allows more broad usage of iterators in some fields such as:

  • BlockchainTest: blocks -> Iterable
  • Block: txs -> Iterable
  • Block: withdrawals -> Iterable
  • Transaction: nonce -> Iterator

This is now possible:

nonce = count()
...
tx1 = Transaction(nonce=nonce)
tx2 = Transaction(nonce=nonce)

Although, when refactoring some of the tests I realized most usages of this pattern didn't really need it 🙃

Anyway, it's nice to allow it. Wdyt? @spencer-tb @danceratopz

🔗 Related Issues

None

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@marioevz marioevz added type:chore Type: Chore scope:fw Scope: Framework (evm|tools|forks|pytest) labels Feb 9, 2024
@marioevz
Copy link
Member Author

marioevz commented Feb 9, 2024

Another pattern I saw is something like this:

txs= [
Transaction(
        ty=0x0,
        nonce=0,
        to=account1,
        data=data1,
        gas_limit=500000,
        gas_price=10,
        protected=True,
    ),
Transaction(
        ty=0x0,
        nonce=0,
        to=account2,
        data=data2,
        gas_limit=500000,
        gas_price=10,
        protected=True,
    ),

I think we can replace it with something like

Transactions(
nonce=count(),
to=[account1, account2],
data=[data1,data2]
gas_limit=500_000,
gas_price=10,
)

Would this be more useful? Basically just a generator that checks all kwargs and if the value is:

  • isinstance(Iterator, arg), nothing to do (use next(arg) on each iteration)
  • isinstance(Iterable, arg) (but not string, nor bytes), do iter(arg)
  • Neither, use itertools.cycle

Until any of the iterators is exhausted. nonce can be optional and just defaults to a new itertools.count if None.

@marioevz
Copy link
Member Author

marioevz commented Feb 9, 2024

Implemented previous comment in #435, and it's much more useful, and supersedes all changes in this PR.

@marioevz marioevz closed this Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:fw Scope: Framework (evm|tools|forks|pytest) type:chore Type: Chore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant