Skip to content

Commit

Permalink
add default encoding in interchaintest
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed May 7, 2024
1 parent 5426ae3 commit 59a3c7e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 48 deletions.
12 changes: 5 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,11 @@ func NewComposableApp(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
devnetGov *string,
baseAppOptions ...func(*baseapp.BaseApp),
) *ComposableApp {
cdc := encodingConfig.Amino
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
Expand All @@ -297,7 +295,7 @@ func NewComposableApp(
std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp := baseapp.NewBaseApp(Name, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(txConfig.TxEncoder())
Expand All @@ -314,7 +312,7 @@ func NewComposableApp(

app.InitSpecialKeepers(
appCodec,
cdc,
legacyAmino,
bApp,
invCheckPeriod,
skipUpgradeHeights,
Expand All @@ -324,7 +322,7 @@ func NewComposableApp(
app.InitNormalKeepers(
logger,
appCodec,
cdc,
legacyAmino,
bApp,
maccPerms,
invCheckPeriod,
Expand Down Expand Up @@ -355,7 +353,7 @@ func NewComposableApp(
app.mm = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app,
encodingConfig.TxConfig,
txConfig,
),

auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
Expand Down Expand Up @@ -568,7 +566,7 @@ func NewComposableApp(
app.FeeGrantKeeper,
nil,
authante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(),
txConfig.SignModeHandler(),
app.IBCKeeper,
app.TransferMiddlewareKeeper,
app.TxBoundaryKeepper,
Expand Down
1 change: 0 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func setup(withGenesis bool, chainID string, opts ...wasmkeeper.Option) (*Compos
map[int64]bool{},
DefaultNodeHome,
5,
MakeEncodingConfig(),
EmptyBaseAppOptions{},
opts,
nil,
Expand Down
37 changes: 17 additions & 20 deletions cmd/picad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ var ChainID string
// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
encodingConfig := app.MakeEncodingConfig()

tempApp := app.NewComposableApp(
log.NewNopLogger(),
Expand All @@ -61,12 +60,18 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
map[int64]bool{},
app.DefaultNodeHome,
5,
encodingConfig,
EmptyAppOptions{},
nil,
nil,
)

encodingConfig := app.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Marshaler: tempApp.AppCodec(),
TxConfig: tempApp.TxConfig(),
Amino: tempApp.LegacyAmino(),
}

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down Expand Up @@ -106,7 +111,7 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
},
}

initRootCmd(rootCmd, encodingConfig)
initRootCmd(rootCmd, encodingConfig.TxConfig)

autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
Expand Down Expand Up @@ -193,32 +198,31 @@ lru_size = 0`
return customAppTemplate, customAppConfig
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
func initRootCmd(rootCmd *cobra.Command, txConfig client.TxConfig) {
cfg := sdk.GetConfig()
cfg.Seal()

gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)

rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator, txConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.GenTxCmd(app.ModuleBasics, txConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, txConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
addDebugCommands(debug.Cmd()),
debug.Cmd(),
vestingcli.GetTxCmd(encodingConfig.TxConfig.SigningContext().AddressCodec()),
vestingcli.GetTxCmd(txConfig.SigningContext().AddressCodec()),
// this line is used by starport scaffolding # stargate/root/commands
)

appCreator := appCreator{encodingConfig}
server.AddCommands(rootCmd, app.DefaultNodeHome, appCreator.newApp, appCreator.appExport, addModuleInitFlags)
server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, appExport, addModuleInitFlags)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
server.StatusCommand(),
genesisCommand(encodingConfig.TxConfig, app.ModuleBasics),
genesisCommand(txConfig, app.ModuleBasics),
queryCommand(),
txCommand(),
keys.Commands(),
Expand Down Expand Up @@ -281,12 +285,8 @@ func txCommand() *cobra.Command {
return cmd
}

type appCreator struct {
encCfg app.EncodingConfig
}

// newApp is an AppCreator
func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
// newApp creates the application
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
skipUpgradeHeights := make(map[int64]bool)
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
h, err := cast.ToInt64E(h)
Expand All @@ -309,7 +309,6 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
a.encCfg,
// this line is used by starport scaffolding # stargate/root/appArgument
appOpts,
emptyWasmOpts,
Expand All @@ -321,7 +320,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
}

// appExport creates a new simapp (optionally at a given height)
func (a appCreator) appExport(
func appExport(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
appOpts servertypes.AppOptions, _ []string,
) (servertypes.ExportedApp, error) {
Expand All @@ -342,7 +341,6 @@ func (a appCreator) appExport(
map[int64]bool{},
homePath,
uint(1),
a.encCfg,
appOpts,
emptyWasmOpts,
nil,
Expand All @@ -360,7 +358,6 @@ func (a appCreator) appExport(
map[int64]bool{},
homePath,
uint(1),
a.encCfg,
appOpts,
emptyWasmOpts,
nil,
Expand Down
3 changes: 3 additions & 0 deletions tests/interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.2

require (
cosmossdk.io/math v1.3.0
github.com/CosmWasm/wasmd v0.42.1-0.20230928145107-894076a25cb2
github.com/cosmos/cosmos-sdk v0.50.5
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845
Expand Down Expand Up @@ -37,6 +38,7 @@ require (
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000 // indirect
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
github.com/CosmWasm/wasmvm v1.4.0 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
Expand Down Expand Up @@ -237,6 +239,7 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions tests/interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRr
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 h1:oknQF/iIhf5lVjbwjsVDzDByupRhga8nhA3NAmwyHDA=
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420/go.mod h1:KYkiMX5AbOlXXYfxkrYPrRPV6EbVUALTQh5ptUOJzu8=
github.com/CosmWasm/wasmd v0.42.1-0.20230928145107-894076a25cb2 h1:j8J9LnhC6IikohLEYMAFX0xPQmgPez9vsj0rNQISkiE=
github.com/CosmWasm/wasmd v0.42.1-0.20230928145107-894076a25cb2/go.mod h1:3sCglc35LoFUGmh4a/auoJALitaE4qw+jAqK53ak7+s=
github.com/CosmWasm/wasmvm v1.4.0 h1:84I3MlvvzcOo2z+ed0ztPi7eeDNk6/sYuK76uyXP1nI=
github.com/CosmWasm/wasmvm v1.4.0/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc=
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
Expand Down
42 changes: 22 additions & 20 deletions tests/interchaintest/ibc_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
nf := 1 // Number of full nodes

consensusOverrides := make(testutil.Toml)
blockTime := 1 // seconds, parachain is 12 second blocks, don't make relayer work harder than needed
blockTime := 5 // seconds, parachain is 12 second blocks, don't make relayer work harder than needed
blockT := (time.Duration(blockTime) * time.Second).String()
consensusOverrides["timeout_commit"] = blockT
consensusOverrides["timeout_propose"] = blockT
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

composable := chains[0].(*polkadot.PolkadotChain)
polkadotChain := chains[0].(*polkadot.PolkadotChain)
centaurid := chains[1].(*cosmos.CosmosChain)

// Get a relayer instance
Expand All @@ -135,11 +135,11 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
const relayerName = "hyperspace"

ic := interchaintest.NewInterchain().
AddChain(composable).
AddChain(polkadotChain).
AddChain(centaurid).
AddRelayer(r, relayerName).
AddLink(interchaintest.InterchainLink{
Chain1: composable,
Chain1: polkadotChain,
Chain2: centaurid,
Relayer: r,
Path: pathName,
Expand All @@ -164,34 +164,36 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
// Set client contract hash in cosmos chain config
err = r.SetClientContractHash(ctx, eRep, centaurid.Config(), codeHash)
require.NoError(t, err)
fmt.Println("hoank")

// Ensure parachain has started (starts 1 session/epoch after relay chain)
//err = testutil.WaitForBlocks(ctx, 1, composable)
//require.NoError(t, err, "polkadot chain failed to make blocks")
err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
require.NoError(t, err, "polkadot chain failed to make blocks")
fmt.Println("waiting")

// Fund users on both cosmos and parachain, mints Asset 1 for Alice
fundAmount := math.NewInt(12_333_000_000_000)
polkadotUser, cosmosUser := fundUsers(t, ctx, fundAmount, composable, centaurid)
polkadotUser, cosmosUser := fundUsers(t, ctx, fundAmount, polkadotChain, centaurid)

err = r.GeneratePath(ctx, eRep, centaurid.Config().ChainID, composable.Config().ChainID, pathName)
err = r.GeneratePath(ctx, eRep, centaurid.Config().ChainID, polkadotChain.Config().ChainID, pathName)
require.NoError(t, err)

// Create new clients
err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts())
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 1, centaurid, composable) // these 1 block waits may be needed, not sure
err = testutil.WaitForBlocks(ctx, 1, centaurid, polkadotChain) // these 1 block waits may be needed, not sure
require.NoError(t, err)

// Create a new connection
err = r.CreateConnections(ctx, eRep, pathName)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 1, centaurid, composable)
err = testutil.WaitForBlocks(ctx, 1, centaurid, polkadotChain)
require.NoError(t, err)

// Create a new channel & get channels from each chain
err = r.CreateChannel(ctx, eRep, pathName, ibc.DefaultChannelOpts())
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 1, centaurid, composable)
err = testutil.WaitForBlocks(ctx, 1, centaurid, polkadotChain)
require.NoError(t, err)

// Get channels - Query channels was removed
Expand All @@ -200,7 +202,7 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
require.Equal(t, len(cosmosChannelOutput), 1)
require.Equal(t, cosmosChannelOutput[0].ChannelID, "channel-0")
require.Equal(t, cosmosChannelOutput[0].PortID, "transfer")
polkadotChannelOutput, err := r.GetChannels(ctx, eRep, composable.Config().ChainID)
polkadotChannelOutput, err := r.GetChannels(ctx, eRep, polkadotChain.Config().ChainID)
require.NoError(t, err)
require.Equal(t, len(polkadotChannelOutput), 1)
require.Equal(t, polkadotChannelOutput[0].ChannelID, "channel-0")
Expand All @@ -226,17 +228,17 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
tx, err := centaurid.SendIBCTransfer(ctx, "channel-0", cosmosUser.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)
require.NoError(t, tx.Validate()) // test source wallet has decreased funds
err = testutil.WaitForBlocks(ctx, 5, centaurid, composable)
err = testutil.WaitForBlocks(ctx, 5, centaurid, polkadotChain)
require.NoError(t, err)

/*// Trace IBC Denom of stake on parachain
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(cosmosChannelOutput[0].PortID, cosmosChannelOutput[0].ChannelID, centaurid.Config().Denom))
dstIbcDenom := srcDenomTrace.IBCDenom()
fmt.Println("Dst Ibc denom: ", dstIbcDenom)
// Test destination wallet has increased funds, this is not working, want to verify IBC balance on parachain
polkadotUserIbcCoins, err := composable.GetIbcBalance(ctx, string(polkadotUser.Address()))
polkadotUserIbcCoins, err := polkadotChain.GetIbcBalance(ctx, string(polkadotUser.Address()))
fmt.Println("UserIbcCoins: ", polkadotUserIbcCoins.String())
aliceIbcCoins, err := composable.GetIbcBalance(ctx, "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL")
aliceIbcCoins, err := polkadotChain.GetIbcBalance(ctx, "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL")
fmt.Println("AliceIbcCoins: ", aliceIbcCoins.String())*/

// Send 1.16 stake from parachainUser to cosmosUser
Expand All @@ -246,7 +248,7 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
Denom: "2", // stake
Amount: amountToReflect,
}
_, err = composable.SendIBCTransfer(ctx, "channel-0", polkadotUser.KeyName(), reflectTransfer, ibc.TransferOptions{})
_, err = polkadotChain.SendIBCTransfer(ctx, "channel-0", polkadotUser.KeyName(), reflectTransfer, ibc.TransferOptions{})
require.NoError(t, err)

// Send 1.88 "UNIT" from Alice to cosmosUser
Expand All @@ -256,7 +258,7 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
Denom: "1", // UNIT
Amount: amountUnits,
}
_, err = composable.SendIBCTransfer(ctx, "channel-0", "alice", unitTransfer, ibc.TransferOptions{})
_, err = polkadotChain.SendIBCTransfer(ctx, "channel-0", "alice", unitTransfer, ibc.TransferOptions{})
require.NoError(t, err)

// Wait for MsgRecvPacket on cosmos chain
Expand All @@ -277,16 +279,16 @@ func TestCentauriPicassoIBCTransfer(t *testing.T) {
cosmosUserUnitBal, err := centaurid.GetBalance(ctx, cosmosUser.FormattedAddress(), unitDenomTrace.IBCDenom())
require.NoError(t, err)
require.Equal(t, amountUnits, cosmosUserUnitBal)
/*polkadotUserIbcCoins, err = composable.GetIbcBalance(ctx, string(polkadotUser.Address()))
/*polkadotUserIbcCoins, err = polkadotChain.GetIbcBalance(ctx, string(polkadotUser.Address()))
fmt.Println("UserIbcCoins: ", polkadotUserIbcCoins.String())
aliceIbcCoins, err = composable.GetIbcBalance(ctx, "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL")
aliceIbcCoins, err = polkadotChain.GetIbcBalance(ctx, "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL")
fmt.Println("AliceIbcCoins: ", aliceIbcCoins.String())*/

fmt.Println("********************************")
fmt.Println("********* Test passed **********")
fmt.Println("********************************")

// err = testutil.WaitForBlocks(ctx, 50, centaurid, composable)
// err = testutil.WaitForBlocks(ctx, 50, centaurid, polkadotChain)
// require.NoError(t, err)
}

Expand Down
12 changes: 12 additions & 0 deletions tests/interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package interchaintest

import (
sdkmath "cosmossdk.io/math"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"os"

"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand Down Expand Up @@ -32,6 +35,7 @@ var (
GasAdjustment: 1.1,
TrustingPeriod: "112h",
NoHostMount: false,
EncodingConfig: composableEncoding(),
ModifyGenesis: nil,
ConfigFileOverrides: nil,
}
Expand All @@ -58,3 +62,11 @@ func GetDockerImageInfo() (repo, version string) {
}
return repo, branchVersion
}

func composableEncoding() *testutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()

// register custom types
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}

0 comments on commit 59a3c7e

Please sign in to comment.