Merge pull request #1449 from nspcc-dev/rpc/client/getcvalidators_fix

rpc: getvalidators -> getnextblockvalidators
This commit is contained in:
Roman Khimov 2020-10-02 13:30:58 +03:00 committed by GitHub
commit 0e5a2f34c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 38 deletions

View file

@ -353,13 +353,13 @@ func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) {
return resp, nil return resp, nil
} }
// GetValidators returns the current NEO consensus nodes information and voting status. // GetNextBlockValidators returns the current NEO consensus nodes information and voting status.
func (c *Client) GetValidators() ([]result.Validator, error) { func (c *Client) GetNextBlockValidators() ([]result.Validator, error) {
var ( var (
params = request.NewRawParams() params = request.NewRawParams()
resp = new([]result.Validator) resp = new([]result.Validator)
) )
if err := c.performRequest("getvalidators", params, resp); err != nil { if err := c.performRequest("getnextblockvalidators", params, resp); err != nil {
return nil, err return nil, err
} }
return *resp, nil return *resp, nil
@ -502,7 +502,7 @@ func (c *Client) ValidateAddress(address string) error {
// CalculateValidUntilBlock calculates ValidUntilBlock field for tx as // CalculateValidUntilBlock calculates ValidUntilBlock field for tx as
// current blockchain height + number of validators. Number of validators // current blockchain height + number of validators. Number of validators
// is the length of blockchain validators list got from GetValidators() // is the length of blockchain validators list got from GetNextBlockValidators()
// method. Validators count is being cached and updated every 100 blocks. // method. Validators count is being cached and updated every 100 blocks.
func (c *Client) CalculateValidUntilBlock() (uint32, error) { func (c *Client) CalculateValidUntilBlock() (uint32, error) {
var ( var (
@ -517,7 +517,7 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
if c.cache.calculateValidUntilBlock.expiresAt > blockCount { if c.cache.calculateValidUntilBlock.expiresAt > blockCount {
validatorsCount = c.cache.calculateValidUntilBlock.validatorsCount validatorsCount = c.cache.calculateValidUntilBlock.validatorsCount
} else { } else {
validators, err := c.GetValidators() validators, err := c.GetNextBlockValidators()
if err != nil { if err != nil {
return result, fmt.Errorf("can't get validators: %w", err) return result, fmt.Errorf("can't get validators: %w", err)
} }

View file

@ -614,7 +614,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
{ {
name: "positive", name: "positive",
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return c.GetValidators() return c.GetNextBlockValidators()
}, },
serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`, serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`,
result: func(c *Client) interface{} { return []result.Validator{} }, result: func(c *Client) interface{} { return []result.Validator{} },
@ -1189,7 +1189,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
{ {
name: "getvalidators_unmarshalling_error", name: "getvalidators_unmarshalling_error",
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return c.GetValidators() return c.GetNextBlockValidators()
}, },
}, },
{ {
@ -1354,7 +1354,7 @@ func TestCalculateValidUntilBlock(t *testing.T) {
case "getblockcount": case "getblockcount":
getBlockCountCalled++ getBlockCountCalled++
response = `{"jsonrpc":"2.0","id":1,"result":50}` response = `{"jsonrpc":"2.0","id":1,"result":50}`
case "getvalidators": case "getnextblockvalidators":
getValidatorsCalled++ getValidatorsCalled++
response = `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}` response = `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`
default: default:

View file

@ -101,7 +101,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
"getstorage": (*Server).getStorage, "getstorage": (*Server).getStorage,
"gettransactionheight": (*Server).getTransactionHeight, "gettransactionheight": (*Server).getTransactionHeight,
"getunclaimedgas": (*Server).getUnclaimedGas, "getunclaimedgas": (*Server).getUnclaimedGas,
"getvalidators": (*Server).getValidators, "getnextblockvalidators": (*Server).getNextBlockValidators,
"getversion": (*Server).getVersion, "getversion": (*Server).getVersion,
"invokefunction": (*Server).invokeFunction, "invokefunction": (*Server).invokeFunction,
"invokescript": (*Server).invokescript, "invokescript": (*Server).invokescript,
@ -906,13 +906,13 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro
}, nil }, nil
} }
// getValidators returns the current NEO consensus nodes information and voting status. // getNextBlockValidators returns validators for the next block with voting status.
func (s *Server) getValidators(_ request.Params) (interface{}, *response.Error) { func (s *Server) getNextBlockValidators(_ request.Params) (interface{}, *response.Error) {
var validators keys.PublicKeys var validators keys.PublicKeys
validators, err := s.chain.GetValidators() validators, err := s.chain.GetNextBlockValidators()
if err != nil { if err != nil {
return nil, response.NewRPCError("can't get validators", "", err) return nil, response.NewRPCError("can't get next block validators", "", err)
} }
enrollments, err := s.chain.GetEnrollments() enrollments, err := s.chain.GetEnrollments()
if err != nil { if err != nil {

View file

@ -491,7 +491,7 @@ var rpcTestCases = map[string][]rpcTestCase{
}, },
}, },
}, },
"getvalidators": { "getnextblockvalidators": {
{ {
params: "[]", params: "[]",
result: func(*executor) interface{} { result: func(*executor) interface{} {