Skip to content

Commit

Permalink
add a few error checks and update some deprecated tendermint calls
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jul 16, 2023
1 parent e1d15e7 commit 09f5086
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
9 changes: 6 additions & 3 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ func TestAppImportExport(t *testing.T) {

ctxA := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})
ctxB := newApp.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})
newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
_, err = newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
require.NoError(t, err)
err = newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
require.NoError(t, err)

t.Log("comparing stores...")
// skip certain prefixes
Expand Down Expand Up @@ -227,10 +229,11 @@ func TestAppSimulationAfterImport(t *testing.T) {
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, wasm.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", newApp.Name())

newApp.InitChain(&abci.RequestInitChain{
_, err = newApp.InitChain(&abci.RequestInitChain{
ChainId: SimAppChainID,
AppStateBytes: exported.AppState,
})
require.NoError(t, err)

_, _, err = simulation.SimulateFromSeed(
t,
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func SetupWithGenesisAccountsAndValSet(b testing.TB, db dbm.DB, genAccs []authty
bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pk, _ := cryptocodec.FromCmtPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
Expand Down Expand Up @@ -116,7 +116,8 @@ func SetupWithGenesisAccountsAndValSet(b testing.TB, db dbm.DB, genAccs []authty
},
)
require.NoError(b, err)
wasmApp.Commit()
_, err = wasmApp.Commit()
require.NoError(b, err)
_, err = wasmApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: wasmApp.LastBlockHeight() + 1})
require.NoError(b, err)

Expand Down Expand Up @@ -225,7 +226,8 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {

_, err = wasmApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: height})
require.NoError(b, err)
wasmApp.Commit()
_, err = wasmApp.Commit()
require.NoError(b, err)

return AppInfo{
App: wasmApp,
Expand Down
3 changes: 1 addition & 2 deletions x/wasm/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ func (chain *TestChain) GetConsensusState(clientID string, height exported.Heigh
// a success boolean depending on if the validator set exists or not at that height.
func (chain *TestChain) GetValsAtHeight(height int64) (*cmttypes.ValidatorSet, bool) {
histInfo, err := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height)
switch {
case stakingtypes.ErrNoHistoricalInfo.Is(err):
if stakingtypes.ErrNoHistoricalInfo.Is(err) {
return nil, false
}
require.NoError(chain.t, err)
Expand Down
6 changes: 4 additions & 2 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ func TestGenesisExportImport(t *testing.T) {
creatorAddress := sdk.MustAccAddressFromBech32(info.Creator)
history := wasmKeeper.GetContractHistory(srcCtx, address)

wasmKeeper.addToContractCodeSecondaryIndex(srcCtx, address, history[len(history)-1])
wasmKeeper.addToContractCreatorSecondaryIndex(srcCtx, creatorAddress, history[0].Updated, address)
err = wasmKeeper.addToContractCodeSecondaryIndex(srcCtx, address, history[len(history)-1])
require.NoError(t, err)
err = wasmKeeper.addToContractCreatorSecondaryIndex(srcCtx, creatorAddress, history[0].Updated, address)
require.NoError(t, err)
return false
})

Expand Down
13 changes: 6 additions & 7 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
stypes "cosmossdk.io/store/types"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -306,7 +305,7 @@ func TestCreateWithSimulation(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)

ctx = ctx.WithBlockHeader(tmproto.Header{Height: 1}).
WithGasMeter(stypes.NewInfiniteGasMeter())
WithGasMeter(storetypes.NewInfiniteGasMeter())

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...)
Expand Down Expand Up @@ -337,15 +336,15 @@ func TestIsSimulationMode(t *testing.T) {
exp bool
}{
"genesis block": {
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{}).WithGasMeter(stypes.NewInfiniteGasMeter()),
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{}).WithGasMeter(storetypes.NewInfiniteGasMeter()),
exp: false,
},
"any regular block": {
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{Height: 1}).WithGasMeter(stypes.NewGasMeter(10000000)),
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{Height: 1}).WithGasMeter(storetypes.NewGasMeter(10000000)),
exp: false,
},
"simulation": {
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{Height: 1}).WithGasMeter(stypes.NewInfiniteGasMeter()),
ctx: sdk.Context{}.WithBlockHeader(tmproto.Header{Height: 1}).WithGasMeter(storetypes.NewInfiniteGasMeter()),
exp: true,
},
}
Expand Down Expand Up @@ -620,13 +619,13 @@ func TestInstantiateWithAccounts(t *testing.T) {
expAccount: authtypes.NewBaseAccount(contractAddr, nil, lastAccountNumber+2, 0), // +1 for next seq, +1 for spec.account created
expBalance: sdk.NewCoins(sdk.NewCoin("denom", sdkmath.NewInt(1))),
},
//"prunable account without balance gets overwritten": { // todo : can not initialize vesting with empty balance
// "prunable account without balance gets overwritten": { // todo : can not initialize vesting with empty balance
// account: must(vestingtypes.NewContinuousVestingAccount(
// authtypes.NewBaseAccount(contractAddr, nil, 0, 0),
// sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(0))), time.Now().Add(time.Hour).Unix(), time.Now().Add(2*time.Hour).Unix())),
// expAccount: authtypes.NewBaseAccount(contractAddr, nil, lastAccountNumber+2, 0), // +1 for next seq, +1 for spec.account created
// expBalance: sdk.NewCoins(),
//},
// },
"unknown account type is rejected with error": {
account: authtypes.NewModuleAccount(
authtypes.NewBaseAccount(contractAddr, nil, 0, 0),
Expand Down
7 changes: 5 additions & 2 deletions x/wasm/keeper/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func nextBlock(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper) sdk.Context
panic(err)
}
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
stakingKeeper.BeginBlocker(ctx)
_ = stakingKeeper.BeginBlocker(ctx)
return ctx
}

Expand All @@ -713,7 +713,10 @@ func setValidatorRewards(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, d
panic(err)
}
payout := sdk.DecCoins{{Denom: "stake", Amount: amount}}
distKeeper.AllocateTokensToValidator(ctx, vali, payout)
err = distKeeper.AllocateTokensToValidator(ctx, vali, payout)
if err != nil {
panic(err)
}
}

func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, addr sdk.AccAddress, expected string) {
Expand Down

0 comments on commit 09f5086

Please sign in to comment.