Basic tend to end test for no errors
This commit is contained in:
@@ -673,7 +673,7 @@ func NewWasmApp(
|
||||
// see cmd/wasmd/root.go: 206 - 214 approx
|
||||
if manager := app.SnapshotManager(); manager != nil {
|
||||
err := manager.RegisterExtensions(
|
||||
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), app.wasmKeeper),
|
||||
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.wasmKeeper),
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
|
||||
|
||||
@@ -50,11 +50,11 @@ type ExtensionSnapshotter interface {
|
||||
*/
|
||||
|
||||
type WasmSnapshotter struct {
|
||||
wasm Keeper
|
||||
wasm *Keeper
|
||||
cms sdk.CommitMultiStore
|
||||
}
|
||||
|
||||
func NewWasmSnapshotter(cms sdk.CommitMultiStore, wasm Keeper) *WasmSnapshotter {
|
||||
func NewWasmSnapshotter(cms sdk.CommitMultiStore, wasm *Keeper) *WasmSnapshotter {
|
||||
return &WasmSnapshotter{
|
||||
wasm: wasm,
|
||||
cms: cms,
|
||||
@@ -122,7 +122,7 @@ func (ws *WasmSnapshotter) Restore(
|
||||
return snapshot.SnapshotItem{}, snapshot.ErrUnknownFormat
|
||||
}
|
||||
|
||||
func restoreV1(ctx sdk.Context, k Keeper, compressedCode []byte) error {
|
||||
func restoreV1(ctx sdk.Context, k *Keeper, compressedCode []byte) error {
|
||||
wasmCode, err := ioutils.Uncompress(compressedCode, k.GetMaxWasmCodeSize(ctx))
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(types.ErrCreateFailed, err.Error())
|
||||
@@ -136,7 +136,7 @@ func restoreV1(ctx sdk.Context, k Keeper, compressedCode []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func finalizeV1(ctx sdk.Context, k Keeper) error {
|
||||
func finalizeV1(ctx sdk.Context, k *Keeper) error {
|
||||
// FIXME: ensure all codes have been uploaded?
|
||||
return k.InitializePinnedCodes(ctx)
|
||||
}
|
||||
@@ -144,8 +144,8 @@ func finalizeV1(ctx sdk.Context, k Keeper) error {
|
||||
func (ws *WasmSnapshotter) processAllItems(
|
||||
height uint64,
|
||||
protoReader protoio.Reader,
|
||||
cb func(sdk.Context, Keeper, []byte) error,
|
||||
finalize func(sdk.Context, Keeper) error,
|
||||
cb func(sdk.Context, *Keeper, []byte) error,
|
||||
finalize func(sdk.Context, *Keeper) error,
|
||||
) (snapshot.SnapshotItem, error) {
|
||||
ctx := sdk.NewContext(ws.cms, tmproto.Header{}, false, log.NewNopLogger())
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -10,10 +11,12 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
protoio "github.com/gogo/protobuf/io"
|
||||
|
||||
"github.com/CosmWasm/wasmd/x/wasm/types"
|
||||
)
|
||||
|
||||
func TestSnapshotRestoreMovesFile(t *testing.T) {
|
||||
func TestSnapshoting(t *testing.T) {
|
||||
// we hack this to "fake" copying over all the iavl data
|
||||
sharedDB := dbm.NewMemDB()
|
||||
|
||||
@@ -46,17 +49,33 @@ func TestSnapshotRestoreMovesFile(t *testing.T) {
|
||||
expected := fmt.Sprintf(`{"verifier":"%s"}`, fred.String())
|
||||
assert.JSONEq(t, string(res), expected)
|
||||
|
||||
// failed attempt to copy state
|
||||
// // now, we make a new app with a copy of the "iavl" db, but no contracts
|
||||
// copyCtx, copyKeepers := createTestInput(t, false, SupportedFeatures, types.DefaultWasmConfig(), sharedDB)
|
||||
// now, create a snapshoter
|
||||
extension := NewWasmSnapshotter(keepers.MultiStore, keepers.WasmKeeper)
|
||||
|
||||
// // contract exists
|
||||
// info := copyKeepers.WasmKeeper.GetContractInfo(ctx, contractAddr)
|
||||
// require.NotNil(t, info)
|
||||
// require.Equal(t, info.CodeID, codeID)
|
||||
// create reader to store data
|
||||
buf := bytes.Buffer{}
|
||||
// Note: we ignore height for now (TODO)
|
||||
err = extension.Snapshot(100, protoio.NewFullWriter(&buf))
|
||||
require.NoError(t, err)
|
||||
require.True(t, buf.Len() > 50000)
|
||||
|
||||
// // querying the existing contract errors, as there is no wasm file
|
||||
// res, err = copyKeepers.WasmKeeper.QuerySmart(copyCtx, contractAddr, queryBz)
|
||||
// require.Error(t, err)
|
||||
// let's try to restore this now
|
||||
_, newKeepers := CreateTestInput(t, false, SupportedFeatures)
|
||||
|
||||
recovery := NewWasmSnapshotter(newKeepers.MultiStore, newKeepers.WasmKeeper)
|
||||
_, err = recovery.Restore(100, 1, protoio.NewFullReader(&buf, buf.Len()))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// failed attempt to copy state
|
||||
// // now, we make a new app with a copy of the "iavl" db, but no contracts
|
||||
// copyCtx, copyKeepers := createTestInput(t, false, SupportedFeatures, types.DefaultWasmConfig(), sharedDB)
|
||||
|
||||
// // contract exists
|
||||
// info := copyKeepers.WasmKeeper.GetContractInfo(ctx, contractAddr)
|
||||
// require.NotNil(t, info)
|
||||
// require.Equal(t, info.CodeID, codeID)
|
||||
|
||||
// // querying the existing contract errors, as there is no wasm file
|
||||
// res, err = copyKeepers.WasmKeeper.QuerySmart(copyCtx, contractAddr, queryBz)
|
||||
// require.Error(t, err)
|
||||
|
||||
@@ -178,7 +178,7 @@ type TestKeepers struct {
|
||||
Router *baseapp.Router
|
||||
EncodingConfig wasmappparams.EncodingConfig
|
||||
Faucet *TestFaucet
|
||||
MultiStore sdk.MultiStore
|
||||
MultiStore sdk.CommitMultiStore
|
||||
}
|
||||
|
||||
// CreateDefaultTestInput common settings for CreateTestInput
|
||||
|
||||
Reference in New Issue
Block a user