mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Update message_test.go
This commit is contained in:
parent
064b6efc53
commit
48634ceb3d
1 changed files with 28 additions and 0 deletions
|
|
@ -23,6 +23,8 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleMsgPipe() {
|
func ExampleMsgPipe() {
|
||||||
|
|
@ -139,3 +141,29 @@ func TestEOFSignal(t *testing.T) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type msgReaderFunc func() (Msg, error)
|
||||||
|
|
||||||
|
func (f msgReaderFunc) ReadMsg() (Msg, error) { return f() }
|
||||||
|
|
||||||
|
func TestExpectMsgRejectsOverlongPayload(t *testing.T) {
|
||||||
|
content := []uint{1, 2, 3}
|
||||||
|
contentEnc, err := rlp.EncodeToBytes(content)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("rlp.EncodeToBytes failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := msgReaderFunc(func() (Msg, error) {
|
||||||
|
// Payload is one byte longer than declared size.
|
||||||
|
payload := append(append([]byte(nil), contentEnc...), 0x00)
|
||||||
|
return Msg{
|
||||||
|
Code: 7,
|
||||||
|
Size: uint32(len(contentEnc)),
|
||||||
|
Payload: bytes.NewReader(payload),
|
||||||
|
}, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := ExpectMsg(r, 7, content); err == nil {
|
||||||
|
t.Fatal("expected error for overlong payload, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue