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.
50 lines
1.7 KiB
50 lines
1.7 KiB
7 years ago
|
package consensus
|
||
|
|
||
|
import (
|
||
7 years ago
|
"testing"
|
||
6 years ago
|
|
||
|
"github.com/simple-rules/harmony-benchmark/crypto"
|
||
6 years ago
|
"github.com/simple-rules/harmony-benchmark/crypto/pki"
|
||
6 years ago
|
"github.com/simple-rules/harmony-benchmark/p2p"
|
||
7 years ago
|
)
|
||
|
|
||
|
func TestConstructAnnounceMessage(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{}
|
||
|
header := consensus.blockHeader
|
||
|
msg := consensus.constructAnnounceMessage()
|
||
7 years ago
|
|
||
6 years ago
|
if len(msg) != 1+1+1+4+32+2+64+len(header) {
|
||
7 years ago
|
test.Errorf("Annouce message is not constructed in the correct size: %d", len(msg))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestConstructChallengeMessage(test *testing.T) {
|
||
6 years ago
|
leaderPriKey := crypto.Ed25519Curve.Scalar()
|
||
6 years ago
|
priKeyInBytes := crypto.HashSha256("12")
|
||
6 years ago
|
leaderPriKey.UnmarshalBinary(priKeyInBytes[:])
|
||
6 years ago
|
leaderPubKey := pki.GetPublicKeyFromScalar(leaderPriKey)
|
||
6 years ago
|
leader := p2p.Peer{Ip: "1", Port: "2", PubKey: leaderPubKey}
|
||
|
|
||
6 years ago
|
validatorPriKey := crypto.Ed25519Curve.Scalar()
|
||
6 years ago
|
priKeyInBytes = crypto.HashSha256("12")
|
||
6 years ago
|
validatorPriKey.UnmarshalBinary(priKeyInBytes[:])
|
||
6 years ago
|
validatorPubKey := pki.GetPublicKeyFromScalar(leaderPriKey)
|
||
6 years ago
|
validator := p2p.Peer{Ip: "3", Port: "5", PubKey: validatorPubKey}
|
||
|
|
||
7 years ago
|
consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
|
||
7 years ago
|
consensus.blockHash = [32]byte{}
|
||
6 years ago
|
consensus.commitments[0] = leaderPubKey
|
||
|
consensus.commitments[1] = validatorPubKey
|
||
|
consensus.bitmap.SetKey(leaderPubKey, true)
|
||
|
consensus.bitmap.SetKey(validatorPubKey, true)
|
||
|
|
||
7 years ago
|
msg := consensus.constructChallengeMessage()
|
||
|
|
||
7 years ago
|
if len(msg) != 1+1+1+4+32+2+33+33+32+64 {
|
||
7 years ago
|
test.Errorf("Annouce message is not constructed in the correct size: %d", len(msg))
|
||
|
}
|
||
7 years ago
|
}
|