@agoric/cosmos 0.35.0-u18.4 → 0.35.0-u18.5
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.
- package/CHANGELOG.md +26 -0
- package/ante/inbound_test.go +2 -2
- package/app/app.go +25 -8
- package/app/upgrade.go +106 -7
- package/daemon/cmd/root.go +48 -15
- package/git-revision.txt +1 -1
- package/go.mod +1 -1
- package/go.sum +2 -2
- package/package.json +2 -2
- package/proto/agoric/swingset/swingset.proto +25 -0
- package/proto/agoric/vbank/vbank.proto +7 -0
- package/types/address_hooks.go +213 -0
- package/types/address_hooks_test.go +218 -0
- package/x/swingset/genesis.go +99 -21
- package/x/swingset/keeper/keeper.go +16 -7
- package/x/swingset/module.go +17 -2
- package/x/swingset/types/default-params.go +31 -5
- package/x/swingset/types/expected_keepers.go +2 -2
- package/x/swingset/types/msgs.go +34 -12
- package/x/swingset/types/params.go +53 -43
- package/x/swingset/types/params_test.go +75 -9
- package/x/swingset/types/swingset.pb.go +386 -56
- package/x/vbank/README.md +6 -1
- package/x/vbank/keeper/keeper.go +4 -9
- package/x/vbank/keeper/migrations.go +30 -0
- package/x/vbank/module.go +8 -2
- package/x/vbank/types/params.go +43 -2
- package/x/vbank/types/vbank.pb.go +105 -36
- package/x/vbank/vbank_test.go +12 -7
- package/x/vstorage/testing/queue.go +4 -3
- package/x/vtransfer/ibc_middleware_test.go +7 -3
- package/x/vtransfer/keeper/keeper.go +40 -38
- package/x/vtransfer/types/genesis.pb.go +1 -0
|
@@ -22,13 +22,23 @@ const (
|
|
|
22
22
|
BeansPerXsnapComputron = "xsnapComputron"
|
|
23
23
|
BeansPerSmartWalletProvision = "smartWalletProvision"
|
|
24
24
|
|
|
25
|
+
// PowerFlags.
|
|
26
|
+
PowerFlagSmartWallet = "SMART_WALLET"
|
|
27
|
+
|
|
25
28
|
// QueueSize keys.
|
|
26
|
-
// Keep up-to-date with updateQueueAllowed() in
|
|
29
|
+
// Keep up-to-date with updateQueueAllowed() in packages/cosmic-swingset/src/launch-chain.js
|
|
27
30
|
QueueInbound = "inbound"
|
|
28
31
|
QueueInboundMempool = "inbound_mempool"
|
|
29
32
|
|
|
30
|
-
//
|
|
31
|
-
|
|
33
|
+
// Vat cleanup budget keys.
|
|
34
|
+
// Keep up-to-date with CleanupBudget in packages/cosmic-swingset/src/launch-chain.js
|
|
35
|
+
VatCleanupDefault = "default"
|
|
36
|
+
VatCleanupExports = "exports"
|
|
37
|
+
VatCleanupImports = "imports"
|
|
38
|
+
VatCleanupPromises = "promises"
|
|
39
|
+
VatCleanupKv = "kv"
|
|
40
|
+
VatCleanupSnapshots = "snapshots"
|
|
41
|
+
VatCleanupTranscripts = "transcripts"
|
|
32
42
|
)
|
|
33
43
|
|
|
34
44
|
var (
|
|
@@ -62,10 +72,26 @@ var (
|
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
DefaultInboundQueueMax = int32(1_000)
|
|
65
|
-
|
|
66
|
-
DefaultQueueMax = []QueueSize{
|
|
75
|
+
DefaultQueueMax = []QueueSize{
|
|
67
76
|
NewQueueSize(QueueInbound, DefaultInboundQueueMax),
|
|
68
77
|
}
|
|
78
|
+
|
|
79
|
+
DefaultVatCleanupDefault = sdk.NewUint(5)
|
|
80
|
+
// DefaultVatCleanupExports = DefaultVatCleanupDefault
|
|
81
|
+
// DefaultVatCleanupImports = DefaultVatCleanupDefault
|
|
82
|
+
// DefaultVatCleanupPromises = DefaultVatCleanupDefault
|
|
83
|
+
DefaultVatCleanupKv = sdk.NewUint(50)
|
|
84
|
+
// DefaultVatCleanupSnapshots = DefaultVatCleanupDefault
|
|
85
|
+
// DefaultVatCleanupTranscripts = DefaultVatCleanupDefault
|
|
86
|
+
DefaultVatCleanupBudget = []UintMapEntry{
|
|
87
|
+
UintMapEntry{VatCleanupDefault, DefaultVatCleanupDefault},
|
|
88
|
+
// UintMapEntry{VatCleanupExports, DefaultVatCleanupExports},
|
|
89
|
+
// UintMapEntry{VatCleanupImports, DefaultVatCleanupImports},
|
|
90
|
+
// UintMapEntry{VatCleanupPromises, DefaultVatCleanupPromises},
|
|
91
|
+
UintMapEntry{VatCleanupKv, DefaultVatCleanupKv},
|
|
92
|
+
// UintMapEntry{VatCleanupSnapshots, DefaultVatCleanupSnapshots},
|
|
93
|
+
// UintMapEntry{VatCleanupTranscripts, DefaultVatCleanupTranscripts},
|
|
94
|
+
}
|
|
69
95
|
)
|
|
70
96
|
|
|
71
97
|
// move DefaultBeansPerUnit to a function to allow for boot overriding of the Default params
|
|
@@ -23,8 +23,8 @@ type AccountKeeper interface {
|
|
|
23
23
|
|
|
24
24
|
type SwingSetKeeper interface {
|
|
25
25
|
GetBeansPerUnit(ctx sdk.Context) map[string]sdkmath.Uint
|
|
26
|
-
ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) error
|
|
26
|
+
ChargeBeans(ctx sdk.Context, beansPerUnit map[string]sdkmath.Uint, addr sdk.AccAddress, beans sdkmath.Uint) error
|
|
27
27
|
IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (bool, error)
|
|
28
28
|
GetSmartWalletState(ctx sdk.Context, addr sdk.AccAddress) SmartWalletState
|
|
29
|
-
ChargeForSmartWallet(ctx sdk.Context, addr sdk.AccAddress) error
|
|
29
|
+
ChargeForSmartWallet(ctx sdk.Context, beansPerUnit map[string]sdkmath.Uint, addr sdk.AccAddress) error
|
|
30
30
|
}
|
package/x/swingset/types/msgs.go
CHANGED
|
@@ -8,9 +8,12 @@ import (
|
|
|
8
8
|
"strings"
|
|
9
9
|
|
|
10
10
|
sdkioerrors "cosmossdk.io/errors"
|
|
11
|
-
"
|
|
11
|
+
sdkmath "cosmossdk.io/math"
|
|
12
|
+
|
|
12
13
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
14
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
15
|
+
|
|
16
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
14
17
|
)
|
|
15
18
|
|
|
16
19
|
const RouterKey = ModuleName // this was defined in your key.go file
|
|
@@ -56,16 +59,26 @@ const (
|
|
|
56
59
|
|
|
57
60
|
// Charge an account address for the beans associated with given messages and storage.
|
|
58
61
|
// See list of bean charges in default-params.go
|
|
59
|
-
func chargeAdmission(
|
|
60
|
-
|
|
62
|
+
func chargeAdmission(
|
|
63
|
+
ctx sdk.Context,
|
|
64
|
+
keeper SwingSetKeeper,
|
|
65
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
66
|
+
addr sdk.AccAddress,
|
|
67
|
+
msgs []string,
|
|
68
|
+
storageLen uint64,
|
|
69
|
+
) error {
|
|
70
|
+
// A flat charge for each transaction.
|
|
61
71
|
beans := beansPerUnit[BeansPerInboundTx]
|
|
72
|
+
// A charge for each message in the transaction.
|
|
62
73
|
beans = beans.Add(beansPerUnit[BeansPerMessage].MulUint64((uint64(len(msgs)))))
|
|
74
|
+
// A charge for the total byte length of all messages.
|
|
63
75
|
for _, msg := range msgs {
|
|
64
76
|
beans = beans.Add(beansPerUnit[BeansPerMessageByte].MulUint64(uint64(len(msg))))
|
|
65
77
|
}
|
|
78
|
+
// A charge for persistent storage.
|
|
66
79
|
beans = beans.Add(beansPerUnit[BeansPerStorageByte].MulUint64(storageLen))
|
|
67
80
|
|
|
68
|
-
return keeper.ChargeBeans(ctx, addr, beans)
|
|
81
|
+
return keeper.ChargeBeans(ctx, beansPerUnit, addr, beans)
|
|
69
82
|
}
|
|
70
83
|
|
|
71
84
|
// checkSmartWalletProvisioned verifies if a smart wallet message (MsgWalletAction
|
|
@@ -74,7 +87,12 @@ func chargeAdmission(ctx sdk.Context, keeper SwingSetKeeper, addr sdk.AccAddress
|
|
|
74
87
|
// provisioning fee is charged successfully.
|
|
75
88
|
// All messages for non-provisioned smart wallets allowed here will result in
|
|
76
89
|
// an auto-provision action generated by the msg server.
|
|
77
|
-
func checkSmartWalletProvisioned(
|
|
90
|
+
func checkSmartWalletProvisioned(
|
|
91
|
+
ctx sdk.Context,
|
|
92
|
+
keeper SwingSetKeeper,
|
|
93
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
94
|
+
addr sdk.AccAddress,
|
|
95
|
+
) error {
|
|
78
96
|
walletState := keeper.GetSmartWalletState(ctx, addr)
|
|
79
97
|
|
|
80
98
|
switch walletState {
|
|
@@ -91,7 +109,7 @@ func checkSmartWalletProvisioned(ctx sdk.Context, keeper SwingSetKeeper, addr sd
|
|
|
91
109
|
// This is a separate charge from the smart wallet action which triggered the check
|
|
92
110
|
// TODO: Currently this call does not mark the smart wallet provisioning as
|
|
93
111
|
// pending, resulting in multiple provisioning charges for the owner.
|
|
94
|
-
return keeper.ChargeForSmartWallet(ctx, addr)
|
|
112
|
+
return keeper.ChargeForSmartWallet(ctx, beansPerUnit, addr)
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
115
|
|
|
@@ -118,7 +136,8 @@ func (msg MsgDeliverInbound) CheckAdmissibility(ctx sdk.Context, data interface{
|
|
|
118
136
|
}
|
|
119
137
|
*/
|
|
120
138
|
|
|
121
|
-
|
|
139
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
140
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Submitter, msg.Messages, 0)
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -184,12 +203,13 @@ func (msg MsgWalletAction) CheckAdmissibility(ctx sdk.Context, data interface{})
|
|
|
184
203
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
185
204
|
}
|
|
186
205
|
|
|
187
|
-
|
|
206
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
207
|
+
err := checkSmartWalletProvisioned(ctx, keeper, beansPerUnit, msg.Owner)
|
|
188
208
|
if err != nil {
|
|
189
209
|
return err
|
|
190
210
|
}
|
|
191
211
|
|
|
192
|
-
return chargeAdmission(ctx, keeper, msg.Owner, []string{msg.Action}, 0)
|
|
212
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Owner, []string{msg.Action}, 0)
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -256,12 +276,13 @@ func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interfa
|
|
|
256
276
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
257
277
|
}
|
|
258
278
|
|
|
259
|
-
|
|
279
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
280
|
+
err := checkSmartWalletProvisioned(ctx, keeper, beansPerUnit, msg.Owner)
|
|
260
281
|
if err != nil {
|
|
261
282
|
return err
|
|
262
283
|
}
|
|
263
284
|
|
|
264
|
-
return chargeAdmission(ctx, keeper, msg.Owner, []string{msg.SpendAction}, 0)
|
|
285
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Owner, []string{msg.SpendAction}, 0)
|
|
265
286
|
}
|
|
266
287
|
|
|
267
288
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -373,7 +394,8 @@ func (msg MsgInstallBundle) CheckAdmissibility(ctx sdk.Context, data interface{}
|
|
|
373
394
|
if !ok {
|
|
374
395
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
375
396
|
}
|
|
376
|
-
|
|
397
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
398
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Submitter, []string{msg.Bundle}, msg.ExpectedUncompressedSize())
|
|
377
399
|
}
|
|
378
400
|
|
|
379
401
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -17,6 +17,7 @@ var (
|
|
|
17
17
|
ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
|
|
18
18
|
ParamStoreKeyPowerFlagFees = []byte("power_flag_fees")
|
|
19
19
|
ParamStoreKeyQueueMax = []byte("queue_max")
|
|
20
|
+
ParamStoreKeyVatCleanupBudget = []byte("vat_cleanup_budget")
|
|
20
21
|
)
|
|
21
22
|
|
|
22
23
|
func NewStringBeans(key string, beans sdkmath.Uint) StringBeans {
|
|
@@ -53,6 +54,7 @@ func DefaultParams() Params {
|
|
|
53
54
|
FeeUnitPrice: DefaultFeeUnitPrice,
|
|
54
55
|
PowerFlagFees: DefaultPowerFlagFees,
|
|
55
56
|
QueueMax: DefaultQueueMax,
|
|
57
|
+
VatCleanupBudget: DefaultVatCleanupBudget,
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -69,6 +71,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
|
|
69
71
|
paramtypes.NewParamSetPair(ParamStoreKeyBootstrapVatConfig, &p.BootstrapVatConfig, validateBootstrapVatConfig),
|
|
70
72
|
paramtypes.NewParamSetPair(ParamStoreKeyPowerFlagFees, &p.PowerFlagFees, validatePowerFlagFees),
|
|
71
73
|
paramtypes.NewParamSetPair(ParamStoreKeyQueueMax, &p.QueueMax, validateQueueMax),
|
|
74
|
+
paramtypes.NewParamSetPair(ParamStoreKeyVatCleanupBudget, &p.VatCleanupBudget, validateVatCleanupBudget),
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -89,6 +92,9 @@ func (p Params) ValidateBasic() error {
|
|
|
89
92
|
if err := validateQueueMax(p.QueueMax); err != nil {
|
|
90
93
|
return err
|
|
91
94
|
}
|
|
95
|
+
if err := validateVatCleanupBudget(p.VatCleanupBudget); err != nil {
|
|
96
|
+
return err
|
|
97
|
+
}
|
|
92
98
|
|
|
93
99
|
return nil
|
|
94
100
|
}
|
|
@@ -165,20 +171,42 @@ func validateQueueMax(i interface{}) error {
|
|
|
165
171
|
return nil
|
|
166
172
|
}
|
|
167
173
|
|
|
174
|
+
func validateVatCleanupBudget(i interface{}) error {
|
|
175
|
+
entries, ok := i.([]UintMapEntry)
|
|
176
|
+
if !ok {
|
|
177
|
+
return fmt.Errorf("invalid parameter type: %T", i)
|
|
178
|
+
}
|
|
179
|
+
hasDefault := false
|
|
180
|
+
for _, entry := range entries {
|
|
181
|
+
if entry.Key == VatCleanupDefault {
|
|
182
|
+
hasDefault = true
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if len(entries) > 0 && !hasDefault {
|
|
187
|
+
return fmt.Errorf("`default` must be present in a non-empty vat cleanup budget")
|
|
188
|
+
}
|
|
189
|
+
return nil
|
|
190
|
+
}
|
|
191
|
+
|
|
168
192
|
// UpdateParams appends any missing params, configuring them to their defaults,
|
|
169
193
|
// then returning the updated params or an error. Existing params are not
|
|
170
194
|
// modified, regardless of their value, and they are not removed if they no
|
|
171
195
|
// longer appear in the defaults.
|
|
172
196
|
func UpdateParams(params Params) (Params, error) {
|
|
173
|
-
newBpu, err :=
|
|
197
|
+
newBpu, err := appendMissingDefaults(params.BeansPerUnit, DefaultBeansPerUnit())
|
|
174
198
|
if err != nil {
|
|
175
199
|
return params, err
|
|
176
200
|
}
|
|
177
|
-
newPff, err :=
|
|
201
|
+
newPff, err := appendMissingDefaults(params.PowerFlagFees, DefaultPowerFlagFees)
|
|
178
202
|
if err != nil {
|
|
179
203
|
return params, err
|
|
180
204
|
}
|
|
181
|
-
newQm, err :=
|
|
205
|
+
newQm, err := appendMissingDefaults(params.QueueMax, DefaultQueueMax)
|
|
206
|
+
if err != nil {
|
|
207
|
+
return params, err
|
|
208
|
+
}
|
|
209
|
+
newVcb, err := appendMissingDefaults(params.VatCleanupBudget, DefaultVatCleanupBudget)
|
|
182
210
|
if err != nil {
|
|
183
211
|
return params, err
|
|
184
212
|
}
|
|
@@ -186,55 +214,37 @@ func UpdateParams(params Params) (Params, error) {
|
|
|
186
214
|
params.BeansPerUnit = newBpu
|
|
187
215
|
params.PowerFlagFees = newPff
|
|
188
216
|
params.QueueMax = newQm
|
|
217
|
+
params.VatCleanupBudget = newVcb
|
|
189
218
|
return params, nil
|
|
190
219
|
}
|
|
191
220
|
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
func
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
221
|
+
// appendMissingDefaults appends to an input list any missing entries with their
|
|
222
|
+
// respective default values and returns the result.
|
|
223
|
+
func appendMissingDefaults[Entry StringBeans | PowerFlagFee | QueueSize | UintMapEntry](entries []Entry, defaults []Entry) ([]Entry, error) {
|
|
224
|
+
getKey := func(entry any) string {
|
|
225
|
+
switch e := entry.(type) {
|
|
226
|
+
case StringBeans:
|
|
227
|
+
return e.Key
|
|
228
|
+
case PowerFlagFee:
|
|
229
|
+
return e.PowerFlag
|
|
230
|
+
case QueueSize:
|
|
231
|
+
return e.Key
|
|
232
|
+
case UintMapEntry:
|
|
233
|
+
return e.Key
|
|
204
234
|
}
|
|
235
|
+
panic("unreachable")
|
|
205
236
|
}
|
|
206
|
-
return bpu, nil
|
|
207
|
-
}
|
|
208
237
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
func appendMissingDefaultPowerFlagFees(pff []PowerFlagFee, defaultPff []PowerFlagFee) ([]PowerFlagFee, error) {
|
|
213
|
-
existingPff := make(map[string]struct{}, len(pff))
|
|
214
|
-
for _, of := range pff {
|
|
215
|
-
existingPff[of.PowerFlag] = struct{}{}
|
|
238
|
+
existingKeys := make(map[string]bool, len(entries))
|
|
239
|
+
for _, entry := range entries {
|
|
240
|
+
existingKeys[getKey(entry)] = true
|
|
216
241
|
}
|
|
217
242
|
|
|
218
|
-
for _,
|
|
219
|
-
if
|
|
220
|
-
|
|
243
|
+
for _, defaultEntry := range defaults {
|
|
244
|
+
if exists := existingKeys[getKey(defaultEntry)]; !exists {
|
|
245
|
+
entries = append(entries, defaultEntry)
|
|
221
246
|
}
|
|
222
247
|
}
|
|
223
|
-
return pff, nil
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// appendMissingDefaultQueueSize appends the default queue size entries not in
|
|
227
|
-
// the list of sizes already, returning the possibly-updated list, or an error.
|
|
228
|
-
func appendMissingDefaultQueueSize(qs []QueueSize, defaultQs []QueueSize) ([]QueueSize, error) {
|
|
229
|
-
existingQs := make(map[string]struct{}, len(qs))
|
|
230
|
-
for _, os := range qs {
|
|
231
|
-
existingQs[os.Key] = struct{}{}
|
|
232
|
-
}
|
|
233
248
|
|
|
234
|
-
|
|
235
|
-
if _, exists := existingQs[s.Key]; !exists {
|
|
236
|
-
qs = append(qs, s)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return qs, nil
|
|
249
|
+
return entries, nil
|
|
240
250
|
}
|
|
@@ -80,7 +80,7 @@ func TestAddStorageBeanCost(t *testing.T) {
|
|
|
80
80
|
},
|
|
81
81
|
} {
|
|
82
82
|
t.Run(tt.name, func(t *testing.T) {
|
|
83
|
-
got, err :=
|
|
83
|
+
got, err := appendMissingDefaults(tt.in, []StringBeans{defaultStorageCost})
|
|
84
84
|
if err != nil {
|
|
85
85
|
t.Errorf("got error %v", err)
|
|
86
86
|
} else if !reflect.DeepEqual(got, tt.want) {
|
|
@@ -90,27 +90,93 @@ func TestAddStorageBeanCost(t *testing.T) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
func
|
|
94
|
-
|
|
93
|
+
func TestUpdateParamsFromEmpty(t *testing.T) {
|
|
95
94
|
in := Params{
|
|
96
|
-
BeansPerUnit:
|
|
97
|
-
BootstrapVatConfig: "
|
|
95
|
+
BeansPerUnit: nil,
|
|
96
|
+
BootstrapVatConfig: "",
|
|
98
97
|
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
99
|
-
PowerFlagFees:
|
|
100
|
-
QueueMax:
|
|
98
|
+
PowerFlagFees: nil,
|
|
99
|
+
QueueMax: nil,
|
|
100
|
+
VatCleanupBudget: nil,
|
|
101
101
|
}
|
|
102
102
|
want := Params{
|
|
103
103
|
BeansPerUnit: DefaultBeansPerUnit(),
|
|
104
|
-
BootstrapVatConfig: "
|
|
104
|
+
BootstrapVatConfig: "",
|
|
105
105
|
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
106
106
|
PowerFlagFees: DefaultPowerFlagFees,
|
|
107
107
|
QueueMax: DefaultQueueMax,
|
|
108
|
+
VatCleanupBudget: DefaultVatCleanupBudget,
|
|
109
|
+
}
|
|
110
|
+
got, err := UpdateParams(in)
|
|
111
|
+
if err != nil {
|
|
112
|
+
t.Fatalf("UpdateParam error %v", err)
|
|
113
|
+
}
|
|
114
|
+
if !reflect.DeepEqual(got, want) {
|
|
115
|
+
t.Errorf("GOT\n%v\nWANTED\n%v", got, want)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func TestUpdateParamsFromExisting(t *testing.T) {
|
|
120
|
+
defaultBeansPerUnit := DefaultBeansPerUnit()
|
|
121
|
+
customBeansPerUnit := NewStringBeans("foo", sdk.NewUint(1))
|
|
122
|
+
customPowerFlagFee := NewPowerFlagFee("bar", sdk.NewCoins(sdk.NewInt64Coin("baz", 2)))
|
|
123
|
+
customQueueSize := NewQueueSize("qux", int32(3))
|
|
124
|
+
customVatCleanup := UintMapEntry{"corge", sdk.NewUint(4)}
|
|
125
|
+
in := Params{
|
|
126
|
+
BeansPerUnit: append([]StringBeans{customBeansPerUnit}, defaultBeansPerUnit[2:4]...),
|
|
127
|
+
BootstrapVatConfig: "",
|
|
128
|
+
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
129
|
+
PowerFlagFees: []PowerFlagFee{customPowerFlagFee},
|
|
130
|
+
QueueMax: []QueueSize{NewQueueSize(QueueInbound, int32(10)), customQueueSize},
|
|
131
|
+
VatCleanupBudget: []UintMapEntry{customVatCleanup, UintMapEntry{VatCleanupDefault, sdk.NewUint(10)}},
|
|
132
|
+
}
|
|
133
|
+
want := Params{
|
|
134
|
+
BeansPerUnit: append(append(in.BeansPerUnit, defaultBeansPerUnit[0:2]...), defaultBeansPerUnit[4:]...),
|
|
135
|
+
BootstrapVatConfig: in.BootstrapVatConfig,
|
|
136
|
+
FeeUnitPrice: in.FeeUnitPrice,
|
|
137
|
+
PowerFlagFees: append(in.PowerFlagFees, DefaultPowerFlagFees...),
|
|
138
|
+
QueueMax: in.QueueMax,
|
|
139
|
+
VatCleanupBudget: append(in.VatCleanupBudget, DefaultVatCleanupBudget[1:]...),
|
|
108
140
|
}
|
|
109
141
|
got, err := UpdateParams(in)
|
|
110
142
|
if err != nil {
|
|
111
143
|
t.Fatalf("UpdateParam error %v", err)
|
|
112
144
|
}
|
|
113
145
|
if !reflect.DeepEqual(got, want) {
|
|
114
|
-
t.Errorf("
|
|
146
|
+
t.Errorf("GOT\n%v\nWANTED\n%v", got, want)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func TestValidateParams(t *testing.T) {
|
|
151
|
+
params := Params{
|
|
152
|
+
BeansPerUnit: DefaultBeansPerUnit(),
|
|
153
|
+
BootstrapVatConfig: "foo",
|
|
154
|
+
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
155
|
+
PowerFlagFees: DefaultPowerFlagFees,
|
|
156
|
+
QueueMax: DefaultQueueMax,
|
|
157
|
+
VatCleanupBudget: DefaultVatCleanupBudget,
|
|
158
|
+
}
|
|
159
|
+
err := params.ValidateBasic()
|
|
160
|
+
if err != nil {
|
|
161
|
+
t.Errorf("unexpected ValidateBasic() error with default params: %v", err)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
customVatCleanup := UintMapEntry{"corge", sdk.NewUint(4)}
|
|
165
|
+
params.VatCleanupBudget = append(params.VatCleanupBudget, customVatCleanup)
|
|
166
|
+
err = params.ValidateBasic()
|
|
167
|
+
if err != nil {
|
|
168
|
+
t.Errorf("unexpected ValidateBasic() error with extended params: %v", err)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
params.VatCleanupBudget = params.VatCleanupBudget[1:]
|
|
172
|
+
err = params.ValidateBasic()
|
|
173
|
+
if err == nil {
|
|
174
|
+
t.Errorf("ValidateBasic() failed to reject VatCleanupBudget with missing `default` %v", params.VatCleanupBudget)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
params.VatCleanupBudget = []UintMapEntry{}
|
|
178
|
+
err = params.ValidateBasic()
|
|
179
|
+
if err != nil {
|
|
180
|
+
t.Errorf("unexpected ValidateBasic() error with empty VatCleanupBudget: %v", params.VatCleanupBudget)
|
|
115
181
|
}
|
|
116
182
|
}
|