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

multi: add getwork tests. #2306

Merged
merged 1 commit into from
Aug 6, 2020
Merged

Conversation

dnldd
Copy link
Member

@dnldd dnldd commented Jul 27, 2020

This adds rpc handler tests for getwork.

Work towards #2069.

@davecgh davecgh added the test coverage Discussion and pull requests for improving test coverage. label Jul 27, 2020
@davecgh davecgh added this to the 1.6.0 milestone Jul 27, 2020
internal/mining/mining.go Outdated Show resolved Hide resolved
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

The interface pieces look good now, but I see that the test coverage is missing several paths and submission altogether.

$ go test -run=TestHandleGetWork -coverprofile=cov.out
$ go tool cover -func=cov.out | grep -E handleGetWork
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3290:            handleGetWorkRequest            92.7%
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3394:            handleGetWorkSubmission         0.0%
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3482:            handleGetWork                   93.3%

rpcadaptors.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
@dnldd
Copy link
Member Author

dnldd commented Aug 3, 2020

All paths not covered could not be hit.

go tool cover -func=cov.out | grep -E handleGetWork
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3287:               handleGetWorkRequest            95.1%
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3391:               handleGetWorkSubmission         92.9%
github.com/decred/dcrd/internal/rpcserver/rpcserver.go:3479:               handleGetWork                   100.0%

Based on that I'd suggest removing the error check here since CheckProofOfWork only returns standalone.RuleError types.

@davecgh
Copy link
Member

davecgh commented Aug 5, 2020

Regarding your comment about removing the unexpected error type check, I agree that it's currently impossible, and hence can't be tested, but I also know that code gets refactored and thus assumptions that like always end up broken over time.

As a case in point, I see you already caught a case where it was checking for the wrong type of error. In this path, if the code gets refactored and some other issue happens, it would be completely hidden if the error check is removed as it would just look a miner submitting a block that didn't meet the work requirements even though it could be a real issue.

internal/rpcserver/rpcserver.go Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
internal/rpcserver/rpcserverhandlers_test.go Outdated Show resolved Hide resolved
Copy link
Member

@rstaudt2 rstaudt2 left a comment

Choose a reason for hiding this comment

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

Looks good. Super minor but I did notice that there is a typo in the commit message (This fixes a proof of work error check and adds rpc handler tests for getWork.)

This fixes a proof of work error check and
adds rpc handler tests for getWork.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test coverage Discussion and pull requests for improving test coverage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants