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

Add tests for partial account helper functions #3745

Merged
merged 11 commits into from
Feb 8, 2025

Conversation

scorbajio
Copy link
Contributor

This change adds unit tests testing a variety of cases for the partial account helper functions:

  • createPartialAccount
  • createPartialAccountFromRLP
  • serializeWithPartialInfo

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.50%. Comparing base (4ed3482) to head (703a657).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 76.87% <ø> (ø)
blockchain 85.69% <ø> (ø)
client 66.26% <ø> (ø)
common 90.31% <ø> (ø)
devp2p 76.27% <ø> (ø)
ethash 81.04% <ø> (ø)
evm 69.34% <ø> (ø)
genesis 99.84% <ø> (ø)
mpt 59.75% <ø> (-0.21%) ⬇️
rlp 69.70% <ø> (ø)
statemanager 70.15% <ø> (ø)
tx 80.52% <ø> (ø)
util 85.16% <ø> (+7.64%) ⬆️
vm 57.81% <ø> (ø)
wallet 83.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this AI generated? If so can we please establish the convention (within the whole team) to always clearly mark/label this as such?

If so, we should clearly exchange on some best practices on how to review such code and what expectation we put on it.

If not: my apologies. 😂

@scorbajio
Copy link
Contributor Author

Is this AI generated? If so can we please establish the convention (within the whole team) to always clearly mark/label this as such?

If so, we should clearly exchange on some best practices on how to review such code and what expectation we put on it.

If not: my apologies. 😂

Sure, we can block this for now. I used AI to generate the boilerplate and cases, then reviewed, corrected, and filled in missing pieces of the tests to get it to compile 🙂.

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests themselves look good! However, if you create a partial account from some data and then assert later it is the correct account (with the same, copied data) it is more clean to read these variables from data and then compare those (now the values are copied, so if you change one value you also have to change it on another place. If it's in a const var, only one place needs to be edited)

Copy link
Contributor

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

Comment on lines 836 to 845
const account = createPartialAccount({
nonce: 1n,
balance: Units.ether(1),
storageRoot: KECCAK256_RLP,
codeHash: KECCAK256_RLP,
codeSize: 10,
version: 1,
})

assert.deepEqual(account, new Account(1n, Units.ether(1), KECCAK256_RLP, KECCAK256_RLP, 10, 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo this could be improved by assigning nonce, balance, etc. to variables, and then testing against that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled out the field data into a const variable and am using that to both create the account and check for equality.

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the comments! lgtm

@gabrocheleau gabrocheleau merged commit cac7cc4 into master Feb 8, 2025
40 of 41 checks passed
@scorbajio scorbajio deleted the partial-account-function-tests branch February 8, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants