|
1 | 1 | package types |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "reflect" |
5 | 6 | "testing" |
6 | 7 |
|
@@ -211,3 +212,64 @@ func TestValidateParams(t *testing.T) { |
211 | 212 | t.Errorf("unexpected ValidateBasic() error with empty VatCleanupBudget: %v", params.VatCleanupBudget) |
212 | 213 | } |
213 | 214 | } |
| 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