-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --broadcasd-mode flag to node tx command
The default value is still block but the flag can change to sync in order to avoid timeout when the tx is broadcasted to busy nodes. Also add a `node query tx` so the user can check when his tx is included in a block.
- Loading branch information
Showing
7 changed files
with
192 additions
and
31 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
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,41 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
|
||
sdkclient "github.com/cosmos/cosmos-sdk/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewNodeQueryTx() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "tx [hash]", | ||
Short: "Query for transaction by hash", | ||
RunE: nodeQueryTxHandler, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
return c | ||
} | ||
|
||
func nodeQueryTxHandler(cmd *cobra.Command, args []string) error { | ||
bz, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
rpc, err := sdkclient.NewClientFromNode(getRPC(cmd)) | ||
if err != nil { | ||
return err | ||
} | ||
resp, err := rpc.Tx(cmd.Context(), bz, false) | ||
if err != nil { | ||
return err | ||
} | ||
bz, err = json.MarshalIndent(resp, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(bz)) | ||
return nil | ||
} |
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
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,97 @@ | ||
package node_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ignite/cli/ignite/pkg/cmdrunner/step" | ||
"github.com/ignite/cli/ignite/pkg/cosmosclient" | ||
"github.com/ignite/cli/ignite/pkg/randstr" | ||
"github.com/ignite/cli/ignite/pkg/xurl" | ||
envtest "github.com/ignite/cli/integration" | ||
) | ||
|
||
func TestNodeQueryTx(t *testing.T) { | ||
var ( | ||
appname = randstr.Runes(10) | ||
// alice = "alice" | ||
// bob = "bob" | ||
|
||
env = envtest.New(t) | ||
app = env.Scaffold(appname) | ||
home = env.AppHome(appname) | ||
servers = app.RandomizeServerPorts() | ||
|
||
// accKeyringDir = t.TempDir() | ||
) | ||
|
||
node, err := xurl.HTTP(servers.RPC) | ||
require.NoError(t, err) | ||
|
||
var ( | ||
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout) | ||
isBackendAliveErr error | ||
) | ||
|
||
go func() { | ||
defer cancel() | ||
|
||
if isBackendAliveErr = env.IsAppServed(ctx, servers); isBackendAliveErr != nil { | ||
return | ||
} | ||
client, err := cosmosclient.New(context.Background(), | ||
cosmosclient.WithAddressPrefix(testPrefix), | ||
cosmosclient.WithNodeAddress(node), | ||
) | ||
require.NoError(t, err) | ||
require.NoError(t, client.WaitForNextBlock()) | ||
|
||
b := &bytes.Buffer{} | ||
env.Exec("send 100token from alice to bob", | ||
step.NewSteps(step.New( | ||
step.Exec( | ||
envtest.IgniteApp, | ||
"node", | ||
"tx", | ||
"bank", | ||
"send", | ||
"alice", | ||
"bob", | ||
"100token", | ||
"--node", node, | ||
"--keyring-dir", home, | ||
"--broadcast-mode", "sync", | ||
), | ||
step.Stdout(b), | ||
)), | ||
) | ||
require.False(t, env.HasFailed(), b.String()) | ||
|
||
// Parse tx hash from output | ||
res := regexp.MustCompile(`\(hash = (\w+)\)`).FindAllStringSubmatch(b.String(), -1) | ||
require.Len(t, res[0], 2, "can't extract hash from command output") | ||
hash := res[0][1] | ||
require.NoError(t, client.WaitForNextBlock()) | ||
|
||
env.Must(env.Exec("query tx", | ||
step.NewSteps(step.New( | ||
step.Exec( | ||
envtest.IgniteApp, | ||
"node", | ||
"query", | ||
"tx", | ||
hash, | ||
"--node", node, | ||
), | ||
)), | ||
)) | ||
}() | ||
|
||
env.Must(app.Serve("should serve with Stargate version", envtest.ExecCtx(ctx))) | ||
|
||
require.NoError(t, isBackendAliveErr, "app cannot get online in time") | ||
} |