Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wasm module's FIXME in the snapshotter.go file #649

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (simapp) [\#620](https://github.com/line/lbm-sdk/pull/620) chore: add iterator feature for simapp
* (x/collection) [\#622](https://github.com/line/lbm-sdk/pull/622) add Query/TokenClassTypeName
* (x/bank) [\#629](https://github.com/line/lbm-sdk/pull/629) remove unsafe balance changing methods from bank keeper such as `SetBalance` and `SetSupply`.
* (x/wasm) [\#649](https://github.com/line/lbm-sdk/pull/649) fix: wasm module's FIXME in the snapshotter.go file

### Improvements

Expand Down
27 changes: 14 additions & 13 deletions simapp/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simapp

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -113,6 +114,7 @@ import (
upgradetypes "github.com/line/lbm-sdk/x/upgrade/types"
"github.com/line/lbm-sdk/x/wasm"
wasmclient "github.com/line/lbm-sdk/x/wasm/client"
wasmkeeper "github.com/line/lbm-sdk/x/wasm/keeper"

// unnamed import of statik for swagger UI support
_ "github.com/line/lbm-sdk/client/docs/statik"
Expand Down Expand Up @@ -616,6 +618,18 @@ func NewSimApp(
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see simapp/simd/cmd/root.go: 257 - 261 approx
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
ostos.Exit(err.Error())
Expand All @@ -638,19 +652,6 @@ func NewSimApp(
// note replicate if you do not need to test core IBC or light clients.
app.ScopedIBCMockKeeper = scopedIBCMockKeeper

// FIXME: After applying cosmos-sdk@0.45.4
// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
// if manager := app.SnapshotManager(); manager != nil {
// err := manager.RegisterExtensions(
// wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.wasmKeeper),
// )
// if err != nil {
// panic(fmt.Errorf("failed to register snapshot extension: %s", err))
// }
// }

return app
}

Expand Down
64 changes: 64 additions & 0 deletions simapp/test_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package simapp

import (
"testing"

"github.com/line/lbm-sdk/baseapp"
"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/codec"
"github.com/line/lbm-sdk/simapp/params"
bankkeeper "github.com/line/lbm-sdk/x/bank/keeper"
capabilitykeeper "github.com/line/lbm-sdk/x/capability/keeper"
ibctransferkeeper "github.com/line/lbm-sdk/x/ibc/applications/transfer/keeper"
stakingkeeper "github.com/line/lbm-sdk/x/staking/keeper"
"github.com/line/lbm-sdk/x/wasm"
)

type TestSupport struct {
t testing.TB
app *SimApp
}

func NewTestSupport(t testing.TB, app *SimApp) *TestSupport {
return &TestSupport{t: t, app: app}
}

func (s TestSupport) WasmKeeper() wasm.Keeper {
return s.app.WasmKeeper
}

func (s TestSupport) AppCodec() codec.Codec {
return s.app.appCodec
}

func (s TestSupport) ScopedWasmIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.ScopedWasmKeeper
}

func (s TestSupport) ScopeIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.ScopedIBCKeeper
}

func (s TestSupport) ScopedTransferKeeper() capabilitykeeper.ScopedKeeper {
return s.app.ScopedTransferKeeper
}

func (s TestSupport) StakingKeeper() stakingkeeper.Keeper {
return s.app.StakingKeeper
}

func (s TestSupport) BankKeeper() bankkeeper.Keeper {
return s.app.BankKeeper
}

func (s TestSupport) TransferKeeper() ibctransferkeeper.Keeper {
return s.app.TransferKeeper
}

func (s TestSupport) GetBaseApp() *baseapp.BaseApp {
return s.app.BaseApp
}

func (s TestSupport) GetTxConfig() client.TxConfig {
return params.MakeTestEncodingConfig().TxConfig
}
19 changes: 18 additions & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"sort"
"strconv"
"testing"
Expand All @@ -24,6 +26,7 @@ import (
"github.com/line/lbm-sdk/crypto/keys/ed25519"
cryptotypes "github.com/line/lbm-sdk/crypto/types"
"github.com/line/lbm-sdk/simapp/helpers"
"github.com/line/lbm-sdk/snapshots"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/types/errors"
authtypes "github.com/line/lbm-sdk/x/auth/types"
Expand Down Expand Up @@ -52,9 +55,16 @@ var DefaultConsensusParams = &abci.ConsensusParams{
}

func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) {
randDir, _ := ioutil.TempDir(DefaultNodeHome, "")
snapshotDir := filepath.Join(randDir, "data", "snapshots")
snapshotDB := dbm.NewMemDB()

snapshotStore, _ := snapshots.NewStore(snapshotDB, snapshotDir)
baseAppOpts := []func(*bam.BaseApp){bam.SetSnapshotStore(snapshotStore), bam.SetSnapshotKeepRecent(2)}

db := dbm.NewMemDB()
encCdc := MakeTestEncodingConfig()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}, nil)
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}, nil, baseAppOpts...)
if withGenesis {
return app, NewDefaultGenesisState(encCdc.Marshaler)
}
Expand Down Expand Up @@ -90,6 +100,7 @@ func Setup(isCheckTx bool) *SimApp {
// account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t *testing.T, valSet *octypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
app, genesisState := setup(true, 5)

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
Expand Down Expand Up @@ -165,6 +176,12 @@ func SetupWithGenesisValSet(t *testing.T, valSet *octypes.ValidatorSet, genAccs
return app
}

// SetupWithEmptyStore setup a wasmd app instance with empty DB
func SetupWithEmptyStore() *SimApp {
app, _ := setup(false, 5)
return app
}

// SetupWithGenesisAccounts initializes a new SimApp with the provided genesis
// accounts and possible balances.
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
Expand Down
Loading