Merge pull request #633 from nspcc-dev/fix-rpc-unused-address-handling

rpc: fix getaccountstate/getunspents for unknown addresses
This commit is contained in:
Roman Khimov 2020-01-29 20:14:27 +03:00 committed by GitHub
commit f773ec69fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/network"
@ -320,7 +321,11 @@ func (s *Server) getAccountState(reqParams Params, unspents bool) (interface{},
return nil, errInvalidParams
} else if scriptHash, err := param.GetUint160FromAddress(); err != nil {
return nil, errInvalidParams
} else if as := s.chain.GetAccountState(scriptHash); as != nil {
} else {
as := s.chain.GetAccountState(scriptHash)
if as == nil {
as = state.NewAccount(scriptHash)
}
if unspents {
str, err := param.GetString()
if err != nil {
@ -330,8 +335,6 @@ func (s *Server) getAccountState(reqParams Params, unspents bool) (interface{},
} else {
results = wrappers.NewAccountState(as)
}
} else {
results = "Invalid public account address"
}
return results, resultsErr
}

View file

@ -50,9 +50,15 @@ var rpcTestCases = map[string][]rpcTestCase{
},
},
{
name: "negative",
name: "positive null",
params: `["AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"]`,
result: func(e *executor) interface{} { return "Invalid public account address" },
result: func(e *executor) interface{} { return &GetAccountStateResponse{} },
check: func(t *testing.T, e *executor, result interface{}) {
res, ok := result.(*GetAccountStateResponse)
require.True(t, ok)
assert.Equal(t, 0, len(res.Result.Balances))
assert.Equal(t, false, res.Result.Frozen)
},
},
{
name: "no params",
@ -235,9 +241,14 @@ var rpcTestCases = map[string][]rpcTestCase{
},
},
{
name: "negative",
name: "positive null",
params: `["AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"]`,
result: func(e *executor) interface{} { return "Invalid public account address" },
result: func(e *executor) interface{} { return &GetUnspents{} },
check: func(t *testing.T, e *executor, result interface{}) {
res, ok := result.(*GetUnspents)
require.True(t, ok)
require.Equal(t, 0, len(res.Result.Balance))
},
},
},
"getversion": {