forked from TrueCloudLab/neoneo-go
Merge pull request #1323 from nspcc-dev/fix/clienttests
rpc: fix (*Client).BalanceOf
This commit is contained in:
commit
70cc8b89e8
2 changed files with 64 additions and 2 deletions
|
@ -78,8 +78,11 @@ func (c *Client) NEP5TotalSupply(tokenHash util.Uint160) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEP5BalanceOf invokes `balanceOf` NEP5 method on a specified contract.
|
// NEP5BalanceOf invokes `balanceOf` NEP5 method on a specified contract.
|
||||||
func (c *Client) NEP5BalanceOf(tokenHash util.Uint160) (int64, error) {
|
func (c *Client) NEP5BalanceOf(tokenHash, acc util.Uint160) (int64, error) {
|
||||||
result, err := c.InvokeFunction(tokenHash, "balanceOf", []smartcontract.Parameter{}, nil)
|
result, err := c.InvokeFunction(tokenHash, "balanceOf", []smartcontract.Parameter{{
|
||||||
|
Type: smartcontract.Hash160Type,
|
||||||
|
Value: acc,
|
||||||
|
}}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
} else if result.State != "HALT" || len(result.Stack) == 0 {
|
} else if result.State != "HALT" || len(result.Stack) == 0 {
|
||||||
|
|
59
pkg/rpc/server/client_test.go
Normal file
59
pkg/rpc/server/client_test.go
Normal file
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue