diff --git a/sharding/shard.go b/sharding/shard.go index baff07ddc..1a5b5f7ca 100644 --- a/sharding/shard.go +++ b/sharding/shard.go @@ -52,8 +52,8 @@ func (s *Shard) GetHeaderByHash(hash *common.Hash) (*CollationHeader, error) { } // GetCollationByHash fetches full collation. -func (s *Shard) GetCollationByHash(hash *common.Hash) (*Collation, error) { - header, err := s.GetHeaderByHash(hash) +func (s *Shard) GetCollationByHash(headerHash *common.Hash) (*Collation, error) { + header, err := s.GetHeaderByHash(headerHash) if err != nil { return nil, err } diff --git a/sharding/shard_test.go b/sharding/shard_test.go index 644bcddc9..ee6e0ba6e 100644 --- a/sharding/shard_test.go +++ b/sharding/shard_test.go @@ -44,3 +44,27 @@ func TestShard_GetHeaderByHash(t *testing.T) { t.Fatalf("Headers do not match. want=%v. got=%v", header, dbHeader) } } + +func TestShard_GetCollationByHash(t *testing.T) { + collation := &Collation{ + header: &CollationHeader{shardID: big.NewInt(1)}, + body: []byte{1, 2, 3}, + } + shard := MakeShard(big.NewInt(1)) + + if err := shard.SaveCollation(collation); err != nil { + t.Fatal(err) + } + hash := collation.Header().Hash() + fmt.Printf("In Test: %s\n", hash.String()) + + // It's being saved, but the .Get func doesn't fetch the value...? + dbCollation, err := shard.GetCollationByHash(&hash) + if err != nil { + t.Fatal(err) + } + // TODO: decode the RLP + if !cmp.Equal(collation, dbCollation) { + t.Fatalf("Collations do not match. want=%v. got=%v", collation, dbCollation) + } +}