Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/staking/api: Check if thresholds for all kinds are defined in genesis #2633

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}