Skip to content

Commit

Permalink
storage fix last snapshot non empty assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Dec 29, 2024
1 parent f8caf5b commit d785da1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 0 additions & 3 deletions storage/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ func TestBadger(t *testing.T) {
require.NotNil(store)
defer store.Close()

snap, _ := store.LastSnapshot()
require.Nil(snap)

err = store.snapshotsDB.Update(func(txn *badger.Txn) error {
return txn.Delete([]byte("key-not-found"))
})
Expand Down
3 changes: 0 additions & 3 deletions storage/badger_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ func (s *BadgerStore) LastSnapshot() (*common.SnapshotWithTopologicalOrder, *com
if err != nil {
panic(err)
}
if topo == 0 && len(snaps) == 0 {
return nil, nil
}
if len(snaps) != 1 {
panic(topo)
}
Expand Down
15 changes: 12 additions & 3 deletions storage/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ func TestTransaction(t *testing.T) {
store, _ := NewBadgerStore(custom, root)
defer store.Close()

last, _ := store.LastSnapshot()
require.Nil(last)

gns, err := common.ReadGenesis("../config/genesis.json")
require.Nil(err)
rounds, snapshots, transactions, err := gns.BuildSnapshots()
Expand Down Expand Up @@ -84,6 +81,10 @@ func TestTransaction(t *testing.T) {
require.Nil(err)
require.Equal("365553.00000000", balance.String())

last, _ := store.LastSnapshot()
require.NotNil(last)
require.Equal(last.PayloadHash(), snapshots[len(snapshots)-1].PayloadHash())

round, _ := store.ReadRound(rounds[0].NodeId)
require.Equal(uint64(1), round.Number)
snap := &common.Snapshot{
Expand Down Expand Up @@ -143,6 +144,10 @@ func TestTransaction(t *testing.T) {
require.Nil(err)
require.Equal("365562.00000000", balance.String())

last, _ = store.LastSnapshot()
require.NotNil(last)
require.Equal(last.PayloadHash(), topo.PayloadHash())

ver, ss, err := store.ReadWithdrawalClaim(submit.AsVersioned().PayloadHash())
require.Nil(err)
require.Equal("", ss)
Expand Down Expand Up @@ -207,6 +212,10 @@ func TestTransaction(t *testing.T) {
oldnCS, oldnRB := store.readConsensusSnapshot(ncs)
require.Equal(ncs.PayloadHash(), oldnCS.PayloadHash())
require.Nil(oldnRB)

last, _ = store.LastSnapshot()
require.NotNil(last)
require.Equal(last.PayloadHash(), topo.PayloadHash())
}

func (s *BadgerStore) readConsensusSnapshot(snap *common.Snapshot) (*common.Snapshot, *crypto.Hash) {
Expand Down

0 comments on commit d785da1

Please sign in to comment.