From 9044cc886d9d5813c6672e2a5a53119f148f0325 Mon Sep 17 00:00:00 2001 From: zale144 Date: Tue, 29 Oct 2024 14:54:18 +0100 Subject: [PATCH] fix: failing tests (#149) --- app/app_test.go | 5 +++++ app/test_helpers.go | 29 +++++++++++++++++++++++++++++ e2e/testing/chain.go | 34 +++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/app/app_test.go b/app/app_test.go index c137a1c..4142d16 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/dymensionxyz/dymension-rdk/server/consensus" "github.com/gogo/protobuf/proto" prototypes "github.com/gogo/protobuf/types" "github.com/stretchr/testify/require" @@ -19,6 +20,10 @@ func TestBeginBlocker(t *testing.T) { ChainID: "testchain_9000-1", }) + app.setAdmissionHandler(consensus.AllowedMessagesHandler([]string{ + proto.MessageName(&banktypes.MsgSend{}), + })) + bankSend := &banktypes.MsgSend{ FromAddress: valAccount.GetAddress().String(), ToAddress: valAccount.GetAddress().String(), diff --git a/app/test_helpers.go b/app/test_helpers.go index d761fe3..bbe0133 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -92,6 +92,20 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [ genesisState = setRollappVersion(app.appCodec, genesisState, "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0") + denomMD := banktypes.Metadata{ + Description: "Stake token", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "stake", + Exponent: 18, + }, + }, + Base: "stake", + Display: "stake", + } + + genesisState = addDenomToBankModule(app.appCodec, genesisState, denomMD) + stateBytes, err := json.MarshalIndent(genesisState, "", " ") require.NoError(t, err) @@ -208,3 +222,18 @@ func setRollappVersion(appCodec appcodec.Codec, genesisState GenesisState, versi return genesisState } + +func addDenomToBankModule(appCodec appcodec.Codec, genesisState GenesisState, denomMD banktypes.Metadata) GenesisState { + var bankGenesis banktypes.GenesisState + if genesisState["bank"] != nil { + appCodec.MustUnmarshalJSON(genesisState["bank"], &bankGenesis) + } else { + bankGenesis = *banktypes.DefaultGenesisState() + } + + bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, denomMD) + + genesisState["bank"] = appCodec.MustMarshalJSON(&bankGenesis) + + return genesisState +} diff --git a/e2e/testing/chain.go b/e2e/testing/chain.go index 8052a90..d0d7fa4 100644 --- a/e2e/testing/chain.go +++ b/e2e/testing/chain.go @@ -5,29 +5,30 @@ import ( "encoding/json" "math/rand" "strconv" + "strings" "testing" "time" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - - seqtypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" - "github.com/CosmWasm/wasmd/x/wasm" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codecTypes "github.com/cosmos/cosmos-sdk/codec/types" cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptoTypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/ibc-go/v6/testing/mock" + rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types" + seqtypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -36,7 +37,6 @@ import ( tmTypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/dymensionxyz/rollapp-wasm/app" ) @@ -72,7 +72,7 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain { // Split options by groups (each group is applied in a different init step) var chainCfgOpts []TestChainConfigOption - //var consensusParamsOpts []TestChainConsensusParamsOption + // var consensusParamsOpts []TestChainConsensusParamsOption var genStateOpts []TestChainGenesisOption for i, opt := range opts { switch opt := opt.(type) { @@ -224,7 +224,19 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain { Coins: bondedPoolCoins, }) - bankGenesis := bankTypes.NewGenesisState(bankTypes.DefaultGenesisState().Params, balances, totalSupply, []bankTypes.Metadata{}) + bankGenesis := bankTypes.NewGenesisState(bankTypes.DefaultGenesisState().Params, balances, totalSupply, []bankTypes.Metadata{ + { + Description: "Stake token", + DenomUnits: []*bankTypes.DenomUnit{ + { + Denom: "stake", + Exponent: 18, + }, + }, + Base: "stake", + Display: "stake", + }, + }) genState[bankTypes.ModuleName] = rollApp.AppCodec().MustMarshalJSON(bankGenesis) signInfo := make([]slashingTypes.SigningInfo, len(validatorSet.Validators)) @@ -238,6 +250,10 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain { } genState[slashingTypes.ModuleName] = rollApp.AppCodec().MustMarshalJSON(slashingTypes.NewGenesisState(slashingTypes.DefaultParams(), signInfo, nil)) + rollappParamsState := rollappparamstypes.DefaultGenesisState() + rollappParamsState.Params.Version = strings.Repeat("x", 40) + genState[rollappparamstypes.ModuleName] = rollApp.AppCodec().MustMarshalJSON(rollappParamsState) + // Apply genesis options for _, opt := range genStateOpts { opt(rollApp.AppCodec(), genState)