0da0bb21ee
Turns out, our getnextvalidators implementation already works the way getcandidates is supposed to work, but original getnextvalidators works a bit differently. It only returns validators, it doesn't return Active flag (all of them are active) and it represents votes as a number. So for the maximum compatibility: * drop non-validator keys from getnextvalidators server-side * drop Active flag client-side (sorry, it doesn't exist) * allow unmarshalling old answers along with the new one This technically breaks `query candidates` CLI command, but it'll be fixed when getcandidates are to be introduced.
22 lines
741 B
Go
22 lines
741 B
Go
package result
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidatorUnmarshal(t *testing.T) {
|
|
old := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"100500","active":true}`)
|
|
v := new(Validator)
|
|
require.NoError(t, json.Unmarshal(old, v))
|
|
require.Equal(t, int64(100500), v.Votes)
|
|
|
|
new := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":42}`)
|
|
require.NoError(t, json.Unmarshal(new, v))
|
|
require.Equal(t, int64(42), v.Votes)
|
|
|
|
bad := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"notanumber"}`)
|
|
require.Error(t, json.Unmarshal(bad, v))
|
|
}
|