Skip to content

Commit

Permalink
Add tests for pruning wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taztingo committed Jan 5, 2024
1 parent 2afc90a commit 73e96d0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/store_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package app

import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)

Expand Down Expand Up @@ -58,7 +60,39 @@ func TestWrapStoreLoader(t *testing.T) {
}

func TestPruningWrapper(t *testing.T) {
tests := []struct {
name string
pruning string
delta uint64
}{
{
name: "recommended pruning should not wait",
pruning: "13",
delta: 0,
},
{
name: "non-recommended pruning should wait",
pruning: "1000",
delta: 30,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
logger := log.NewNopLogger()
appOpts := MockAppOptions{pruning: tc.pruning}
storeLoader := PruningWrapper(logger, appOpts, createMockStoreLoader())
db := dbm.GoLevelDB{}
ms := rootmulti.NewStore(&db, nil)
assert.NotNil(t, ms, "should create a new multistore for testing")

start := time.Now()
err := storeLoader(ms)
delta := uint64(time.Now().Sub(start).Seconds())
assert.NoError(t, err, "should not throw error")
assert.GreaterOrEqual(t, delta, tc.delta, "should wait with non recommended pruning")
})
}
}

func createMockStoreLoader() baseapp.StoreLoader {
Expand All @@ -80,3 +114,11 @@ func createMockStoreWrapper(flag *bool) StoreLoaderWrapper {
return nil
}
}

type MockAppOptions struct {
pruning string
}

func (m MockAppOptions) Get(string) interface{} {
return m.pruning
}

0 comments on commit 73e96d0

Please sign in to comment.