-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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 Debug Tracing Methods #30911
base: master
Are you sure you want to change the base?
Add Tests for Debug Tracing Methods #30911
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.
Hey thanks for this. I have requested some changes please take a look.
eth/tracers/api_test.go
Outdated
} | ||
|
||
func createTestFile(name string, data []byte) { | ||
_ = os.WriteFile(name, data, 0644) |
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.
Let's use testing's TempDir to put the files in so the working directory is not polluted. https://pkg.go.dev/testing#F.TempDir
eth/tracers/api_test.go
Outdated
// Fetch the first block and RLP encode it | ||
encodedBlock, err := rlp.EncodeToBytes(block) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to encode block: %v", err)) |
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.
Either return the error and use t.Fatalf
or pass t
to the function so you can do it here.
} | ||
genBlock := 3 | ||
signer := types.HomesteadSigner{} | ||
backend := newTestBackend(nil, genBlock, genesis, func(i int, b *core.BlockGen) { |
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.
This is a good start but the blocks will have empty traces. It will be great if some code is executed too as part of a tx in there.
eth/tracers/api_test.go
Outdated
signer := types.HomesteadSigner{} | ||
var badBlockHash, genesisHash common.Hash | ||
|
||
backend := newTestBackend(t, 2, genesis, func(i int, b *core.BlockGen) { |
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.
Specifically when it comes to intermediate roots it would be good to modify the state apart from only the transfer. e.g. some SSTORE as part of a tx.
eth/tracers/api_test.go
Outdated
config: nil, | ||
expectErr: false, | ||
validateFn: func(roots []common.Hash) { | ||
if len(roots) == 0 { |
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.
Right this is not enough we need to actually check the root hashes.
@s1na Thanks for the feedback! 😊 I've made all the changes you suggested. Whenever you get a chance, please take another look and let me know if everything’s good now. |
This PR addresses issue #30833, which highlights the need for improved test coverage for debug tracing methods in the project.
Changes
The following methods now have tests to ensure their reliability and functionality:
debug_standardTraceBlockToFile
debug_standardTraceBadBlockToFile
debug_intermediateRoots
debug_traceBadBlock
These tests have been added to the
eth/tracers/api_test.go file
.Purpose
These methods are crucial for debugging and diagnosing issues when something goes wrong. Expanding test coverage will help ensure they are ready for use in critical situations.
Notes
This contribution is aimed at improving the tracing API’s reliability. Feedback is welcome to:
If these changes align with the project’s goals, I’d be happy to continue contributing!