-
Notifications
You must be signed in to change notification settings - Fork 32
/
lastconfirmedblock_test.go
36 lines (29 loc) · 1.24 KB
/
lastconfirmedblock_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
package db_test
import (
"github.com/brianvoe/gofakeit/v6"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/services/scribe/db"
)
func (t *DBSuite) TestStoreRetrieveLastConfirmedBlock() {
t.RunOnAllDBs(func(testDB db.EventDB) {
chainID := gofakeit.Uint32()
// Before storing, ensure that the last confirmed block is 0.
retrievedLastConfirmedBlock, err := testDB.RetrieveLastConfirmedBlock(t.GetTestContext(), chainID)
Nil(t.T(), err)
Equal(t.T(), retrievedLastConfirmedBlock, uint64(0))
// Store a new last confirmed block.
err = testDB.StoreLastConfirmedBlock(t.GetTestContext(), chainID, 1)
Nil(t.T(), err)
// Ensure the last confirmed block matches the one stored.
retrievedLastConfirmedBlock, err = testDB.RetrieveLastConfirmedBlock(t.GetTestContext(), chainID)
Nil(t.T(), err)
Equal(t.T(), retrievedLastConfirmedBlock, uint64(1))
// Update the last confirmed block to a new value.
err = testDB.StoreLastConfirmedBlock(t.GetTestContext(), chainID, 2)
Nil(t.T(), err)
// Ensure the last confirmed block matches the one stored.
retrievedLastConfirmedBlock, err = testDB.RetrieveLastConfirmedBlock(t.GetTestContext(), chainID)
Nil(t.T(), err)
Equal(t.T(), retrievedLastConfirmedBlock, uint64(2))
})
}