aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-04 19:03:43 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 19:27:24 +0800
commit7964f30dcbdde00b2960ef6e98320e0a0f9300e2 (patch)
treeadd3fbd54ec615135f3ecdac2917d22e77581d56 /p2p/message_test.go
parent21649100b1ed64c9bd73c547360dd6db9b5218fb (diff)
downloaddexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.tar.gz
dexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.tar.zst
dexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.zip
p2p: msg.Payload contains list data
With RLPx frames, the message code is contained in the frame and is no longer part of the encoded data. EncodeMsg, Msg.Decode have been updated to match. Code that decodes RLP directly from Msg.Payload will need to change.
Diffstat (limited to 'p2p/message_test.go')
-rw-r--r--p2p/message_test.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/p2p/message_test.go b/p2p/message_test.go
index 1757cbe7a..31ed61d87 100644
--- a/p2p/message_test.go
+++ b/p2p/message_test.go
@@ -2,10 +2,12 @@ package p2p
import (
"bytes"
+ "encoding/hex"
"fmt"
"io"
"io/ioutil"
"runtime"
+ "strings"
"testing"
"time"
)
@@ -15,11 +17,11 @@ func TestNewMsg(t *testing.T) {
if msg.Code != 3 {
t.Errorf("incorrect code %d, want %d", msg.Code)
}
- if msg.Size != 5 {
- t.Errorf("incorrect size %d, want %d", msg.Size, 5)
+ expect := unhex("c50183303030")
+ if msg.Size != uint32(len(expect)) {
+ t.Errorf("incorrect size %d, want %d", msg.Size, len(expect))
}
pl, _ := ioutil.ReadAll(msg.Payload)
- expect := []byte{0x01, 0x83, 0x30, 0x30, 0x30}
if !bytes.Equal(pl, expect) {
t.Errorf("incorrect payload content, got %x, want %x", pl, expect)
}
@@ -139,3 +141,11 @@ func TestEOFSignal(t *testing.T) {
default:
}
}
+
+func unhex(str string) []byte {
+ b, err := hex.DecodeString(strings.Replace(str, "\n", "", -1))
+ if err != nil {
+ panic(fmt.Sprintf("invalid hex string: %q", str))
+ }
+ return b
+}