rpc: support stringified address in getnep5balances RPC
This commit is contained in:
parent
62bb130ccb
commit
c4c2ce1465
2 changed files with 36 additions and 28 deletions
|
@ -496,7 +496,7 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
|||
}
|
||||
|
||||
func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Error) {
|
||||
u, err := ps.ValueWithType(0, request.StringT).GetUint160FromHex()
|
||||
u, err := ps.Value(0).GetUint160FromAddressOrHex()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
|
|
@ -129,33 +129,13 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
name: "positive",
|
||||
params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `"]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Balances{} },
|
||||
check: func(t *testing.T, e *executor, acc interface{}) {
|
||||
res, ok := acc.(*result.NEP5Balances)
|
||||
require.True(t, ok)
|
||||
rubles, err := util.Uint160DecodeStringLE(testContractHash)
|
||||
require.NoError(t, err)
|
||||
expected := result.NEP5Balances{
|
||||
Balances: []result.NEP5Balance{
|
||||
{
|
||||
Asset: rubles,
|
||||
Amount: "8.77",
|
||||
LastUpdated: 6,
|
||||
check: checkNep5Balances,
|
||||
},
|
||||
{
|
||||
Asset: e.chain.GoverningTokenHash(),
|
||||
Amount: "99998000",
|
||||
LastUpdated: 4,
|
||||
},
|
||||
{
|
||||
Asset: e.chain.UtilityTokenHash(),
|
||||
Amount: "915.79002700",
|
||||
LastUpdated: 6,
|
||||
}},
|
||||
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
|
||||
}
|
||||
require.Equal(t, testchain.PrivateKeyByID(0).Address(), res.Address)
|
||||
require.ElementsMatch(t, expected.Balances, res.Balances)
|
||||
},
|
||||
name: "positive_address",
|
||||
params: `["` + address.Uint160ToString(testchain.PrivateKeyByID(0).GetScriptHash()) + `"]`,
|
||||
result: func(e *executor) interface{} { return &result.NEP5Balances{} },
|
||||
check: checkNep5Balances,
|
||||
},
|
||||
},
|
||||
"getnep5transfers": {
|
||||
|
@ -1110,3 +1090,31 @@ func doRPCCallOverHTTP(rpcCall string, url string, t *testing.T) []byte {
|
|||
assert.NoErrorf(t, err, "could not read response from the request: %s", rpcCall)
|
||||
return bytes.TrimSpace(body)
|
||||
}
|
||||
|
||||
func checkNep5Balances(t *testing.T, e *executor, acc interface{}) {
|
||||
res, ok := acc.(*result.NEP5Balances)
|
||||
require.True(t, ok)
|
||||
rubles, err := util.Uint160DecodeStringLE(testContractHash)
|
||||
require.NoError(t, err)
|
||||
expected := result.NEP5Balances{
|
||||
Balances: []result.NEP5Balance{
|
||||
{
|
||||
Asset: rubles,
|
||||
Amount: "8.77",
|
||||
LastUpdated: 6,
|
||||
},
|
||||
{
|
||||
Asset: e.chain.GoverningTokenHash(),
|
||||
Amount: "99998000",
|
||||
LastUpdated: 4,
|
||||
},
|
||||
{
|
||||
Asset: e.chain.UtilityTokenHash(),
|
||||
Amount: "915.79002700",
|
||||
LastUpdated: 6,
|
||||
}},
|
||||
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
|
||||
}
|
||||
require.Equal(t, testchain.PrivateKeyByID(0).Address(), res.Address)
|
||||
require.ElementsMatch(t, expected.Balances, res.Balances)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue