*: replace all NEP5 occurences to NEP17
This commit is contained in:
parent
b97dfae8d8
commit
31eca342eb
33 changed files with 335 additions and 335 deletions
|
@ -19,7 +19,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClient_NEP5(t *testing.T) {
|
||||
func TestClient_NEP17(t *testing.T) {
|
||||
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
|
||||
defer chain.Close()
|
||||
defer rpcSrv.Shutdown()
|
||||
|
@ -32,22 +32,22 @@ func TestClient_NEP5(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
t.Run("Decimals", func(t *testing.T) {
|
||||
d, err := c.NEP5Decimals(h)
|
||||
d, err := c.NEP17Decimals(h)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, d)
|
||||
})
|
||||
t.Run("TotalSupply", func(t *testing.T) {
|
||||
s, err := c.NEP5TotalSupply(h)
|
||||
s, err := c.NEP17TotalSupply(h)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 1_000_000, s)
|
||||
})
|
||||
t.Run("Symbol", func(t *testing.T) {
|
||||
sym, err := c.NEP5Symbol(h)
|
||||
sym, err := c.NEP17Symbol(h)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "RUB", sym)
|
||||
})
|
||||
t.Run("TokenInfo", func(t *testing.T) {
|
||||
tok, err := c.NEP5TokenInfo(h)
|
||||
tok, err := c.NEP17TokenInfo(h)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, h, tok.Hash)
|
||||
require.Equal(t, "Rubl", tok.Name)
|
||||
|
@ -56,7 +56,7 @@ func TestClient_NEP5(t *testing.T) {
|
|||
})
|
||||
t.Run("BalanceOf", func(t *testing.T) {
|
||||
acc := testchain.PrivateKeyByID(0).GetScriptHash()
|
||||
b, err := c.NEP5BalanceOf(h, acc)
|
||||
b, err := c.NEP17BalanceOf(h, acc)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 877, b)
|
||||
})
|
||||
|
@ -259,7 +259,7 @@ func TestCreateTxFromScript(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestCreateNEP5TransferTx(t *testing.T) {
|
||||
func TestCreateNEP17TransferTx(t *testing.T) {
|
||||
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
|
||||
defer chain.Close()
|
||||
defer rpcSrv.Shutdown()
|
||||
|
@ -275,7 +275,7 @@ func TestCreateNEP5TransferTx(t *testing.T) {
|
|||
gasContractHash, err := c.GetNativeContractHash("gas")
|
||||
require.NoError(t, err)
|
||||
|
||||
tx, err := c.CreateNEP5TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0)
|
||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, acc.SignTx(tx))
|
||||
require.NoError(t, chain.VerifyTx(tx))
|
||||
|
|
|
@ -97,8 +97,8 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
|
|||
"getcommittee": (*Server).getCommittee,
|
||||
"getconnectioncount": (*Server).getConnectionCount,
|
||||
"getcontractstate": (*Server).getContractState,
|
||||
"getnep5balances": (*Server).getNEP5Balances,
|
||||
"getnep5transfers": (*Server).getNEP5Transfers,
|
||||
"getnep17balances": (*Server).getNEP17Balances,
|
||||
"getnep17transfers": (*Server).getNEP17Transfers,
|
||||
"getpeers": (*Server).getPeers,
|
||||
"getproof": (*Server).getProof,
|
||||
"getrawmempool": (*Server).getRawMempool,
|
||||
|
@ -550,16 +550,16 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
|||
return result.NewApplicationLog(hash, appExecResults, trig), nil
|
||||
}
|
||||
|
||||
func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Error) {
|
||||
func (s *Server) getNEP17Balances(ps request.Params) (interface{}, *response.Error) {
|
||||
u, err := ps.Value(0).GetUint160FromAddressOrHex()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
||||
as := s.chain.GetNEP5Balances(u)
|
||||
bs := &result.NEP5Balances{
|
||||
as := s.chain.GetNEP17Balances(u)
|
||||
bs := &result.NEP17Balances{
|
||||
Address: address.Uint160ToString(u),
|
||||
Balances: []result.NEP5Balance{},
|
||||
Balances: []result.NEP17Balance{},
|
||||
}
|
||||
if as != nil {
|
||||
cache := make(map[int32]util.Uint160)
|
||||
|
@ -568,7 +568,7 @@ func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Erro
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
bs.Balances = append(bs.Balances, result.NEP5Balance{
|
||||
bs.Balances = append(bs.Balances, result.NEP17Balance{
|
||||
Asset: h,
|
||||
Amount: bal.Balance.String(),
|
||||
LastUpdated: bal.LastUpdatedBlock,
|
||||
|
@ -628,7 +628,7 @@ func getTimestampsAndLimit(ps request.Params, index int) (uint64, uint64, int, i
|
|||
return start, end, limit, page, nil
|
||||
}
|
||||
|
||||
func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Error) {
|
||||
func (s *Server) getNEP17Transfers(ps request.Params) (interface{}, *response.Error) {
|
||||
u, err := ps.Value(0).GetUint160FromAddressOrHex()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
|
@ -639,14 +639,14 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
|||
return nil, response.NewInvalidParamsError(err.Error(), err)
|
||||
}
|
||||
|
||||
bs := &result.NEP5Transfers{
|
||||
bs := &result.NEP17Transfers{
|
||||
Address: address.Uint160ToString(u),
|
||||
Received: []result.NEP5Transfer{},
|
||||
Sent: []result.NEP5Transfer{},
|
||||
Received: []result.NEP17Transfer{},
|
||||
Sent: []result.NEP17Transfer{},
|
||||
}
|
||||
cache := make(map[int32]util.Uint160)
|
||||
var resCount, frameCount int
|
||||
err = s.chain.ForEachNEP5Transfer(u, func(tr *state.NEP5Transfer) (bool, error) {
|
||||
err = s.chain.ForEachNEP17Transfer(u, func(tr *state.NEP17Transfer) (bool, error) {
|
||||
// Iterating from newest to oldest, not yet reached required
|
||||
// time frame, continue looping.
|
||||
if tr.Timestamp > end {
|
||||
|
@ -668,7 +668,7 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
|||
return false, err
|
||||
}
|
||||
|
||||
transfer := result.NEP5Transfer{
|
||||
transfer := result.NEP17Transfer{
|
||||
Timestamp: tr.Timestamp,
|
||||
Asset: h,
|
||||
Index: tr.Block,
|
||||
|
@ -696,7 +696,7 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
|||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, response.NewInternalServerError("invalid NEP5 transfer log", err)
|
||||
return nil, response.NewInternalServerError("invalid NEP17 transfer log", err)
|
||||
}
|
||||
return bs, nil
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
},
|
||||
},
|
||||
|
||||
"getnep5balances": {
|
||||
"getnep17balances": {
|
||||
{
|
||||
name: "no params",
|
||||
params: `[]`,
|
||||
|
@ -216,17 +216,17 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
{
|
||||
name: "positive",
|
||||
params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `"]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Balances{} },
|
||||
check: checkNep5Balances,
|
||||
result: func(e *executor) interface{} { return &result.NEP17Balances{} },
|
||||
check: checkNep17Balances,
|
||||
},
|
||||
{
|
||||
name: "positive_address",
|
||||
params: `["` + address.Uint160ToString(testchain.PrivateKeyByID(0).GetScriptHash()) + `"]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Balances{} },
|
||||
check: checkNep5Balances,
|
||||
result: func(e *executor) interface{} { return &result.NEP17Balances{} },
|
||||
check: checkNep17Balances,
|
||||
},
|
||||
},
|
||||
"getnep5transfers": {
|
||||
"getnep17transfers": {
|
||||
{
|
||||
name: "no params",
|
||||
params: `[]`,
|
||||
|
@ -275,14 +275,14 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
{
|
||||
name: "positive",
|
||||
params: `["` + testchain.PrivateKeyByID(0).Address() + `", 0]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Transfers{} },
|
||||
check: checkNep5Transfers,
|
||||
result: func(e *executor) interface{} { return &result.NEP17Transfers{} },
|
||||
check: checkNep17Transfers,
|
||||
},
|
||||
{
|
||||
name: "positive_hash",
|
||||
params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `", 0]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Transfers{} },
|
||||
check: checkNep5Transfers,
|
||||
result: func(e *executor) interface{} { return &result.NEP17Transfers{} },
|
||||
check: checkNep17Transfers,
|
||||
},
|
||||
},
|
||||
"getproof": {
|
||||
|
@ -1198,8 +1198,8 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
|||
assert.ElementsMatch(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("getnep5transfers", func(t *testing.T) {
|
||||
testNEP5T := func(t *testing.T, start, stop, limit, page int, sent, rcvd []int) {
|
||||
t.Run("getnep17transfers", func(t *testing.T) {
|
||||
testNEP17T := func(t *testing.T, start, stop, limit, page int, sent, rcvd []int) {
|
||||
ps := []string{`"` + testchain.PrivateKeyByID(0).Address() + `"`}
|
||||
if start != 0 {
|
||||
h, err := e.chain.GetHeader(e.chain.GetHeaderHash(start))
|
||||
|
@ -1228,19 +1228,19 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
|||
ps = append(ps, strconv.FormatInt(int64(page), 10))
|
||||
}
|
||||
p := strings.Join(ps, ", ")
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getnep5transfers", "params": [%s]}`, p)
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getnep17transfers", "params": [%s]}`, p)
|
||||
body := doRPCCall(rpc, httpSrv.URL, t)
|
||||
res := checkErrGetResult(t, body, false)
|
||||
actual := new(result.NEP5Transfers)
|
||||
actual := new(result.NEP17Transfers)
|
||||
require.NoError(t, json.Unmarshal(res, actual))
|
||||
checkNep5TransfersAux(t, e, actual, sent, rcvd)
|
||||
checkNep17TransfersAux(t, e, actual, sent, rcvd)
|
||||
}
|
||||
t.Run("time frame only", func(t *testing.T) { testNEP5T(t, 4, 5, 0, 0, []int{3, 4, 5, 6}, []int{1, 2}) })
|
||||
t.Run("no res", func(t *testing.T) { testNEP5T(t, 100, 100, 0, 0, []int{}, []int{}) })
|
||||
t.Run("limit", func(t *testing.T) { testNEP5T(t, 1, 7, 3, 0, []int{0, 1}, []int{0}) })
|
||||
t.Run("limit 2", func(t *testing.T) { testNEP5T(t, 4, 5, 2, 0, []int{3}, []int{1}) })
|
||||
t.Run("limit with page", func(t *testing.T) { testNEP5T(t, 1, 7, 3, 1, []int{2, 3}, []int{1}) })
|
||||
t.Run("limit with page 2", func(t *testing.T) { testNEP5T(t, 1, 7, 3, 2, []int{4, 5}, []int{2}) })
|
||||
t.Run("time frame only", func(t *testing.T) { testNEP17T(t, 4, 5, 0, 0, []int{3, 4, 5, 6}, []int{1, 2}) })
|
||||
t.Run("no res", func(t *testing.T) { testNEP17T(t, 100, 100, 0, 0, []int{}, []int{}) })
|
||||
t.Run("limit", func(t *testing.T) { testNEP17T(t, 1, 7, 3, 0, []int{0, 1}, []int{0}) })
|
||||
t.Run("limit 2", func(t *testing.T) { testNEP17T(t, 4, 5, 2, 0, []int{3}, []int{1}) })
|
||||
t.Run("limit with page", func(t *testing.T) { testNEP17T(t, 1, 7, 3, 1, []int{2, 3}, []int{1}) })
|
||||
t.Run("limit with page 2", func(t *testing.T) { testNEP17T(t, 1, 7, 3, 2, []int{4, 5}, []int{2}) })
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1326,13 +1326,13 @@ func doRPCCallOverHTTP(rpcCall string, url string, t *testing.T) []byte {
|
|||
return bytes.TrimSpace(body)
|
||||
}
|
||||
|
||||
func checkNep5Balances(t *testing.T, e *executor, acc interface{}) {
|
||||
res, ok := acc.(*result.NEP5Balances)
|
||||
func checkNep17Balances(t *testing.T, e *executor, acc interface{}) {
|
||||
res, ok := acc.(*result.NEP17Balances)
|
||||
require.True(t, ok)
|
||||
rubles, err := util.Uint160DecodeStringLE(testContractHash)
|
||||
require.NoError(t, err)
|
||||
expected := result.NEP5Balances{
|
||||
Balances: []result.NEP5Balance{
|
||||
expected := result.NEP17Balances{
|
||||
Balances: []result.NEP17Balance{
|
||||
{
|
||||
Asset: rubles,
|
||||
Amount: "877",
|
||||
|
@ -1354,12 +1354,12 @@ func checkNep5Balances(t *testing.T, e *executor, acc interface{}) {
|
|||
require.ElementsMatch(t, expected.Balances, res.Balances)
|
||||
}
|
||||
|
||||
func checkNep5Transfers(t *testing.T, e *executor, acc interface{}) {
|
||||
checkNep5TransfersAux(t, e, acc, []int{0, 1, 2, 3, 4, 5, 6, 7, 8}, []int{0, 1, 2, 3, 4, 5, 6})
|
||||
func checkNep17Transfers(t *testing.T, e *executor, acc interface{}) {
|
||||
checkNep17TransfersAux(t, e, acc, []int{0, 1, 2, 3, 4, 5, 6, 7, 8}, []int{0, 1, 2, 3, 4, 5, 6})
|
||||
}
|
||||
|
||||
func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcvd []int) {
|
||||
res, ok := acc.(*result.NEP5Transfers)
|
||||
func checkNep17TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcvd []int) {
|
||||
res, ok := acc.(*result.NEP17Transfers)
|
||||
require.True(t, ok)
|
||||
rublesHash, err := util.Uint160DecodeStringLE(testContractHash)
|
||||
require.NoError(t, err)
|
||||
|
@ -1410,8 +1410,8 @@ func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcv
|
|||
// * to check chain events consistency
|
||||
// Technically these could be retrieved from application log, but that would almost
|
||||
// duplicate the Server method.
|
||||
expected := result.NEP5Transfers{
|
||||
Sent: []result.NEP5Transfer{
|
||||
expected := result.NEP17Transfers{
|
||||
Sent: []result.NEP17Transfer{
|
||||
{
|
||||
Timestamp: blockDeploy2.Timestamp,
|
||||
Asset: e.chain.UtilityTokenHash(),
|
||||
|
@ -1487,7 +1487,7 @@ func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcv
|
|||
TxHash: blockCtrDeploy.Hash(),
|
||||
},
|
||||
},
|
||||
Received: []result.NEP5Transfer{
|
||||
Received: []result.NEP17Transfer{
|
||||
{
|
||||
Timestamp: blockGASBounty.Timestamp,
|
||||
Asset: e.chain.UtilityTokenHash(),
|
||||
|
@ -1547,7 +1547,7 @@ func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcv
|
|||
|
||||
require.Equal(t, expected.Address, res.Address)
|
||||
|
||||
arr := make([]result.NEP5Transfer, 0, len(expected.Sent))
|
||||
arr := make([]result.NEP17Transfer, 0, len(expected.Sent))
|
||||
for i := range expected.Sent {
|
||||
for _, j := range sent {
|
||||
if i == j {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue