Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nit: panic with error #4741

Merged
merged 12 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 214 additions & 2 deletions e2e/tests/upgrades/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/gogoproto/proto"

// intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand Down Expand Up @@ -73,8 +74,7 @@ func (s *UpgradeTestSuite) UpgradeChain(ctx context.Context, chain *cosmos.Cosmo
err = chain.StopAllNodes(ctx)
s.Require().NoError(err, "error stopping node(s)")

repository := chain.Nodes()[0].Image.Repository
chain.UpgradeVersion(ctx, s.DockerClient, repository, upgradeVersion)
chain.UpgradeVersion(ctx, s.DockerClient, getChainImage(chain), upgradeVersion)

err = chain.StartAllNodes(ctx)
s.Require().NoError(err, "error starting upgraded node(s)")
Expand Down Expand Up @@ -251,6 +251,201 @@ func (s *UpgradeTestSuite) TestChainUpgrade() {
})
}

// func (s *UpgradeTestSuite) TestV5ToV6ChainUpgrade() {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// t := s.T()
// testCfg := testsuite.LoadConfig()

// ctx := context.Background()
// relayer, _ := s.SetupChainsRelayerAndChannel(ctx)
// chainA, chainB := s.GetChains()

// // create separate user specifically for the upgrade proposal to more easily verify starting
// // and end balances of the chainA users.
// chainAUpgradeProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

// s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")

// // setup 2 accounts: controller account on chain A, a second chain B account.
// // host account will be created when the ICA is registered
// controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
// chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
// var hostAccount string

// t.Run("register interchain account", func(t *testing.T) {
// // explicitly set the version string because intertx with ibfc-go v5 does not support incentivized channels.
// version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
// msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, version)
// s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount)
// })

// t.Run("start relayer", func(t *testing.T) {
// s.StartRelayer(relayer)
// })

// t.Run("verify interchain account", func(t *testing.T) {
// var err error
// hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID)
// s.Require().NoError(err)
// s.Require().NotZero(len(hostAccount))

// channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID)
// s.Require().NoError(err)
// s.Require().Equal(len(channels), 2)
// })

// t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) {
// t.Run("fund interchain account wallet", func(t *testing.T) {
// // fund the host account, so it has some $$ to send
// err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
// Address: hostAccount,
// Amount: sdkmath.NewInt(testvalues.StartingTokenAmount),
// Denom: chainB.Config().Denom,
// })
// s.Require().NoError(err)
// })

// t.Run("broadcast MsgSubmitTx (legacy)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }

// // assemble submitMessage tx for intertx
// msgSubmitTx, err := intertxtypes.NewMsgSubmitTx(
// msgSend,
// ibctesting.FirstConnectionID,
// controllerAccount.FormattedAddress(),
// )
// s.Require().NoError(err)

// // broadcast submitMessage tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSubmitTx,
// )

// s.AssertTxSuccess(resp)

// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })

// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)

// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)

// expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })
// })

// s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")

// t.Run("upgrade chainA", func(t *testing.T) {
// s.UpgradeChain(ctx, chainA, chainAUpgradeProposalWallet, testCfg.UpgradeConfig.PlanName, testCfg.ChainConfigs[0].Tag, testCfg.UpgradeConfig.Tag)
// })

// t.Run("restart relayer", func(t *testing.T) {
// s.StopRelayer(ctx, relayer)
// s.StartRelayer(relayer)
// })

// t.Run("broadcast MsgSubmitTx (legacy)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }

// // assemble submitMessage tx for intertx
// msgSubmitTx, err := intertxtypes.NewMsgSubmitTx(
// msgSend,
// ibctesting.FirstConnectionID,
// controllerAccount.FormattedAddress(),
// )
// s.Require().NoError(err)

// // broadcast submitMessage tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSubmitTx,
// )

// s.AssertTxSuccess(resp)

// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })

// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)

// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)

// expected := (testvalues.IBCTransferAmount * 2) + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })

// t.Run("broadcast MsgSendTx (MsgServer)", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }

// data, err := icatypes.SerializeCosmosTx(testsuite.Codec(), []proto.Message{msgSend}, icatypes.EncodingProtobuf)
// s.Require().NoError(err)

// icaPacketData := icatypes.InterchainAccountPacketData{
// Type: icatypes.EXECUTE_TX,
// Data: data,
// }

// relativeTimeoutTimestamp := uint64(time.Hour.Nanoseconds())
// msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, relativeTimeoutTimestamp, icaPacketData)

// // broadcast MsgSendTx tx from controller account on chain A
// // this message should trigger the sending of an ICA packet over channel-1 (channel created between controller and host)
// // this ICA packet contains the assembled bank transfer message from above, which will be executed by the host account on the host chain.
// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSendTx,
// )

// s.AssertTxSuccess(resp)

// s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
// })

// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)

// _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom)
// s.Require().NoError(err)

// expected := (testvalues.IBCTransferAmount * 3) + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance)
// })
// }

// TestV6ToV7ChainUpgrade will test that an upgrade from a v6 ibc-go binary to a v7 ibc-go binary is successful
// and that the automatic migrations associated with the 02-client module are performed. Namely that the solo machine
// proto definition is migrated in state from the v2 to v3 definition. This is checked by creating a solo machine client
Expand Down Expand Up @@ -595,6 +790,12 @@ func (s *UpgradeTestSuite) TestV7ToV8ChainUpgrade() {
})
}

// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain.
// func (s *UpgradeTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) {
// txResp := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
// s.AssertTxSuccess(txResp)
// }

// ClientState queries the current ClientState by clientID
func (s *UpgradeTestSuite) ClientState(ctx context.Context, chain ibc.Chain, clientID string) (*clienttypes.QueryClientStateResponse, error) {
queryClient := s.GetChainGRCPClients(chain).ClientQueryClient
Expand All @@ -607,3 +808,14 @@ func (s *UpgradeTestSuite) ClientState(ctx context.Context, chain ibc.Chain, cli

return res, nil
}

// getChainImage returns the image of a given chain.
func getChainImage(chain *cosmos.CosmosChain) string {
tc := testsuite.LoadConfig()
for _, c := range tc.ChainConfigs {
if c.ChainID == chain.Config().ChainID {
return c.Image
}
}
panic(fmt.Errorf("unable to find image for chain: " + chain.Config().ChainID))
}
2 changes: 1 addition & 1 deletion e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (s *E2ETestSuite) RecoverRelayerWallets(ctx context.Context, ibcrelayer ibc
// StartRelayer starts the given ibcrelayer.
func (s *E2ETestSuite) StartRelayer(ibcrelayer ibc.Relayer) {
if s.startRelayerFn == nil {
panic("cannot start relayer before it is created!")
panic(fmt.Errorf("cannot start relayer before it is created!"))
}

s.startRelayerFn(ibcrelayer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller

import (
"fmt"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -239,7 +241,7 @@ func (IBCMiddleware) SendPacket(
timeoutTimestamp uint64,
data []byte,
) (uint64, error) {
panic("SendPacket not supported for ICA controller module. Please use SendTx")
panic(fmt.Errorf("SendPacket not supported for ICA controller module. Please use SendTx"))
}

// WriteAcknowledgement implements the ICS4 Wrapper interface
Expand All @@ -249,7 +251,7 @@ func (IBCMiddleware) WriteAcknowledgement(
packet ibcexported.PacketI,
ack ibcexported.Acknowledgement,
) error {
panic("WriteAcknowledgement not supported for ICA controller module")
panic(fmt.Errorf("WriteAcknowledgement not supported for ICA controller module"))
}

// GetAppVersion returns the interchain accounts metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("ica/controller params are not set in store")
panic(fmt.Errorf("ica/controller params are not set in store"))
}

var params types.Params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("ica/host params are not set in store")
panic(fmt.Errorf("ica/host params are not set in store"))
}

var params types.Params
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
func GetSimApp(chain *ibctesting.TestChain) *simapp.SimApp {
app, ok := chain.App.(*simapp.SimApp)
if !ok {
panic("chain is not a simapp.SimApp")
panic(fmt.Errorf("chain is not a simapp.SimApp"))
}
return app
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (s *CallbacksTestSuite) TestProcessCallback() {
func() {
callbackExecutor = func(cachedCtx sdk.Context) error {
cachedCtx.GasMeter().ConsumeGas(expGasConsumed, "callbackExecutor gas consumption")
panic("callbackExecutor panic")
panic(fmt.Errorf("callbackExecutor panic"))
}
},
false,
Expand Down Expand Up @@ -862,7 +862,7 @@ func (s *CallbacksTestSuite) TestProcessCallback() {
callbackType = types.CallbackTypeSendPacket
callbackExecutor = func(cachedCtx sdk.Context) error {
cachedCtx.GasMeter().ConsumeGas(expGasConsumed, "callbackExecutor gas consumption")
panic("callbackExecutor panic")
panic(fmt.Errorf("callbackExecutor panic"))
}
},
true,
Expand Down
5 changes: 3 additions & 2 deletions modules/apps/callbacks/testing/simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simapp

import (
"encoding/json"
"fmt"
"log"

storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -206,7 +207,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic("expected validator, not found")
panic(fmt.Errorf("expected validator, not found"))
}

validator.UnbondingHeight = 0
Expand All @@ -216,7 +217,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []

err = app.StakingKeeper.SetValidator(ctx, validator)
if err != nil {
panic("couldn't set validator")
panic(fmt.Errorf("couldn't set validator"))
}
counter++
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("transfer params are not set in store")
panic(fmt.Errorf("transfer params are not set in store"))
}

var params types.Params
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func AddressFromString(address string) string {

func AddressFromTla(addr []string) string {
if len(addr) != 3 {
panic("failed to convert from TLA+ address: wrong number of address components")
panic(fmt.Errorf("failed to convert from TLA+ address: wrong number of address components"))
}
s := ""
if len(addr[0]) == 0 && len(addr[1]) == 0 { //nolint:gocritic
Expand All @@ -109,7 +109,7 @@ func AddressFromTla(addr []string) string {
// escrow address: ics20-1\x00port/channel
s = fmt.Sprintf("%s\x00%s/%s", types.Version, addr[0], addr[1])
} else {
panic("failed to convert from TLA+ address: neither simple nor escrow address")
panic(fmt.Errorf("failed to convert from TLA+ address: neither simple nor escrow address"))
}
return s
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() {
var sender sdk.AccAddress
sender, err = sdk.AccAddressFromBech32(tc.packet.Data.Sender)
if err != nil {
panic("MBT failed to convert sender address")
panic(fmt.Errorf("MBT failed to convert sender address"))
}
registerDenomFn()
denomTrace := types.ParseDenomTrace(tc.packet.Data.Denom)
Expand All @@ -342,7 +342,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() {
if err == nil {
amount, ok := sdkmath.NewIntFromString(tc.packet.Data.Amount)
if !ok {
panic("MBT failed to parse amount from string")
panic(fmt.Errorf("MBT failed to parse amount from string"))
}
msg := types.NewMsgTransfer(
tc.packet.SourcePort,
Expand Down
Loading
Loading