native: sort GetValidators result

As it's returned sorted now. Fixes state change mismatch for
NextValidators. It also partially reverts
2f8e7e4d33 and significantly changes the test
chain as the fees are no longer being sent to the same account.
This commit is contained in:
Roman Khimov 2020-08-10 19:16:54 +03:00
parent dba248236c
commit c16040aecc
5 changed files with 13 additions and 17 deletions

View file

@ -226,7 +226,7 @@ func newTestService(t *testing.T) *service {
} }
func getTestValidator(i int) (*privateKey, *publicKey) { func getTestValidator(i int) (*privateKey, *publicKey) {
key := testchain.PrivateKeyByID(i) key := testchain.PrivateKey(i)
return &privateKey{PrivateKey: key}, &publicKey{PublicKey: key.PublicKey()} return &privateKey{PrivateKey: key}, &publicKey{PublicKey: key.PublicKey()}
} }

View file

@ -416,6 +416,7 @@ func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (ke
count = len(result) count = len(result)
} }
result = result[:count] result = result[:count]
sort.Sort(result)
n.validators.Store(result) n.validators.Store(result)
return result, nil return result, nil
} }

View file

@ -2,6 +2,7 @@ package core
import ( import (
"math/big" "math/big"
"sort"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/config/netmode"
@ -31,9 +32,11 @@ func TestNEO_Vote(t *testing.T) {
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx) ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
ic.VM = vm.New() ic.VM = vm.New()
standBySorted := bc.GetStandByValidators()
sort.Sort(standBySorted)
pubs, err := neo.GetValidatorsInternal(bc, ic.DAO) pubs, err := neo.GetValidatorsInternal(bc, ic.DAO)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, bc.GetStandByValidators(), pubs) require.Equal(t, standBySorted, pubs)
sz := testchain.Size() sz := testchain.Size()
@ -65,7 +68,7 @@ func TestNEO_Vote(t *testing.T) {
// We still haven't voted enough validators in. // We still haven't voted enough validators in.
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO) pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, bc.GetStandByValidators(), pubs) require.Equal(t, standBySorted, pubs)
// Register and give some value to the last validator. // Register and give some value to the last validator.
require.NoError(t, neo.RegisterCandidateInternal(ic, candidates[0])) require.NoError(t, neo.RegisterCandidateInternal(ic, candidates[0]))
@ -77,7 +80,9 @@ func TestNEO_Vote(t *testing.T) {
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO) pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, candidates, pubs) sortedCandidates := candidates.Copy()
sort.Sort(sortedCandidates)
require.EqualValues(t, sortedCandidates, pubs)
require.NoError(t, neo.UnregisterCandidateInternal(ic, candidates[0])) require.NoError(t, neo.UnregisterCandidateInternal(ic, candidates[0]))
require.Error(t, neo.VoteInternal(ic, h, candidates[0])) require.Error(t, neo.VoteInternal(ic, h, candidates[0]))

View file

@ -52,8 +52,8 @@ type rpcTestCase struct {
check func(t *testing.T, e *executor, result interface{}) check func(t *testing.T, e *executor, result interface{})
} }
const testContractHash = "36c3b0c85d98607db00b711885ec3e411d9b1672" const testContractHash = "5b5f77b947194ba45ff5fa1ba6e066af5636d110"
const deploymentTxHash = "60a1fc8ceb7948d9933aec0cedd148441568575c40af7e0985cc366ed153d57e" const deploymentTxHash = "af0f94f6bdc5aada7abf1db19f1fcd2ea56cea596c41dc4abdfa6cd9664a7d72"
var rpcTestCases = map[string][]rpcTestCase{ var rpcTestCases = map[string][]rpcTestCase{
"getapplicationlog": { "getapplicationlog": {
@ -1027,7 +1027,7 @@ func checkNep5Balances(t *testing.T, e *executor, acc interface{}) {
}, },
{ {
Asset: e.chain.UtilityTokenHash(), Asset: e.chain.UtilityTokenHash(),
Amount: "915.78962700", Amount: "915.61054740",
LastUpdated: 6, LastUpdated: 6,
}}, }},
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
@ -1145,16 +1145,6 @@ func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, start, en
} }
netFee += b.Transactions[j].NetworkFee netFee += b.Transactions[j].NetworkFee
} }
if i > 0 {
expected.Received = append(expected.Received, result.NEP5Transfer{
Timestamp: b.Timestamp,
Asset: e.chain.UtilityTokenHash(),
Address: "", // minted from network fees.
Amount: amountToString(big.NewInt(netFee), 8),
Index: b.Index,
TxHash: b.Hash(),
})
}
} }
require.Equal(t, expected.Address, res.Address) require.Equal(t, expected.Address, res.Address)

Binary file not shown.