From 02bcbbbd73e6352c5635b2f10f5a250a5d1d3738 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 7 May 2018 17:33:35 -0400 Subject: [PATCH] sharding: add test for get collation by hash Former-commit-id: 9a715b24b4d04ef7a9bd006cb4f90cbdae55624b [formerly 3fd25eec8d68b7cf5b8f56ab7db86e9e92bed8ae] Former-commit-id: d878d4578faf7053b914428a12ee3d7eeff83b3c --- sharding/shard.go | 4 ++-- sharding/shard_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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) + } +}