From c16040aecc8973662e5b7c0bd78d25286036931e Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 10 Aug 2020 19:16:54 +0300 Subject: [PATCH] native: sort GetValidators result As it's returned sorted now. Fixes state change mismatch for NextValidators. It also partially reverts 2f8e7e4d33d0c38cbd1310136f7a663942c3f640 and significantly changes the test chain as the fees are no longer being sent to the same account. --- pkg/consensus/consensus_test.go | 2 +- pkg/core/native/native_neo.go | 1 + pkg/core/native_neo_test.go | 11 ++++++++--- pkg/rpc/server/server_test.go | 16 +++------------- pkg/rpc/server/testdata/testblocks.acc | Bin 7236 -> 7230 bytes 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 4dd826e94..acf219fe1 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -226,7 +226,7 @@ func newTestService(t *testing.T) *service { } func getTestValidator(i int) (*privateKey, *publicKey) { - key := testchain.PrivateKeyByID(i) + key := testchain.PrivateKey(i) return &privateKey{PrivateKey: key}, &publicKey{PublicKey: key.PublicKey()} } diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 66430b673..12b0dc1c6 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -416,6 +416,7 @@ func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (ke count = len(result) } result = result[:count] + sort.Sort(result) n.validators.Store(result) return result, nil } diff --git a/pkg/core/native_neo_test.go b/pkg/core/native_neo_test.go index 250c9195f..3fe7591b9 100644 --- a/pkg/core/native_neo_test.go +++ b/pkg/core/native_neo_test.go @@ -2,6 +2,7 @@ package core import ( "math/big" + "sort" "testing" "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.VM = vm.New() + standBySorted := bc.GetStandByValidators() + sort.Sort(standBySorted) pubs, err := neo.GetValidatorsInternal(bc, ic.DAO) require.NoError(t, err) - require.Equal(t, bc.GetStandByValidators(), pubs) + require.Equal(t, standBySorted, pubs) sz := testchain.Size() @@ -65,7 +68,7 @@ func TestNEO_Vote(t *testing.T) { // We still haven't voted enough validators in. pubs, err = neo.GetValidatorsInternal(bc, ic.DAO) require.NoError(t, err) - require.Equal(t, bc.GetStandByValidators(), pubs) + require.Equal(t, standBySorted, pubs) // Register and give some value to the last validator. 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) 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.Error(t, neo.VoteInternal(ic, h, candidates[0])) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 18ea335fe..8c6c3cba6 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -52,8 +52,8 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "36c3b0c85d98607db00b711885ec3e411d9b1672" -const deploymentTxHash = "60a1fc8ceb7948d9933aec0cedd148441568575c40af7e0985cc366ed153d57e" +const testContractHash = "5b5f77b947194ba45ff5fa1ba6e066af5636d110" +const deploymentTxHash = "af0f94f6bdc5aada7abf1db19f1fcd2ea56cea596c41dc4abdfa6cd9664a7d72" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { @@ -1027,7 +1027,7 @@ func checkNep5Balances(t *testing.T, e *executor, acc interface{}) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "915.78962700", + Amount: "915.61054740", LastUpdated: 6, }}, 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 } - 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) diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index e34c40cd33d2b134f7426c85964d380bcec29d4a..430f85dcd94de8c18a4ecd3ec43ef900b4ba7326 100644 GIT binary patch delta 2799 zcmaKtc{J4P8^9T|&3BA-j3t?ILw1?5OqQ=L%GeoOS?116NMjp~lKmEu#FwN}*)QWN zYmr-*!L@X4=TXzL}LlY$`1ME}#)LPbX!mMU2V!0VC1j(#q|(T7=1&84ZKTOUwggyRDpz6>`FYVh}`e)FKZ>*Thd4>s6%!BJ-;BpZdM{FyLGIza+JN{-x0P_`@M z7R#F+W&q-w?#s5EXZP`BvIjf5qwC8-1o)OaqW zh}r$w1wE3ZGyqN=x(PQ_& zq0B`?^U;HjIRV1dcJ~G`w~3ndm0U!a2mr2#c~C{Om`^KR;2jeU0;=Z=tUZkbd!{-v z&Te(uG`H}EZ+#|R@*a=;@@3IY$uwE6;^9Gs_yj<}WP=qelnx!*8}S1q@BVD3;I6Q} zbkR>0@|Bf0=i=ING{*}db)ZP9UX1xFM(5#vXBT2uLEHO4?+1t*dKXZNE|AMi^KGA&@=cA z$Q7=@gVV?VDA~frp>INxFr49D2@PT3#!!%u7);S4Gzg5gi6_=i&>umo?Y70}?_P<>XBc8E*i`Wq=xK_&`CzZC_igYB0w}!C! z;H{PhZ_#w@PDy3{+b#8{ijWiXD6ynZcQE;$E-GtB7hNiQ;&GkJvd8FPP0{A%P_MO< zXeSewa`DBH&d+}Oi@uhYq~wFix6NJRX*~7qSsL}i)sb_1YZ<}K#l^D+0Mda;#_b4j z17IXSyH}HcOp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