Skip to content

Commit

Permalink
stake CLI various fixes, confirmed working
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Apr 18, 2018
1 parent 4572373 commit c80b967
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 172 deletions.
43 changes: 24 additions & 19 deletions cmd/gaia/cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestGaiaCLISend(t *testing.T) {

tests.ExecuteT(t, "gaiad unsafe_reset_all")
tests.ExecuteT(t, "gaiad unsafe_reset_all", 1)
pass := "1234567890"
executeWrite(t, "gaiacli keys delete foo", pass)
executeWrite(t, "gaiacli keys delete bar", pass)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestGaiaCLISend(t *testing.T) {

func TestGaiaCLIDeclareCandidacy(t *testing.T) {

tests.ExecuteT(t, "gaiad unsafe_reset_all")
tests.ExecuteT(t, "gaiad unsafe_reset_all", 1)
pass := "1234567890"
executeWrite(t, "gaiacli keys delete foo", pass)
masterKey, chainID := executeInit(t, "gaiad init")
Expand All @@ -76,18 +76,6 @@ func TestGaiaCLIDeclareCandidacy(t *testing.T) {
assert.Equal(t, int64(100000), fooAcc.GetCoins().AmountOf("fermion"))

// declare candidacy
//--address-candidate string hex address of the validator/candidate
//--amount string Amount of coins to bond (default "1fermion")
//--chain-id string Chain ID of tendermint node
//--fee string Fee to pay along with transaction
//--keybase-sig string optional keybase signature
//--moniker string validator-candidate name
//--name string Name of private key with which to sign
//--node string <host>:<port> to tendermint rpc interface for this chain (default "tcp://localhost:46657")
//--pubkey string PubKey of the validator-candidate
//--sequence int Sequence number to sign the tx
//--website string optional website
//_ = fooPubKey
declStr := fmt.Sprintf("gaiacli declare-candidacy %v", flags)
declStr += fmt.Sprintf(" --name=%v", "foo")
declStr += fmt.Sprintf(" --address-candidate=%v", fooAddr)
Expand All @@ -99,8 +87,25 @@ func TestGaiaCLIDeclareCandidacy(t *testing.T) {
time.Sleep(time.Second * 3) // waiting for some blocks to pass
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags))
assert.Equal(t, int64(99997), fooAcc.GetCoins().AmountOf("fermion"))
candidate := executeGetCandidate(t, fmt.Sprintf("gaiacli candidate %v --address=%v", flags, fooAddr))
candidate := executeGetCandidate(t, fmt.Sprintf("gaiacli candidate %v --address-candidate=%v", flags, fooAddr))
assert.Equal(t, candidate.Address.String(), fooAddr)
assert.Equal(t, int64(3), candidate.Assets.Evaluate())

// TODO figure out why this times out with connection refused errors in go-bash
// unbond a single share
//unbondStr := fmt.Sprintf("gaiacli unbond %v", flags)
//unbondStr += fmt.Sprintf(" --name=%v", "foo")
//unbondStr += fmt.Sprintf(" --address-candidate=%v", fooAddr)
//unbondStr += fmt.Sprintf(" --address-delegator=%v", fooAddr)
//unbondStr += fmt.Sprintf(" --shares=%v", "1")
//unbondStr += fmt.Sprintf(" --sequence=%v", "1")
//fmt.Printf("debug unbondStr: %v\n", unbondStr)
//executeWrite(t, unbondStr, pass)
//time.Sleep(time.Second * 3) // waiting for some blocks to pass
//fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags))
//assert.Equal(t, int64(99998), fooAcc.GetCoins().AmountOf("fermion"))
//candidate = executeGetCandidate(t, fmt.Sprintf("gaiacli candidate %v --address-candidate=%v", flags, fooAddr))
//assert.Equal(t, int64(2), candidate.Assets.Evaluate())
}

func executeWrite(t *testing.T, cmdStr string, writes ...string) {
Expand Down Expand Up @@ -128,7 +133,7 @@ func executeWritePrint(t *testing.T, cmdStr string, writes ...string) {
}

func executeInit(t *testing.T, cmdStr string) (masterKey, chainID string) {
out := tests.ExecuteT(t, cmdStr)
out := tests.ExecuteT(t, cmdStr, 1)
outCut := "{" + strings.SplitN(out, "{", 2)[1] // weird I'm sorry

var initRes map[string]json.RawMessage
Expand All @@ -142,7 +147,7 @@ func executeInit(t *testing.T, cmdStr string) (masterKey, chainID string) {
}

func executeGetAddr(t *testing.T, cmdStr string) (addr, pubKey string) {
out := tests.ExecuteT(t, cmdStr)
out := tests.ExecuteT(t, cmdStr, 2)
var info crkeys.Info
keys.UnmarshalJSON([]byte(out), &info)
pubKey = hex.EncodeToString(info.PubKey.(crypto.PubKeyEd25519).Bytes())
Expand All @@ -158,7 +163,7 @@ func executeGetAddr(t *testing.T, cmdStr string) (addr, pubKey string) {
}

func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount {
out := tests.ExecuteT(t, cmdStr)
out := tests.ExecuteT(t, cmdStr, 2)
var initRes map[string]json.RawMessage
err := json.Unmarshal([]byte(out), &initRes)
require.NoError(t, err, "out %v, err %v", out, err)
Expand All @@ -170,7 +175,7 @@ func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount {
}

func executeGetCandidate(t *testing.T, cmdStr string) stake.Candidate {
out := tests.ExecuteT(t, cmdStr)
out := tests.ExecuteT(t, cmdStr, 2)
var candidate stake.Candidate
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &candidate)
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func main() {
rootCmd.AddCommand(
client.GetCommands(
authcmd.GetAccountCmd("main", cdc, authcmd.GetAccountDecoder(cdc)),
stakecmd.GetCmdQueryCandidates("stake", cdc),
stakecmd.GetCmdQueryCandidate("stake", cdc),
//stakecmd.GetCmdQueryCandidates("stake", cdc),
stakecmd.GetCmdQueryDelegatorBond("stake", cdc),
stakecmd.GetCmdQueryDelegatorBonds("stake", cdc),
//stakecmd.GetCmdQueryDelegatorBonds("stake", cdc),
)...)
rootCmd.AddCommand(
client.PostCommands(
Expand Down
2 changes: 1 addition & 1 deletion server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c initCmd) run(cmd *cobra.Command, args []string) error {
return nil
}

// generate secrete and address
// generate secret and address
addr, secret, err := GenerateCoinKey()
if err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions tests/gobash.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"io"
"os/exec"
"strings"
Expand All @@ -25,10 +26,15 @@ func getCmd(t *testing.T, command string) *exec.Cmd {
return cmd
}

// Execute the command, return standard output and error
func ExecuteT(t *testing.T, command string) (out string) {
// Execute the command, return standard output and error, try a few times if requested
func ExecuteT(t *testing.T, command string, trials int) (out string) {
cmd := getCmd(t, command)
bz, err := cmd.CombinedOutput()
if err != nil && trials > 1 {
fmt.Printf("trial %v, retrying: %v\n", trials, command)
time.Sleep(time.Second * 10)
return ExecuteT(t, command, trials-1)
}
require.NoError(t, err, string(bz))
out = strings.Trim(string(bz), "\n") //trim any new lines
time.Sleep(time.Second)
Expand Down
41 changes: 41 additions & 0 deletions x/stake/commands/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package commands

import (
flag "github.com/spf13/pflag"
)

// nolint
const (
FlagAddressDelegator = "address-delegator"
FlagAddressCandidate = "address-candidate"
FlagPubKey = "pubkey"
FlagAmount = "amount"
FlagShares = "shares"

FlagMoniker = "moniker"
FlagIdentity = "keybase-sig"
FlagWebsite = "website"
FlagDetails = "details"
)

// common flagsets to add to various functions
var (
fsPk = flag.NewFlagSet("", flag.ContinueOnError)
fsAmount = flag.NewFlagSet("", flag.ContinueOnError)
fsShares = flag.NewFlagSet("", flag.ContinueOnError)
fsDescription = flag.NewFlagSet("", flag.ContinueOnError)
fsCandidate = flag.NewFlagSet("", flag.ContinueOnError)
fsDelegator = flag.NewFlagSet("", flag.ContinueOnError)
)

func init() {
fsPk.String(FlagPubKey, "", "PubKey of the validator-candidate")
fsAmount.String(FlagAmount, "1fermion", "Amount of coins to bond")
fsShares.String(FlagShares, "", "Amount of shares to unbond, either in decimal or keyword MAX (ex. 1.23456789, 99, MAX)")
fsDescription.String(FlagMoniker, "", "validator-candidate name")
fsDescription.String(FlagIdentity, "", "optional keybase signature")
fsDescription.String(FlagWebsite, "", "optional website")
fsDescription.String(FlagDetails, "", "optional details")
fsCandidate.String(FlagAddressCandidate, "", "hex address of the validator/candidate")
fsDelegator.String(FlagAddressDelegator, "", "hex address of the delegator")
}
Loading

0 comments on commit c80b967

Please sign in to comment.