forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks_test.go
43 lines (35 loc) · 1.05 KB
/
blocks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package db
import (
"errors"
"math/big"
"testing"
"github.com/ten-protocol/go-ten/go/common/errutil"
"github.com/ethereum/go-ethereum/core/types"
)
// An arbitrary number to put in the header, to check that the header is retrieved correctly from the DB.
const batchNumber = 777
func TestCanStoreAndRetrieveBlockHeader(t *testing.T) {
db := NewInMemoryDB(nil, nil)
header := types.Header{
Number: big.NewInt(batchNumber),
}
err := db.AddBlock(&header)
if err != nil {
t.Errorf("could not add block header. Cause: %s", err)
}
blockHeader, err := db.GetBlockByHash(header.Hash())
if err != nil {
t.Errorf("stored block header but could not retrieve it. Cause: %s", err)
}
if blockHeader.Number.Cmp(header.Number) != 0 {
t.Errorf("block header was not stored correctly")
}
}
func TestUnknownBlockHeaderReturnsNotFound(t *testing.T) {
db := NewInMemoryDB(nil, nil)
header := types.Header{}
_, err := db.GetBlockByHash(header.Hash())
if !errors.Is(err, errutil.ErrNotFound) {
t.Errorf("did not store block header but was able to retrieve it")
}
}