-
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
cmd/devp2p: fixes for eth and discv4 tests #23155
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d9e3e3
p2p/discover/v4wire: add testcase for regression
holiman a838366
cmd/devp2p/internal/v4test: better error message
holiman f9cb25e
p2p/discover: remove moot test
holiman 5f85f75
cmd/devp2p/internal/ethtest: refactor code + clarify output
holiman 13af105
Update helpers.go
fjl 57de3a7
cmd/devp2p/internal: fix test failures
holiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2019 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package v4wire | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
) | ||
|
||
func TestDecode(t *testing.T) { | ||
for i, test := range []struct { | ||
input string | ||
expEnr int | ||
}{ | ||
{ | ||
input: "f83acb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a3558082999983999999", | ||
expEnr: 0, | ||
}, | ||
{ | ||
input: "f83acb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a3550182999983999999", | ||
expEnr: 1, | ||
}, | ||
{ | ||
input: "f2cb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a355", | ||
expEnr: 0, | ||
}, | ||
{ | ||
input: "f3cb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a35501", | ||
expEnr: 1, | ||
}, | ||
{ | ||
// This is how we previously encoded ENR sequence number of 0. | ||
input: "f3cb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a35580", | ||
expEnr: 0, | ||
}, | ||
{ | ||
// This input was previously accepted, it contains a non-canonical rlp rest `00`. This vector | ||
// fails after commit '3e6f46caec51d82aef363632517eb5842eef6db6' | ||
input: "f3cb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a35500", | ||
expEnr: -1, | ||
}, | ||
{ // This is how besu encodes a pong with enr sequence 0 | ||
input: "f83bcb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a355880000000000000000", | ||
expEnr: -1, | ||
}, | ||
{ // This is how besu encodes a pong with enr sequence 1 | ||
input: "f83bcb847f000001820cfa8215a8a000000000000000000000000000000000000000000000000000000000000012348443b9a355880000000000000001", | ||
expEnr: -1, | ||
}, | ||
} { | ||
input, err := hex.DecodeString(test.input) | ||
if err != nil { | ||
t.Fatalf("test %d: invalid hex: %s", i, test.input) | ||
} | ||
var pongPacket Pong | ||
err = rlp.DecodeBytes(input, &pongPacket) | ||
if err != nil && test.expEnr > -1 { | ||
t.Errorf("test %d: did not accept packet %s\n%v", i, test.input, err) | ||
continue | ||
} | ||
if test.expEnr == -1 { | ||
if err == nil { | ||
t.Errorf("test %d: expected failure", i) | ||
} | ||
continue | ||
} | ||
if have, want := pongPacket.ENRSeq, uint64(test.expEnr); have != want { | ||
t.Logf("test %d: got %s\n", i, spew.Sdump(pongPacket)) | ||
t.Errorf("test %d, wrong enr seq, have %d, want %d", i, have, want) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure we should keep this test. The test basically checks that RLP decoding works, but there are enough tests in package rlp to cover this, I think.
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.
Yeah, sure