mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
p2p: Add additional test case specified in EIP-7636
This commit is contained in:
parent
79ab35c29c
commit
18aeb9c436
1 changed files with 38 additions and 0 deletions
|
|
@ -18,9 +18,11 @@ package enr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -108,6 +110,40 @@ func TestGetSetClientInfo(t *testing.T) {
|
||||||
assert.Equal(t, clientWithBuild, clientWithBuild2)
|
assert.Equal(t, clientWithBuild, clientWithBuild2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This tests the decoding of an EIP-7636 compatible ENR
|
||||||
|
func TestDecodingENRWith7636(t *testing.T) {
|
||||||
|
enr := "enr:-MO4QBn4OF-y-dqULg4WOIlc8gQAt-arldNFe0_YQ4HNX28jDtg41xjDyKfCXGfZaPN97I-MCfogeK91TyqmWTpb0_AChmNsaWVudNqKTmV0aGVybWluZIYxLjkuNTOHN2ZjYjU2N4JpZIJ2NIJpcIR_AAABg2lwNpAAAAAAAAAAAAAAAAAAAAABiXNlY3AyNTZrMaECn-TTdCwfZP4XgJyq8Lxoj-SgEoIFgDLVBEUqQk4HnAqDdWRwgiMshHVkcDaCIyw"
|
||||||
|
b, err := base64.RawURLEncoding.DecodeString(strings.Replace(enr, "enr:", "", 1))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
record, _, err := decodeRecord(rlp.NewStream(bytes.NewReader(b), 0))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var client Client;
|
||||||
|
err = record.Load(&client);
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if client[0] == nil || client[1] == nil || client[2] == nil {
|
||||||
|
t.Error("Client info is not decoded correctly")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the client info is correct
|
||||||
|
assert.Equal(t, "Nethermind", *client[0])
|
||||||
|
assert.Equal(t, "1.9.53", *client[1])
|
||||||
|
assert.Equal(t, "7fcb567", *client[2])
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadErrors(t *testing.T) {
|
func TestLoadErrors(t *testing.T) {
|
||||||
var r Record
|
var r Record
|
||||||
ip4 := IPv4{127, 0, 0, 1}
|
ip4 := IPv4{127, 0, 0, 1}
|
||||||
|
|
@ -135,6 +171,8 @@ func TestLoadErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TestSortedGetAndSet tests that Set produced a sorted pairs slice.
|
// TestSortedGetAndSet tests that Set produced a sorted pairs slice.
|
||||||
func TestSortedGetAndSet(t *testing.T) {
|
func TestSortedGetAndSet(t *testing.T) {
|
||||||
type pair struct {
|
type pair struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue