From 7cfcf072b832ff4c848c0a107efc82f38ebfdf83 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 29 Aug 2022 18:43:25 +0300 Subject: [PATCH] cli/wallet: make NEP-17 token selection logic a bit more robust 1. In the single token mode compare known hashes instead of names, names can be misleading. 2. Hardcode NEO/GAS, they are special (if not overrided by the wallet data). --- cli/nep17_test.go | 1 + cli/wallet/nep17.go | 115 +++++++++++++++++++++++++------------------- docs/cli.md | 7 +-- 3 files changed, 70 insertions(+), 53 deletions(-) diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 2d00dfbfb..b318616d1 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -106,6 +106,7 @@ func TestNEP17Balance(t *testing.T) { t.Run("Bad token", func(t *testing.T) { e.Run(t, append(cmd, "--token", "kek")...) e.checkNextLine(t, "^\\s*Account\\s+"+validatorAddr) + e.checkNextLine(t, `^\s*Can't find data for "kek" token\s*`) e.checkEOF(t) }) t.Run("Bad wallet", func(t *testing.T) { diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 3ef164bbe..891bd0adc 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/cli/options" "github.com/nspcc-dev/neo-go/cli/paramcontext" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" @@ -20,7 +21,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/rpcclient/gas" - "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" "github.com/nspcc-dev/neo-go/pkg/rpcclient/neo" "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" @@ -100,8 +100,21 @@ func newNEP17Commands() []cli.Command { Name: "balance", Usage: "get address balance", UsageText: "balance -w wallet [--wallet-config path] --rpc-endpoint [--timeout