-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add cosmos message poller (#325)
- Loading branch information
Showing
6 changed files
with
163 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package cosmos_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" | ||
"github.com/strangelove-ventures/ibctest/v6" | ||
"github.com/strangelove-ventures/ibctest/v6/chain/cosmos" | ||
"github.com/strangelove-ventures/ibctest/v6/ibc" | ||
"github.com/strangelove-ventures/ibctest/v6/testreporter" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
func TestUpdateLightClients(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
|
||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
// Chains | ||
cf := ibctest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*ibctest.ChainSpec{ | ||
{Name: "gaia", Version: gaiaVersion}, | ||
{Name: "osmosis", Version: osmosisVersion}, | ||
}) | ||
|
||
chains, err := cf.Chains(t.Name()) | ||
require.NoError(t, err) | ||
gaia, osmosis := chains[0], chains[1] | ||
|
||
// Relayer | ||
client, network := ibctest.DockerSetup(t) | ||
r := ibctest.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t)).Build( | ||
t, client, network) | ||
|
||
ic := ibctest.NewInterchain(). | ||
AddChain(gaia). | ||
AddChain(osmosis). | ||
AddRelayer(r, "relayer"). | ||
AddLink(ibctest.InterchainLink{ | ||
Chain1: gaia, | ||
Chain2: osmosis, | ||
Relayer: r, | ||
Path: "client-test-path", | ||
}) | ||
|
||
// Build interchain | ||
rep := testreporter.NewNopReporter() | ||
eRep := rep.RelayerExecReporter(t) | ||
require.NoError(t, ic.Build(ctx, eRep, ibctest.InterchainBuildOptions{ | ||
TestName: t.Name(), | ||
Client: client, | ||
NetworkID: network, | ||
})) | ||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
|
||
require.NoError(t, r.StartRelayer(ctx, eRep)) | ||
t.Cleanup(func() { | ||
_ = r.StopRelayer(ctx, eRep) | ||
}) | ||
|
||
// Create and Fund User Wallets | ||
fundAmount := int64(10_000_000) | ||
users := ibctest.GetAndFundTestUsers(t, ctx, "default", fundAmount, gaia, osmosis) | ||
gaiaUser, osmoUser := users[0], users[1] | ||
|
||
// Get Channel ID | ||
gaiaChannelInfo, err := r.GetChannels(ctx, eRep, gaia.Config().ChainID) | ||
require.NoError(t, err) | ||
chanID := gaiaChannelInfo[0].ChannelID | ||
|
||
height, err := osmosis.Height(ctx) | ||
require.NoError(t, err) | ||
|
||
amountToSend := int64(553255) // Unique amount to make log searching easier. | ||
dstAddress := osmoUser.Bech32Address(osmosis.Config().Bech32Prefix) | ||
tx, err := gaia.SendIBCTransfer(ctx, chanID, gaiaUser.KeyName, ibc.WalletAmount{ | ||
Address: dstAddress, | ||
Denom: gaia.Config().Denom, | ||
Amount: amountToSend, | ||
}, | ||
nil, | ||
) | ||
require.NoError(t, err) | ||
require.NoError(t, tx.Validate()) | ||
|
||
chain := osmosis.(*cosmos.CosmosChain) | ||
reg := chain.Config().EncodingConfig.InterfaceRegistry | ||
msg, err := cosmos.PollForMessage[*clienttypes.MsgUpdateClient](ctx, chain, reg, height, height+10, nil) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "07-tendermint-0", msg.ClientId) | ||
require.NotEmpty(t, msg.Signer) | ||
// TODO: Assert header information | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package cosmos_test | ||
|
||
const ( | ||
gaiaVersion = "v7.1.0" | ||
osmosisVersion = "v12.2.0" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters