Skip to content

Commit

Permalink
go/staking/api: Check if thresholds for all kinds are defined in genesis
Browse files Browse the repository at this point in the history
Update stake-cli End-to-End test use a valid staking genesis document
and omit the invalid staking threshold kind warnings check from the info
subcommand.
  • Loading branch information
tjanez committed Feb 3, 2020
1 parent d1489f8 commit 3314d0c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/2633.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/staking/api: Check if thresholds for all kinds are defined in genesis.
8 changes: 0 additions & 8 deletions go/oasis-test-runner/scenario/e2e/stake_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,6 @@ func (s *stakeCLIImpl) getInfo(childEnv *env.Env) error {
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
}

Expand Down
8 changes: 6 additions & 2 deletions go/staking/api/sanity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ func SanityCheckAccountShares(acct *Account, delegations map[signature.PublicKey

// SanityCheck does basic sanity checking on the genesis state.
func (g *Genesis) SanityCheck(now epochtime.EpochTime) error { // nolint: gocyclo
for thr, val := range g.Parameters.Thresholds {
for kind := KindEntity; kind <= KindMax; kind++ {
val, ok := g.Parameters.Thresholds[kind]
if !ok {
return fmt.Errorf("staking: sanity check failed: threshold for kind '%s' not defined", kind)
}
if !val.IsValid() {
return fmt.Errorf("staking: sanity check failed: threshold '%s' has invalid value", thr.String())
return fmt.Errorf("staking: sanity check failed: threshold '%s' has invalid value", kind)
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/fixture-data/stake-cli/staking-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"thresholds": {
"0": "0",
"1": "0"
"1": "0",
"2": "0",
"3": "0"
}
}
}

0 comments on commit 3314d0c

Please sign in to comment.