Skip to content

Commit 76254e2

Browse files
michaelfigcodex
authored andcommitted
fix(cosmos): validate installation deadline params
Co-authored-by: Codex <codex@openai.com>
1 parent 4f7223c commit 76254e2

2 files changed

Lines changed: 84 additions & 4 deletions

File tree

golang/cosmos/x/swingset/types/params.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func (p Params) ValidateBasic() error {
107107
if err := validateVatCleanupBudget(p.VatCleanupBudget); err != nil {
108108
return err
109109
}
110+
if err := validateInstallationDeadlineBlocks(p.InstallationDeadlineBlocks); err != nil {
111+
return err
112+
}
113+
if err := validateInstallationDeadlineSeconds(p.InstallationDeadlineSeconds); err != nil {
114+
return err
115+
}
110116
if err := validateBundleUncompressedSizeLimitBytes(p.BundleUncompressedSizeLimitBytes); err != nil {
111117
return err
112118
}
@@ -226,18 +232,30 @@ func validateChunkSizeLimitBytes(i interface{}) error {
226232
}
227233

228234
func validateInstallationDeadlineSeconds(i interface{}) error {
229-
if _, ok := i.(int64); !ok {
235+
value, ok := i.(int64)
236+
if !ok {
230237
return fmt.Errorf("installation_deadline_seconds must be int64, got %#v", i)
231238
}
232-
// -1 means unlimited, 0 means expire immediately, positive is a duration.
239+
if value < -1 {
240+
return fmt.Errorf(
241+
"installation_deadline_seconds must be -1 (unlimited), 0 (expire immediately), or positive, got %d",
242+
value,
243+
)
244+
}
233245
return nil
234246
}
235247

236248
func validateInstallationDeadlineBlocks(i interface{}) error {
237-
if _, ok := i.(int64); !ok {
249+
value, ok := i.(int64)
250+
if !ok {
238251
return fmt.Errorf("installation_deadline_blocks must be int64, got %#v", i)
239252
}
240-
// -1 means unlimited, 0 means expire immediately, positive is a block count.
253+
if value < -1 {
254+
return fmt.Errorf(
255+
"installation_deadline_blocks must be -1 (unlimited), 0 (expire immediately), or positive, got %d",
256+
value,
257+
)
258+
}
241259
return nil
242260
}
243261

golang/cosmos/x/swingset/types/params_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
import (
4+
"strings"
45
"reflect"
56
"testing"
67

@@ -211,3 +212,64 @@ func TestValidateParams(t *testing.T) {
211212
t.Errorf("unexpected ValidateBasic() error with empty VatCleanupBudget: %v", params.VatCleanupBudget)
212213
}
213214
}
215+
216+
func TestValidateInstallationDeadlineBounds(t *testing.T) {
217+
const minInt64 int64 = -1 << 63
218+
219+
for _, tc := range []struct {
220+
name string
221+
seconds int64
222+
blocks int64
223+
wantErrSubstr string
224+
}{
225+
{name: "both unlimited", seconds: -1, blocks: -1},
226+
{name: "both immediate", seconds: 0, blocks: 0},
227+
{name: "both positive", seconds: 1, blocks: 1},
228+
{
229+
name: "seconds below minimum",
230+
seconds: -2,
231+
blocks: -1,
232+
wantErrSubstr: "installation_deadline_seconds must be -1 (unlimited), 0 (expire immediately), or positive, got -2",
233+
},
234+
{
235+
name: "blocks below minimum",
236+
seconds: -1,
237+
blocks: -2,
238+
wantErrSubstr: "installation_deadline_blocks must be -1 (unlimited), 0 (expire immediately), or positive, got -2",
239+
},
240+
{
241+
name: "seconds at int64 minimum",
242+
seconds: minInt64,
243+
blocks: -1,
244+
wantErrSubstr: "installation_deadline_seconds must be -1 (unlimited), 0 (expire immediately), or positive, got -9223372036854775808",
245+
},
246+
{
247+
name: "blocks at int64 minimum",
248+
seconds: -1,
249+
blocks: minInt64,
250+
wantErrSubstr: "installation_deadline_blocks must be -1 (unlimited), 0 (expire immediately), or positive, got -9223372036854775808",
251+
},
252+
} {
253+
t.Run(tc.name, func(t *testing.T) {
254+
params := DefaultParams()
255+
params.BootstrapVatConfig = "foo"
256+
params.FeeUnitPrice = sdk.NewCoins(sdk.NewInt64Coin("denom", 789))
257+
params.InstallationDeadlineSeconds = tc.seconds
258+
params.InstallationDeadlineBlocks = tc.blocks
259+
260+
err := params.ValidateBasic()
261+
if tc.wantErrSubstr == "" {
262+
if err != nil {
263+
t.Fatalf("unexpected ValidateBasic() error: %v", err)
264+
}
265+
return
266+
}
267+
if err == nil {
268+
t.Fatal("expected ValidateBasic() error, got nil")
269+
}
270+
if !strings.Contains(err.Error(), tc.wantErrSubstr) {
271+
t.Fatalf("expected error containing %q, got %q", tc.wantErrSubstr, err)
272+
}
273+
})
274+
}
275+
}

0 commit comments

Comments
 (0)