2020-09-01 13:55:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"math/big"
|
2021-05-28 15:05:19 +00:00
|
|
|
"strconv"
|
2020-09-01 13:55:00 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Register standby validator and vote for it.
|
|
|
|
// We don't create a new account here, because chain will
|
|
|
|
// stop working after validator will change.
|
|
|
|
func TestRegisterCandidate(t *testing.T) {
|
|
|
|
e := newExecutor(t, true)
|
|
|
|
|
2021-07-22 11:40:18 +00:00
|
|
|
validatorHex := hex.EncodeToString(validatorPriv.PublicKey().Bytes())
|
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
|
2020-10-14 15:13:20 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2020-09-01 13:55:00 +00:00
|
|
|
"--wallet", validatorWallet,
|
|
|
|
"--from", validatorAddr,
|
2020-12-13 18:05:49 +00:00
|
|
|
"NEO:"+validatorPriv.Address()+":10",
|
2021-01-21 20:02:59 +00:00
|
|
|
"GAS:"+validatorPriv.Address()+":10000")
|
2020-09-01 13:55:00 +00:00
|
|
|
e.checkTxPersisted(t)
|
|
|
|
|
2021-07-22 11:40:18 +00:00
|
|
|
e.Run(t, "neo-go", "query", "committee",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr)
|
|
|
|
e.checkNextLine(t, "^\\s*"+validatorHex)
|
|
|
|
|
|
|
|
e.Run(t, "neo-go", "query", "candidates",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr)
|
|
|
|
e.checkNextLine(t, "^\\s*Key.+$") // Header.
|
|
|
|
e.checkEOF(t)
|
|
|
|
|
2021-04-16 09:03:03 +00:00
|
|
|
// missing address
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "candidate", "register",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", validatorWallet)
|
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "register",
|
2020-10-14 15:13:20 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2020-09-01 13:55:00 +00:00
|
|
|
"--wallet", validatorWallet,
|
|
|
|
"--address", validatorPriv.Address())
|
|
|
|
e.checkTxPersisted(t)
|
|
|
|
|
|
|
|
vs, err := e.Chain.GetEnrollments()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(vs))
|
|
|
|
require.Equal(t, validatorPriv.PublicKey(), vs[0].Key)
|
|
|
|
require.Equal(t, big.NewInt(0), vs[0].Votes)
|
|
|
|
|
2021-05-28 12:15:37 +00:00
|
|
|
t.Run("VoteUnvote", func(t *testing.T) {
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
2020-10-14 15:13:20 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2020-09-01 13:55:00 +00:00
|
|
|
"--wallet", validatorWallet,
|
|
|
|
"--address", validatorPriv.Address(),
|
2021-07-22 11:40:18 +00:00
|
|
|
"--candidate", validatorHex)
|
2021-05-28 15:05:19 +00:00
|
|
|
_, index := e.checkTxPersisted(t)
|
2020-09-01 13:55:00 +00:00
|
|
|
|
|
|
|
vs, err = e.Chain.GetEnrollments()
|
|
|
|
require.Equal(t, 1, len(vs))
|
|
|
|
require.Equal(t, validatorPriv.PublicKey(), vs[0].Key)
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(validatorPriv.GetScriptHash())
|
|
|
|
require.Equal(t, b, vs[0].Votes)
|
2021-05-28 12:15:37 +00:00
|
|
|
|
2021-07-22 11:40:18 +00:00
|
|
|
e.Run(t, "neo-go", "query", "committee",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr)
|
|
|
|
e.checkNextLine(t, "^\\s*"+validatorHex)
|
|
|
|
|
|
|
|
e.Run(t, "neo-go", "query", "candidates",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr)
|
|
|
|
e.checkNextLine(t, "^\\s*Key.+$") // Header.
|
|
|
|
e.checkNextLine(t, "^\\s*"+validatorHex+"\\s*"+b.String()+"\\s*true\\s*true$")
|
|
|
|
e.checkEOF(t)
|
|
|
|
|
2021-05-28 15:05:19 +00:00
|
|
|
// check state
|
2021-07-22 11:57:29 +00:00
|
|
|
e.Run(t, "neo-go", "query", "voter",
|
2021-05-28 15:05:19 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2021-07-22 11:57:29 +00:00
|
|
|
validatorPriv.Address())
|
2021-07-22 12:05:09 +00:00
|
|
|
e.checkNextLine(t, "^\\s*Voted:\\s+"+validatorHex+"\\s+\\("+validatorPriv.Address()+"\\)$")
|
2021-05-28 15:05:19 +00:00
|
|
|
e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
|
|
|
|
e.checkNextLine(t, "^\\s*Block\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
|
|
|
e.checkEOF(t)
|
|
|
|
|
2021-05-28 12:15:37 +00:00
|
|
|
// unvote
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", validatorWallet,
|
|
|
|
"--address", validatorPriv.Address())
|
2021-05-28 15:05:19 +00:00
|
|
|
_, index = e.checkTxPersisted(t)
|
2021-05-28 12:15:37 +00:00
|
|
|
|
|
|
|
vs, err = e.Chain.GetEnrollments()
|
|
|
|
require.Equal(t, 1, len(vs))
|
|
|
|
require.Equal(t, validatorPriv.PublicKey(), vs[0].Key)
|
|
|
|
require.Equal(t, big.NewInt(0), vs[0].Votes)
|
2021-05-28 15:05:19 +00:00
|
|
|
|
|
|
|
// check state
|
2021-07-22 11:57:29 +00:00
|
|
|
e.Run(t, "neo-go", "query", "voter",
|
2021-05-28 15:05:19 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2021-07-22 11:57:29 +00:00
|
|
|
validatorPriv.Address())
|
2021-05-28 15:05:19 +00:00
|
|
|
e.checkNextLine(t, "^\\s*Voted:\\s+"+"null") // no vote.
|
|
|
|
e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
|
|
|
|
e.checkNextLine(t, "^\\s*Block\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
|
|
|
e.checkEOF(t)
|
2020-09-01 13:55:00 +00:00
|
|
|
})
|
|
|
|
|
2021-04-16 09:03:03 +00:00
|
|
|
// missing address
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", validatorWallet)
|
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "unregister",
|
2020-10-14 15:13:20 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2020-09-01 13:55:00 +00:00
|
|
|
"--wallet", validatorWallet,
|
|
|
|
"--address", validatorPriv.Address())
|
|
|
|
e.checkTxPersisted(t)
|
|
|
|
|
|
|
|
vs, err = e.Chain.GetEnrollments()
|
|
|
|
require.Equal(t, 0, len(vs))
|
2021-05-28 15:05:19 +00:00
|
|
|
|
2021-07-22 11:57:29 +00:00
|
|
|
// query voter: missing address
|
|
|
|
e.RunWithError(t, "neo-go", "query", "voter")
|
2020-09-01 13:55:00 +00:00
|
|
|
}
|