Skip to content

Commit

Permalink
reorganize test
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Mar 22, 2024
1 parent b66163a commit e658007
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions consensus/polybft/state_store_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,32 @@ func TestEpochStore_getNearestOrEpochSnapshot(t *testing.T) {

require.NoError(t, state.EpochStore.insertValidatorSnapshot(snapshot, nil))

// Test with existing DB transaction
dbTx, err := state.EpochStore.db.Begin(false)
require.NoError(t, err)
defer dbTx.Rollback()
t.Run("with existing dbTx", func(t *testing.T) {
t.Parallel()

result, err := state.EpochStore.getNearestOrEpochSnapshot(epoch, dbTx)
assert.NoError(t, err)
assert.Equal(t, snapshot, result)
dbTx, err := state.EpochStore.db.Begin(false)
require.NoError(t, err)

// Test without DB transaction
result, err = state.EpochStore.getNearestOrEpochSnapshot(epoch, nil)
assert.NoError(t, err)
assert.Equal(t, snapshot, result)
result, err := state.EpochStore.getNearestOrEpochSnapshot(epoch, dbTx)
assert.NoError(t, err)
assert.Equal(t, snapshot, result)

// Test with non-existing epoch
result, err = state.EpochStore.getNearestOrEpochSnapshot(2, nil)
assert.NoError(t, err)
assert.Equal(t, result, snapshot)
require.NoError(t, dbTx.Rollback())
})

t.Run("without existing dbTx", func(t *testing.T) {
t.Parallel()

result, err := state.EpochStore.getNearestOrEpochSnapshot(epoch, nil)
assert.NoError(t, err)
assert.Equal(t, snapshot, result)
})

t.Run("with non-existing epoch", func(t *testing.T) {
t.Parallel()

result, err := state.EpochStore.getNearestOrEpochSnapshot(2, nil)
assert.NoError(t, err)
assert.Equal(t, result, snapshot)
})
}

0 comments on commit e658007

Please sign in to comment.