2022-10-05 06:44:10 +00:00
|
|
|
package wallet_test
|
2020-09-01 13:55:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
2021-05-28 15:05:19 +00:00
|
|
|
"strconv"
|
2020-09-01 13:55:00 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
2020-09-01 13:55:00 +00:00
|
|
|
"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) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2020-09-01 13:55:00 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
validatorAddress := testcli.ValidatorPriv.Address()
|
|
|
|
validatorPublic := testcli.ValidatorPriv.PublicKey()
|
2024-04-09 09:13:43 +00:00
|
|
|
validatorHex := validatorPublic.StringCompressed()
|
2021-07-22 11:40:18 +00:00
|
|
|
|
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",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--from", testcli.ValidatorAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2022-10-05 06:44:10 +00:00
|
|
|
"NEO:"+validatorAddress+":10",
|
|
|
|
"GAS:"+validatorAddress+":10000")
|
|
|
|
e.CheckTxPersisted(t)
|
2020-09-01 13:55:00 +00:00
|
|
|
|
2021-07-22 11:40:18 +00:00
|
|
|
e.Run(t, "neo-go", "query", "committee",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*"+validatorHex)
|
2021-07-22 11:40:18 +00:00
|
|
|
|
|
|
|
e.Run(t, "neo-go", "query", "candidates",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Key.+$") // Header.
|
|
|
|
e.CheckEOF(t)
|
2021-07-22 11:40:18 +00:00
|
|
|
|
2021-04-16 09:03:03 +00:00
|
|
|
// missing address
|
2024-07-04 22:34:40 +00:00
|
|
|
e.RunWithErrorCheck(t, `Required flag "address" not set`, "neo-go", "wallet", "candidate", "register",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet)
|
2021-04-16 09:03:03 +00:00
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
// additional parameter
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "candidate", "register",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
2022-08-05 10:32:37 +00:00
|
|
|
"error")
|
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "register",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2022-10-06 19:19:40 +00:00
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2020-09-01 13:55:00 +00:00
|
|
|
|
|
|
|
vs, err := e.Chain.GetEnrollments()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(vs))
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, validatorPublic, vs[0].Key)
|
2020-09-01 13:55:00 +00:00
|
|
|
require.Equal(t, big.NewInt(0), vs[0].Votes)
|
|
|
|
|
2021-05-28 12:15:37 +00:00
|
|
|
t.Run("VoteUnvote", func(t *testing.T) {
|
2022-08-05 10:32:37 +00:00
|
|
|
// positional instead of a flag.
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "candidate", "vote",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
2022-08-05 10:32:37 +00:00
|
|
|
validatorHex) // not "--candidate hex", but "hex".
|
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
2022-10-06 19:19:40 +00:00
|
|
|
"--candidate", validatorHex,
|
|
|
|
"--force")
|
2022-10-05 06:44:10 +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))
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, validatorPublic, vs[0].Key)
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(testcli.ValidatorPriv.GetScriptHash())
|
2020-09-01 13:55:00 +00:00
|
|
|
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",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*"+validatorHex)
|
2021-07-22 11:40:18 +00:00
|
|
|
|
|
|
|
e.Run(t, "neo-go", "query", "candidates",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Key.+$") // Header.
|
|
|
|
e.CheckNextLine(t, "^\\s*"+validatorHex+"\\s*"+b.String()+"\\s*true\\s*true$")
|
|
|
|
e.CheckEOF(t)
|
2021-07-22 11:40:18 +00:00
|
|
|
|
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",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
validatorAddress)
|
|
|
|
e.CheckNextLine(t, "^\\s*Voted:\\s+"+validatorHex+"\\s+\\("+validatorAddress+"\\)$")
|
|
|
|
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 15:05:19 +00:00
|
|
|
|
2021-05-28 12:15:37 +00:00
|
|
|
// unvote
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2022-10-06 19:19:40 +00:00
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force")
|
2022-10-05 06:44:10 +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))
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, validatorPublic, vs[0].Key)
|
2021-05-28 12:15:37 +00:00
|
|
|
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",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
validatorAddress)
|
|
|
|
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
|
2024-07-04 22:34:40 +00:00
|
|
|
e.RunWithErrorCheck(t, `Required flag "address" not set`, "neo-go", "wallet", "candidate", "unregister",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet)
|
2022-08-05 10:32:37 +00:00
|
|
|
// additional argument
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
2022-08-05 10:32:37 +00:00
|
|
|
"argument")
|
2021-04-16 09:03:03 +00:00
|
|
|
|
2020-09-01 13:55:00 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "unregister",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2022-10-06 19:19:40 +00:00
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2020-09-01 13:55:00 +00:00
|
|
|
|
|
|
|
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
|
2024-07-04 22:34:40 +00:00
|
|
|
e.RunWithError(t, "neo-go", "query", "voter", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
|
2022-08-05 10:32:37 +00:00
|
|
|
// Excessive parameters.
|
2022-11-25 10:20:53 +00:00
|
|
|
e.RunWithError(t, "neo-go", "query", "voter", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], validatorAddress, validatorAddress)
|
|
|
|
e.RunWithError(t, "neo-go", "query", "committee", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "something")
|
|
|
|
e.RunWithError(t, "neo-go", "query", "candidates", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "something")
|
2023-12-28 11:58:38 +00:00
|
|
|
|
|
|
|
t.Run("VoteUnvote await", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "register",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force", "--await")
|
|
|
|
e.CheckAwaitableTxPersisted(t)
|
|
|
|
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
|
|
|
"--candidate", validatorHex,
|
|
|
|
"--force",
|
|
|
|
"--await")
|
|
|
|
|
|
|
|
e.CheckAwaitableTxPersisted(t)
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(testcli.ValidatorPriv.GetScriptHash())
|
|
|
|
|
|
|
|
// unvote
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "vote",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force", "--await")
|
|
|
|
_, index := e.CheckAwaitableTxPersisted(t)
|
|
|
|
|
|
|
|
vs, err = e.Chain.GetEnrollments()
|
|
|
|
require.Equal(t, 1, len(vs))
|
|
|
|
require.Equal(t, validatorPublic, vs[0].Key)
|
|
|
|
require.Equal(t, big.NewInt(0), vs[0].Votes)
|
|
|
|
|
|
|
|
// check state
|
|
|
|
e.Run(t, "neo-go", "query", "voter",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
|
|
|
validatorAddress)
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "candidate", "unregister",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--address", validatorAddress,
|
|
|
|
"--force",
|
|
|
|
"--await")
|
|
|
|
e.CheckAwaitableTxPersisted(t)
|
|
|
|
|
|
|
|
vs, err = e.Chain.GetEnrollments()
|
|
|
|
require.Equal(t, 0, len(vs))
|
2020-09-01 13:55:00 +00:00
|
|
|
}
|