diff --git a/.changelog/2633.bugfix.md b/.changelog/2633.bugfix.md new file mode 100644 index 00000000000..c7207a00000 --- /dev/null +++ b/.changelog/2633.bugfix.md @@ -0,0 +1 @@ +go/staking/api: Check if thresholds for all kinds are defined in genesis. diff --git a/go/oasis-test-runner/scenario/e2e/stake_cli.go b/go/oasis-test-runner/scenario/e2e/stake_cli.go index 0f802e0a089..5fe15d01b04 100644 --- a/go/oasis-test-runner/scenario/e2e/stake_cli.go +++ b/go/oasis-test-runner/scenario/e2e/stake_cli.go @@ -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 } diff --git a/go/staking/api/sanity_check.go b/go/staking/api/sanity_check.go index 397f799d42d..664cc0151c7 100644 --- a/go/staking/api/sanity_check.go +++ b/go/staking/api/sanity_check.go @@ -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) } } diff --git a/tests/fixture-data/stake-cli/staking-genesis.json b/tests/fixture-data/stake-cli/staking-genesis.json index 7bd53497a4b..1fc49770776 100644 --- a/tests/fixture-data/stake-cli/staking-genesis.json +++ b/tests/fixture-data/stake-cli/staking-genesis.json @@ -8,7 +8,9 @@ }, "thresholds": { "0": "0", - "1": "0" + "1": "0", + "2": "0", + "3": "0" } } }