Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed May 1, 2024
1 parent 224b19f commit 04d429f
Show file tree
Hide file tree
Showing 29 changed files with 53 additions and 23,505 deletions.
4 changes: 3 additions & 1 deletion module/cmd/gravity/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/module"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
Expand Down Expand Up @@ -61,7 +63,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec := simapp.MakeTestEncodingConfig().Codec
appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}).Codec
err = genutiltest.ExecInitCmd(testMbm, home, appCodec)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions module/x/gravity/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestSignerSetTxCreationUponUnbonding(t *testing.T) {
require.NoError(t, err)

// Run the staking endblocker to ensure signer set tx is set in state
staking.EndBlocker(input.Context, input.StakingKeeper)
staking.EndBlocker(input.Context, &input.StakingKeeper)

// power diff should be less than 5%
latestSignerSetTx := input.GravityKeeper.GetLatestSignerSetTx(input.Context)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestSignerSetTxCreationUponUnbonding(t *testing.T) {
)
require.NoError(t, err)

staking.EndBlocker(input.Context, input.StakingKeeper)
staking.EndBlocker(input.Context, &input.StakingKeeper)

// last unbonding height should not be the current block
lastUnbondingHeight = input.GravityKeeper.GetLastUnbondingBlockHeight(input.Context)
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestSignerSetTxSlashing_UnbondingValidator_UnbondWindow_NotExpired(t *testi
}
gravityKeeper.SetEthereumSignature(ctx, &types.SignerSetTxConfirmation{vs.Nonce, keeper.EthAddrs[i].Hex(), []byte("dummySig")}, val)
}
staking.EndBlocker(input.Context, input.StakingKeeper)
staking.EndBlocker(input.Context, &input.StakingKeeper)

ctx = ctx.WithBlockHeight(currentBlockHeight)
gravity.EndBlocker(ctx, gravityKeeper)
Expand Down
3 changes: 2 additions & 1 deletion module/x/gravity/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"testing"

"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/stretchr/testify/require"
)

func TestParseCommunityPoolEthereumSpendProposal(t *testing.T) {
encodingConfig := params.MakeTestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down
7 changes: 3 additions & 4 deletions module/x/gravity/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cometbft/cometbft/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/peggyjv/gravity-bridge/module/v4/x/gravity/migrations/v1/keeper"
"github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -220,7 +219,7 @@ func TestKeeper_UnsignedSignerSetTxs(t *testing.T) {
t.Run("read after there's something in state", func(t *testing.T) {
env, ctx := SetupFiveValChain(t)
gk := env.GravityKeeper
orchAddr := keeper.AccAddrs[0]
orchAddr := AccAddrs[0]
signer := orchAddr.String()
valAddr, err := sdk.ValAddressFromBech32(env.StakingKeeper.GetValidators(ctx, 5)[0].OperatorAddress)
require.NoError(t, err)
Expand Down Expand Up @@ -257,7 +256,7 @@ func TestKeeper_UnsignedBatchTxs(t *testing.T) {
t.Run("read after there's something in state", func(t *testing.T) {
env, ctx := SetupFiveValChain(t)
gk := env.GravityKeeper
orchAddr := keeper.AccAddrs[0]
orchAddr := AccAddrs[0]
signer := orchAddr.String()
valAddr, err := sdk.ValAddressFromBech32(env.StakingKeeper.GetValidators(ctx, 5)[0].OperatorAddress)
require.NoError(t, err)
Expand Down Expand Up @@ -309,7 +308,7 @@ func TestKeeper_UnsignedContractCallTxs(t *testing.T) {
t.Run("read after there's something in state", func(t *testing.T) {
env, ctx := SetupFiveValChain(t)
gk := env.GravityKeeper
orchAddr := keeper.AccAddrs[0]
orchAddr := AccAddrs[0]
signer := orchAddr.String()
valAddr, err := sdk.ValAddressFromBech32(env.StakingKeeper.GetValidators(ctx, 5)[0].OperatorAddress)
require.NoError(t, err)
Expand Down
48 changes: 42 additions & 6 deletions module/x/gravity/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -29,6 +30,7 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
Expand All @@ -54,7 +56,10 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
gethcommon "github.com/ethereum/go-ethereum/common"
gravityclient "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/client"
"github.com/stretchr/testify/require"

"github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types"
Expand Down Expand Up @@ -340,13 +345,15 @@ func CreateTestEnv(t *testing.T) TestInput {
types.ModuleName: {authtypes.Minter, authtypes.Burner},
}

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()

accountKeeper := authkeeper.NewAccountKeeper(
marshaler,
keyAcc, // target store
authtypes.ProtoBaseAccount, // prototype
maccPerms,
"gravity",
govtypes.ModuleName,
authority,
)

blockedAddr := make(map[string]bool, len(maccPerms))
Expand All @@ -359,14 +366,14 @@ func CreateTestEnv(t *testing.T) TestInput {
keyBank,
accountKeeper,
blockedAddr,
govtypes.ModuleName,
authority,
)
bankKeeper.SetParams(ctx, banktypes.Params{DefaultSendEnabled: true})

stakingKeeper := stakingkeeper.NewKeeper(marshaler, keyStaking, accountKeeper, bankKeeper, govtypes.ModuleName)
stakingKeeper := stakingkeeper.NewKeeper(marshaler, keyStaking, accountKeeper, bankKeeper, authority)
stakingKeeper.SetParams(ctx, TestingStakeParams)

distKeeper := distrkeeper.NewKeeper(marshaler, keyDistro, accountKeeper, bankKeeper, stakingKeeper, authtypes.FeeCollectorName, govtypes.ModuleName)
distKeeper := distrkeeper.NewKeeper(marshaler, keyDistro, accountKeeper, bankKeeper, stakingKeeper, authtypes.FeeCollectorName, authority)
distKeeper.SetParams(ctx, distrtypes.DefaultParams())

// set genesis items required for distribution
Expand Down Expand Up @@ -403,7 +410,7 @@ func CreateTestEnv(t *testing.T) TestInput {

router := baseapp.NewMsgServiceRouter()
govKeeper := govkeeper.NewKeeper(
marshaler, keyGov, accountKeeper, bankKeeper, stakingKeeper, router, govtypes.DefaultConfig(), govtypes.ModuleName,
marshaler, keyGov, accountKeeper, bankKeeper, stakingKeeper, router, govtypes.DefaultConfig(), authority,
)

govKeeper.SetProposalID(ctx, govtypesv1beta1.DefaultStartingProposalID)
Expand All @@ -413,7 +420,7 @@ func CreateTestEnv(t *testing.T) TestInput {
cdc,
keySlashing,
stakingKeeper,
govtypes.ModuleName,
authority,
)

k := NewKeeper(
Expand Down Expand Up @@ -475,6 +482,35 @@ func MakeTestCodec() *codec.LegacyAmino {
return cdc
}

func MakeTestEncodingConfig() moduletestutil.TestEncodingConfig {
return moduletestutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
consensus.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distribution.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
gravityclient.ProposalHandler,
},
),
//params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
vesting.AppModuleBasic{},
)
}

// MakeTestMarshaler creates a proto codec for use in testing
func MakeTestMarshaler() codec.Codec {
interfaceRegistry := codectypes.NewInterfaceRegistry()
Expand Down
88 changes: 0 additions & 88 deletions module/x/gravity/migrations/v1/keeper/hooks.go

This file was deleted.

65 changes: 0 additions & 65 deletions module/x/gravity/migrations/v1/keeper/keeper.go

This file was deleted.

Loading

0 comments on commit 04d429f

Please sign in to comment.