Skip to content

Commit

Permalink
e2e tests: fix errors in provider relay
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Mar 6, 2024
1 parent 76999af commit c9fbc79
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
50 changes: 31 additions & 19 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,32 @@ import (
)

const (
AppName = "interchain-security-c"
upgradeName = "ics-v1-to-v2"
AccountAddressPrefix = "cosmos"
AppName = "interchain-security-c"
upgradeName = "ics-v1-to-v2"

Bech32MainPrefix = "consumer"
Bech32PrefixAccAddr = Bech32MainPrefix
Bech32PrefixAccPub = Bech32MainPrefix + sdk.PrefixPublic
Bech32PrefixValAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
Bech32PrefixValPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
Bech32PrefixConsAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
Bech32PrefixConsPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
stdlog.Println("Failed to get home dir %2", err)
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName)
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32MainPrefix+"pub")
cfg.SetBech32PrefixForValidator(Bech32MainPrefix+"valoper", Bech32MainPrefix+"valoperpub")
cfg.SetBech32PrefixForConsensusNode(Bech32MainPrefix+"valcons", Bech32MainPrefix+"valconspub")
cfg.Seal()
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand Down Expand Up @@ -194,15 +215,6 @@ type App struct { // nolint: golint
configurator module.Configurator
}

func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
stdlog.Println("Failed to get home dir %2", err)
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName)
}

// New returns a reference to an initialized App.
func New(
logger log.Logger,
Expand Down Expand Up @@ -281,8 +293,8 @@ func New(
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
authtypes.ProtoBaseAccount,
maccPerms,
authcodec.NewBech32Codec(sdk.Bech32MainPrefix),
sdk.Bech32MainPrefix,
authcodec.NewBech32Codec(Bech32MainPrefix),
Bech32MainPrefix,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down Expand Up @@ -388,8 +400,8 @@ func New(
app.IBCKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
authcodec.NewBech32Codec(Bech32PrefixValAddr),
authcodec.NewBech32Codec(Bech32PrefixConsAddr),
)

// register slashing module Slashing hooks to the consumer keeper
Expand Down Expand Up @@ -799,9 +811,9 @@ func (app *App) AutoCliOpts() autocli.AppOptions {

return autocli.AppOptions{
Modules: modules,
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
AddressCodec: authcodec.NewBech32Codec(Bech32PrefixAccAddr),
ValidatorAddressCodec: authcodec.NewBech32Codec(Bech32PrefixValAddr),
ConsensusAddressCodec: authcodec.NewBech32Codec(Bech32PrefixConsAddr),
}
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/interchain-security-cd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -195,9 +194,6 @@ lru_size = 0`
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig appencoding.EncodingConfig) {
cfg := sdk.GetConfig()
cfg.Seal()

rootCmd.AddCommand(
genutilcli.InitCmd(consumer.ModuleBasics, consumer.DefaultNodeHome),
debug.Cmd(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/interchain-security-pd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "simd",
Short: "simulation app",
SilenceErrors: false,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
Expand Down
3 changes: 2 additions & 1 deletion x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"
"strconv"

Expand Down Expand Up @@ -217,7 +218,7 @@ func (k Keeper) SendPackets(ctx sdk.Context) {
k.GetCCVTimeoutPeriod(ctx),
)
if err != nil {
if clienttypes.ErrClientNotActive.Is(err) {
if errors.Is(err, clienttypes.ErrClientNotActive) {
// IBC client is expired!
// leave the packet data stored to be sent once the client is upgraded
k.Logger(ctx).Info("IBC client is expired, cannot send IBC packet; leaving packet data stored:", "type", p.Type.String())
Expand Down
3 changes: 2 additions & 1 deletion x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"
"strconv"
"time"
Expand Down Expand Up @@ -261,7 +262,7 @@ func (k Keeper) MakeConsumerGenesis(
}

val, err := k.stakingKeeper.GetValidator(ctx, addr)
if err != nil && stakingtypes.ErrNoValidatorFound.Is(err) {
if err != nil && errors.Is(err, stakingtypes.ErrNoValidatorFound) {
return gen, nil, errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "error getting validator from LastValidatorPowers")
} else if err != nil {
return gen, nil, errorsmod.Wrapf(err, "error getting validator from LastValidatorPowers")
Expand Down
15 changes: 8 additions & 7 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"
"strconv"

Expand Down Expand Up @@ -88,10 +89,10 @@ func (k Keeper) completeMaturedUnbondingOps(ctx sdk.Context) {
// Attempt to complete unbonding in staking module
err := k.stakingKeeper.UnbondingCanComplete(ctx, id)
if err != nil {
if stakingtypes.ErrUnbondingNotFound.Is(err) {
if errors.Is(err, stakingtypes.ErrNoUnbondingDelegation) {
// The unbonding was not found.
unbondingType, err := k.stakingKeeper.GetUnbondingType(ctx, id)
if err == nil && unbondingType == stakingtypes.UnbondingType_UnbondingDelegation {
unbondingType, errGet := k.stakingKeeper.GetUnbondingType(ctx, id)
if errGet == nil && unbondingType == stakingtypes.UnbondingType_UnbondingDelegation {
// If this is an unbonding delegation, it may have been removed
// after through a CancelUnbondingDelegation message
k.Logger(ctx).Debug("unbonding delegation was already removed:", "unbondingID", id)
Expand Down Expand Up @@ -185,7 +186,7 @@ func (k Keeper) SendVSCPacketsToChain(ctx sdk.Context, chainID, channelID string
k.GetCCVTimeoutPeriod(ctx),
)
if err != nil {
if clienttypes.ErrClientNotActive.Is(err) {
if errors.Is(err, clienttypes.ErrClientNotActive) {
// IBC client is expired!
// leave the packet data stored to be sent once the client is upgraded
// the client cannot expire during iteration (in the middle of a block)
Expand Down Expand Up @@ -393,7 +394,7 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.Slas

// Obtain validator from staking keeper
validator, err := k.stakingKeeper.GetValidatorByConsAddr(ctx, providerConsAddr.ToSdkConsAddr())
if err != nil && stakingtypes.ErrNoValidatorFound.Is(err) {
if err != nil && errors.Is(err, stakingtypes.ErrNoValidatorFound) {
k.Logger(ctx).Error("validator not found or is unbonded", "validator", providerConsAddr.String())
return
}
Expand Down Expand Up @@ -474,7 +475,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) {
"chainID", initTimeoutTimestamp.ChainId)
err := k.StopConsumerChain(ctx, initTimeoutTimestamp.ChainId, false)
if err != nil {
if providertypes.ErrConsumerChainNotFound.Is(err) {
if errors.Is(err, providertypes.ErrConsumerChainNotFound) {
// consumer chain not found
continue
}
Expand All @@ -501,7 +502,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) {
)
err := k.StopConsumerChain(ctx, channelToChain.ChainId, true)
if err != nil {
if providertypes.ErrConsumerChainNotFound.Is(err) {
if errors.Is(err, providertypes.ErrConsumerChainNotFound) {
// consumer chain not found
continue
}
Expand Down

0 comments on commit c9fbc79

Please sign in to comment.