Skip to content

Commit

Permalink
chore: add instructions and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Jan 6, 2024
1 parent 2da8cc1 commit 005b7f5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
65 changes: 44 additions & 21 deletions interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {

t.Parallel()

// Create chain factory with Seda and Gaia
/* =================================================== */
/* CHAIN FACTORY */
/* =================================================== */
numVals := 1
numFullNodes := 1

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "seda",
ChainConfig: SedaCfg,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
NumValidators: &numVals, // defaults to 2 when unspecified
NumFullNodes: &numFullNodes, // defaults to 1 when unspecified
},
// pre configured chain pulled from
// https://github.com/strangelove-ventures/heighliner
{
Name: "gaia",
Version: "v14.1.0",
Expand All @@ -45,19 +49,16 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
},
})

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)

seda, gaia := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain)

/* =================================================== */
/* RELAYER FACTORY */
/* =================================================== */
relayerType, relayerName := ibc.CosmosRly, "relay"
client, network := interchaintest.DockerSetup(t)

// Get a relayer instance
rf := interchaintest.NewBuiltinRelayerFactory(
Expand All @@ -66,9 +67,15 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
interchaintestrelayer.CustomDockerImage(RelayerImage, RelayerVersion, "100:1000"),
interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "100"),
)

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

/* =================================================== */
/* INTERCHAIN SPAWN */
/* =================================================== */
const (
ibcPath = "ibc-path"
)

ic := interchaintest.NewInterchain().
AddChain(seda).
AddChain(gaia).
Expand All @@ -77,14 +84,21 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
Chain1: seda,
Chain2: gaia,
Relayer: r,
Path: path,
Path: ibcPath,
})

ctx := context.Background()

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

/*
* Stake Distribution on Genesis
* - 2,000,000,000,000 for each validator
* - 1,000,000,000,000 for each full node
* - 10,000,000,000 for each faucet on each chain
* - 1,000,000,000 for relayer
*/
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
Expand All @@ -96,19 +110,20 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
_ = ic.Close()
})

/* =================================================== */
/* WALLETS & USERS */
/* =================================================== */

// Create some user accounts on both chains
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), GenesisWalletAmount, seda, gaia)
sedaUser, gaiaUser := users[0], users[1]
sedaUserAddr := sedaUser.FormattedAddress()
gaiaUserAddr := gaiaUser.FormattedAddress()

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

// Get our Bech32 encoded user addresses
sedaUser, gaiaUser := users[0], users[1]

sedaUserAddr := sedaUser.FormattedAddress()
gaiaUserAddr := gaiaUser.FormattedAddress()

// Get original account balances
sedaOrigBal, err := seda.GetBalance(ctx, sedaUserAddr, seda.Config().Denom)
require.NoError(t, err)
Expand All @@ -118,8 +133,12 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
require.NoError(t, err)
require.Equal(t, GenesisWalletAmount, gaiaOrigBal.Int64())

// Compose an IBC transfer and send from Seda -> Gaia
/* =================================================== */
/* INTERCHAIN TEST */
/* =================================================== */
var transferAmount = math.NewInt(1_000)

// Compose an IBC transfer and send from Seda -> Gaia
transfer := ibc.WalletAmount{
Address: gaiaUserAddr,
Denom: seda.Config().Denom,
Expand All @@ -135,7 +154,11 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
transferTx, err := seda.SendIBCTransfer(ctx, channel.ChannelID, sedaUserAddr, transfer, ibc.TransferOptions{})
require.NoError(t, err)

err = r.StartRelayer(ctx, eRep, path)
/*
* Starts the relayer on a loop to avoid having to
* manually flush packets and ack's
*/
err = r.StartRelayer(ctx, eRep, ibcPath)
require.NoError(t, err)

t.Cleanup(
Expand All @@ -154,7 +177,7 @@ func TestSedaGaiaIBCTransfer(t *testing.T) {
err = testutil.WaitForBlocks(ctx, 10, seda)
require.NoError(t, err)

// Get the IBC denom for useda on Gaia
// Get the IBC denom for aseda on Gaia
sedaTokenDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, seda.Config().Denom)
sedaIBCDenom := transfertypes.ParseDenomTrace(sedaTokenDenom).IBCDenom()

Expand Down
4 changes: 2 additions & 2 deletions interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var (

// TO-DO
dockerImage = ibc.DockerImage{
Repository: "",
Version: "",
Repository: "", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "", // FOR LOCAL IMAGE USE: Docker Image Tag
UidGid: "",
}

Expand Down

0 comments on commit 005b7f5

Please sign in to comment.