diff --git a/cli/nep11_test.go b/cli/nep11_test.go index 0fd8966cd..6ba752ec3 100644 --- a/cli/nep11_test.go +++ b/cli/nep11_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/stretchr/testify/require" ) @@ -38,4 +40,25 @@ func TestNEP11Import(t *testing.T) { // not a NEP11 token e.RunWithError(t, append(args, "--token", neoContractHash.StringLE())...) + + t.Run("Info", func(t *testing.T) { + checkNNSInfo := func(t *testing.T) { + e.checkNextLine(t, "^Name:\\s*NameService") + e.checkNextLine(t, "^Symbol:\\s*NNS") + e.checkNextLine(t, "^Hash:\\s*"+nnsContractHash.StringLE()) + e.checkNextLine(t, "^Decimals:\\s*0") + e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(nnsContractHash)) + e.checkNextLine(t, "^Standard:\\s*"+string(manifest.NEP11StandardName)) + } + t.Run("WithToken", func(t *testing.T) { + e.Run(t, "neo-go", "wallet", "nep11", "info", + "--wallet", walletPath, "--token", nnsContractHash.StringLE()) + checkNNSInfo(t) + }) + t.Run("NoToken", func(t *testing.T) { + e.Run(t, "neo-go", "wallet", "nep11", "info", + "--wallet", walletPath) + checkNNSInfo(t) + }) + }) } diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index 81258dbcd..7a126edb0 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -14,9 +14,23 @@ func newNEP11Commands() []cli.Command { Action: importNEP11Token, Flags: importFlags, }, + { + Name: "info", + Usage: "print imported NEP11 token info", + UsageText: "print --wallet [--token ]", + Action: printNEP11Info, + Flags: []cli.Flag{ + walletPathFlag, + tokenFlag, + }, + }, } } func importNEP11Token(ctx *cli.Context) error { return importNEPToken(ctx, manifest.NEP11StandardName) } + +func printNEP11Info(ctx *cli.Context) error { + return printNEPInfo(ctx, manifest.NEP11StandardName) +} diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 79bc59795..34deb606a 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -312,6 +312,10 @@ func printTokenInfo(ctx *cli.Context, tok *wallet.Token) { } func printNEP17Info(ctx *cli.Context) error { + return printNEPInfo(ctx, manifest.NEP17StandardName) +} + +func printNEPInfo(ctx *cli.Context, standard string) error { wall, err := openWallet(ctx.String("wallet")) if err != nil { return cli.NewExitError(err, 1) @@ -319,7 +323,7 @@ func printNEP17Info(ctx *cli.Context) error { defer wall.Close() if name := ctx.String("token"); name != "" { - token, err := getMatchingToken(ctx, wall, name, manifest.NEP17StandardName) + token, err := getMatchingToken(ctx, wall, name, standard) if err != nil { return cli.NewExitError(err, 1) } @@ -327,11 +331,15 @@ func printNEP17Info(ctx *cli.Context) error { return nil } - for i, t := range wall.Extra.Tokens { - if i > 0 { + var count int + for _, t := range wall.Extra.Tokens { + if count > 0 { fmt.Fprintln(ctx.App.Writer) } - printTokenInfo(ctx, t) + if t.Standard == standard { + printTokenInfo(ctx, t) + count++ + } } return nil }