Skip to content

Commit

Permalink
fix: failing tests (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Oct 29, 2024
1 parent 21753d2 commit 9044cc8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand Down
29 changes: 29 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
34 changes: 25 additions & 9 deletions e2e/testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit 9044cc8

Please sign in to comment.