sharding: test validate shard id

Former-commit-id: 4d83cbd308332a40187191501836e92d3973367c [formerly d5b64486b85afd0c215399b8de520b2d48e8e773]
Former-commit-id: 4a06d18566b3f76eb67405c0e27e78ec06c2144f
This commit is contained in:
Raul Jordan 2018-05-07 16:51:27 -04:00
parent 1e31653514
commit 191568b957
2 changed files with 16 additions and 13 deletions

View File

@ -25,6 +25,11 @@ func MakeShard(shardID *big.Int) *Shard {
}
}
// ShardID gets the shard's identifier.
func (s *Shard) ShardID() *big.Int {
return s.shardID
}
// ValidateShardID checks if header belongs to shard.
func (s *Shard) ValidateShardID(h *CollationHeader) error {
if s.shardID.Cmp(h.shardID) != 0 {

View File

@ -1,24 +1,22 @@
package sharding
import (
"math/big"
"testing"
)
func TestShard_ValidateShardID(t *testing.T) {
tests := []struct {
headers []*CollationHeader
}{
{
headers: nil,
}, {
headers: nil,
},
header := &CollationHeader{shardID: big.NewInt(4)}
shard := MakeShard(big.NewInt(3))
if err := shard.ValidateShardID(header); err == nil {
t.Fatalf("Shard ID validation incorrect. Function should throw error when shardID's do not match. want=%d. got=%d", header.shardID.Int64(), shard.ShardID().Int64())
}
for _, tt := range tests {
t.Logf("val: %v", tt.headers)
if 0 == 1 {
t.Fatalf("Wrong number of transactions. want=%d. got=%d", 5, 3)
}
header2 := &CollationHeader{shardID: big.NewInt(100)}
shard2 := MakeShard(big.NewInt(100))
if err := shard2.ValidateShardID(header2); err != nil {
t.Fatalf("Shard ID validation incorrect. Function should not throw error when shardID's match. want=%d. got=%d", header2.shardID.Int64(), shard2.ShardID().Int64())
}
}