@agoric/cosmos 0.34.2-dev-a29afed.0.a29afed → 0.34.2-dev-cb1866d.0.cb1866d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,6 @@ package types
2
2
 
3
3
  import (
4
4
  "bytes"
5
- "math"
6
5
  "testing"
7
6
 
8
7
  "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
@@ -120,6 +119,16 @@ func TestInstallBundle_ValidateBasic(t *testing.T) {
120
119
  UncompressedSize: 4,
121
120
  },
122
121
  },
122
+ {
123
+ name: "compressed with empty chunked artifact",
124
+ msg: &MsgInstallBundle{
125
+ Submitter: addr,
126
+ CompressedBundle: []byte{1, 2, 3},
127
+ UncompressedSize: 4,
128
+ ChunkedArtifact: &ChunkedArtifact{},
129
+ },
130
+ shouldErr: true,
131
+ },
123
132
  {
124
133
  name: "both",
125
134
  msg: &MsgInstallBundle{
@@ -151,28 +160,9 @@ func TestInstallBundle_ValidateBasic(t *testing.T) {
151
160
  msg: &MsgInstallBundle{
152
161
  Submitter: addr,
153
162
  CompressedBundle: []byte{1, 2, 3},
154
- UncompressedSize: bundleUncompressedSizeLimit - 1,
163
+ UncompressedSize: int64(DefaultBundleUncompressedSizeLimitBytes - 1),
155
164
  },
156
165
  },
157
-
158
- {
159
- name: "limit",
160
- msg: &MsgInstallBundle{
161
- Submitter: addr,
162
- CompressedBundle: []byte{1, 2, 3},
163
- UncompressedSize: bundleUncompressedSizeLimit,
164
- },
165
- shouldErr: true,
166
- },
167
- {
168
- name: "max",
169
- msg: &MsgInstallBundle{
170
- Submitter: addr,
171
- CompressedBundle: []byte{1, 2, 3},
172
- UncompressedSize: math.MaxInt64,
173
- },
174
- shouldErr: true,
175
- },
176
166
  } {
177
167
  t.Run(tt.name, func(t *testing.T) {
178
168
  err := tt.msg.ValidateBasic()
@@ -12,12 +12,14 @@ import (
12
12
 
13
13
  // Parameter keys
14
14
  var (
15
- ParamStoreKeyBeansPerUnit = []byte("beans_per_unit")
16
- ParamStoreKeyBootstrapVatConfig = []byte("bootstrap_vat_config")
17
- ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
18
- ParamStoreKeyPowerFlagFees = []byte("power_flag_fees")
19
- ParamStoreKeyQueueMax = []byte("queue_max")
20
- ParamStoreKeyVatCleanupBudget = []byte("vat_cleanup_budget")
15
+ ParamStoreKeyBeansPerUnit = []byte("beans_per_unit")
16
+ ParamStoreKeyBootstrapVatConfig = []byte("bootstrap_vat_config")
17
+ ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
18
+ ParamStoreKeyPowerFlagFees = []byte("power_flag_fees")
19
+ ParamStoreKeyQueueMax = []byte("queue_max")
20
+ ParamStoreKeyVatCleanupBudget = []byte("vat_cleanup_budget")
21
+ ParamStoreKeyBundleUncompressedSizeLimitBytes = []byte("bundle_uncompressed_size_limit_bytes")
22
+ ParamStoreKeyChunkSizeLimitBytes = []byte("chunk_size_limit_bytes")
21
23
  )
22
24
 
23
25
  func NewStringBeans(key string, beans sdkmath.Uint) StringBeans {
@@ -49,12 +51,14 @@ func ParamKeyTable() paramtypes.KeyTable {
49
51
  // DefaultParams returns default swingset parameters
50
52
  func DefaultParams() Params {
51
53
  return Params{
52
- BeansPerUnit: DefaultBeansPerUnit(),
53
- BootstrapVatConfig: DefaultBootstrapVatConfig,
54
- FeeUnitPrice: DefaultFeeUnitPrice,
55
- PowerFlagFees: DefaultPowerFlagFees,
56
- QueueMax: DefaultQueueMax,
57
- VatCleanupBudget: DefaultVatCleanupBudget,
54
+ BeansPerUnit: DefaultBeansPerUnit(),
55
+ BootstrapVatConfig: DefaultBootstrapVatConfig,
56
+ FeeUnitPrice: DefaultFeeUnitPrice,
57
+ PowerFlagFees: DefaultPowerFlagFees,
58
+ QueueMax: DefaultQueueMax,
59
+ VatCleanupBudget: DefaultVatCleanupBudget,
60
+ BundleUncompressedSizeLimitBytes: DefaultBundleUncompressedSizeLimitBytes,
61
+ ChunkSizeLimitBytes: DefaultChunkSizeLimitBytes,
58
62
  }
59
63
  }
60
64
 
@@ -72,6 +76,8 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
72
76
  paramtypes.NewParamSetPair(ParamStoreKeyPowerFlagFees, &p.PowerFlagFees, validatePowerFlagFees),
73
77
  paramtypes.NewParamSetPair(ParamStoreKeyQueueMax, &p.QueueMax, validateQueueMax),
74
78
  paramtypes.NewParamSetPair(ParamStoreKeyVatCleanupBudget, &p.VatCleanupBudget, validateVatCleanupBudget),
79
+ paramtypes.NewParamSetPair(ParamStoreKeyBundleUncompressedSizeLimitBytes, &p.BundleUncompressedSizeLimitBytes, validateBundleUncompressedSizeLimitBytes),
80
+ paramtypes.NewParamSetPair(ParamStoreKeyChunkSizeLimitBytes, &p.ChunkSizeLimitBytes, validateChunkSizeLimitBytes),
75
81
  }
76
82
  }
77
83
 
@@ -95,6 +101,12 @@ func (p Params) ValidateBasic() error {
95
101
  if err := validateVatCleanupBudget(p.VatCleanupBudget); err != nil {
96
102
  return err
97
103
  }
104
+ if err := validateBundleUncompressedSizeLimitBytes(p.BundleUncompressedSizeLimitBytes); err != nil {
105
+ return err
106
+ }
107
+ if err := validateChunkSizeLimitBytes(p.ChunkSizeLimitBytes); err != nil {
108
+ return err
109
+ }
98
110
 
99
111
  return nil
100
112
  }
@@ -189,10 +201,33 @@ func validateVatCleanupBudget(i interface{}) error {
189
201
  return nil
190
202
  }
191
203
 
204
+ func validateBundleUncompressedSizeLimitBytes(i interface{}) error {
205
+ if value, ok := i.(int64); !ok {
206
+ return fmt.Errorf("bundle_uncompressed_size_limit_bytes must be int64, got %#v", i)
207
+ } else if value <= 0 {
208
+ return fmt.Errorf("bundle_uncompressed_size_limit_bytes must be positive (>0), got %d", value)
209
+ }
210
+ return nil
211
+ }
212
+
213
+ func validateChunkSizeLimitBytes(i interface{}) error {
214
+ if value, ok := i.(int64); !ok {
215
+ return fmt.Errorf("chunk_size_limit_bytes must be int64, got %#v", i)
216
+ } else if value <= 0 {
217
+ return fmt.Errorf("chunk_size_limit_bytes must be positive (>0), got %d", value)
218
+ }
219
+ return nil
220
+ }
221
+
192
222
  // UpdateParams appends any missing params, configuring them to their defaults,
193
- // then returning the updated params or an error. Existing params are not
223
+ // then returning the updated params or an error.
224
+ // Existing params are not
194
225
  // modified, regardless of their value, and they are not removed if they no
195
226
  // longer appear in the defaults.
227
+ // UpdateParams appends missing entries and fills defaults. Note that
228
+ // InstallationDeadlineBlocks and InstallationDeadlineSeconds treat 0 as
229
+ // "unset" and will be replaced with DefaultInstallationDeadlineBlocks and
230
+ // DefaultInstallationDeadlineSeconds, respectively.
196
231
  func UpdateParams(params Params) (Params, error) {
197
232
  newBpu, err := appendMissingDefaults(params.BeansPerUnit, DefaultBeansPerUnit())
198
233
  if err != nil {
@@ -215,6 +250,21 @@ func UpdateParams(params Params) (Params, error) {
215
250
  params.PowerFlagFees = newPff
216
251
  params.QueueMax = newQm
217
252
  params.VatCleanupBudget = newVcb
253
+
254
+ // 0 is treated as unset for these fields.
255
+ if params.InstallationDeadlineBlocks == 0 {
256
+ params.InstallationDeadlineBlocks = DefaultInstallationDeadlineBlocks
257
+ }
258
+ if params.InstallationDeadlineSeconds == 0 {
259
+ params.InstallationDeadlineSeconds = DefaultInstallationDeadlineSeconds
260
+ }
261
+ if params.BundleUncompressedSizeLimitBytes == 0 {
262
+ params.BundleUncompressedSizeLimitBytes = DefaultBundleUncompressedSizeLimitBytes
263
+ }
264
+ if params.ChunkSizeLimitBytes == 0 {
265
+ params.ChunkSizeLimitBytes = DefaultChunkSizeLimitBytes
266
+ }
267
+
218
268
  return params, nil
219
269
  }
220
270
 
@@ -101,12 +101,16 @@ func TestUpdateParamsFromEmpty(t *testing.T) {
101
101
  VatCleanupBudget: nil,
102
102
  }
103
103
  want := Params{
104
- BeansPerUnit: DefaultBeansPerUnit(),
105
- BootstrapVatConfig: "",
106
- FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
107
- PowerFlagFees: DefaultPowerFlagFees,
108
- QueueMax: DefaultQueueMax,
109
- VatCleanupBudget: DefaultVatCleanupBudget,
104
+ BeansPerUnit: DefaultBeansPerUnit(),
105
+ BootstrapVatConfig: "",
106
+ FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
107
+ PowerFlagFees: DefaultPowerFlagFees,
108
+ QueueMax: DefaultQueueMax,
109
+ VatCleanupBudget: DefaultVatCleanupBudget,
110
+ InstallationDeadlineBlocks: DefaultInstallationDeadlineBlocks,
111
+ InstallationDeadlineSeconds: DefaultInstallationDeadlineSeconds,
112
+ BundleUncompressedSizeLimitBytes: DefaultBundleUncompressedSizeLimitBytes,
113
+ ChunkSizeLimitBytes: DefaultChunkSizeLimitBytes,
110
114
  }
111
115
  got, err := UpdateParams(in)
112
116
  if err != nil {
@@ -124,20 +128,26 @@ func TestUpdateParamsFromExisting(t *testing.T) {
124
128
  customQueueSize := NewQueueSize("qux", int32(3))
125
129
  customVatCleanup := UintMapEntry{"corge", sdkmath.NewUint(4)}
126
130
  in := Params{
127
- BeansPerUnit: append([]StringBeans{customBeansPerUnit}, defaultBeansPerUnit[2:4]...),
128
- BootstrapVatConfig: "",
129
- FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
130
- PowerFlagFees: []PowerFlagFee{customPowerFlagFee},
131
- QueueMax: []QueueSize{NewQueueSize(QueueInbound, int32(10)), customQueueSize},
132
- VatCleanupBudget: []UintMapEntry{customVatCleanup, UintMapEntry{VatCleanupDefault, sdkmath.NewUint(10)}},
131
+ BeansPerUnit: append([]StringBeans{customBeansPerUnit}, defaultBeansPerUnit[2:4]...),
132
+ BootstrapVatConfig: "",
133
+ FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
134
+ PowerFlagFees: []PowerFlagFee{customPowerFlagFee},
135
+ QueueMax: []QueueSize{NewQueueSize(QueueInbound, int32(10)), customQueueSize},
136
+ VatCleanupBudget: []UintMapEntry{customVatCleanup, UintMapEntry{VatCleanupDefault, sdkmath.NewUint(10)}},
137
+ InstallationDeadlineBlocks: 300,
138
+ InstallationDeadlineSeconds: -1,
133
139
  }
134
140
  want := Params{
135
- BeansPerUnit: append(append(in.BeansPerUnit, defaultBeansPerUnit[0:2]...), defaultBeansPerUnit[4:]...),
136
- BootstrapVatConfig: in.BootstrapVatConfig,
137
- FeeUnitPrice: in.FeeUnitPrice,
138
- PowerFlagFees: append(in.PowerFlagFees, DefaultPowerFlagFees...),
139
- QueueMax: in.QueueMax,
140
- VatCleanupBudget: append(in.VatCleanupBudget, DefaultVatCleanupBudget[1:]...),
141
+ BeansPerUnit: append(append(in.BeansPerUnit, defaultBeansPerUnit[0:2]...), defaultBeansPerUnit[4:]...),
142
+ BootstrapVatConfig: in.BootstrapVatConfig,
143
+ FeeUnitPrice: in.FeeUnitPrice,
144
+ PowerFlagFees: append(in.PowerFlagFees, DefaultPowerFlagFees...),
145
+ QueueMax: in.QueueMax,
146
+ VatCleanupBudget: append(in.VatCleanupBudget, DefaultVatCleanupBudget[1:]...),
147
+ InstallationDeadlineBlocks: in.InstallationDeadlineBlocks,
148
+ InstallationDeadlineSeconds: in.InstallationDeadlineSeconds,
149
+ BundleUncompressedSizeLimitBytes: DefaultBundleUncompressedSizeLimitBytes,
150
+ ChunkSizeLimitBytes: DefaultChunkSizeLimitBytes,
141
151
  }
142
152
  got, err := UpdateParams(in)
143
153
  if err != nil {
@@ -148,15 +158,35 @@ func TestUpdateParamsFromExisting(t *testing.T) {
148
158
  }
149
159
  }
150
160
 
151
- func TestValidateParams(t *testing.T) {
152
- params := Params{
153
- BeansPerUnit: DefaultBeansPerUnit(),
154
- BootstrapVatConfig: "foo",
155
- FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
156
- PowerFlagFees: DefaultPowerFlagFees,
157
- QueueMax: DefaultQueueMax,
158
- VatCleanupBudget: DefaultVatCleanupBudget,
161
+ func TestUpdateParamsTreatsZeroDeadlinesAsUnset(t *testing.T) {
162
+ in := DefaultParams()
163
+ in.InstallationDeadlineBlocks = 0
164
+ in.InstallationDeadlineSeconds = 0
165
+
166
+ got, err := UpdateParams(in)
167
+ if err != nil {
168
+ t.Fatalf("UpdateParam error %v", err)
169
+ }
170
+ if got.InstallationDeadlineBlocks != DefaultInstallationDeadlineBlocks {
171
+ t.Fatalf(
172
+ "expected InstallationDeadlineBlocks to default when set to 0: got %d, want %d",
173
+ got.InstallationDeadlineBlocks,
174
+ DefaultInstallationDeadlineBlocks,
175
+ )
176
+ }
177
+ if got.InstallationDeadlineSeconds != DefaultInstallationDeadlineSeconds {
178
+ t.Fatalf(
179
+ "expected InstallationDeadlineSeconds to default when set to 0: got %d, want %d",
180
+ got.InstallationDeadlineSeconds,
181
+ DefaultInstallationDeadlineSeconds,
182
+ )
159
183
  }
184
+ }
185
+
186
+ func TestValidateParams(t *testing.T) {
187
+ params := DefaultParams()
188
+ params.BootstrapVatConfig = "foo"
189
+ params.FeeUnitPrice = sdk.NewCoins(sdk.NewInt64Coin("denom", 789))
160
190
  err := params.ValidateBasic()
161
191
  if err != nil {
162
192
  t.Errorf("unexpected ValidateBasic() error with default params: %v", err)