Skip to content
1 change: 1 addition & 0 deletions .github/workflows/e2e-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
matrix:
# names of `make` commands to run tests
test:
- "ictest-txs-auth"
- "ictest-upgrade"
- "ictest-ibc"
- "ictest-ibchooks"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ ictest-liquidstake: rm-testcache
ictest-liquidstake-all: rm-testcache
cd interchaintest && go test -race -v -run "(TestLiquidStakeStkXPRT|TestLiquidStakeUnstakeStkXPRT|TestPauseLiquidStakeStkXPRT)" .

# Executes different tx types
ictest-txs-auth: rm-testcache
cd interchaintest && go test -race -v -run "(TestTxAuthSignModesAndOrdering)" .

rm-testcache:
go clean -testcache

Expand Down
101 changes: 101 additions & 0 deletions interchaintest/txs_auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package interchaintest

import (
"context"
"fmt"
"testing"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/interchaintest/v10"
"github.com/cosmos/interchaintest/v10/ibc"
"github.com/cosmos/interchaintest/v10/testutil"
"github.com/stretchr/testify/require"

"github.com/persistenceOne/persistenceCore/v17/interchaintest/helpers"
)

// TestTxAuthSignModesAndOrdering executes 6 independent bank sends to cover:
// - ordered (default delivery): direct, amino-json, textual
// - unordered (with timeout): direct, amino-json, textual
// Each tx uses a distinct from_user, so no sleeps are required and execution is fast.
func TestTxAuthSignModesAndOrdering(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Parallel()

ctx, cancelFn := context.WithCancel(context.Background())
t.Cleanup(func() {
cancelFn()
})

// Single chain with 1 validator is sufficient
validators := 1
ic, chain := CreateChain(t, ctx, validators, 0)
require.NotNil(t, ic)
require.NotNil(t, chain)

t.Cleanup(func() {
_ = ic.Close()
})
// ensure chain has produced at least one block before first tx
require.NoError(t, testutil.WaitForBlocks(ctx, 1, chain))

chainNode := chain.Nodes()[0]
denom := chain.Config().Denom

// Create 6 independent senders and 1 common recipient
fromFunds := math.NewInt(1_000_000) // enough for amount + fees
var senders []ibc.Wallet
for i := 1; i <= 6; i++ {
name := fmt.Sprintf("%s-from-%d", t.Name(), i)
u := interchaintest.GetAndFundTestUsers(t, ctx, name, fromFunds, chain)[0]
senders = append(senders, u)
}

toFunds := math.NewInt(1_000_000)
toUser := interchaintest.GetAndFundTestUsers(t, ctx, fmt.Sprintf("%s-to", t.Name()), toFunds, chain)[0]

amount := sdk.NewCoin(denom, math.NewInt(100_000))

doSend := func(sender ibc.Wallet, signMode string, unordered bool) {
cmd := []string{
"bank", "send",
sender.FormattedAddress(),
toUser.FormattedAddress(),
amount.String(),
"--gas=auto",
fmt.Sprintf("--sign-mode=%s", signMode),
fmt.Sprintf("--node=http://%s:26657", chainNode.HostName()),
}
if unordered {
cmd = append(cmd, "--unordered", "--timeout-duration=20s")
}

txHash, err := chainNode.ExecTx(ctx, sender.KeyName(), cmd...)
require.NoError(t, err)
require.NotEmpty(t, txHash)
_, err = helpers.QueryTx(ctx, chainNode, txHash)
require.NoError(t, err)
}

beforeTo, err := chain.GetBalance(ctx, toUser.FormattedAddress(), denom)
require.NoError(t, err)

doSend(senders[0], "direct", false)
doSend(senders[1], "direct", true)

doSend(senders[2], "amino-json", false)
doSend(senders[3], "amino-json", true)

doSend(senders[4], "textual", false)
doSend(senders[5], "textual", true)

afterTo, err := chain.GetBalance(ctx, toUser.FormattedAddress(), denom)
require.NoError(t, err)
require.Equal(t, beforeTo.Add(amount.Amount.MulRaw(6)), afterTo, "recipient should receive 6 transfers")

require.NoError(t, testutil.WaitForBlocks(ctx, 2, chain))
}
Loading