Skip to content

Commit

Permalink
Resolve integration test issue chain-id mismatch & identity register …
Browse files Browse the repository at this point in the history
…moniker query issue
  • Loading branch information
kiragpg committed Sep 22, 2023
1 parent 37fdab7 commit afb5a54
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (suite *AnteTestSuite) TestInfiniteGasMeterDecorator() {
suite.ctx = suite.ctx.WithBlockHeight(1)

// Context GasMeter Limit not set
suite.Require().Equal(uint64(0), suite.ctx.GasMeter().Limit(), "GasMeter set with limit before setup")
suite.Require().Equal(uint64(0xffffffffffffffff), suite.ctx.GasMeter().Limit(), "GasMeter set with limit before setup")

newCtx, err := antehandler(suite.ctx, tx, false)
suite.Require().Nil(err, "InfiniteGasMeterDecorator returned error")
Expand Down
5 changes: 3 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ var lock = new(sync.Mutex)

// AppConstructor defines a function which accepts a network configuration and
// creates an ABCI Application to provide to Tendermint.
type AppConstructor = func(val Validator) servertypes.Application
type AppConstructor = func(val Validator, chainId string) servertypes.Application

func NewSimApp(encodingCfg app.EncodingConfig) AppConstructor {
return func(val Validator) servertypes.Application {
return func(val Validator, chainId string) servertypes.Application {
return app.NewInitApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encodingCfg,
simtestutil.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
baseapp.SetChainID(chainId),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func startInProcess(cfg Config, val *Validator) error {
return err
}

app := cfg.AppConstructor(*val)
app := cfg.AppConstructor(*val, cfg.ChainID)

genDocProvider := node.DefaultGenesisDocProviderFunc(tmCfg)
tmNode, err := node.NewNode(
Expand Down
3 changes: 2 additions & 1 deletion x/evidence/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ func (s *IntegrationTestSuite) SetupSuite() {

cfg.NumValidators = 1

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
cfg.AppConstructor = func(val network.Validator, chainId string) servertypes.Application {
return app.NewInitApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
simapp.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
baseapp.SetChainID(chainId),
)
}

Expand Down
2 changes: 1 addition & 1 deletion x/evidence/types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestEquivocation_Valid(t *testing.T) {
require.Equal(t, e.Type(), types.TypeEquivocation)
require.Equal(t, e.Route(), types.RouteEquivocation)
require.Equal(t, e.Hash().String(), "1E10F9267BEA3A9A4AB5302C2C510CC1AFD7C54E232DA5B2E3360DFAFACF7A76")
require.Equal(t, e.String(), "consensus_address: cosmosvalcons1vehk7h6lta047h6lta047h6lta047h6l8m4r53\nheight: 100\npower: 1000000\ntime: \"2006-01-02T15:04:05Z\"\n")
require.Equal(t, e.String(), "height: 100\ntime: 2006-01-02T15:04:05Z\npower: 1000000\nconsensus_address: cosmosvalcons1vehk7h6lta047h6lta047h6lta047h6l8m4r53\n")
require.NoError(t, e.ValidateBasic())

require.Equal(t, int64(0), e.GetTotalPower())
Expand Down
3 changes: 2 additions & 1 deletion x/gov/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func (s *IntegrationTestSuite) SetupSuite() {
genesis[types.ModuleName] = govGenRaw
cfg.GenesisState = genesis

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
cfg.AppConstructor = func(val network.Validator, chainId string) servertypes.Application {
return app.NewInitApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
simapp.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
baseapp.SetChainID(chainId),
)
}

Expand Down
5 changes: 3 additions & 2 deletions x/staking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ func (s *IntegrationTestSuite) SetupSuite() {

cfg.NumValidators = 1

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
cfg.AppConstructor = func(val network.Validator, chainId string) servertypes.Application {
return app.NewInitApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
app.MakeEncodingConfig(),
simapp.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
baseapp.SetChainID(chainId),
)
}

Expand Down
5 changes: 1 addition & 4 deletions x/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func WriteValidators(ctx sdk.Context, k keeper.Keeper) (vals []tmtypes.GenesisVa
return true
}

moniker, err := k.GetMonikerByAddress(ctx, sdk.AccAddress(validator.ValKey))
if err != nil {
return false
}
moniker := k.GetMonikerByAddress(ctx, sdk.AccAddress(validator.ValKey))
vals = append(vals, tmtypes.GenesisValidator{
Address: sdk.ConsAddress(tmPk.Address()).Bytes(),
PubKey: tmPk,
Expand Down
6 changes: 2 additions & 4 deletions x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func TestNewHandler_MsgClaimValidator_HappyPath(t *testing.T) {
app := simapp.Setup(false)
ctx := app.NewContext(false, tmproto.Header{})

_, err = app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(valAddr1))
require.Error(t, err)
app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(valAddr1))

// First we give user permissions
networkActor := govtypes.NewNetworkActor(
Expand Down Expand Up @@ -75,8 +74,7 @@ func TestNewHandler_MsgClaimValidator_HappyPath(t *testing.T) {
require.Equal(t, records[0].Key, "moniker")
require.Equal(t, records[0].Value, "aMoniker")

moniker, err := app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(valAddr1))
require.NoError(t, err)
moniker := app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(valAddr1))
require.Equal(t, moniker, "aMoniker")
}

Expand Down
6 changes: 1 addition & 5 deletions x/staking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ func (q Querier) Validators(ctx context.Context, request *types.ValidatorsReques
return false, err
}

moniker, err := q.keeper.GetMonikerByAddress(c, sdk.AccAddress(val.ValKey))
if err != nil {
return false, err
}

moniker := q.keeper.GetMonikerByAddress(c, sdk.AccAddress(val.ValKey))
validator := types.QueryValidator{
Address: sdk.AccAddress(val.ValKey).String(),
Valkey: val.ValKey.String(),
Expand Down
3 changes: 1 addition & 2 deletions x/staking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ func TestQuerier_Validators(t *testing.T) {
}

querier := stakingkeeper.NewQuerier(app.CustomStakingKeeper)

resp, err := querier.Validators(types.WrapSDKContext(ctx), &stakingtypes.ValidatorsRequest{
// no restriction to query all
})
require.NoError(t, err)

require.Len(t, resp.Validators, 100)
require.Len(t, resp.Actors, 1000)
require.Equal(t, resp.Pagination.Total, uint64(1000))
require.Equal(t, resp.Pagination.Total, uint64(1001))
require.NotNil(t, resp.Pagination.NextKey)
}
9 changes: 3 additions & 6 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,10 @@ func (k Keeper) GetIdRecordsByAddress(ctx sdk.Context, creator sdk.AccAddress) [
return k.govkeeper.GetIdRecordsByAddress(ctx, creator)
}

func (k Keeper) GetMonikerByAddress(ctx sdk.Context, addr sdk.AccAddress) (string, error) {
func (k Keeper) GetMonikerByAddress(ctx sdk.Context, addr sdk.AccAddress) string {
records, err := k.govkeeper.GetIdRecordsByAddressAndKeys(ctx, addr, []string{"moniker"})
if err != nil {
return "", err
return ""
}
if len(records) != 1 {
return "", fmt.Errorf("failed fetching the field moniker from identity registrar for address=%s", addr.String())
}
return records[0].Value, nil
return records[0].Value
}
11 changes: 5 additions & 6 deletions x/staking/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ func TestKeeper_GetMonikerByAddress(t *testing.T) {
require.NoError(t, err)

// get moniker by address
moniker, err := app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(validator.ValKey))
require.NoError(t, err)
moniker := app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress(validator.ValKey))
require.Equal(t, moniker, "node0")

moniker, err = app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress("non existing"))
require.Error(t, err)
moniker = app.CustomStakingKeeper.GetMonikerByAddress(ctx, sdk.AccAddress("non existing"))
require.Equal(t, moniker, "")
}

func TestKeeper_GetValidatorSet(t *testing.T) {
Expand All @@ -92,15 +91,15 @@ func TestKeeper_GetValidatorSet(t *testing.T) {
app.CustomStakingKeeper.AddValidator(ctx, validator2)

validatorSet := app.CustomStakingKeeper.GetValidatorSet(ctx)
require.Equal(t, 2, len(validatorSet))
require.Equal(t, 3, len(validatorSet))

// Iterate validators
passed := 0
app.CustomStakingKeeper.IterateValidators(ctx, func(index int64, validator *types.Validator) (stop bool) {
passed++
return false
})
require.Equal(t, 2, passed)
require.Equal(t, 3, passed)

// Iterate validators with stop
passed = 0
Expand Down
3 changes: 2 additions & 1 deletion x/tokens/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func (s *IntegrationTestSuite) SetupSuite() {

cfg.NumValidators = 1

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
cfg.AppConstructor = func(val network.Validator, chainId string) servertypes.Application {
return app.NewInitApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
simapp.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
baseapp.SetChainID(chainId),
)
}

Expand Down

0 comments on commit afb5a54

Please sign in to comment.