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.
95 lines
2.1 KiB
95 lines
2.1 KiB
5 years ago
|
package shard
|
||
6 years ago
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
5 years ago
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
var (
|
||
5 years ago
|
blsPubKey1 = [48]byte{}
|
||
|
blsPubKey2 = [48]byte{}
|
||
|
blsPubKey3 = [48]byte{}
|
||
|
blsPubKey4 = [48]byte{}
|
||
|
blsPubKey5 = [48]byte{}
|
||
|
blsPubKey6 = [48]byte{}
|
||
|
blsPubKey11 = [48]byte{}
|
||
|
blsPubKey22 = [48]byte{}
|
||
6 years ago
|
)
|
||
|
|
||
|
func init() {
|
||
|
copy(blsPubKey1[:], []byte("random key 1"))
|
||
|
copy(blsPubKey2[:], []byte("random key 2"))
|
||
|
copy(blsPubKey3[:], []byte("random key 3"))
|
||
|
copy(blsPubKey4[:], []byte("random key 4"))
|
||
|
copy(blsPubKey5[:], []byte("random key 5"))
|
||
|
copy(blsPubKey6[:], []byte("random key 6"))
|
||
|
copy(blsPubKey11[:], []byte("random key 11"))
|
||
|
copy(blsPubKey22[:], []byte("random key 22"))
|
||
|
}
|
||
|
|
||
6 years ago
|
func TestGetHashFromNodeList(t *testing.T) {
|
||
6 years ago
|
l1 := []NodeID{
|
||
5 years ago
|
{common.Address{0x11}, blsPubKey1},
|
||
|
{common.Address{0x22}, blsPubKey2},
|
||
|
{common.Address{0x33}, blsPubKey3},
|
||
6 years ago
|
}
|
||
6 years ago
|
l2 := []NodeID{
|
||
5 years ago
|
{common.Address{0x22}, blsPubKey2},
|
||
|
{common.Address{0x11}, blsPubKey1},
|
||
|
{common.Address{0x33}, blsPubKey3},
|
||
6 years ago
|
}
|
||
6 years ago
|
h1 := GetHashFromNodeList(l1)
|
||
|
h2 := GetHashFromNodeList(l2)
|
||
|
|
||
5 years ago
|
if bytes.Compare(h1, h2) == 0 {
|
||
|
t.Error("node list l1 and l2 should be different")
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func TestHash(t *testing.T) {
|
||
6 years ago
|
com1 := Committee{
|
||
|
ShardID: 22,
|
||
6 years ago
|
NodeList: []NodeID{
|
||
5 years ago
|
{common.Address{0x12}, blsPubKey11},
|
||
|
{common.Address{0x23}, blsPubKey22},
|
||
|
{common.Address{0x11}, blsPubKey1},
|
||
6 years ago
|
},
|
||
|
}
|
||
|
com2 := Committee{
|
||
|
ShardID: 2,
|
||
6 years ago
|
NodeList: []NodeID{
|
||
5 years ago
|
{common.Address{0x44}, blsPubKey4},
|
||
|
{common.Address{0x55}, blsPubKey5},
|
||
|
{common.Address{0x66}, blsPubKey6},
|
||
6 years ago
|
},
|
||
|
}
|
||
6 years ago
|
shardState1 := ShardState{com1, com2}
|
||
|
h1 := shardState1.Hash()
|
||
|
|
||
6 years ago
|
com3 := Committee{
|
||
|
ShardID: 2,
|
||
6 years ago
|
NodeList: []NodeID{
|
||
5 years ago
|
{common.Address{0x44}, blsPubKey4},
|
||
5 years ago
|
{common.Address{0x55}, blsPubKey5},
|
||
|
{common.Address{0x66}, blsPubKey6},
|
||
6 years ago
|
},
|
||
|
}
|
||
|
com4 := Committee{
|
||
|
ShardID: 22,
|
||
6 years ago
|
NodeList: []NodeID{
|
||
5 years ago
|
{common.Address{0x12}, blsPubKey11},
|
||
|
{common.Address{0x23}, blsPubKey22},
|
||
5 years ago
|
{common.Address{0x11}, blsPubKey1},
|
||
6 years ago
|
},
|
||
|
}
|
||
|
|
||
6 years ago
|
shardState2 := ShardState{com3, com4}
|
||
|
h2 := shardState2.Hash()
|
||
|
|
||
|
if bytes.Compare(h1[:], h2[:]) != 0 {
|
||
|
t.Error("shardState1 and shardState2 should have equal hash")
|
||
|
}
|
||
|
}
|