Skip to content

Commit

Permalink
e2e: simplify, add encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 17, 2023
1 parent 92d9ad1 commit bdf2e4c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 87 deletions.
26 changes: 15 additions & 11 deletions modules/ibc-hooks/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ module github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/e2e

go 1.20

replace (
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 //indirect
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)


require (
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231011223558-1e83cdf5cd71
cosmossdk.io/math v1.1.2
github.com/CosmWasm/wasmd v0.41.0
github.com/cosmos/cosmos-sdk v0.47.5
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231017162224-ef23cf66f163
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
)

require (
Expand All @@ -19,7 +30,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/log v1.2.1 // indirect
cosmossdk.io/math v1.1.2 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand All @@ -28,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.3.0 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
Expand All @@ -53,7 +64,6 @@ require (
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/cosmos-sdk v0.47.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
Expand Down Expand Up @@ -195,6 +205,7 @@ require (
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/mod v0.12.0 // indirect
Expand Down Expand Up @@ -233,10 +244,3 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 //indirect
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)
8 changes: 6 additions & 2 deletions modules/ibc-hooks/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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.41.0 h1:fmwxSbwb50zZDcBaayYFRLIaSFca+EFld1WOaQi49jg=
github.com/CosmWasm/wasmd v0.41.0/go.mod h1:0Sds1q2IsPaTN1gHa3BNOYcUFgtGvxH7CXEXPgoihns=
github.com/CosmWasm/wasmvm v1.3.0 h1:x12X4bKlUPS7TT9QQP45+fJo2sp30GEbiSSgb9jsec8=
github.com/CosmWasm/wasmvm v1.3.0/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
Expand Down Expand Up @@ -999,8 +1003,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc=
github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231011223558-1e83cdf5cd71 h1:cqMQxjkfD+TDR6AxLjJ0NeQCcwBBSsx+eq1NJgTeknU=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231011223558-1e83cdf5cd71/go.mod h1:8oeA4y0gCxEK8tgp+/oaHC4+iZXaAS2Sx+rd84hWzMQ=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231017162224-ef23cf66f163 h1:FzNWmm3Dv/QCm8jmJlNAIAPIpEbztGnicQiwGiJCg2U=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231017162224-ef23cf66f163/go.mod h1:8oeA4y0gCxEK8tgp+/oaHC4+iZXaAS2Sx+rd84hWzMQ=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
16 changes: 12 additions & 4 deletions modules/ibc-hooks/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (

"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/stretchr/testify/require"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
)

type WasmCoin struct {
Expand Down Expand Up @@ -34,10 +37,15 @@ func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain,
return codeId, contractAddr
}

func WasmEncodingConfig() *moduletestutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}

func GetIBCHooksUserAddress(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, channel, uaddr string) string {
// junod q ibchooks wasm-sender channel-0 "juno1hj5fveer5cjtn4wd6wstzugjfdxzl0xps73ftl" --node http://localhost:26657
cmd := []string{
"junod", "query", "ibchooks", "wasm-sender", channel, uaddr,
chain.Config().Bin, "query", "ibchooks", "wasm-sender", channel, uaddr,
"--node", chain.GetRPCAddress(),
"--chain-id", chain.Config().ChainID,
"--output", "json",
Expand All @@ -53,7 +61,7 @@ func GetIBCHooksUserAddress(t *testing.T, ctx context.Context, chain *cosmos.Cos

// GetIBCHookTotalFunds
type GetTotalFundsQuery struct {
// {"get_total_funds":{"addr":"juno1..."}}
// {"get_total_funds":{"addr":"osmo1..."}}
Addr string `json:"addr"`
}
type GetTotalFundsResponse struct {
Expand All @@ -73,7 +81,7 @@ func GetIBCHookTotalFunds(t *testing.T, ctx context.Context, chain *cosmos.Cosmo

// GetIBCHookCount
type GetCountQuery struct {
// {"get_total_funds":{"addr":"juno1..."}}
// {"get_total_funds":{"addr":"osmo1..."}}
Addr string `json:"addr"`
}
type GetCountResponse struct {
Expand Down
101 changes: 31 additions & 70 deletions modules/ibc-hooks/e2e/ibchooks_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"context"
"fmt"
"strings"
"testing"
Expand All @@ -10,11 +9,8 @@ import (
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
interchaintestrelayer "github.com/strangelove-ventures/interchaintest/v7/relayer"
"github.com/strangelove-ventures/interchaintest/v7/testreporter"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

// TestIBCHooks ensures the ibc-hooks middleware from osmosis works as expected.
Expand Down Expand Up @@ -43,90 +39,64 @@ func TestIBCHooks(t *testing.T) {
UidGid: "1025:1025",
},
},
Bech32Prefix: "cosmos",
Denom: "uosmo",
CoinType: "118",
Bech32Prefix: "cosmos",
Denom: "uosmo",
CoinType: "118",
GasPrices: "0uosmo",
GasAdjustment: 1.5,
TrustingPeriod: "330h",
EncodingConfig: WasmEncodingConfig(),
}

cfg2 := cfg.Clone()
cfg2.Name = "osmosis-counterparty"
cfg2.ChainID = "counterparty-2"

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
chains := interchaintest.CreateChainsWithChainSpecs(t, []*interchaintest.ChainSpec{
{
Name: "osmosis",
ChainName: "osmosis",
ChainConfig: cfg,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
{
Name: "osmosis",
Name: "counterparty",
ChainName: "counterparty",
ChainConfig: cfg2,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})

const (
path = "ibc-path"
)

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

client, network := interchaintest.DockerSetup(t)

osmosis, osmosis2 := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain)

relayerType, relayerName := ibc.CosmosRly, "relay"

// Get a relayer instance
rf := interchaintest.NewBuiltinRelayerFactory(
relayerType,
zaptest.NewLogger(t),
interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "100"),
const path = "ibc-path"
enableBlockDB := false
skipPathCreations := false
ctx, _, r, _, eRep, _, _ := interchaintest.BuildInitialChainWithRelayer(
t,
chains,
enableBlockDB,
ibc.CosmosRly,
[]string{"--processor", "events", "--block-history", "100"},
[]interchaintest.InterchainLink{
{
Chain1: osmosis,
Chain2: osmosis2,
Path: path,
},
},
skipPathCreations,
)

r := rf.Build(t, client, network)

ic := interchaintest.NewInterchain().
AddChain(osmosis).
AddChain(osmosis2).
AddRelayer(r, relayerName).
AddLink(interchaintest.InterchainLink{
Chain1: osmosis,
Chain2: osmosis2,
Relayer: r,
Path: path,
})

ctx := context.Background()

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})
if err := r.StartRelayer(ctx, eRep, path); err != nil {
t.Fatal(err)
}

// Create some user accounts on both chains
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), genesisWalletAmount, osmosis, osmosis2)

err = r.StartRelayer(ctx, eRep, path)
require.NoError(t, err)

// Wait a few blocks for relayer to start and for user accounts to be created
err = testutil.WaitForBlocks(ctx, 5, osmosis, osmosis2)
require.NoError(t, err)

// Get our Bech32 encoded user addresses
osmosisUser, osmosis2User := users[0], users[1]

Expand All @@ -136,15 +106,6 @@ func TestIBCHooks(t *testing.T) {
channel, err := ibc.GetTransferChannel(ctx, r, eRep, osmosis.Config().ChainID, osmosis2.Config().ChainID)
require.NoError(t, err)

t.Cleanup(
func() {
err := r.StopRelayer(ctx, eRep)
if err != nil {
t.Logf("an error occurred while stopping the relayer: %s", err)
}
},
)

_, contractAddr := SetupContract(t, ctx, osmosis2, osmosis2User.KeyName(), "contracts/ibchooks_counter.wasm", `{"count":0}`)

// do an ibc transfer through the memo to the other chain.
Expand Down

0 comments on commit bdf2e4c

Please sign in to comment.