rpc: check token standard in nepTokenInfo

This commit is contained in:
Anna Shaleva 2021-04-23 17:47:43 +03:00
parent 40ae78cb88
commit c3264c065d
2 changed files with 14 additions and 2 deletions

View file

@ -280,7 +280,7 @@ func TestNEP17ImportToken(t *testing.T) {
e.checkNextLine(t, "^Hash:\\s*"+gasContractHash.StringLE())
e.checkNextLine(t, "^Decimals:\\s*8")
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(gasContractHash))
e.checkNextLine(t, "^Standard:\\s*"+manifest.NEP17StandardName)
e.checkNextLine(t, "^Standard:\\s*"+string(manifest.NEP17StandardName))
}
t.Run("WithToken", func(t *testing.T) {
e.Run(t, "neo-go", "wallet", "nep17", "info",
@ -298,7 +298,7 @@ func TestNEP17ImportToken(t *testing.T) {
e.checkNextLine(t, "^Hash:\\s*"+neoContractHash.StringLE())
e.checkNextLine(t, "^Decimals:\\s*0")
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(neoContractHash))
e.checkNextLine(t, "^Standard:\\s*"+manifest.NEP17StandardName)
e.checkNextLine(t, "^Standard:\\s*"+string(manifest.NEP17StandardName))
})
t.Run("Remove", func(t *testing.T) {
e.In.WriteString("y\r")

View file

@ -1,6 +1,8 @@
package client
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet"
@ -78,6 +80,16 @@ func (c *Client) nepTokenInfo(tokenHash util.Uint160, standard string) (*wallet.
if err != nil {
return nil, err
}
var isStandardOK bool
for _, st := range cs.Manifest.SupportedStandards {
if st == standard {
isStandardOK = true
break
}
}
if !isStandardOK {
return nil, fmt.Errorf("token %s does not support %s standard", tokenHash.StringLE(), standard)
}
symbol, err := c.nepSymbol(tokenHash)
if err != nil {
return nil, err