@agoric/cosmos 0.34.2-dev-3c8aafe.0 → 0.34.2-dev-74fbe43.0.74fbe43
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/Makefile +6 -2
- package/ante/ante.go +2 -2
- package/ante/inbound.go +1 -2
- package/ante/inbound_test.go +3 -1
- package/ante/vm_admission.go +1 -2
- package/app/app.go +256 -174
- package/app/encoding.go +6 -3
- package/app/export.go +50 -21
- package/app/genesis.go +7 -5
- package/app/params/encoding.go +1 -1
- package/app/params/proto.go +6 -4
- package/app/sim_test.go +11 -13
- package/app/txconfig/tx_config.go +169 -0
- package/app/upgrade.go +40 -90
- package/cmd/agd/agvm.go +1 -1
- package/cmd/agd/main.go +1 -1
- package/cmd/libdaemon/main.go +2 -2
- package/daemon/cmd/root.go +99 -30
- package/daemon/cmd/root_test.go +12 -27
- package/daemon/main.go +2 -9
- package/git-revision.txt +1 -1
- package/go.mod +130 -109
- package/go.sum +228 -469
- package/package.json +2 -2
- package/proto/agoric/swingset/msgs.proto +72 -9
- package/proto/agoric/swingset/swingset.proto +7 -2
- package/proto/agoric/vbank/vbank.proto +1 -1
- package/proto/agoric/vibc/msgs.proto +4 -0
- package/scripts/mockgen.sh +4 -0
- package/tests/e2e/vbank/vbank_test.go +172 -0
- package/tests/integrations/types/aminojson_test.go +214 -0
- package/tests/integrations/vbank/vbank_test.go +349 -0
- package/third_party/proto/amino/amino.proto +6 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +18 -5
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +4 -8
- package/third_party/proto/ibc/core/channel/v1/channel.proto +42 -17
- package/third_party/proto/ibc/core/client/v1/client.proto +48 -40
- package/types/address_hooks.go +2 -2
- package/types/address_hooks_test.go +3 -3
- package/types/ibc_packet.go +3 -3
- package/types/ibc_packet_test.go +3 -3
- package/types/kv_entry_helpers.go +3 -27
- package/types/kv_entry_helpers_test.go +2 -2
- package/types/legacy_address_encoder.go +58 -0
- package/vm/proto_json_test.go +1 -1
- package/vm/server.go +2 -1
- package/x/swingset/abci.go +2 -2
- package/x/swingset/client/cli/tx.go +16 -14
- package/x/swingset/config.go +1 -1
- package/x/swingset/genesis.go +2 -1
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +14 -5
- package/x/swingset/keeper/extension_snapshotter_test.go +1 -1
- package/x/swingset/keeper/keeper.go +28 -23
- package/x/swingset/keeper/keeper_test.go +10 -7
- package/x/swingset/keeper/msg_server.go +52 -5
- package/x/swingset/keeper/msg_server_test.go +121 -0
- package/x/swingset/keeper/proposal.go +4 -0
- package/x/swingset/keeper/querier.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
- package/x/swingset/keeper/test_utils.go +2 -2
- package/x/swingset/module.go +20 -22
- package/x/swingset/testing/queue.go +5 -2
- package/x/swingset/testutil/mocks.go +379 -0
- package/x/swingset/types/codec.go +10 -5
- package/x/swingset/types/default-params.go +13 -12
- package/x/swingset/types/expected_keepers.go +29 -4
- package/x/swingset/types/msgs.go +51 -36
- package/x/swingset/types/msgs.pb.go +561 -51
- package/x/swingset/types/params_test.go +21 -20
- package/x/swingset/types/swingset.pb.go +67 -61
- package/x/vbank/genesis.go +13 -9
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/grpc_query.go +4 -1
- package/x/vbank/keeper/keeper.go +108 -23
- package/x/vbank/keeper/querier.go +4 -1
- package/x/vbank/keeper/rewards.go +10 -5
- package/x/vbank/module.go +47 -75
- package/x/vbank/types/expected_keepers.go +15 -10
- package/x/vbank/types/key.go +3 -0
- package/x/vbank/types/params.go +4 -3
- package/x/vbank/types/vbank.pb.go +41 -40
- package/x/vbank/vbank.go +29 -11
- package/x/vbank/vbank_test.go +213 -154
- package/x/vibc/handler.go +2 -1
- package/x/vibc/keeper/keeper.go +10 -10
- package/x/vibc/keeper/migrations.go +1 -1
- package/x/vibc/keeper/triggers.go +1 -1
- package/x/vibc/module.go +5 -22
- package/x/vibc/types/codec.go +2 -1
- package/x/vibc/types/expected_keepers.go +7 -5
- package/x/vibc/types/ibc_module.go +5 -5
- package/x/vibc/types/msgs.go +30 -7
- package/x/vibc/types/msgs.pb.go +29 -25
- package/x/vibc/types/receiver.go +2 -2
- package/x/vlocalchain/handler.go +2 -1
- package/x/vlocalchain/keeper/keeper.go +17 -5
- package/x/vlocalchain/keeper/keeper_test.go +3 -2
- package/x/vlocalchain/types/expected_keepers.go +7 -4
- package/x/vlocalchain/vlocalchain_test.go +38 -26
- package/x/vstorage/genesis.go +10 -10
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +1 -1
- package/x/vstorage/keeper/keeper.go +72 -50
- package/x/vstorage/keeper/keeper_test.go +74 -54
- package/x/vstorage/keeper/querier.go +1 -1
- package/x/vstorage/module.go +27 -13
- package/x/vstorage/testing/queue.go +5 -3
- package/x/vstorage/vstorage.go +10 -9
- package/x/vstorage/vstorage_test.go +24 -18
- package/x/vtransfer/genesis.go +1 -3
- package/x/vtransfer/handler.go +3 -2
- package/x/vtransfer/ibc_middleware.go +5 -5
- package/x/vtransfer/ibc_middleware_test.go +43 -29
- package/x/vtransfer/keeper/keeper.go +35 -33
- package/x/vtransfer/module.go +8 -11
- package/x/vtransfer/types/expected_keepers.go +3 -3
- package/x/vtransfer/utils_test.go +26 -11
- package/daemon/cmd/testnet.go +0 -539
|
@@ -7,23 +7,21 @@ import (
|
|
|
7
7
|
stdlog "log"
|
|
8
8
|
"math"
|
|
9
9
|
|
|
10
|
+
corestore "cosmossdk.io/core/store"
|
|
11
|
+
"cosmossdk.io/log"
|
|
10
12
|
sdkmath "cosmossdk.io/math"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
13
|
+
"cosmossdk.io/store/prefix"
|
|
14
|
+
storetypes "cosmossdk.io/store/types"
|
|
14
15
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
15
16
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
16
|
-
"github.com/cosmos/cosmos-sdk/
|
|
17
|
-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
17
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
18
18
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
19
|
-
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
|
20
19
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
21
20
|
|
|
22
21
|
"github.com/Agoric/agoric-sdk/golang/cosmos/ante"
|
|
23
22
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
24
23
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
25
24
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
26
|
-
vstoragekeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/keeper"
|
|
27
25
|
)
|
|
28
26
|
|
|
29
27
|
// Top-level paths for chain storage should remain synchronized with
|
|
@@ -53,15 +51,17 @@ const (
|
|
|
53
51
|
|
|
54
52
|
// Keeper maintains the link to data vstorage and exposes getter/setter methods for the various parts of the state machine
|
|
55
53
|
type Keeper struct {
|
|
56
|
-
|
|
57
|
-
cdc
|
|
58
|
-
paramSpace
|
|
54
|
+
storeService corestore.KVStoreService
|
|
55
|
+
cdc codec.Codec
|
|
56
|
+
paramSpace paramtypes.Subspace
|
|
59
57
|
|
|
60
58
|
accountKeeper types.AccountKeeper
|
|
61
|
-
bankKeeper
|
|
62
|
-
vstorageKeeper
|
|
59
|
+
bankKeeper types.BankKeeper
|
|
60
|
+
vstorageKeeper types.VstorageKeeper
|
|
63
61
|
feeCollectorName string
|
|
64
62
|
|
|
63
|
+
authority string
|
|
64
|
+
|
|
65
65
|
// CallToController dispatches a message to the controlling process
|
|
66
66
|
callToController func(ctx sdk.Context, str string) (string, error)
|
|
67
67
|
}
|
|
@@ -71,9 +71,10 @@ var _ ante.SwingsetKeeper = &Keeper{}
|
|
|
71
71
|
|
|
72
72
|
// NewKeeper creates a new IBC transfer Keeper instance
|
|
73
73
|
func NewKeeper(
|
|
74
|
-
cdc codec.Codec,
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
cdc codec.Codec, storeService corestore.KVStoreService,
|
|
75
|
+
paramSpace paramtypes.Subspace,
|
|
76
|
+
accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
|
|
77
|
+
vstorageKeeper types.VstorageKeeper, feeCollectorName string, authority string,
|
|
77
78
|
callToController func(ctx sdk.Context, str string) (string, error),
|
|
78
79
|
) Keeper {
|
|
79
80
|
|
|
@@ -83,14 +84,15 @@ func NewKeeper(
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
return Keeper{
|
|
86
|
-
storeKey: key,
|
|
87
87
|
cdc: cdc,
|
|
88
|
+
storeService: storeService,
|
|
88
89
|
paramSpace: paramSpace,
|
|
89
90
|
accountKeeper: accountKeeper,
|
|
90
91
|
bankKeeper: bankKeeper,
|
|
91
92
|
vstorageKeeper: vstorageKeeper,
|
|
92
93
|
feeCollectorName: feeCollectorName,
|
|
93
94
|
callToController: callToController,
|
|
95
|
+
authority: authority,
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -171,7 +173,7 @@ func (k Keeper) GetSmartWalletState(ctx sdk.Context, addr sdk.AccAddress) types.
|
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
func (k Keeper) InboundQueueLength(ctx sdk.Context) (int32, error) {
|
|
174
|
-
size :=
|
|
176
|
+
size := sdkmath.NewInt(0)
|
|
175
177
|
|
|
176
178
|
highPriorityQueueLength, err := k.vstorageKeeper.GetQueueLength(ctx, StoragePathHighPriorityQueue)
|
|
177
179
|
if err != nil {
|
|
@@ -258,7 +260,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
func (k Keeper) GetState(ctx sdk.Context) types.State {
|
|
261
|
-
|
|
263
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
264
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
262
265
|
bz := store.Get([]byte(stateKey))
|
|
263
266
|
state := types.State{}
|
|
264
267
|
k.cdc.MustUnmarshal(bz, &state)
|
|
@@ -266,7 +269,8 @@ func (k Keeper) GetState(ctx sdk.Context) types.State {
|
|
|
266
269
|
}
|
|
267
270
|
|
|
268
271
|
func (k Keeper) SetState(ctx sdk.Context, state types.State) {
|
|
269
|
-
|
|
272
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
273
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
270
274
|
bz := k.cdc.MustMarshal(&state)
|
|
271
275
|
store.Set([]byte(stateKey), bz)
|
|
272
276
|
}
|
|
@@ -323,8 +327,8 @@ func (k Keeper) ChargeBeans(
|
|
|
323
327
|
beansToDebit := nowOwing.Sub(remainderOwing)
|
|
324
328
|
|
|
325
329
|
// Convert the debit to coins.
|
|
326
|
-
beansPerFeeUnitDec :=
|
|
327
|
-
beansToDebitDec :=
|
|
330
|
+
beansPerFeeUnitDec := sdkmath.LegacyNewDecFromBigInt(beansPerUnit[types.BeansPerFeeUnit].BigInt())
|
|
331
|
+
beansToDebitDec := sdkmath.LegacyNewDecFromBigInt(beansToDebit.BigInt())
|
|
328
332
|
feeUnitPrice := k.GetParams(ctx).FeeUnitPrice
|
|
329
333
|
feeDecCoins := sdk.NewDecCoinsFromCoins(feeUnitPrice...).MulDec(beansToDebitDec).QuoDec(beansPerFeeUnitDec)
|
|
330
334
|
|
|
@@ -485,8 +489,9 @@ func (k Keeper) SetMailbox(ctx sdk.Context, peer string, mailbox string) {
|
|
|
485
489
|
k.vstorageKeeper.LegacySetStorageAndNotify(ctx, agoric.NewKVEntry(path, mailbox))
|
|
486
490
|
}
|
|
487
491
|
|
|
488
|
-
func (k Keeper) GetSwingStore(ctx sdk.Context)
|
|
489
|
-
|
|
492
|
+
func (k Keeper) GetSwingStore(ctx sdk.Context) storetypes.KVStore {
|
|
493
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
494
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
490
495
|
return prefix.NewStore(store, []byte(swingStoreKeyPrefix))
|
|
491
496
|
}
|
|
492
497
|
|
|
@@ -5,13 +5,15 @@ import (
|
|
|
5
5
|
"reflect"
|
|
6
6
|
"testing"
|
|
7
7
|
|
|
8
|
+
"cosmossdk.io/log"
|
|
9
|
+
"cosmossdk.io/store"
|
|
10
|
+
storemetrics "cosmossdk.io/store/metrics"
|
|
11
|
+
prefixstore "cosmossdk.io/store/prefix"
|
|
12
|
+
storetypes "cosmossdk.io/store/types"
|
|
8
13
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
9
|
-
"github.com/cosmos/cosmos-sdk/store"
|
|
10
|
-
prefixstore "github.com/cosmos/cosmos-sdk/store/prefix"
|
|
11
|
-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
12
14
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
15
|
|
|
14
|
-
dbm "github.com/
|
|
16
|
+
dbm "github.com/cosmos/cosmos-db"
|
|
15
17
|
)
|
|
16
18
|
|
|
17
19
|
func mkcoin(denom string) func(amt int64) sdk.Coin {
|
|
@@ -188,7 +190,7 @@ func Test_calculateFees(t *testing.T) {
|
|
|
188
190
|
t.Errorf("calculateFees() error = %v, want %v", err, tt.errMsg)
|
|
189
191
|
return
|
|
190
192
|
}
|
|
191
|
-
if !got.
|
|
193
|
+
if !got.Equal(tt.want) {
|
|
192
194
|
t.Errorf("calculateFees() = %v, want %v", got, tt.want)
|
|
193
195
|
}
|
|
194
196
|
})
|
|
@@ -199,9 +201,10 @@ var (
|
|
|
199
201
|
swingsetStoreKey = storetypes.NewKVStoreKey(types.StoreKey)
|
|
200
202
|
)
|
|
201
203
|
|
|
202
|
-
func makeTestStore()
|
|
204
|
+
func makeTestStore() storetypes.KVStore {
|
|
203
205
|
db := dbm.NewMemDB()
|
|
204
|
-
|
|
206
|
+
logger := log.NewNopLogger()
|
|
207
|
+
ms := store.NewCommitMultiStore(db, logger, storemetrics.NewNoOpMetrics())
|
|
205
208
|
ms.MountStoreWithDB(swingsetStoreKey, storetypes.StoreTypeIAVL, db)
|
|
206
209
|
err := ms.LoadLatestVersion()
|
|
207
210
|
if err != nil {
|
|
@@ -3,6 +3,9 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
5
|
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
7
|
+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
|
+
|
|
6
9
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
7
10
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
8
11
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@@ -43,6 +46,18 @@ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionM
|
|
|
43
46
|
func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
|
|
44
47
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
45
48
|
|
|
49
|
+
if msg.Submitter.Empty() {
|
|
50
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Submitter address cannot be empty")
|
|
51
|
+
}
|
|
52
|
+
if len(msg.Messages) != len(msg.Nums) {
|
|
53
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Messages and Nums must be the same length")
|
|
54
|
+
}
|
|
55
|
+
for _, m := range msg.Messages {
|
|
56
|
+
if len(m) == 0 {
|
|
57
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Messages cannot be empty")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
46
61
|
// msg.Nums and msg.Messages must be zipped into an array of [num, message] pairs.
|
|
47
62
|
messages := make([][]interface{}, len(msg.Messages))
|
|
48
63
|
for i, message := range msg.Messages {
|
|
@@ -190,20 +205,52 @@ type installBundleAction struct {
|
|
|
190
205
|
|
|
191
206
|
func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
|
|
192
207
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
208
|
+
if err := msg.ValidateBasic(); err != nil {
|
|
209
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
|
|
210
|
+
}
|
|
193
211
|
|
|
194
|
-
err := msg.Uncompress()
|
|
195
|
-
if err != nil {
|
|
212
|
+
if err := msg.Uncompress(); err != nil {
|
|
196
213
|
return nil, err
|
|
197
214
|
}
|
|
215
|
+
|
|
216
|
+
if err := msg.ValidateBasic(); err != nil {
|
|
217
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
|
|
218
|
+
}
|
|
219
|
+
|
|
198
220
|
action := installBundleAction{
|
|
199
221
|
MsgInstallBundle: msg,
|
|
200
222
|
}
|
|
201
223
|
|
|
202
|
-
err
|
|
203
|
-
|
|
204
|
-
if err != nil {
|
|
224
|
+
if err := keeper.routeAction(ctx, msg, action); err != nil {
|
|
225
|
+
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
|
|
205
226
|
return nil, err
|
|
206
227
|
}
|
|
207
228
|
|
|
208
229
|
return &types.MsgInstallBundleResponse{}, nil
|
|
209
230
|
}
|
|
231
|
+
|
|
232
|
+
func (k msgServer) CoreEval(goCtx context.Context, msg *types.MsgCoreEval) (*types.MsgCoreEvalResponse, error) {
|
|
233
|
+
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
234
|
+
|
|
235
|
+
if msg.Authority != k.authority {
|
|
236
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnauthorized, "only governance authority can call CoreEval")
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
action := coreEvalAction{
|
|
240
|
+
Evals: []types.CoreEval{
|
|
241
|
+
{
|
|
242
|
+
JsonPermits: msg.JsonPermits,
|
|
243
|
+
JsCode: msg.JsCode,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
err := k.PushCoreEvalAction(ctx, action)
|
|
249
|
+
if err != nil {
|
|
250
|
+
return &types.MsgCoreEvalResponse{
|
|
251
|
+
Result: err.Error(),
|
|
252
|
+
}, err
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return &types.MsgCoreEvalResponse{}, nil
|
|
256
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
package keeper_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/stretchr/testify/suite"
|
|
5
|
+
"go.uber.org/mock/gomock"
|
|
6
|
+
|
|
7
|
+
storetypes "cosmossdk.io/store/types"
|
|
8
|
+
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
9
|
+
cmttime "github.com/cometbft/cometbft/types/time"
|
|
10
|
+
"github.com/cosmos/cosmos-sdk/codec"
|
|
11
|
+
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
|
|
12
|
+
|
|
13
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
14
|
+
"github.com/cosmos/cosmos-sdk/testutil"
|
|
15
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
16
|
+
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
17
|
+
|
|
18
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
19
|
+
swingtestutil "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/testutil"
|
|
20
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
21
|
+
vbanktypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
type KeeperTestSuite struct {
|
|
25
|
+
suite.Suite
|
|
26
|
+
|
|
27
|
+
msgServer types.MsgServer
|
|
28
|
+
keeper keeper.Keeper
|
|
29
|
+
ctx sdk.Context
|
|
30
|
+
|
|
31
|
+
encCfg moduletestutil.TestEncodingConfig
|
|
32
|
+
ctrl *gomock.Controller
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const authority = "agoric10d07y265gmmuvt4z0w9aw880jnsr6hcznym2zg"
|
|
36
|
+
|
|
37
|
+
func (suite *KeeperTestSuite) SetupTest() {
|
|
38
|
+
key := storetypes.NewKVStoreKey(types.StoreKey)
|
|
39
|
+
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
|
40
|
+
ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
|
|
41
|
+
encCfg := moduletestutil.MakeTestEncodingConfig()
|
|
42
|
+
|
|
43
|
+
suite.ctx = ctx
|
|
44
|
+
suite.encCfg = encCfg
|
|
45
|
+
suite.ctrl = gomock.NewController(suite.T())
|
|
46
|
+
|
|
47
|
+
// Create mock keepers using gomock
|
|
48
|
+
mockAccountKeeper := swingtestutil.NewMockAccountKeeper(suite.ctrl)
|
|
49
|
+
mockBankKeeper := swingtestutil.NewMockBankKeeper(suite.ctrl)
|
|
50
|
+
mockVstorageKeeper := swingtestutil.NewMockVstorageKeeper(suite.ctrl)
|
|
51
|
+
|
|
52
|
+
callToController := func(ctx sdk.Context, jsonRequest string) (jsonReply string, err error) {
|
|
53
|
+
return "", nil
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Initialize params keeper and subspace properly
|
|
57
|
+
paramsKey := storetypes.NewKVStoreKey("params")
|
|
58
|
+
paramsTKey := storetypes.NewTransientStoreKey("transient_params")
|
|
59
|
+
paramsKeeper := paramskeeper.NewKeeper(suite.encCfg.Codec, codec.NewLegacyAmino(), paramsKey, paramsTKey)
|
|
60
|
+
paramsKeeper.Subspace(types.ModuleName)
|
|
61
|
+
paramsSubspace, _ := paramsKeeper.GetSubspace(types.ModuleName)
|
|
62
|
+
|
|
63
|
+
suite.keeper = keeper.NewKeeper(
|
|
64
|
+
suite.encCfg.Codec,
|
|
65
|
+
runtime.NewKVStoreService(key),
|
|
66
|
+
paramsSubspace,
|
|
67
|
+
mockAccountKeeper,
|
|
68
|
+
mockBankKeeper,
|
|
69
|
+
mockVstorageKeeper,
|
|
70
|
+
vbanktypes.ReservePoolName,
|
|
71
|
+
authority,
|
|
72
|
+
callToController,
|
|
73
|
+
)
|
|
74
|
+
suite.msgServer = keeper.NewMsgServerImpl(suite.keeper)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func (suite *KeeperTestSuite) TearDownTest() {
|
|
78
|
+
suite.ctrl.Finish()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// TestCoreEval tests the CoreEval message handler
|
|
82
|
+
// Verifies that:
|
|
83
|
+
// 1. Authorized CoreEval requests create proper CORE_EVAL actions
|
|
84
|
+
// 2. Actions are pushed to the high priority queue with correct
|
|
85
|
+
// 3. Eval contains the expected JS code and permits
|
|
86
|
+
// 4. Proper metadata
|
|
87
|
+
func (suite *KeeperTestSuite) TestCoreEval() {
|
|
88
|
+
suite.SetupTest()
|
|
89
|
+
// Create a mock vstorage keeper that expects a queue push with the correct action
|
|
90
|
+
mockVstorageKeeper := swingtestutil.NewMockVstorageKeeper(suite.ctrl)
|
|
91
|
+
mockVstorageKeeper.EXPECT().
|
|
92
|
+
PushQueueItem(gomock.Any(), gomock.Eq("highPriorityQueue"), gomock.Any()).
|
|
93
|
+
DoAndReturn(func(ctx interface{}, queueName string, actionData string) error {
|
|
94
|
+
// Verify the queue name is correct
|
|
95
|
+
suite.Equal("highPriorityQueue", queueName)
|
|
96
|
+
|
|
97
|
+
// Verify the action data contains the expected CoreEval action
|
|
98
|
+
suite.Contains(actionData, `"type":"CORE_EVAL"`)
|
|
99
|
+
suite.Contains(actionData, `"json_permits":"true"`)
|
|
100
|
+
suite.Contains(actionData, `"js_code":"()=\u003e{}"`)
|
|
101
|
+
|
|
102
|
+
suite.Contains(actionData, `"context":{"blockHeight":`)
|
|
103
|
+
suite.Contains(actionData, `"txHash":"x/gov"`)
|
|
104
|
+
suite.Contains(actionData, `"msgIdx":0`)
|
|
105
|
+
|
|
106
|
+
return nil
|
|
107
|
+
}).
|
|
108
|
+
Times(1)
|
|
109
|
+
|
|
110
|
+
// Test successful CoreEval
|
|
111
|
+
msg := &types.MsgCoreEval{
|
|
112
|
+
Authority: authority,
|
|
113
|
+
JsonPermits: "true",
|
|
114
|
+
JsCode: `()=>{}`,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
resp, err := suite.msgServer.CoreEval(suite.ctx, msg)
|
|
118
|
+
suite.NoError(err)
|
|
119
|
+
suite.NotNil(resp)
|
|
120
|
+
suite.Empty(resp.Result)
|
|
121
|
+
}
|
|
@@ -21,6 +21,10 @@ func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) err
|
|
|
21
21
|
Evals: p.Evals,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
return k.PushAction(ctx, action)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func (k Keeper) PushCoreEvalAction(ctx sdk.Context, action coreEvalAction) error {
|
|
24
28
|
// While the CoreEvalProposal was originally created by a transaction, by the time it
|
|
25
29
|
// passes by governance, we no longer have its provenance information, so we need to
|
|
26
30
|
// synthesize unique context information.
|
|
@@ -75,7 +75,7 @@ func legacyQueryStorage(ctx sdk.Context, path string, req abci.RequestQuery, kee
|
|
|
75
75
|
// nolint: unparam
|
|
76
76
|
func legacyQueryKeys(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
|
|
77
77
|
children := keeper.vstorageKeeper.GetChildren(ctx, path)
|
|
78
|
-
chlist := children
|
|
78
|
+
chlist := children
|
|
79
79
|
|
|
80
80
|
if chlist == nil {
|
|
81
81
|
chlist = []string{}
|
|
@@ -10,10 +10,10 @@ import (
|
|
|
10
10
|
"regexp"
|
|
11
11
|
|
|
12
12
|
sdkioerrors "cosmossdk.io/errors"
|
|
13
|
+
"cosmossdk.io/log"
|
|
13
14
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
14
15
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
15
16
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
16
|
-
"github.com/cometbft/cometbft/libs/log"
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
// This module abstracts the generation and handling of swing-store exports,
|
|
@@ -3,12 +3,12 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
"testing"
|
|
5
5
|
|
|
6
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/x/
|
|
6
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
7
7
|
)
|
|
8
8
|
|
|
9
9
|
// GetVstorageKeeper returns the vstorage keeper from the swingset keeper
|
|
10
10
|
// for testing purposes.
|
|
11
|
-
func GetVstorageKeeper(t *testing.T, k Keeper)
|
|
11
|
+
func GetVstorageKeeper(t *testing.T, k Keeper) types.VstorageKeeper {
|
|
12
12
|
if t == nil {
|
|
13
13
|
panic("this function is reserved for testing")
|
|
14
14
|
}
|
package/x/swingset/module.go
CHANGED
|
@@ -3,8 +3,8 @@ package swingset
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
5
|
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
6
|
|
|
7
|
+
"cosmossdk.io/core/appmodule"
|
|
8
8
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
9
9
|
"github.com/spf13/cobra"
|
|
10
10
|
|
|
@@ -16,20 +16,28 @@ import (
|
|
|
16
16
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
17
17
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
18
18
|
|
|
19
|
-
abci "github.com/cometbft/cometbft/abci/types"
|
|
20
19
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
21
20
|
)
|
|
22
21
|
|
|
23
22
|
// type check to ensure the interface is properly implemented
|
|
24
23
|
var (
|
|
25
|
-
_ module.AppModule
|
|
26
|
-
_ module.AppModuleBasic
|
|
24
|
+
_ module.AppModule = AppModule{}
|
|
25
|
+
_ module.AppModuleBasic = AppModuleBasic{}
|
|
26
|
+
_ appmodule.HasBeginBlocker = AppModule{}
|
|
27
|
+
_ appmodule.HasEndBlocker = AppModule{}
|
|
28
|
+
_ module.HasGenesis = AppModule{}
|
|
27
29
|
)
|
|
28
30
|
|
|
29
31
|
// app module Basics object
|
|
30
32
|
type AppModuleBasic struct {
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
// IsAppModule implements the appmodule.AppModule interface.
|
|
36
|
+
func (am AppModule) IsAppModule() {}
|
|
37
|
+
|
|
38
|
+
// IsOnePerModuleType is a marker function just indicates that this is a one-per-module type.
|
|
39
|
+
func (am AppModule) IsOnePerModuleType() {}
|
|
40
|
+
|
|
33
41
|
func (AppModuleBasic) Name() string {
|
|
34
42
|
return ModuleName
|
|
35
43
|
}
|
|
@@ -128,26 +136,17 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
128
136
|
|
|
129
137
|
func (AppModule) ConsensusVersion() uint64 { return 2 }
|
|
130
138
|
|
|
131
|
-
func (am AppModule) BeginBlock(
|
|
139
|
+
func (am AppModule) BeginBlock(goCtx context.Context) error {
|
|
140
|
+
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
132
141
|
am.ensureControllerInited(ctx)
|
|
133
142
|
|
|
134
|
-
|
|
135
|
-
if err != nil {
|
|
136
|
-
fmt.Println("BeginBlock error:", err)
|
|
137
|
-
}
|
|
143
|
+
return BeginBlock(ctx, am.keeper)
|
|
138
144
|
}
|
|
139
145
|
|
|
140
|
-
func (am AppModule) EndBlock(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
if valUpdate != nil {
|
|
146
|
-
return valUpdate
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Prevent Cosmos SDK internal errors.
|
|
150
|
-
return []abci.ValidatorUpdate{}
|
|
146
|
+
func (am AppModule) EndBlock(goCtx context.Context) error {
|
|
147
|
+
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
148
|
+
_, err := EndBlock(ctx, am.keeper)
|
|
149
|
+
return err
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
func (am *AppModule) checkSwingStoreExportSetup() {
|
|
@@ -156,7 +155,7 @@ func (am *AppModule) checkSwingStoreExportSetup() {
|
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage)
|
|
158
|
+
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
|
|
160
159
|
var genesisState types.GenesisState
|
|
161
160
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
|
162
161
|
am.checkSwingStoreExportSetup()
|
|
@@ -164,7 +163,6 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
|
|
|
164
163
|
if bootstrapNeeded {
|
|
165
164
|
am.setBootstrapNeeded()
|
|
166
165
|
}
|
|
167
|
-
return []abci.ValidatorUpdate{}
|
|
168
166
|
}
|
|
169
167
|
|
|
170
168
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
@@ -4,6 +4,7 @@ import (
|
|
|
4
4
|
"testing"
|
|
5
5
|
|
|
6
6
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
7
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage"
|
|
7
8
|
vstoragetesting "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/testing"
|
|
8
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
10
|
)
|
|
@@ -13,7 +14,8 @@ import (
|
|
|
13
14
|
func GetActionQueueRecords(t *testing.T, ctx sdk.Context, swingsetKeeper keeper.Keeper) ([]string, error) {
|
|
14
15
|
vstorageKeeper := keeper.GetVstorageKeeper(t, swingsetKeeper)
|
|
15
16
|
actionQueueName := keeper.StoragePathActionQueue
|
|
16
|
-
|
|
17
|
+
// TODO: fix this type assertion vstorage needs interface needs to be updated
|
|
18
|
+
return vstoragetesting.GetQueueItems(ctx, vstorageKeeper.(vstorage.Keeper), actionQueueName)
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
// ResetActionQueue resets the action queue.
|
|
@@ -21,5 +23,6 @@ func GetActionQueueRecords(t *testing.T, ctx sdk.Context, swingsetKeeper keeper.
|
|
|
21
23
|
func ResetActionQueue(t *testing.T, ctx sdk.Context, swingsetKeeper keeper.Keeper) error {
|
|
22
24
|
vstorageKeeper := keeper.GetVstorageKeeper(t, swingsetKeeper)
|
|
23
25
|
actionQueueName := keeper.StoragePathActionQueue
|
|
24
|
-
|
|
26
|
+
// TODO: fix this type assertion vstorage needs interface needs to be updated
|
|
27
|
+
return vstoragetesting.ResetQueue(ctx, vstorageKeeper.(vstorage.Keeper), actionQueueName)
|
|
25
28
|
}
|