From 7cb08abeca0b359f06e4a4250cb7947185426e0e Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sat, 12 May 2018 11:23:14 -0400 Subject: [PATCH] sharding: finished remaining test bodies, now just need to pass Former-commit-id: df5d0d09dfd223df52c1986b41f2620c21291629 [formerly 52445dd5719ba379d419b74f9759f52960a6f77b] Former-commit-id: 5441958a8649dfaa4015032ba0701902ab4adedc --- sharding/shard_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/sharding/shard_test.go b/sharding/shard_test.go index 791237c26..55bb99eed 100644 --- a/sharding/shard_test.go +++ b/sharding/shard_test.go @@ -154,6 +154,9 @@ func TestShard_CanonicalCollation(t *testing.T) { if err != nil { t.Fatalf("failed to get canonical collation from shardDB: %v", err) } + if canonicalCollation.Hash() != collation.Hash() { + t.Errorf("collations are not equal. want=%v. got=%v.", collation, canonicalCollation) + } } func TestShard_BodyByChunkRoot(t *testing.T) { @@ -182,5 +185,33 @@ func TestShard_BodyByChunkRoot(t *testing.T) { } func TestShard_CheckAvailability(t *testing.T) { - t.Fatalf("cannot save availability") + shardID := big.NewInt(1) + period := big.NewInt(1) + proposerAddress := common.StringToAddress("") + proposerSignature := []byte{} + emptyHash := common.StringToHash("") + header := NewCollationHeader(shardID, &emptyHash, period, &proposerAddress, proposerSignature) + + shardDB := database.MakeShardKV() + shard := MakeShard(shardID, shardDB) + + collation := &Collation{ + header: header, + body: []byte{1, 2, 3}, + } + + // We set the chunk root. + collation.CalculateChunkRoot() + + if err := shard.SaveBody(collation.body); err != nil { + t.Fatalf("cannot save body: %v", err) + } + + available, err := shard.CheckAvailability(header) + if err != nil { + t.Errorf("could not check availability: %v", err) + } + if !available { + t.Errorf("collation body is not available: chunkRoot=%v, body=%v", header.ChunkRoot(), collation.body) + } }