Skip to content

Commit

Permalink
oasis-node/cmd/stake: Make info subcommand tolerate invalid thresholds
Browse files Browse the repository at this point in the history
Change the subcommand to print valid staking threshold kinds and warn
about invalid ones.

Add test for info subcommand to the stake-cli End-to-End test.
  • Loading branch information
tjanez committed Feb 3, 2020
1 parent e33f3b4 commit 255b2f8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/2632.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
oasis-node/cmd/stake: Make info subcommand tolerate invalid thresholds.

Change the subcommand to print valid staking threshold kinds and warn about invalid ones.
22 changes: 19 additions & 3 deletions go/oasis-node/cmd/stake/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/grpc"

"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/errors"
"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/common/quantity"
consensus "github.com/oasislabs/oasis-core/go/consensus/api"
Expand Down Expand Up @@ -113,7 +114,11 @@ func doInfo(cmd *cobra.Command, args []string) {
api.KindCompute,
api.KindStorage,
}
thresholds := make(map[api.ThresholdKind]*quantity.Quantity)
type threshold struct {
value *quantity.Quantity
valid bool
}
thresholds := make(map[api.ThresholdKind]*threshold)
doWithRetries(cmd, "query staking threshold(s)", func() error {
for _, k := range thresholdsToQuery {
if thresholds[k] != nil {
Expand All @@ -122,14 +127,25 @@ func doInfo(cmd *cobra.Command, args []string) {

q, err := client.Threshold(ctx, &api.ThresholdQuery{Kind: k, Height: consensus.HeightLatest})
if err != nil {
if errors.Is(err, api.ErrInvalidThreshold) {
logger.Warn(fmt.Sprintf("invalid staking threshold kind: %s", k))
thresholds[k] = &threshold{}
continue
}
return err
}
thresholds[k] = q
thresholds[k] = &threshold{
value: q,
valid: true,
}
}
return nil
})
for _, k := range thresholdsToQuery {
fmt.Printf("Staking threshold (%s): %v\n", k, thresholds[k])
thres := thresholds[k]
if thres.valid {
fmt.Printf("Staking threshold (%s): %v\n", k, thres.value)
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions go/oasis-test-runner/scenario/e2e/stake_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (s *stakeCLIImpl) Run(childEnv *env.Env) error {

cli := cli.New(childEnv, s.net, s.logger)

// General token info.
if err := s.getInfo(childEnv); err != nil {
return err
}

// Account list.
accounts, err := s.listAccounts(childEnv)
if err != nil {
Expand Down Expand Up @@ -333,6 +338,28 @@ func (s *stakeCLIImpl) testAmendCommissionSchedule(childEnv *env.Env, cli *cli.H
return nil
}

func (s *stakeCLIImpl) getInfo(childEnv *env.Env) error {
s.logger.Info("querying common token info")
args := []string{
"stake", "info",
"--" + grpc.CfgAddress, "unix:" + s.basicImpl.net.Validators()[0].SocketPath(),
}

b, err := cli.RunSubCommandWithOutput(childEnv, s.logger, "info", s.basicImpl.net.Config().NodeBinary, args)
if err != nil {
return fmt.Errorf("scenario/e2e/stake: failed to query common token info: %s error: %w", b.String(), err)
}
// Check that subcommand reported warnings for invalid staking threshold kinds.
subCmdOutput := b.String()
thresholdKinds := []string{"compute", "storage"}
for _, kind := range thresholdKinds {
if !strings.Contains(subCmdOutput, fmt.Sprintf("invalid staking threshold kind: %s", kind)) {
return fmt.Errorf("scenario/e2e/stake: querying common token info should warn about invalid staking threshold for kind: %s", kind)
}
}
return nil
}

func (s *stakeCLIImpl) listAccounts(childEnv *env.Env) ([]signature.PublicKey, error) {
s.logger.Info("listing all accounts")
args := []string{
Expand Down
4 changes: 4 additions & 0 deletions tests/fixture-data/stake-cli/staking-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"rate_bound_lead": 30,
"max_rate_steps": 4,
"max_bound_steps": 12
},
"thresholds": {
"0": "0",
"1": "0"
}
}
}

0 comments on commit 255b2f8

Please sign in to comment.