//go:build system_test package systemtests import ( "fmt" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" systest "cosmossdk.io/systemtests" ) func TestUnorderedTXDuplicate(t *testing.T) { // TODO: remove once unordered tx handling is working in v2 t.Skip("The unordered tx handling is not wired in v2") // scenario: test unordered tx duplicate // given a running chain with a tx in the unordered tx pool // when a new tx with the same hash is broadcasted // then the new tx should be rejected systest.Sut.ResetChain(t) cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose) // add genesis account with some tokens account1Addr := cli.AddKey("account1") account2Addr := cli.AddKey("account2") systest.Sut.ModifyGenesisCLI(t, []string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, ) systest.Sut.StartChain(t) timeoutTimestamp := time.Now().Add(time.Minute) // send tokens rsp1 := cli.Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake", fmt.Sprintf("--timeout-timestamp=%v", timeoutTimestamp.Unix()), "--unordered", "--sequence=1", "--note=1") systest.RequireTxSuccess(t, rsp1) assertDuplicateErr := func(xt assert.TestingT, gotErr error, gotOutputs ...interface{}) bool { require.Len(t, gotOutputs, 1) assert.Contains(t, gotOutputs[0], "is duplicated: invalid request") return false // always abort } rsp2 := cli.WithRunErrorMatcher(assertDuplicateErr).Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake", fmt.Sprintf("--timeout-timestamp=%v", timeoutTimestamp.Unix()), "--unordered", "--sequence=1") systest.RequireTxFailure(t, rsp2) require.Eventually(t, func() bool { return cli.QueryBalance(account2Addr, "stake") == 5000 }, 10*systest.Sut.BlockTime(), 200*time.Millisecond, "TX was not executed before timeout") }