diff --git a/golang/cosmos/x/swingset/types/params.go b/golang/cosmos/x/swingset/types/params.go index 30b12d19be3..9b53ae58fbf 100644 --- a/golang/cosmos/x/swingset/types/params.go +++ b/golang/cosmos/x/swingset/types/params.go @@ -172,10 +172,20 @@ func validateQueueMax(i interface{}) error { } func validateVatCleanupBudget(i interface{}) error { - _, ok := i.([]UintMapEntry) + entries, ok := i.([]UintMapEntry) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } + hasDefault := false + for _, entry := range entries { + if entry.Key == VatCleanupDefault { + hasDefault = true + break + } + } + if len(entries) > 0 && !hasDefault { + return fmt.Errorf("`default` must be present in a non-empty vat cleanup budget") + } return nil } diff --git a/golang/cosmos/x/swingset/types/params_test.go b/golang/cosmos/x/swingset/types/params_test.go index b43e08351f3..ff3a7cbe149 100644 --- a/golang/cosmos/x/swingset/types/params_test.go +++ b/golang/cosmos/x/swingset/types/params_test.go @@ -146,3 +146,37 @@ func TestUpdateParamsFromExisting(t *testing.T) { t.Errorf("GOT\n%v\nWANTED\n%v", got, want) } } + +func TestValidateParams(t *testing.T) { + params := Params{ + BeansPerUnit: DefaultBeansPerUnit(), + BootstrapVatConfig: "foo", + FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)), + PowerFlagFees: DefaultPowerFlagFees, + QueueMax: DefaultQueueMax, + VatCleanupBudget: DefaultVatCleanupBudget, + } + err := params.ValidateBasic() + if err != nil { + t.Errorf("unexpected ValidateBasic() error with default params: %v", err) + } + + customVatCleanup := UintMapEntry{"corge", sdk.NewUint(4)} + params.VatCleanupBudget = append(params.VatCleanupBudget, customVatCleanup) + err = params.ValidateBasic() + if err != nil { + t.Errorf("unexpected ValidateBasic() error with extended params: %v", err) + } + + params.VatCleanupBudget = params.VatCleanupBudget[1:] + err = params.ValidateBasic() + if err == nil { + t.Errorf("ValidateBasic() failed to reject VatCleanupBudget with missing `default` %v", params.VatCleanupBudget) + } + + params.VatCleanupBudget = []UintMapEntry{} + err = params.ValidateBasic() + if err != nil { + t.Errorf("unexpected ValidateBasic() error with empty VatCleanupBudget: %v", params.VatCleanupBudget) + } +}