rpc: add NEP11 API support to the RPC client
This commit is contained in:
parent
2bb3ff2aff
commit
f955589370
5 changed files with 317 additions and 44 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -476,3 +477,58 @@ func TestClient_GetNativeContracts(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, chain.GetNatives(), cs)
|
||||
}
|
||||
|
||||
func TestClient_NEP11(t *testing.T) {
|
||||
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
|
||||
defer chain.Close()
|
||||
defer rpcSrv.Shutdown()
|
||||
|
||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.Init())
|
||||
|
||||
h, err := chain.GetNativeContractScriptHash(nativenames.NameService)
|
||||
require.NoError(t, err)
|
||||
acc := testchain.PrivateKeyByID(0).GetScriptHash()
|
||||
|
||||
t.Run("Decimals", func(t *testing.T) {
|
||||
d, err := c.NEP11Decimals(h)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 0, d) // non-divisible
|
||||
})
|
||||
t.Run("TotalSupply", func(t *testing.T) {
|
||||
s, err := c.NEP11TotalSupply(h)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 1, s) // the only `neo.com` of acc0
|
||||
})
|
||||
t.Run("Symbol", func(t *testing.T) {
|
||||
sym, err := c.NEP11Symbol(h)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "NNS", sym)
|
||||
})
|
||||
t.Run("BalanceOf", func(t *testing.T) {
|
||||
b, err := c.NEP11BalanceOf(h, acc)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 1, b)
|
||||
})
|
||||
t.Run("OwnerOf", func(t *testing.T) {
|
||||
b, err := c.NEP11NDOwnerOf(h, "neo.com")
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, acc, b)
|
||||
})
|
||||
t.Run("Properties", func(t *testing.T) {
|
||||
p, err := c.NEP11Properties(h, "neo.com")
|
||||
require.NoError(t, err)
|
||||
blockRegisterDomain, err := chain.GetBlock(chain.GetHeaderHash(13)) // `neo.com` domain was registered in 13th block
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(blockRegisterDomain.Transactions))
|
||||
expected := stackitem.NewMap()
|
||||
expected.Add(stackitem.Make([]byte("name")), stackitem.Make([]byte("neo.com")))
|
||||
expected.Add(stackitem.Make([]byte("expiration")), stackitem.Make(blockRegisterDomain.Timestamp/1000+365*24*3600)) // expiration formula
|
||||
require.EqualValues(t, expected, p)
|
||||
})
|
||||
t.Run("Transfer", func(t *testing.T) {
|
||||
_, err := c.TransferNEP11(wallet.NewAccountFromPrivateKey(testchain.PrivateKeyByID(0)), testchain.PrivateKeyByID(1).GetScriptHash(), h, "neo.com", 0)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue