cli: add wallet candidate getstate

This commit is contained in:
Anna Shaleva 2021-05-28 18:05:19 +03:00
parent 999fba81cd
commit c2b5459646
2 changed files with 90 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"encoding/hex"
"math/big"
"strconv"
"testing"
"github.com/stretchr/testify/require"
@ -48,7 +49,7 @@ func TestRegisterCandidate(t *testing.T) {
"--wallet", validatorWallet,
"--address", validatorPriv.Address(),
"--candidate", hex.EncodeToString(validatorPriv.PublicKey().Bytes()))
e.checkTxPersisted(t)
_, index := e.checkTxPersisted(t)
vs, err = e.Chain.GetEnrollments()
require.Equal(t, 1, len(vs))
@ -56,18 +57,36 @@ func TestRegisterCandidate(t *testing.T) {
b, _ := e.Chain.GetGoverningTokenBalance(validatorPriv.GetScriptHash())
require.Equal(t, b, vs[0].Votes)
// check state
e.Run(t, "neo-go", "wallet", "candidate", "getstate",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--address", validatorPriv.Address())
e.checkNextLine(t, "^\\s*Voted:\\s+"+validatorPriv.Address())
e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
e.checkNextLine(t, "^\\s*Block\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
e.checkEOF(t)
// 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())
e.checkTxPersisted(t)
_, index = e.checkTxPersisted(t)
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)
// check state
e.Run(t, "neo-go", "wallet", "candidate", "getstate",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--address", validatorPriv.Address())
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)
})
// missing address
@ -84,4 +103,7 @@ func TestRegisterCandidate(t *testing.T) {
vs, err = e.Chain.GetEnrollments()
require.Equal(t, 0, len(vs))
// getstate: missing address
e.RunWithError(t, "neo-go", "wallet", "candidate", "getstate")
}