diff --git a/cli/executor_test.go b/cli/executor_test.go index 2a753d02b..e4198d437 100644 --- a/cli/executor_test.go +++ b/cli/executor_test.go @@ -127,9 +127,14 @@ func (e *executor) GetTransaction(t *testing.T, h util.Uint256) (*transaction.Tr return tx, height } -func (e *executor) checkNextLine(t *testing.T, expected string) { +func (e *executor) getNextLine(t *testing.T) string { line, err := e.Out.ReadString('\n') require.NoError(t, err) + return line +} + +func (e *executor) checkNextLine(t *testing.T, expected string) { + line := e.getNextLine(t) e.checkLine(t, line, expected) } diff --git a/cli/multisig_test.go b/cli/multisig_test.go index 0d163764d..24e9f9762 100644 --- a/cli/multisig_test.go +++ b/cli/multisig_test.go @@ -74,7 +74,7 @@ func TestSignMultisigTx(t *testing.T) { e.In.WriteString("pass\r") e.Run(t, "neo-go", "wallet", "multisig", "sign", "--unittest", "--rpc-endpoint", "http://"+e.RPC.Addr, - "--wallet", wallet2Path, "--addr", multisigAddr, + "--wallet", wallet2Path, "--address", multisigAddr, "--in", txPath, "--out", txPath) e.checkTxPersisted(t) diff --git a/cli/nep5_test.go b/cli/nep5_test.go index 2f879ecc3..3c07ffceb 100644 --- a/cli/nep5_test.go +++ b/cli/nep5_test.go @@ -6,6 +6,7 @@ import ( "os" "path" "strconv" + "strings" "testing" "github.com/nspcc-dev/neo-go/pkg/encoding/address" @@ -18,16 +19,17 @@ import ( func TestNEP5Balance(t *testing.T) { e := newExecutor(t, true) defer e.Close(t) - cmd := []string{ - "neo-go", "wallet", "nep5", "balance", - "--rpc-endpoint", "http://" + e.RPC.Addr, + cmdbalance := []string{"neo-go", "wallet", "nep5", "balance"} + cmdbase := append(cmdbalance, + "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", validatorWallet, - "--addr", validatorAddr, - } + ) + cmd := append(cmdbase, "--address", validatorAddr) t.Run("NEO", func(t *testing.T) { b, index := e.Chain.GetGoverningTokenBalance(validatorHash) checkResult := func(t *testing.T) { - e.checkNextLine(t, "^\\s*TokenHash:\\s*"+e.Chain.GoverningTokenHash().StringLE()) + e.checkNextLine(t, "^\\s*Account\\s+"+validatorAddr) + e.checkNextLine(t, "^\\s*NEO:\\s+NEO \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)") e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()) e.checkNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10)) e.checkEOF(t) @@ -43,12 +45,57 @@ func TestNEP5Balance(t *testing.T) { }) t.Run("GAS", func(t *testing.T) { e.Run(t, append(cmd, "--token", "gas")...) - e.checkNextLine(t, "^\\s*TokenHash:\\s*"+e.Chain.UtilityTokenHash().StringLE()) + e.checkNextLine(t, "^\\s*Account\\s+"+validatorAddr) + e.checkNextLine(t, "^\\s*GAS:\\s+GAS \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") b := e.Chain.GetUtilityTokenBalance(validatorHash) e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+util.Fixed8(b.Int64()).String()) }) - t.Run("Invalid", func(t *testing.T) { - e.RunWithError(t, append(cmd, "--token", "kek")...) + t.Run("all accounts", func(t *testing.T) { + e.Run(t, cmdbase...) + addr1, err := address.StringToUint160("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc") + require.NoError(t, err) + e.checkNextLine(t, "^Account "+address.Uint160ToString(addr1)) + e.checkNextLine(t, "^\\s*GAS:\\s+GAS \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") + balance := e.Chain.GetUtilityTokenBalance(addr1) + e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+util.Fixed8(balance.Int64()).String()) + e.checkNextLine(t, "^\\s*Updated:") + e.checkNextLine(t, "^\\s*$") + + addr2, err := address.StringToUint160("NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY") + require.NoError(t, err) + e.checkNextLine(t, "^Account "+address.Uint160ToString(addr2)) + e.checkNextLine(t, "^\\s*$") + + addr3, err := address.StringToUint160("NVNvVRW5Q5naSx2k2iZm7xRgtRNGuZppAK") + require.NoError(t, err) + e.checkNextLine(t, "^Account "+address.Uint160ToString(addr3)) + // The order of assets is undefined. + for i := 0; i < 2; i++ { + line := e.getNextLine(t) + if strings.Contains(line, "GAS") { + e.checkLine(t, line, "^\\s*GAS:\\s+GAS \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") + balance = e.Chain.GetUtilityTokenBalance(addr3) + e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+util.Fixed8(balance.Int64()).String()) + e.checkNextLine(t, "^\\s*Updated:") + } else { + balance, index := e.Chain.GetGoverningTokenBalance(validatorHash) + e.checkLine(t, line, "^\\s*NEO:\\s+NEO \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)") + e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+balance.String()) + e.checkNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10)) + } + } + e.checkEOF(t) + }) + t.Run("Bad token", func(t *testing.T) { + e.Run(t, append(cmd, "--token", "kek")...) + e.checkNextLine(t, "^\\s*Account\\s+"+validatorAddr) + e.checkEOF(t) + }) + t.Run("Bad wallet", func(t *testing.T) { + e.RunWithError(t, append(cmdbalance, "--wallet", "/dev/null")...) + }) + t.Run("Bad address", func(t *testing.T) { + e.RunWithError(t, append(cmdbalance, "--rpc-endpoint", "http://"+e.RPC.Addr, "--wallet", validatorWallet, "--address", "xxx")...) }) return } diff --git a/cli/wallet/multisig.go b/cli/wallet/multisig.go index 58cf2012c..41d5b72e2 100644 --- a/cli/wallet/multisig.go +++ b/cli/wallet/multisig.go @@ -18,7 +18,7 @@ func newMultisigCommands() []cli.Command { outFlag, inFlag, cli.StringFlag{ - Name: "addr", + Name: "address, a", Usage: "Address to use", }, } @@ -27,7 +27,7 @@ func newMultisigCommands() []cli.Command { { Name: "sign", Usage: "sign a transaction", - UsageText: "multisig sign --wallet --addr --in --out ", + UsageText: "multisig sign --wallet --address
--in --out ", Action: signMultisig, Flags: signFlags, }, @@ -45,7 +45,7 @@ func signMultisig(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - addr := ctx.String("addr") + addr := ctx.String("address") sh, err := address.StringToUint160(addr) if err != nil { return cli.NewExitError(fmt.Errorf("invalid address: %w", err), 1) diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index 5ca1e293f..3a61994f3 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -28,7 +28,7 @@ var ( var ( tokenFlag = cli.StringFlag{ Name: "token", - Usage: "Token to use", + Usage: "Token to use (hash or name (for NEO/GAS or imported tokens))", } gasFlag = flags.Fixed8Flag{ Name: "gas", @@ -41,7 +41,7 @@ func newNEP5Commands() []cli.Command { walletPathFlag, tokenFlag, cli.StringFlag{ - Name: "addr", + Name: "address, a", Usage: "Address to use", }, } @@ -78,7 +78,7 @@ func newNEP5Commands() []cli.Command { { Name: "balance", Usage: "get address balance", - UsageText: "balance --wallet --rpc-endpoint --timeout