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.
33 lines
1022 B
33 lines
1022 B
7 years ago
|
package consensus
|
||
|
|
||
|
import (
|
||
7 years ago
|
"testing"
|
||
6 years ago
|
|
||
|
"github.com/simple-rules/harmony-benchmark/crypto"
|
||
|
"github.com/simple-rules/harmony-benchmark/p2p"
|
||
7 years ago
|
)
|
||
|
|
||
|
func TestConstructCommitMessage(test *testing.T) {
|
||
7 years ago
|
leader := p2p.Peer{Ip: "1", Port: "2"}
|
||
|
validator := p2p.Peer{Ip: "3", Port: "5"}
|
||
7 years ago
|
consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
|
||
7 years ago
|
consensus.blockHash = [32]byte{}
|
||
6 years ago
|
_, msg := consensus.constructCommitMessage()
|
||
7 years ago
|
|
||
6 years ago
|
if len(msg) != 1+1+1+4+32+2+32+64 {
|
||
7 years ago
|
test.Errorf("Commit message is not constructed in the correct size: %d", len(msg))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestConstructResponseMessage(test *testing.T) {
|
||
7 years ago
|
leader := p2p.Peer{Ip: "1", Port: "2"}
|
||
|
validator := p2p.Peer{Ip: "3", Port: "5"}
|
||
7 years ago
|
consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
|
||
7 years ago
|
consensus.blockHash = [32]byte{}
|
||
6 years ago
|
msg := consensus.constructResponseMessage(crypto.Ed25519Curve.Scalar())
|
||
7 years ago
|
|
||
7 years ago
|
if len(msg) != 1+1+1+4+32+2+32+64 {
|
||
7 years ago
|
test.Errorf("Response message is not constructed in the correct size: %d", len(msg))
|
||
|
}
|
||
7 years ago
|
}
|