diff --git a/pkg/rpc/client/nep5.go b/pkg/rpc/client/nep5.go index 1c8bd1cca..bc11fa3ac 100644 --- a/pkg/rpc/client/nep5.go +++ b/pkg/rpc/client/nep5.go @@ -78,8 +78,11 @@ func (c *Client) NEP5TotalSupply(tokenHash util.Uint160) (int64, error) { } // NEP5BalanceOf invokes `balanceOf` NEP5 method on a specified contract. -func (c *Client) NEP5BalanceOf(tokenHash util.Uint160) (int64, error) { - result, err := c.InvokeFunction(tokenHash, "balanceOf", []smartcontract.Parameter{}, nil) +func (c *Client) NEP5BalanceOf(tokenHash, acc util.Uint160) (int64, error) { + result, err := c.InvokeFunction(tokenHash, "balanceOf", []smartcontract.Parameter{{ + Type: smartcontract.Hash160Type, + Value: acc, + }}, nil) if err != nil { return 0, err } else if result.State != "HALT" || len(result.Stack) == 0 { diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go new file mode 100644 index 000000000..ca4b9750e --- /dev/null +++ b/pkg/rpc/server/client_test.go @@ -0,0 +1,59 @@ +package server + +import ( + "context" + "testing" + + "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/internal/testchain" + "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/stretchr/testify/require" +) + +func TestClient_NEP5(t *testing.T) { + chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t) + defer chain.Close() + defer rpcSrv.Shutdown() + + c, err := client.New(context.Background(), httpSrv.URL, client.Options{Network: netmode.UnitTestNet}) + require.NoError(t, err) + + h, err := util.Uint160DecodeStringLE(testContractHash) + require.NoError(t, err) + + t.Run("Decimals", func(t *testing.T) { + d, err := c.NEP5Decimals(h) + require.NoError(t, err) + require.EqualValues(t, 2, d) + }) + t.Run("TotalSupply", func(t *testing.T) { + s, err := c.NEP5TotalSupply(h) + require.NoError(t, err) + require.EqualValues(t, 1_000_000, s) + }) + t.Run("Name", func(t *testing.T) { + name, err := c.NEP5Name(h) + require.NoError(t, err) + require.Equal(t, "Rubl", name) + }) + t.Run("Symbol", func(t *testing.T) { + sym, err := c.NEP5Symbol(h) + require.NoError(t, err) + require.Equal(t, "RUB", sym) + }) + t.Run("TokenInfo", func(t *testing.T) { + tok, err := c.NEP5TokenInfo(h) + require.NoError(t, err) + require.Equal(t, h, tok.Hash) + require.Equal(t, "Rubl", tok.Name) + require.Equal(t, "RUB", tok.Symbol) + require.EqualValues(t, 2, tok.Decimals) + }) + t.Run("BalanceOf", func(t *testing.T) { + acc := testchain.PrivateKeyByID(0).GetScriptHash() + b, err := c.NEP5BalanceOf(h, acc) + require.NoError(t, err) + require.EqualValues(t, 877, b) + }) +}