sharding: add test for get collation by hash

Former-commit-id: 9a715b24b4d04ef7a9bd006cb4f90cbdae55624b [formerly 3fd25eec8d68b7cf5b8f56ab7db86e9e92bed8ae]
Former-commit-id: d878d4578faf7053b914428a12ee3d7eeff83b3c
This commit is contained in:
Raul Jordan 2018-05-07 17:33:35 -04:00
parent b56056668c
commit 02bcbbbd73
2 changed files with 26 additions and 2 deletions

View File

@ -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
}

View File

@ -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)
}
}