You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
package drand
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
"github.com/harmony-one/harmony/p2p"
|
|
"github.com/harmony-one/harmony/p2p/p2pimpl"
|
|
)
|
|
|
|
func TestConstructInitMessage(test *testing.T) {
|
|
leader := p2p.Peer{IP: "127.0.0.1", Port: "19999"}
|
|
validator := p2p.Peer{IP: "127.0.0.1", Port: "55555"}
|
|
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
|
|
host, err := p2pimpl.NewHost(&leader, priKey)
|
|
if err != nil {
|
|
test.Fatalf("newhost failure: %v", err)
|
|
}
|
|
dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true)
|
|
dRand.blockHash = [32]byte{}
|
|
msg := dRand.constructInitMessage()
|
|
|
|
if len(msg) != 93 {
|
|
test.Errorf("Init message is not constructed in the correct size: %d", len(msg))
|
|
}
|
|
}
|
|
|
|
func TestProcessCommitMessage(test *testing.T) {
|
|
leader := p2p.Peer{IP: "127.0.0.1", Port: "19999"}
|
|
validator := p2p.Peer{IP: "127.0.0.1", Port: "55555"}
|
|
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
|
|
host, err := p2pimpl.NewHost(&leader, priKey)
|
|
if err != nil {
|
|
test.Fatalf("newhost failure: %v", err)
|
|
}
|
|
dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true)
|
|
dRand.blockHash = [32]byte{}
|
|
msg := dRand.constructCommitMessage([32]byte{}, []byte{})
|
|
|
|
if len(msg) != 191 {
|
|
test.Errorf("Commit message is not constructed in the correct size: %d", len(msg))
|
|
}
|
|
dRand.ProcessMessageLeader(msg)
|
|
}
|
|
|