Merge pull request #212 from harmony-one/open_source_cleanup

Open source cleanup
pull/213/head
Leo Chen 6 years ago committed by GitHub
commit 720885e7a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      api/proto/node/node.go
  2. 26
      api/proto/node/pingpong_test.go
  3. 2
      test/test_before_submit.sh

@ -5,6 +5,7 @@ import (
"encoding/gob" "encoding/gob"
"log" "log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
@ -34,7 +35,7 @@ const (
// BlockchainSyncMessage is a struct for blockchain sync message. // BlockchainSyncMessage is a struct for blockchain sync message.
type BlockchainSyncMessage struct { type BlockchainSyncMessage struct {
BlockHeight int BlockHeight int
BlockHashes [][32]byte BlockHashes []common.Hash
} }
// BlockchainSyncMessageType represents BlockchainSyncMessageType type. // BlockchainSyncMessageType represents BlockchainSyncMessageType type.

@ -2,6 +2,7 @@ package node
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"testing" "testing"
@ -57,8 +58,6 @@ func TestString(test *testing.T) {
r1 := fmt.Sprintf("%v", *ping1) r1 := fmt.Sprintf("%v", *ping1)
if strings.Compare(r1, e1) != 0 { if strings.Compare(r1, e1) != 0 {
test.Errorf("expect: %v, got: %v", e1, r1) test.Errorf("expect: %v, got: %v", e1, r1)
} else {
fmt.Println(r1)
} }
ping1.Node.Role = ClientRole ping1.Node.Role = ClientRole
@ -66,8 +65,6 @@ func TestString(test *testing.T) {
r3 := fmt.Sprintf("%v", *ping1) r3 := fmt.Sprintf("%v", *ping1)
if strings.Compare(r3, e3) != 0 { if strings.Compare(r3, e3) != 0 {
test.Errorf("expect: %v, got: %v", e3, r3) test.Errorf("expect: %v, got: %v", e3, r3)
} else {
fmt.Println(r3)
} }
pong1 := NewPongMessage(p2, pubKeys) pong1 := NewPongMessage(p2, pubKeys)
@ -75,22 +72,12 @@ func TestString(test *testing.T) {
if !strings.HasPrefix(r2, e2) { if !strings.HasPrefix(r2, e2) {
test.Errorf("expect: %v, got: %v", e2, r2) test.Errorf("expect: %v, got: %v", e2, r2)
} else {
fmt.Println(r2)
} }
} }
func TestSerialize(test *testing.T) { func TestSerialize(test *testing.T) {
ping1 := NewPingMessage(p1) ping1 := NewPingMessage(p1)
buf1 = ping1.ConstructPingMessage() buf1 = ping1.ConstructPingMessage()
fmt.Printf("buf ping: %v\n", buf1)
pong1 := NewPongMessage(p2, pubKeys)
buf2 = pong1.ConstructPongMessage()
fmt.Printf("buf pong: %v\n", buf2)
}
func TestDeserialize(test *testing.T) {
msg1, err := proto.GetMessagePayload(buf1) msg1, err := proto.GetMessagePayload(buf1)
if err != nil { if err != nil {
test.Error("GetMessagePayload Failed!") test.Error("GetMessagePayload Failed!")
@ -99,13 +86,20 @@ func TestDeserialize(test *testing.T) {
if err != nil { if err != nil {
test.Error("Ping failed!") test.Error("Ping failed!")
} }
fmt.Println(ping) if !reflect.DeepEqual(ping, ping1) {
test.Error("Serialize/Deserialze Ping Message Failed")
}
pong1 := NewPongMessage(p2, pubKeys)
buf2 = pong1.ConstructPongMessage()
msg2, err := proto.GetMessagePayload(buf2) msg2, err := proto.GetMessagePayload(buf2)
pong, err := GetPongMessage(msg2) pong, err := GetPongMessage(msg2)
if err != nil { if err != nil {
test.Error("Pong failed!") test.Error("Pong failed!")
} }
fmt.Println(pong)
if !reflect.DeepEqual(pong, pong1) {
test.Error("Serialize/Deserialze Pong Message Failed")
}
} }

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIRROOT=$(dirname $0) DIRROOT=$(dirname $0)/..
OS=$(uname -s) OS=$(uname -s)
go test ./... go test ./...
Loading…
Cancel
Save