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 Debug Tracing Methods #30911

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sina-haseli
Copy link

@sina-haseli sina-haseli commented Dec 13, 2024

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:

  • Suggest improvements for the tests.
  • Guide further contributions to the project.

If these changes align with the project’s goals, I’d be happy to continue contributing!

@sina-haseli sina-haseli requested a review from s1na as a code owner December 13, 2024 19:01
Copy link
Contributor

@s1na s1na left a 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.

}

func createTestFile(name string, data []byte) {
_ = os.WriteFile(name, data, 0644)
Copy link
Contributor

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

// 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))
Copy link
Contributor

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) {
Copy link
Contributor

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.

signer := types.HomesteadSigner{}
var badBlockHash, genesisHash common.Hash

backend := newTestBackend(t, 2, genesis, func(i int, b *core.BlockGen) {
Copy link
Contributor

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.

config: nil,
expectErr: false,
validateFn: func(roots []common.Hash) {
if len(roots) == 0 {
Copy link
Contributor

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.

@sina-haseli
Copy link
Author

@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.

@sina-haseli sina-haseli requested a review from s1na December 16, 2024 21:17
@fjl fjl assigned s1na Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants