-
Notifications
You must be signed in to change notification settings - Fork 32
/
blocktime_test.go
78 lines (70 loc) · 2.78 KB
/
blocktime_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package db_test
import (
"github.com/brianvoe/gofakeit/v6"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/services/scribe/db"
)
func (t *DBSuite) TestStoreRetrieveBlockTime() {
t.RunOnAllDBs(func(testDB db.EventDB) {
chainIDA := gofakeit.Uint32()
chainIDB := gofakeit.Uint32()
blockTime := uint64(gofakeit.Uint32())
// Store 10 blocks for both chains.
for i := uint64(0); i < 10; i++ {
err := testDB.StoreBlockTime(t.GetTestContext(), chainIDA, i, blockTime+i)
Nil(t.T(), err)
err = testDB.StoreBlockTime(t.GetTestContext(), chainIDB, i, blockTime+(i*2))
Nil(t.T(), err)
}
// Ensure the block time for the chain ID matches the one stored.
for i := uint64(0); i < 10; i++ {
retrievedBlockTimeA, err := testDB.RetrieveBlockTime(t.GetTestContext(), chainIDA, i)
Nil(t.T(), err)
Equal(t.T(), retrievedBlockTimeA, blockTime+i)
retrievedBlockTimeB, err := testDB.RetrieveBlockTime(t.GetTestContext(), chainIDB, i)
Nil(t.T(), err)
Equal(t.T(), retrievedBlockTimeB, blockTime+(i*2))
}
lastBlockA, err := testDB.RetrieveLastBlockStored(t.GetTestContext(), chainIDA)
Nil(t.T(), err)
Equal(t.T(), lastBlockA, uint64(9))
lastBlockB, err := testDB.RetrieveLastBlockStored(t.GetTestContext(), chainIDB)
Nil(t.T(), err)
Equal(t.T(), lastBlockB, uint64(9))
firstBlockA, err := testDB.RetrieveFirstBlockStored(t.GetTestContext(), chainIDA)
Nil(t.T(), err)
Equal(t.T(), firstBlockA, uint64(0))
firstBlockB, err := testDB.RetrieveFirstBlockStored(t.GetTestContext(), chainIDB)
Nil(t.T(), err)
Equal(t.T(), firstBlockB, uint64(0))
})
}
func (t *DBSuite) TestRetrieveBlockTimesCountForChain() {
t.RunOnAllDBs(func(testDB db.EventDB) {
chainIDA := gofakeit.Uint32()
chainIDB := gofakeit.Uint32()
blockTime := uint64(gofakeit.Uint32())
// Store 10 blocks for both chains.
for i := uint64(0); i < 10; i++ {
err := testDB.StoreBlockTime(t.GetTestContext(), chainIDA, i, blockTime+i)
Nil(t.T(), err)
err = testDB.StoreBlockTime(t.GetTestContext(), chainIDB, i, blockTime+(i*2))
Nil(t.T(), err)
}
// Ensure the block time for the chain ID matches the one stored.
for i := uint64(0); i < 10; i++ {
retrievedBlockTimeA, err := testDB.RetrieveBlockTime(t.GetTestContext(), chainIDA, i)
Nil(t.T(), err)
Equal(t.T(), retrievedBlockTimeA, blockTime+i)
retrievedBlockTimeB, err := testDB.RetrieveBlockTime(t.GetTestContext(), chainIDB, i)
Nil(t.T(), err)
Equal(t.T(), retrievedBlockTimeB, blockTime+(i*2))
}
blockTimeCountA, err := testDB.RetrieveBlockTimesCountForChain(t.GetTestContext(), chainIDA)
Nil(t.T(), err)
Equal(t.T(), int64(10), blockTimeCountA)
blockTimeCountB, err := testDB.RetrieveBlockTimesCountForChain(t.GetTestContext(), chainIDB)
Nil(t.T(), err)
Equal(t.T(), int64(10), blockTimeCountB)
})
}