-
Notifications
You must be signed in to change notification settings - Fork 840
test: Use predictable accounts for TestTracingwithOverrides #4666
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a flaky test (TestTracingWithOverrides) that fails approximately 1/256 times when randomly generated block hashes start with 0xef, which conflicts with London hard fork validation rules.
Key changes:
- Introduces deterministic account generation using a fixed random seed
- Adds
newAccountsWithSeedhelper function to generate predictable test accounts
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: Austin Larson <[email protected]>
ARR4N
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work in finding that! I'd usually try to understand why it happens, but this will all be deleted in time.
|
I'm not changing the dependencies right before subnet-evm merger, so I'll just wait to push for a review |
alarso16
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to update all the commits used in versioning to trick the go.mod into accepting the lower semantic version
fa6d8c3 to
a55d7af
Compare
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | ||
| seed := make([]byte, 8) // int64 size | ||
| for i := 0; i < n; i++ { | ||
| binary.BigEndian.PutUint64(seed, uint64(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | |
| seed := make([]byte, 8) // int64 size | |
| for i := 0; i < n; i++ { | |
| binary.BigEndian.PutUint64(seed, uint64(i)) | |
| func UNSAFEDeterministicAccounts(t *testing.T, n uint64) (accounts []Account) { | |
| seed := make([]byte, 8) // int64 size | |
| for i := range n { | |
| binary.BigEndian.PutUint64(seed, i) |
| addr := crypto.PubkeyToAddress(key.PublicKey) | ||
| accounts = append(accounts, Account{key: key, addr: addr}) | ||
| } | ||
| slices.SortFunc(accounts, func(a, b Account) int { return a.addr.Cmp(b.addr) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sort them?
| func testTracingWithOverrides(t *testing.T, scheme string) { | ||
| // Initialize test accounts | ||
| accounts := newAccounts(3) | ||
| // This test requires deterministic block hashes, since it will fail 1/256 times,Expand commentComment on line R635ResolvedCode has comments. Press enter to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand commentComment on line R635ResolvedCode
?
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | ||
| seed := make([]byte, 8) // int64 size | ||
| for i := 0; i < n; i++ { | ||
| binary.BigEndian.PutUint64(seed, uint64(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| func UNSAFEDeterministicAccounts(t *testing.T, n int) (accounts []Account) { | |
| seed := make([]byte, 8) // int64 size | |
| for i := 0; i < n; i++ { | |
| binary.BigEndian.PutUint64(seed, uint64(i)) | |
| func UNSAFEDeterministicAccounts(t *testing.T, n uint64) (accounts []Account) { | |
| seed := make([]byte, 8) // int64 size | |
| for i := range n { | |
| binary.BigEndian.PutUint64(seed, i) |
Why this should be merged
This test flakes because every once in a while, the final block hash starts with
0xef, which is incompatible with the London hard fork. It's unintuitive that theErrInvalidCodeerror would be encountered for return values that are not code hashes, but this testing only fix will remove failures in CICloses #4560
How this works
Uses a random seed to pre-fill the state with the same data every time.
How this was tested
Locally, logging the resulting block hash.
Need to be documented in RELEASES.md?
No