diff options
author | zelig <viktor.tron@gmail.com> | 2014-10-23 23:57:54 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-10-23 23:57:54 +0800 |
commit | 771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb (patch) | |
tree | 15a966dbe15e2f8388f69b396e613c7759b06f6d /p2p/message_test.go | |
parent | 119c5b40a7ed1aea1c871c0cb56956b8ef9303d9 (diff) | |
download | go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.gz go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.zst go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.zip |
initial commit of p2p package
Diffstat (limited to 'p2p/message_test.go')
-rw-r--r-- | p2p/message_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/p2p/message_test.go b/p2p/message_test.go new file mode 100644 index 000000000..e9d46f2c3 --- /dev/null +++ b/p2p/message_test.go @@ -0,0 +1,38 @@ +package p2p + +import ( + "testing" +) + +func TestNewMsg(t *testing.T) { + msg, _ := NewMsg(3, 1, "000") + if msg.Code() != 3 { + t.Errorf("incorrect code %v", msg.Code()) + } + data0 := msg.Data().Get(0).Uint() + data1 := string(msg.Data().Get(1).Bytes()) + if data0 != 1 { + t.Errorf("incorrect data %v", data0) + } + if data1 != "000" { + t.Errorf("incorrect data %v", data1) + } +} + +func TestEncodeDecodeMsg(t *testing.T) { + msg, _ := NewMsg(3, 1, "000") + encoded := msg.Encode(3) + msg, _ = NewMsgFromBytes(encoded) + msg.Decode(3) + if msg.Code() != 3 { + t.Errorf("incorrect code %v", msg.Code()) + } + data0 := msg.Data().Get(0).Uint() + data1 := msg.Data().Get(1).Str() + if data0 != 1 { + t.Errorf("incorrect data %v", data0) + } + if data1 != "000" { + t.Errorf("incorrect data %v", data1) + } +} |