|
|
@ -13,14 +13,18 @@ func TestFBFTLog_id(t *testing.T) { |
|
|
|
tests := []FBFTMessage{ |
|
|
|
tests := []FBFTMessage{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageType: msg_pb.MessageType_ANNOUNCE, |
|
|
|
MessageType: msg_pb.MessageType_ANNOUNCE, |
|
|
|
|
|
|
|
ViewID: 4, |
|
|
|
BlockHash: [32]byte{01, 02}, |
|
|
|
BlockHash: [32]byte{01, 02}, |
|
|
|
SenderPubkey: &bls.PublicKeyWrapper{ |
|
|
|
SenderPubkeys: []*bls.PublicKeyWrapper{&bls.PublicKeyWrapper{ |
|
|
|
Bytes: bls.SerializedPublicKey{0x01, 0x02}, |
|
|
|
Bytes: bls.SerializedPublicKey{0x01, 0x02}, |
|
|
|
}, |
|
|
|
}}, |
|
|
|
|
|
|
|
SenderPubkeyBitmap: []byte{05, 07}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageType: msg_pb.MessageType_COMMIT, |
|
|
|
MessageType: msg_pb.MessageType_COMMIT, |
|
|
|
BlockHash: [32]byte{02, 03}, |
|
|
|
ViewID: 4, |
|
|
|
|
|
|
|
BlockHash: [32]byte{02, 03}, |
|
|
|
|
|
|
|
SenderPubkeyBitmap: []byte{05, 07}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
for _, msg := range tests { |
|
|
|
for _, msg := range tests { |
|
|
@ -29,16 +33,18 @@ func TestFBFTLog_id(t *testing.T) { |
|
|
|
if uint32(msg.MessageType) != binary.LittleEndian.Uint32(id[:]) { |
|
|
|
if uint32(msg.MessageType) != binary.LittleEndian.Uint32(id[:]) { |
|
|
|
t.Errorf("message type not expected") |
|
|
|
t.Errorf("message type not expected") |
|
|
|
} |
|
|
|
} |
|
|
|
if !bytes.Equal(id[idTypeBytes:idTypeBytes+idHashBytes], msg.BlockHash[:]) { |
|
|
|
if msg.ViewID != binary.LittleEndian.Uint64(id[idTypeBytes:]) { |
|
|
|
|
|
|
|
t.Errorf("view id not expected") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !bytes.Equal(id[idTypeBytes+idViewIDBytes:idTypeBytes+idViewIDBytes+idHashBytes], msg.BlockHash[:]) { |
|
|
|
t.Errorf("block hash not expected") |
|
|
|
t.Errorf("block hash not expected") |
|
|
|
} |
|
|
|
} |
|
|
|
if msg.SenderPubkey == nil { |
|
|
|
if len(msg.SenderPubkeys) != 1 { |
|
|
|
var emptyKey bls.SerializedPublicKey |
|
|
|
if !bytes.Equal(id[idTypeBytes+idViewIDBytes+idHashBytes:idTypeBytes+idViewIDBytes+idHashBytes+len(msg.SenderPubkeyBitmap)], msg.SenderPubkeyBitmap[:]) { |
|
|
|
if !bytes.Equal(id[idTypeBytes+idHashBytes:], emptyKey[:]) { |
|
|
|
t.Errorf("sender key expected to be the bitmap when key list is not size 1") |
|
|
|
t.Errorf("sender key not expected when empty") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if !bytes.Equal(id[idTypeBytes+idHashBytes:], msg.SenderPubkey.Bytes[:]) { |
|
|
|
if !bytes.Equal(id[idTypeBytes+idViewIDBytes+idHashBytes:], msg.SenderPubkeys[0].Bytes[:]) { |
|
|
|
t.Errorf("sender key not expected") |
|
|
|
t.Errorf("sender key not expected") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|