@agoric/cosmos 0.35.0-upgrade-14-dev-c8f9e7b.0 → 0.35.0-upgrade-16a-dev-fb592e4.0
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 +121 -77
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +7 -9
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +212 -140
- package/app/upgrade.go +76 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +130 -11
- package/cmd/libdaemon/main.go +64 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/root.go +171 -74
- package/daemon/cmd/root_test.go +189 -1
- package/daemon/main.go +4 -2
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -1
- package/go.mod +22 -11
- package/go.sum +17 -13
- package/package.json +9 -5
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +7 -8
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +8 -8
- package/vm/action.go +5 -4
- package/vm/action_test.go +31 -11
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +17 -40
- package/vm/core_proposals.go +22 -2
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +10 -10
- package/x/swingset/alias.go +2 -0
- package/x/swingset/client/cli/tx.go +4 -0
- package/x/swingset/genesis.go +84 -24
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/keeper/keeper.go +13 -25
- package/x/swingset/keeper/msg_server.go +18 -18
- package/x/swingset/keeper/proposal.go +3 -3
- package/x/swingset/keeper/querier.go +12 -11
- package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +2 -1
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/expected_keepers.go +3 -2
- package/x/swingset/types/genesis.pb.go +78 -25
- package/x/swingset/types/msgs.go +44 -24
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +5 -4
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/querier.go +4 -3
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +9 -9
- package/x/vbank/vbank_test.go +2 -2
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +102 -65
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +13 -0
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +13 -20
- package/x/vstorage/keeper/querier.go +6 -5
- package/x/vstorage/keeper/querier_test.go +4 -3
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/ante/fee.go +0 -96
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -290
- package/x/lien/keeper/keeper.go +0 -255
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -205
- package/x/lien/lien_test.go +0 -533
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/vibc/ibc.go +0 -394
- /package/{src/index.cjs → index.cjs} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
package keeper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"bytes"
|
|
5
|
+
"context"
|
|
6
|
+
"fmt"
|
|
7
|
+
"reflect"
|
|
8
|
+
"strings"
|
|
9
|
+
"unicode"
|
|
10
|
+
|
|
11
|
+
"github.com/gogo/protobuf/jsonpb"
|
|
12
|
+
"github.com/gogo/protobuf/proto"
|
|
13
|
+
|
|
14
|
+
"github.com/cosmos/cosmos-sdk/codec"
|
|
15
|
+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
16
|
+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
17
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
18
|
+
sdkaddress "github.com/cosmos/cosmos-sdk/types/address"
|
|
19
|
+
|
|
20
|
+
abci "github.com/tendermint/tendermint/abci/types"
|
|
21
|
+
|
|
22
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vlocalchain/types"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
|
|
26
|
+
type Keeper struct {
|
|
27
|
+
key storetypes.StoreKey
|
|
28
|
+
cdc codec.Codec
|
|
29
|
+
msgRouter types.MsgRouter
|
|
30
|
+
queryRouter types.GRPCQueryRouter
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// NewKeeper creates a new dIBC Keeper instance
|
|
34
|
+
func NewKeeper(
|
|
35
|
+
cdc codec.Codec,
|
|
36
|
+
key storetypes.StoreKey,
|
|
37
|
+
msgRouter types.MsgRouter,
|
|
38
|
+
queryRouter types.GRPCQueryRouter,
|
|
39
|
+
) Keeper {
|
|
40
|
+
return Keeper{
|
|
41
|
+
key: key,
|
|
42
|
+
cdc: cdc,
|
|
43
|
+
msgRouter: msgRouter,
|
|
44
|
+
queryRouter: queryRouter,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// DeserializeRequests uses the global proto codec's proto3 JSON
|
|
49
|
+
// unmarshaller and then unpacks the Any types into actual objects.
|
|
50
|
+
func (k Keeper) DeserializeRequests(bz []byte) ([]types.QueryRequest, error) {
|
|
51
|
+
var cosmosTx types.CosmosTx
|
|
52
|
+
unmarshaler := &jsonpb.Unmarshaler{}
|
|
53
|
+
|
|
54
|
+
// Convert the bz byte slice to an io.Reader
|
|
55
|
+
rdr := bytes.NewReader(bz)
|
|
56
|
+
if err := unmarshaler.Unmarshal(rdr, &cosmosTx); err != nil {
|
|
57
|
+
return nil, err
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
msgs := make([]types.QueryRequest, len(cosmosTx.Messages))
|
|
61
|
+
for i, anyMsg := range cosmosTx.Messages {
|
|
62
|
+
// TODO: Generalize using proto service reflection.
|
|
63
|
+
fullMethod, responseURL := parseRequestTypeURL(anyMsg.TypeUrl)
|
|
64
|
+
msgs[i] = types.QueryRequest{
|
|
65
|
+
FullMethod: fullMethod,
|
|
66
|
+
ReplyType: responseURL,
|
|
67
|
+
Request: anyMsg,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return msgs, nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const (
|
|
74
|
+
requestSuffix = "Request"
|
|
75
|
+
responseSuffix = "Response"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
// parseRequestTypeURL returns the full method and response type URL
|
|
79
|
+
//
|
|
80
|
+
// This is a hack that only works if the names are conventionally
|
|
81
|
+
// abc.def.1beta1.QueryFooBarRequest
|
|
82
|
+
// abc.def.1beta1.Query/FooBar
|
|
83
|
+
// abc.def.1beta1.QueryFooBarResponse
|
|
84
|
+
func parseRequestTypeURL(typeURL string) (string, string) {
|
|
85
|
+
typePrefix := strings.TrimSuffix(typeURL, requestSuffix)
|
|
86
|
+
responseURL := typePrefix + responseSuffix
|
|
87
|
+
|
|
88
|
+
ifacePos := strings.LastIndex(typePrefix, ".") + 1
|
|
89
|
+
iface := typePrefix[ifacePos:]
|
|
90
|
+
|
|
91
|
+
// Find the second uppercase letter.
|
|
92
|
+
first := true
|
|
93
|
+
serviceEnd := strings.IndexFunc(iface, func(r rune) bool {
|
|
94
|
+
if first {
|
|
95
|
+
first = false
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
return unicode.IsUpper(r)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
var fullMethod string
|
|
102
|
+
serviceEnd += ifacePos
|
|
103
|
+
if serviceEnd < 0 {
|
|
104
|
+
fullMethod = typePrefix[0:ifacePos] + "/" + iface
|
|
105
|
+
} else {
|
|
106
|
+
fullMethod = typePrefix[0:serviceEnd] + "/" + typePrefix[serviceEnd:]
|
|
107
|
+
}
|
|
108
|
+
return fullMethod, responseURL
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
func (k Keeper) ResolveProtoMessage(typeUrl string) (proto.Message, error) {
|
|
112
|
+
unprefixed := strings.TrimPrefix(typeUrl, "/")
|
|
113
|
+
msgPointerType := proto.MessageType(unprefixed)
|
|
114
|
+
if msgPointerType == nil {
|
|
115
|
+
return nil, fmt.Errorf("unable to resolve type URL %s", typeUrl)
|
|
116
|
+
}
|
|
117
|
+
newMsg := reflect.New(msgPointerType.Elem())
|
|
118
|
+
target, ok := newMsg.Interface().(proto.Message)
|
|
119
|
+
if !ok {
|
|
120
|
+
return nil, fmt.Errorf("unable to cast %s to proto.Message", typeUrl)
|
|
121
|
+
}
|
|
122
|
+
return target, nil
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func (k Keeper) Query(cctx context.Context, qm types.QueryRequest) (*types.QueryResponse, error) {
|
|
126
|
+
// We currently only handle a few kinds of requests.
|
|
127
|
+
handler := k.queryRouter.Route(qm.FullMethod)
|
|
128
|
+
if handler == nil {
|
|
129
|
+
return nil, fmt.Errorf("unrecognized query route for method %s", qm.FullMethod)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
133
|
+
req := abci.RequestQuery{
|
|
134
|
+
Data: qm.Request.Value,
|
|
135
|
+
Height: ctx.BlockHeight(),
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
abcires, err := handler(ctx, req)
|
|
139
|
+
if err != nil {
|
|
140
|
+
return nil, err
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
res := types.QueryResponse{
|
|
144
|
+
Height: abcires.Height,
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if abcires.IsOK() {
|
|
148
|
+
// Wrap the reply in an Any.
|
|
149
|
+
res.Reply = &codectypes.Any{TypeUrl: qm.ReplyType, Value: abcires.Value}
|
|
150
|
+
} else {
|
|
151
|
+
res.Error = abcires.Info
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return &res, nil
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
func (k Keeper) DeserializeTxMessages(bz []byte) ([]sdk.Msg, error) {
|
|
158
|
+
var cosmosTx types.CosmosTx
|
|
159
|
+
if err := k.cdc.UnmarshalJSON(bz, &cosmosTx); err != nil {
|
|
160
|
+
return nil, err
|
|
161
|
+
}
|
|
162
|
+
msgs := make([]sdk.Msg, len(cosmosTx.Messages))
|
|
163
|
+
for i, anyMsg := range cosmosTx.Messages {
|
|
164
|
+
err := k.cdc.UnpackAny(anyMsg, &msgs[i])
|
|
165
|
+
if err != nil {
|
|
166
|
+
return nil, err
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return msgs, nil
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
type HasValidateBasic interface {
|
|
174
|
+
ValidateBasic() error
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
func (k Keeper) authenticateTx(msgs []sdk.Msg, actualSigner string) error {
|
|
178
|
+
for _, msg := range msgs {
|
|
179
|
+
// Validate that all required signers are satisfied (i.e. they match the actual signer).
|
|
180
|
+
for _, requiredSignerAddress := range msg.GetSigners() {
|
|
181
|
+
requiredSigner := requiredSignerAddress.String()
|
|
182
|
+
if requiredSigner != actualSigner {
|
|
183
|
+
err := fmt.Errorf("required signer %s does not match actual signer", requiredSigner)
|
|
184
|
+
return err
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return nil
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
func (k Keeper) ExecuteTx(origCtx sdk.Context, addr string, msgs []sdk.Msg) ([]interface{}, error) {
|
|
192
|
+
// Do any preliminary basic stateless validation.
|
|
193
|
+
for _, msg := range msgs {
|
|
194
|
+
if m, ok := msg.(HasValidateBasic); ok {
|
|
195
|
+
if err := m.ValidateBasic(); err != nil {
|
|
196
|
+
return nil, err
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if err := k.authenticateTx(msgs, addr); err != nil {
|
|
202
|
+
return nil, err
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
resps := make([]interface{}, len(msgs))
|
|
206
|
+
|
|
207
|
+
// CacheContext returns a new context with the multi-store branched into a cached storage object
|
|
208
|
+
// writeCache is called only if all msgs succeed, performing state transitions atomically
|
|
209
|
+
cacheCtx, writeCache := origCtx.CacheContext()
|
|
210
|
+
|
|
211
|
+
for i, msg := range msgs {
|
|
212
|
+
protoAny, err := k.executeMsg(cacheCtx, msg)
|
|
213
|
+
if err != nil {
|
|
214
|
+
return nil, err
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if err = k.cdc.UnpackAny(protoAny, &resps[i]); err != nil {
|
|
218
|
+
return nil, err
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// NOTE: The context returned by CacheContext() creates a new EventManager, so events must be correctly propagated back to the current context
|
|
223
|
+
origCtx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
|
|
224
|
+
writeCache()
|
|
225
|
+
|
|
226
|
+
return resps, nil
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Attempts to get the message handler from the router and if found will then execute the message.
|
|
230
|
+
// If the message execution is successful, the proto marshaled message response will be returned.
|
|
231
|
+
func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) {
|
|
232
|
+
handler := k.msgRouter.Handler(msg)
|
|
233
|
+
if handler == nil {
|
|
234
|
+
return nil, fmt.Errorf("invalid message route for msg %s", sdk.MsgTypeURL(msg))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
res, err := handler(ctx, msg)
|
|
238
|
+
if err != nil {
|
|
239
|
+
return nil, err
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if len(res.MsgResponses) != 1 {
|
|
243
|
+
panic(fmt.Errorf("expected 1 MsgResponse, got %d", len(res.MsgResponses)))
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// NOTE: The sdk msg handler creates a new EventManager, so events must be correctly propagated back to the current context
|
|
247
|
+
ctx.EventManager().EmitEvents(res.GetEvents())
|
|
248
|
+
|
|
249
|
+
// Each individual sdk.Result has exactly one Msg response. We aggregate here.
|
|
250
|
+
msgResponse := res.MsgResponses[0]
|
|
251
|
+
if msgResponse == nil {
|
|
252
|
+
return nil, fmt.Errorf("got nil Msg response for msg %s", sdk.MsgTypeURL(msg))
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return msgResponse, nil
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// AllocateAddress returns an sdk.AccAddress derived using a host module account
|
|
259
|
+
// address, sequence number, the current block app hash, and the current block
|
|
260
|
+
// data hash. The sdk.AccAddress returned is a sub-address of the host module
|
|
261
|
+
// account.
|
|
262
|
+
func (k Keeper) AllocateAddress(cctx context.Context) sdk.AccAddress {
|
|
263
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
264
|
+
store := ctx.KVStore(k.key)
|
|
265
|
+
|
|
266
|
+
localchainModuleAcc := sdkaddress.Module(types.ModuleName, []byte("localchain"))
|
|
267
|
+
header := ctx.BlockHeader()
|
|
268
|
+
|
|
269
|
+
// Increment our sequence number.
|
|
270
|
+
seq := store.Get(types.KeyLastSequence)
|
|
271
|
+
seq = types.NextSequence(seq)
|
|
272
|
+
store.Set(types.KeyLastSequence, seq)
|
|
273
|
+
|
|
274
|
+
buf := seq
|
|
275
|
+
buf = append(buf, header.AppHash...)
|
|
276
|
+
buf = append(buf, header.DataHash...)
|
|
277
|
+
|
|
278
|
+
return sdkaddress.Derive(localchainModuleAcc, buf)
|
|
279
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
package keeper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
"github.com/stretchr/testify/require"
|
|
7
|
+
|
|
8
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
|
|
9
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
|
+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
func TestKeeper_ParseRequestTypeURL(t *testing.T) {
|
|
15
|
+
testCases := []struct {
|
|
16
|
+
name string
|
|
17
|
+
typeUrl string
|
|
18
|
+
fullMethod string
|
|
19
|
+
responseURL string
|
|
20
|
+
}{
|
|
21
|
+
{"valid Request", "abc.def.1beta1.QueryFooBarRequest", "abc.def.1beta1.Query/FooBar", "abc.def.1beta1.QueryFooBarResponse"},
|
|
22
|
+
{"not Request", "abc.def.1beta1.QueryFooBar", "abc.def.1beta1.Query/FooBar", "abc.def.1beta1.QueryFooBarResponse"},
|
|
23
|
+
{"valid Msg", "cosmos.bank.v1beta1.MsgSend", "cosmos.bank.v1beta1.Msg/Send", "cosmos.bank.v1beta1.MsgSendResponse"},
|
|
24
|
+
{"GIGO", "helloWorld", "hello/World", "helloWorldResponse"},
|
|
25
|
+
{"one message", "Hello", "/Hello", "HelloResponse"},
|
|
26
|
+
{"one namespace", "world", "/world", "worldResponse"},
|
|
27
|
+
{"empty", "", "/", "Response"},
|
|
28
|
+
}
|
|
29
|
+
for _, tc := range testCases {
|
|
30
|
+
tc := tc
|
|
31
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
32
|
+
fullMethod, responseURL := parseRequestTypeURL(tc.typeUrl)
|
|
33
|
+
if fullMethod != tc.fullMethod {
|
|
34
|
+
t.Errorf("%v fullMethod expected %v, got %v", tc.typeUrl, tc.fullMethod, fullMethod)
|
|
35
|
+
}
|
|
36
|
+
if responseURL != tc.responseURL {
|
|
37
|
+
t.Errorf("%v response expected %v, got %v", tc.typeUrl, tc.responseURL, responseURL)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func TestKeeper_DeserializeTxMessages(t *testing.T) {
|
|
44
|
+
encodingConfig := params.MakeEncodingConfig()
|
|
45
|
+
cdc := encodingConfig.Marshaler
|
|
46
|
+
|
|
47
|
+
banktypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
|
|
48
|
+
|
|
49
|
+
keeper := NewKeeper(cdc, nil, nil, nil)
|
|
50
|
+
|
|
51
|
+
expectedMsgSend := []sdk.Msg{
|
|
52
|
+
&banktypes.MsgSend{
|
|
53
|
+
FromAddress: "cosmos1abc",
|
|
54
|
+
ToAddress: "cosmos1xyz",
|
|
55
|
+
Amount: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))),
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
testCases := []struct {
|
|
60
|
+
name string
|
|
61
|
+
json string
|
|
62
|
+
expected []sdk.Msg
|
|
63
|
+
wantErr bool
|
|
64
|
+
}{
|
|
65
|
+
{
|
|
66
|
+
name: "camelCase keys",
|
|
67
|
+
json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","fromAddress":"cosmos1abc","toAddress":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
|
|
68
|
+
expected: expectedMsgSend,
|
|
69
|
+
wantErr: false,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "snake_case keys",
|
|
73
|
+
json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
|
|
74
|
+
expected: expectedMsgSend,
|
|
75
|
+
wantErr: false,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "misspelled key",
|
|
79
|
+
json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_addresss":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
|
|
80
|
+
expected: expectedMsgSend,
|
|
81
|
+
wantErr: true,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for _, tc := range testCases {
|
|
86
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
87
|
+
msgs, err := keeper.DeserializeTxMessages([]byte(tc.json))
|
|
88
|
+
|
|
89
|
+
if tc.wantErr {
|
|
90
|
+
require.Error(t, err)
|
|
91
|
+
} else {
|
|
92
|
+
require.NoError(t, err)
|
|
93
|
+
require.Equal(t, tc.expected, msgs)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/cosmos/cosmos-sdk/codec"
|
|
5
|
+
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
6
|
+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
|
7
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
var (
|
|
11
|
+
amino = codec.NewLegacyAmino()
|
|
12
|
+
|
|
13
|
+
// ModuleCdc references the global x/deployment module codec. Note, the codec should
|
|
14
|
+
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
|
15
|
+
// still used for that purpose.
|
|
16
|
+
//
|
|
17
|
+
// The actual codec used for serialization should be provided to x/swingset and
|
|
18
|
+
// defined at the application level.
|
|
19
|
+
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
func init() {
|
|
23
|
+
RegisterCodec(amino)
|
|
24
|
+
cryptocodec.RegisterCrypto(amino)
|
|
25
|
+
amino.Seal()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// RegisterCodec registers concrete types on the Amino codec
|
|
29
|
+
func RegisterCodec(cdc *codec.LegacyAmino) {}
|
|
30
|
+
|
|
31
|
+
// RegisterInterfaces registers the x/swingset interfaces types with the interface registry
|
|
32
|
+
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
|
|
33
|
+
registry.RegisterImplementations((*sdk.Msg)(nil))
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
const (
|
|
8
|
+
// module name
|
|
9
|
+
ModuleName = "vlocalchain"
|
|
10
|
+
|
|
11
|
+
// StoreKey to be used when creating the KVStore
|
|
12
|
+
StoreKey = ModuleName
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
var (
|
|
16
|
+
// KeyLastSequence is the key used to store the last sequence (big-endian
|
|
17
|
+
// uint64) to help derive a fresh module account address
|
|
18
|
+
KeyLastSequence = []byte("lastSequence")
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// NextSequence interprets the value byte slice as a big-endian uint64, and
|
|
22
|
+
// returns a new big-endian byte slice representing the value plus 1.
|
|
23
|
+
func NextSequence(value []byte) []byte {
|
|
24
|
+
lastSequence := sdk.BigEndianToUint64(value)
|
|
25
|
+
lastSequence += 1
|
|
26
|
+
return sdk.Uint64ToBigEndian(lastSequence)
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
5
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
const RouterKey = ModuleName // this was defined in your key.go file
|
|
9
|
+
|
|
10
|
+
type MsgRouter interface {
|
|
11
|
+
Handler(msg sdk.Msg) func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type GRPCQueryRouter interface {
|
|
15
|
+
Route(path string) baseapp.GRPCQueryHandler
|
|
16
|
+
}
|