Skip to content

Commit

Permalink
chore: fixing linter errors and tests (#463)
Browse files Browse the repository at this point in the history
* fixing lint issues

* fixing x/tracking tests

* fixing app_test.go

* replacing gov v1beta1 stuff with gov v1

* fixig app-upgrade-test

txRes.Data is deprecated in favour of txRes.MsgResponses

* removing depracated field usage

* fixing ibctm not setup

* making the flat fees e2e test simpler

* fixing interchaintest chain upgrade

* fixing TestTxFees thanks @fdymylja 🎉

* fixing more tests with initgenesis failure

* fixing testcase to be compatible with this change cosmos/cosmos-sdk#9651

* removing the ante.DeductFeeDecorator as we alreayd have a custom one

* fixing TestRewardsFlatFees

* undo the mintkeeper fix
  • Loading branch information
spoo-bar authored Oct 4, 2023
1 parent 87fd9e1 commit d5c0374
Show file tree
Hide file tree
Showing 28 changed files with 1,302 additions and 510 deletions.
1 change: 0 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
Expand Down
43 changes: 20 additions & 23 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import (
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -159,15 +160,15 @@ var (

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into archwayd app.
func GetEnabledProposals() []wasm.ProposalType {
func GetEnabledProposals() []wasmdTypes.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
return wasmdTypes.EnableAllProposals
}
return wasm.DisableAllProposals
return wasmdTypes.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
proposals, err := wasmdTypes.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -216,6 +217,7 @@ var (
authzmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ibcfee.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
Expand All @@ -242,7 +244,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
wasmdTypes.ModuleName: {authtypes.Burner},
rewardsTypes.TreasuryCollector: {authtypes.Burner},
}
)
Expand Down Expand Up @@ -301,9 +303,9 @@ func NewArchwayApp(
homePath string,
invCheckPeriod uint,
encodingConfig archwayappparams.EncodingConfig,
enabledProposals []wasm.ProposalType,
enabledProposals []wasmdTypes.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
wasmOpts []wasmdKeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *ArchwayApp {
appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino
Expand All @@ -321,7 +323,7 @@ func NewArchwayApp(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, consensusparamtypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasmdTypes.StoreKey, consensusparamtypes.StoreKey,
icahosttypes.StoreKey, ibcfeetypes.StoreKey, crisistypes.StoreKey, group.StoreKey, nftkeeper.StoreKey,

trackingTypes.StoreKey, rewardsTypes.StoreKey,
Expand Down Expand Up @@ -362,7 +364,7 @@ func NewArchwayApp(
scopedIBCKeeper := app.Keepers.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedICAHostKeeper := app.Keepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedTransferKeeper := app.Keepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.Keepers.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.Keepers.CapabilityKeeper.ScopeToModule(wasmdTypes.ModuleName)
app.Keepers.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -539,7 +541,7 @@ func NewArchwayApp(

app.Keepers.WASMKeeper = wasmdKeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmdTypes.StoreKey],
app.Keepers.AccountKeeper,
app.Keepers.BankKeeper,
app.Keepers.StakingKeeper,
Expand Down Expand Up @@ -582,11 +584,6 @@ func NewArchwayApp(
govModuleAddr,
)

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.Keepers.WASMKeeper, enabledProposals))
}

var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.Keepers.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.Keepers.IBCFeeKeeper)
Expand All @@ -605,7 +602,7 @@ func NewArchwayApp(
// create static IBC router, add transfer route, add wasm route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
ibcRouter.AddRoute(wasm.ModuleName, wasmStack)
ibcRouter.AddRoute(wasmdTypes.ModuleName, wasmStack)
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostStack)
app.Keepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -647,7 +644,7 @@ func NewArchwayApp(
distr.NewAppModule(appCodec, app.Keepers.DistrKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.StakingKeeper, app.getSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.getSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(&app.Keepers.UpgradeKeeper),
wasm.NewAppModule(appCodec, &app.Keepers.WASMKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.getSubspace(wasm.ModuleName)),
wasm.NewAppModule(appCodec, &app.Keepers.WASMKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.getSubspace(wasmdTypes.ModuleName)),
evidence.NewAppModule(app.Keepers.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.Keepers.AuthzKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -694,7 +691,7 @@ func NewArchwayApp(
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// wasm
wasm.ModuleName,
wasmdTypes.ModuleName,
// wasm gas tracking
trackingTypes.ModuleName,
rewardsTypes.ModuleName,
Expand Down Expand Up @@ -726,7 +723,7 @@ func NewArchwayApp(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
// wasm
wasm.ModuleName,
wasmdTypes.ModuleName,
// wasm gas tracking
trackingTypes.ModuleName,
rewardsTypes.ModuleName,
Expand Down Expand Up @@ -767,7 +764,7 @@ func NewArchwayApp(
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
wasmdTypes.ModuleName,
// wasm gas tracking
trackingTypes.ModuleName,
genmsg.ModuleName,
Expand Down Expand Up @@ -801,7 +798,7 @@ func NewArchwayApp(
slashing.NewAppModule(appCodec, app.Keepers.SlashingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.StakingKeeper, app.getSubspace(slashingtypes.ModuleName)),
params.NewAppModule(app.Keepers.ParamsKeeper),
evidence.NewAppModule(app.Keepers.EvidenceKeeper),
wasm.NewAppModule(appCodec, &app.Keepers.WASMKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.getSubspace(wasm.ModuleName)),
wasm.NewAppModule(appCodec, &app.Keepers.WASMKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.getSubspace(wasmdTypes.ModuleName)),
ibc.NewAppModule(app.Keepers.IBCKeeper),
transferModule,
)
Expand All @@ -825,7 +822,7 @@ func NewArchwayApp(
IBCKeeper: app.Keepers.IBCKeeper,
WasmConfig: &wasmConfig,
RewardsAnteBankKeeper: app.Keepers.BankKeeper,
TXCounterStoreKey: keys[wasm.StoreKey],
TXCounterStoreKey: keys[wasmdTypes.StoreKey],
TrackingKeeper: app.Keepers.TrackingKeeper,
RewardsKeeper: app.Keepers.RewardsKeeper,
},
Expand Down Expand Up @@ -1042,7 +1039,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmdTypes.ModuleName)
paramsKeeper.Subspace(rewardsTypes.ModuleName)

return paramsKeeper
Expand Down
151 changes: 128 additions & 23 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,97 @@
package app

import (
"encoding/json"
"fmt"
"os"
"testing"
"time"

db "github.com/cometbft/cometbft-db"
tmdb "github.com/cometbft/cometbft-db"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmtypes "github.com/cometbft/cometbft/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/testutil/mock"
simapp "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

var emptyWasmOpts []wasm.Option = nil
var emptyWasmOpts []wasmkeeper.Option = nil

func TestArchwaydExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewArchwayApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)
db := tmdb.NewMemDB()
logger := log.NewNopLogger()
encoding := MakeEncodingConfig()
gapp := NewArchwayApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding,
wasmtypes.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)

privValidator := mock.NewPV()
pubKey, err := privValidator.GetPubKey()
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}

genesisState := NewDefaultGenesisState(gapp.AppCodec())
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
genesisState = genesisStateWithValSet(t, gapp, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
// init chain must be called to stop deliverState from being nil
stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
gapp.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simapp.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)

gapp.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewArchwayApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)
_, err = newGapp.ExportAppStateAndValidators(false, []string{}, []string{})
_, err = gapp.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := db.NewMemDB()
gapp := NewArchwayApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)
gapp := NewArchwayApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), wasmtypes.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)

for acc := range maccPerms {
t.Run(acc, func(t *testing.T) {
require.True(t, gapp.Keepers.BankKeeper.BlockedAddr(gapp.Keepers.AccountKeeper.GetModuleAddress(acc)),
"ensure that blocked addresses are properly set in bank keeper",
)
})
for acc := range BlockedAddresses() {
var addr sdk.AccAddress
if modAddr, err := sdk.AccAddressFromBech32(acc); err == nil {
addr = modAddr
} else {
addr = gapp.Keepers.AccountKeeper.GetModuleAddress(acc)
}

require.True(
t,
gapp.Keepers.BankKeeper.BlockedAddr(addr),
fmt.Sprintf("ensure that blocked addresses are properly set in bank keeper: %s should be blocked", acc),
)
}
}

Expand All @@ -63,20 +104,20 @@ func TestGetEnabledProposals(t *testing.T) {
cases := map[string]struct {
proposalsEnabled string
specificEnabled string
expected []wasm.ProposalType
expected []wasmtypes.ProposalType
}{
"all disabled": {
proposalsEnabled: "false",
expected: wasm.DisableAllProposals,
expected: wasmtypes.DisableAllProposals,
},
"all enabled": {
proposalsEnabled: "true",
expected: wasm.EnableAllProposals,
expected: wasmtypes.EnableAllProposals,
},
"some enabled": {
proposalsEnabled: "okay",
specificEnabled: "StoreCode,InstantiateContract",
expected: []wasm.ProposalType{wasm.ProposalTypeStoreCode, wasm.ProposalTypeInstantiateContract},
expected: []wasmtypes.ProposalType{wasmtypes.ProposalTypeStoreCode, wasmtypes.ProposalTypeInstantiateContract},
},
}

Expand All @@ -89,3 +130,67 @@ func TestGetEnabledProposals(t *testing.T) {
})
}
}

func genesisStateWithValSet(t *testing.T,
app *ArchwayApp, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) GenesisState {
t.Helper()
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
}
// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt))
}

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)},
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, banktypes.DefaultGenesisState().SendEnabled)
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

return genesisState
}
Loading

0 comments on commit d5c0374

Please sign in to comment.