-
Notifications
You must be signed in to change notification settings - Fork 4.1k
refactor(client): change flag for unordered tx timeouts #24561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
bce1646
d2dbae4
e271719
f80ebf1
f347e93
133477d
8840e39
8815abf
7fea034
ec75e3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||||||||||||||||
| "testing" | ||||||||||||||||||||
| "time" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/testutil" | ||||||||||||||||||||
|
Check failure on line 10 in tests/systemtests/unordered_tx_test.go
|
||||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||||
| "github.com/tidwall/gjson" | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -17,8 +17,8 @@ | |||||||||||||||||||
| func TestUnorderedTXDuplicate(t *testing.T) { | ||||||||||||||||||||
| // 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 | ||||||||||||||||||||
| // when a new tx with the same unordered nonce is broadcasted, | ||||||||||||||||||||
| // then the new tx should be rejected. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| systest.Sut.ResetChain(t) | ||||||||||||||||||||
| cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose) | ||||||||||||||||||||
|
|
@@ -31,22 +31,28 @@ | |||||||||||||||||||
|
|
||||||||||||||||||||
| systest.Sut.StartChain(t) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| timeoutTimestamp := time.Now().Add(time.Minute) | ||||||||||||||||||||
| // send tokens | ||||||||||||||||||||
| cmd := []string{"tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from=" + account1Addr, "--fees=1stake", fmt.Sprintf("--timeout-timestamp=%v", timeoutTimestamp.Unix()), "--unordered", "--sequence=1", "--note=1"} | ||||||||||||||||||||
| rsp1 := cli.Run(cmd...) | ||||||||||||||||||||
| cmd := []string{"tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from=" + account1Addr, "--fees=1stake", "--timeout-duration=5m", "--unordered", "--note=1", "--chain-id=testing", "--generate-only"} | ||||||||||||||||||||
| rsp1 := cli.RunCommandWithArgs(cmd...) | ||||||||||||||||||||
| txFile := testutil.TempFile(t) | ||||||||||||||||||||
| _, err := txFile.WriteString(rsp1) | ||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| signCmd := []string{"tx", "sign", txFile.Name(), "--from=" + account1Addr, "--chain-id=testing"} | ||||||||||||||||||||
| rsp1 = cli.RunCommandWithArgs(signCmd...) | ||||||||||||||||||||
| signedFile := testutil.TempFile(t) | ||||||||||||||||||||
| signedFile.WriteString(rsp1) | ||||||||||||||||||||
|
Check failure on line 44 in tests/systemtests/unordered_tx_test.go
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Properly implemented transaction signing step The explicit signing step is correctly implemented using the transaction file and chain ID. Note that line 44 is missing error handling for the file write operation. Add error handling for the file write operation: -signedFile.WriteString(rsp1)
+_, err = signedFile.WriteString(rsp1)
+require.NoError(t, err)📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
| cmd = []string{"tx", "broadcast", signedFile.Name(), "--chain-id=testing"} | ||||||||||||||||||||
| rsp1 = cli.RunCommandWithArgs(cmd...) | ||||||||||||||||||||
| systest.RequireTxSuccess(t, rsp1) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| assertDuplicateErr := func(xt assert.TestingT, gotErr error, gotOutputs ...interface{}) bool { | ||||||||||||||||||||
| require.Len(t, gotOutputs, 1) | ||||||||||||||||||||
| output := gotOutputs[0].(string) | ||||||||||||||||||||
| code := gjson.Get(output, "code") | ||||||||||||||||||||
| require.True(t, code.Exists()) | ||||||||||||||||||||
| require.Equal(t, int64(19), code.Int()) // 19 == already in mempool. | ||||||||||||||||||||
| return false // always abort | ||||||||||||||||||||
| } | ||||||||||||||||||||
| rsp2 := cli.WithRunErrorMatcher(assertDuplicateErr).Run(cmd...) | ||||||||||||||||||||
| cmd = []string{"tx", "broadcast", signedFile.Name(), "--chain-id=testing"} | ||||||||||||||||||||
| rsp2, _ := cli.RunOnly(cmd...) | ||||||||||||||||||||
| systest.RequireTxFailure(t, rsp2) | ||||||||||||||||||||
| code := gjson.Get(rsp2, "code") | ||||||||||||||||||||
| require.True(t, code.Exists()) | ||||||||||||||||||||
| require.Equal(t, int64(19), code.Int()) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| require.Eventually(t, func() bool { | ||||||||||||||||||||
| return cli.QueryBalance(account2Addr, "stake") == 5000 | ||||||||||||||||||||
|
|
@@ -86,7 +92,7 @@ | |||||||||||||||||||
| code := gjson.Get(response, "code").Int() | ||||||||||||||||||||
| require.Equal(t, int64(0), code) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| bankSendCmdArgs = []string{"tx", "bank", "send", senderAddr, valAddr, fmt.Sprintf("%d%s", transferAmount, denom), "--chain-id=" + v50CLI.ChainID(), "--fees=10stake", "--sign-mode=direct", "--unordered", "--timeout-timestamp=10000"} | ||||||||||||||||||||
| bankSendCmdArgs = []string{"tx", "bank", "send", senderAddr, valAddr, fmt.Sprintf("%d%s", transferAmount, denom), "--chain-id=" + v50CLI.ChainID(), "--fees=10stake", "--sign-mode=direct", "--unordered", "--timeout-duration=8m"} | ||||||||||||||||||||
| res, ok = v53CLI.RunOnly(bankSendCmdArgs...) | ||||||||||||||||||||
| require.True(t, ok) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
Check warning
Code scanning / CodeQL
Calling the system time Warning