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

chore: fixing linter errors and tests #463

Merged
merged 15 commits into from
Oct 4, 2023
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: 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
Loading