@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-dabccdc.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.
Files changed (193) hide show
  1. package/MAINTAINERS.md +3 -0
  2. package/Makefile +67 -41
  3. package/agoric/config.go +35 -0
  4. package/ante/ante.go +65 -0
  5. package/ante/expected_keepers.go +26 -0
  6. package/ante/inbound.go +137 -0
  7. package/ante/inbound_test.go +228 -0
  8. package/ante/vm_admission.go +65 -0
  9. package/app/app.go +396 -211
  10. package/app/export.go +13 -9
  11. package/app/sim_test.go +4 -4
  12. package/app/upgrade.go +215 -0
  13. package/binding.gyp.in +29 -4
  14. package/buf.work.yaml +4 -0
  15. package/cmd/agd/agvm.go +42 -0
  16. package/cmd/agd/find_binary.go +22 -7
  17. package/cmd/agd/main.go +133 -10
  18. package/cmd/libdaemon/main.go +67 -53
  19. package/cmd/libdaemon/main_test.go +37 -0
  20. package/daemon/cmd/genaccounts.go +22 -18
  21. package/daemon/cmd/root.go +253 -52
  22. package/daemon/cmd/root_test.go +190 -2
  23. package/daemon/cmd/testnet.go +17 -6
  24. package/daemon/main.go +6 -3
  25. package/e2e_test/Makefile +29 -0
  26. package/e2e_test/README.md +100 -0
  27. package/e2e_test/go.mod +217 -0
  28. package/e2e_test/go.sum +1323 -0
  29. package/e2e_test/ibc_conformance_test.go +56 -0
  30. package/e2e_test/pfm_test.go +613 -0
  31. package/e2e_test/util.go +271 -0
  32. package/git-revision.txt +1 -0
  33. package/go.mod +207 -0
  34. package/go.sum +1877 -0
  35. package/package.json +13 -21
  36. package/proto/agoric/swingset/genesis.proto +14 -0
  37. package/proto/agoric/swingset/swingset.proto +6 -3
  38. package/proto/agoric/vlocalchain/.clang-format +7 -0
  39. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  40. package/proto/agoric/vstorage/query.proto +53 -1
  41. package/proto/agoric/vtransfer/genesis.proto +18 -0
  42. package/scripts/protocgen.sh +16 -6
  43. package/third_party/proto/buf.yaml +1 -0
  44. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  45. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  46. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  47. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  48. package/third_party/proto/google/api/annotations.proto +1 -1
  49. package/third_party/proto/google/api/http.proto +181 -120
  50. package/third_party/proto/google/api/httpbody.proto +9 -6
  51. package/third_party/proto/google/protobuf/any.proto +1 -7
  52. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  53. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  54. package/tools/tools.go +11 -0
  55. package/types/events.go +41 -0
  56. package/types/kv_entry.go +114 -0
  57. package/types/kv_entry_helpers.go +276 -0
  58. package/types/kv_entry_helpers_test.go +237 -0
  59. package/types/kv_entry_test.go +143 -0
  60. package/upgradegaia.sh +75 -0
  61. package/vm/action.go +134 -0
  62. package/vm/action_test.go +149 -0
  63. package/vm/client.go +113 -0
  64. package/vm/client_test.go +182 -0
  65. package/vm/controller.go +49 -0
  66. package/vm/core_proposals.go +51 -0
  67. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  68. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  69. package/vm/proto_json.go +38 -0
  70. package/vm/proto_json_test.go +103 -0
  71. package/vm/server.go +124 -0
  72. package/x/swingset/abci.go +26 -37
  73. package/x/swingset/alias.go +9 -6
  74. package/x/swingset/client/cli/query.go +2 -2
  75. package/x/swingset/client/cli/tx.go +52 -33
  76. package/x/swingset/client/proposal_handler.go +2 -17
  77. package/x/swingset/genesis.go +163 -37
  78. package/x/swingset/handler.go +2 -1
  79. package/x/swingset/keeper/extension_snapshotter.go +309 -0
  80. package/x/swingset/keeper/extension_snapshotter_test.go +104 -0
  81. package/x/swingset/keeper/keeper.go +95 -48
  82. package/x/swingset/keeper/keeper_test.go +77 -0
  83. package/x/swingset/keeper/migrations.go +7 -2
  84. package/x/swingset/keeper/msg_server.go +71 -56
  85. package/x/swingset/keeper/proposal.go +15 -9
  86. package/x/swingset/keeper/querier.go +24 -15
  87. package/x/swingset/keeper/swing_store_exports_handler.go +872 -0
  88. package/x/swingset/keeper/swing_store_exports_handler_test.go +247 -0
  89. package/x/swingset/keeper/test_utils.go +16 -0
  90. package/x/swingset/module.go +33 -11
  91. package/x/swingset/proposal_handler.go +5 -4
  92. package/x/swingset/swingset.go +73 -0
  93. package/x/swingset/testing/queue.go +17 -0
  94. package/x/swingset/types/codec.go +2 -2
  95. package/x/swingset/types/default-params.go +23 -17
  96. package/x/swingset/types/expected_keepers.go +14 -2
  97. package/x/swingset/types/genesis.pb.go +361 -18
  98. package/x/swingset/types/msgs.go +87 -26
  99. package/x/swingset/types/msgs.pb.go +16 -16
  100. package/x/swingset/types/params.go +76 -1
  101. package/x/swingset/types/params_test.go +116 -0
  102. package/x/swingset/types/proposal.go +10 -9
  103. package/x/swingset/types/swingset.pb.go +83 -81
  104. package/x/swingset/types/types.go +30 -28
  105. package/x/vbank/genesis.go +0 -2
  106. package/x/vbank/handler.go +2 -1
  107. package/x/vbank/keeper/keeper.go +3 -2
  108. package/x/vbank/keeper/querier.go +9 -4
  109. package/x/vbank/keeper/rewards.go +1 -1
  110. package/x/vbank/module.go +0 -5
  111. package/x/vbank/types/msgs.go +0 -12
  112. package/x/vbank/vbank.go +34 -32
  113. package/x/vbank/vbank_test.go +20 -20
  114. package/x/vibc/alias.go +3 -0
  115. package/x/vibc/handler.go +17 -15
  116. package/x/vibc/keeper/keeper.go +113 -89
  117. package/x/vibc/keeper/triggers.go +101 -0
  118. package/x/vibc/module.go +5 -8
  119. package/x/vibc/types/expected_keepers.go +28 -6
  120. package/x/vibc/types/ibc_module.go +336 -0
  121. package/x/vibc/types/msgs.go +1 -1
  122. package/x/vibc/types/msgs.pb.go +1 -1
  123. package/x/vibc/types/receiver.go +170 -0
  124. package/x/vlocalchain/alias.go +19 -0
  125. package/x/vlocalchain/handler.go +21 -0
  126. package/x/vlocalchain/keeper/keeper.go +279 -0
  127. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  128. package/x/vlocalchain/types/codec.go +34 -0
  129. package/x/vlocalchain/types/key.go +27 -0
  130. package/x/vlocalchain/types/msgs.go +16 -0
  131. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  132. package/x/vlocalchain/vlocalchain.go +114 -0
  133. package/x/vlocalchain/vlocalchain_test.go +434 -0
  134. package/x/vstorage/README.md +138 -0
  135. package/x/vstorage/capdata/capdata.go +298 -0
  136. package/x/vstorage/capdata/capdata_test.go +352 -0
  137. package/x/vstorage/client/cli/query.go +51 -4
  138. package/x/vstorage/genesis.go +0 -3
  139. package/x/vstorage/handler.go +2 -1
  140. package/x/vstorage/keeper/grpc_query.go +220 -0
  141. package/x/vstorage/keeper/keeper.go +75 -57
  142. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  143. package/x/vstorage/keeper/keeper_test.go +40 -62
  144. package/x/vstorage/keeper/querier.go +39 -14
  145. package/x/vstorage/keeper/querier_test.go +113 -0
  146. package/x/vstorage/module.go +0 -5
  147. package/x/vstorage/testing/queue.go +27 -0
  148. package/x/vstorage/types/path_keys.go +22 -10
  149. package/x/vstorage/types/path_keys_test.go +84 -18
  150. package/x/vstorage/types/query.pb.go +646 -36
  151. package/x/vstorage/types/query.pb.gw.go +119 -0
  152. package/x/vstorage/types/types.go +0 -66
  153. package/x/vstorage/vstorage.go +33 -35
  154. package/x/vstorage/vstorage_test.go +19 -19
  155. package/x/vtransfer/alias.go +13 -0
  156. package/x/vtransfer/genesis.go +39 -0
  157. package/x/vtransfer/genesis_test.go +12 -0
  158. package/x/vtransfer/handler.go +20 -0
  159. package/x/vtransfer/ibc_middleware.go +186 -0
  160. package/x/vtransfer/ibc_middleware_test.go +448 -0
  161. package/x/vtransfer/keeper/keeper.go +281 -0
  162. package/x/vtransfer/module.go +124 -0
  163. package/x/vtransfer/types/expected_keepers.go +38 -0
  164. package/x/vtransfer/types/genesis.pb.go +327 -0
  165. package/x/vtransfer/types/key.go +9 -0
  166. package/x/vtransfer/types/msgs.go +9 -0
  167. package/app/const.go +0 -6
  168. package/cmd/helper/main.go +0 -21
  169. package/proto/agoric/lien/genesis.proto +0 -25
  170. package/proto/agoric/lien/lien.proto +0 -25
  171. package/x/lien/alias.go +0 -17
  172. package/x/lien/genesis.go +0 -58
  173. package/x/lien/genesis_test.go +0 -101
  174. package/x/lien/keeper/account.go +0 -285
  175. package/x/lien/keeper/keeper.go +0 -254
  176. package/x/lien/keeper/keeper_test.go +0 -623
  177. package/x/lien/lien.go +0 -203
  178. package/x/lien/lien_test.go +0 -529
  179. package/x/lien/module.go +0 -115
  180. package/x/lien/spec/01_concepts.md +0 -146
  181. package/x/lien/spec/02_messages.md +0 -96
  182. package/x/lien/types/accountkeeper.go +0 -81
  183. package/x/lien/types/accountstate.go +0 -27
  184. package/x/lien/types/expected_keepers.go +0 -18
  185. package/x/lien/types/genesis.pb.go +0 -567
  186. package/x/lien/types/key.go +0 -25
  187. package/x/lien/types/lien.pb.go +0 -403
  188. package/x/swingset/keeper/snapshotter.go +0 -491
  189. package/x/swingset/keeper/snapshotter_test.go +0 -185
  190. package/x/swingset/legacy/v32/params.go +0 -37
  191. package/x/swingset/legacy/v32/params_test.go +0 -133
  192. package/x/vibc/ibc.go +0 -442
  193. /package/{src/index.cjs → index.cjs} +0 -0
@@ -0,0 +1,300 @@
1
+ package keeper
2
+
3
+ import (
4
+ "fmt"
5
+ "reflect"
6
+ "strings"
7
+ "testing"
8
+
9
+ grpcCodes "google.golang.org/grpc/codes"
10
+ grpcStatus "google.golang.org/grpc/status"
11
+
12
+ agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
13
+ "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/capdata"
14
+ "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
15
+
16
+ sdk "github.com/cosmos/cosmos-sdk/types"
17
+ )
18
+
19
+ func ptr[T any](v T) *T {
20
+ return &v
21
+ }
22
+
23
+ func mustJsonMarshal(val any) string {
24
+ jsonText, err := capdata.JsonMarshal(val)
25
+ if err != nil {
26
+ panic(err)
27
+ }
28
+ return string(jsonText)
29
+ }
30
+
31
+ func mustMarshalStreamCell(blockHeight string, values []string) string {
32
+ cell := map[string]any{
33
+ "blockHeight": blockHeight,
34
+ "values": values,
35
+ }
36
+ return mustJsonMarshal(cell)
37
+ }
38
+
39
+ func TestCapData(t *testing.T) {
40
+ testKit := makeTestKit()
41
+ ctx, keeper := testKit.ctx, testKit.vstorageKeeper
42
+ querier := Querier{keeper}
43
+
44
+ type testCase struct {
45
+ label string
46
+ data *string
47
+ request types.QueryCapDataRequest
48
+ expected types.QueryCapDataResponse
49
+ errCode grpcCodes.Code
50
+ errContains *string
51
+ }
52
+ testCases := []testCase{}
53
+
54
+ // Test simple cases (various kinds of bad data up to simple flat JSON-compatible CapData).
55
+ decodableSmallcaps := `{"body":"#true","slots":[]}`
56
+ decodableLegacy := `{"body":"true","slots":[]}`
57
+ testCases = append(testCases, []testCase{
58
+ {label: "no data",
59
+ data: nil,
60
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
61
+ errCode: grpcCodes.FailedPrecondition,
62
+ errContains: ptr("no data"),
63
+ },
64
+ {label: "zero-length data",
65
+ data: ptr(""),
66
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
67
+ errCode: grpcCodes.FailedPrecondition,
68
+ errContains: ptr("JSON"),
69
+ },
70
+ {label: "cell with empty string",
71
+ data: ptr(mustMarshalStreamCell("1", []string{decodableSmallcaps, "", decodableLegacy})),
72
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
73
+ errCode: grpcCodes.FailedPrecondition,
74
+ errContains: ptr("JSON"),
75
+ },
76
+ {label: "non-JSON data",
77
+ data: ptr("foo"),
78
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
79
+ errCode: grpcCodes.FailedPrecondition,
80
+ errContains: ptr("invalid"),
81
+ },
82
+ {label: "cell with non-JSON",
83
+ data: ptr(mustMarshalStreamCell("1", []string{decodableSmallcaps, "foo", decodableLegacy})),
84
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
85
+ errCode: grpcCodes.FailedPrecondition,
86
+ errContains: ptr("invalid"),
87
+ },
88
+ {label: "lone non-CapData",
89
+ data: ptr("{}"),
90
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
91
+ errCode: grpcCodes.FailedPrecondition,
92
+ errContains: ptr("invalid CapData"),
93
+ },
94
+ {label: "cell with non-CapData",
95
+ data: ptr(mustMarshalStreamCell("1", []string{decodableSmallcaps, "{}", decodableLegacy})),
96
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
97
+ errCode: grpcCodes.FailedPrecondition,
98
+ errContains: ptr("invalid CapData"),
99
+ },
100
+ {label: "lone smallcaps CapData",
101
+ data: ptr(decodableSmallcaps),
102
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
103
+ expected: types.QueryCapDataResponse{Value: `true`},
104
+ },
105
+ {label: "cell with smallcaps CapData",
106
+ data: ptr(mustMarshalStreamCell("1", []string{decodableSmallcaps})),
107
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
108
+ expected: types.QueryCapDataResponse{BlockHeight: "1", Value: `true`},
109
+ },
110
+ {label: "lone legacy CapData",
111
+ data: ptr(decodableLegacy),
112
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
113
+ expected: types.QueryCapDataResponse{Value: `true`},
114
+ },
115
+ {label: "cell with legacy CapData",
116
+ data: ptr(mustMarshalStreamCell("1", []string{decodableLegacy})),
117
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
118
+ expected: types.QueryCapDataResponse{BlockHeight: "1", Value: `true`},
119
+ },
120
+ }...)
121
+
122
+ // Test option validation.
123
+ testCases = append(testCases, []testCase{
124
+ {label: "explicit JSON Lines",
125
+ data: ptr(decodableSmallcaps),
126
+ request: types.QueryCapDataRequest{MediaType: "JSON Lines", RemotableValueFormat: "string"},
127
+ expected: types.QueryCapDataResponse{Value: `true`},
128
+ },
129
+ {label: "invalid media type",
130
+ data: ptr(decodableSmallcaps),
131
+ request: types.QueryCapDataRequest{MediaType: "JSONLines", RemotableValueFormat: "string"},
132
+ errCode: grpcCodes.InvalidArgument,
133
+ errContains: ptr("media_type"),
134
+ },
135
+ {label: "invalid item format",
136
+ data: ptr(decodableSmallcaps),
137
+ request: types.QueryCapDataRequest{ItemFormat: "deep", RemotableValueFormat: "string"},
138
+ errCode: grpcCodes.InvalidArgument,
139
+ errContains: ptr("item_format"),
140
+ },
141
+ {label: "missing remotable value format",
142
+ data: ptr(decodableSmallcaps),
143
+ request: types.QueryCapDataRequest{},
144
+ errCode: grpcCodes.InvalidArgument,
145
+ errContains: ptr("remotable_value_format"),
146
+ },
147
+ {label: "invalid remotable value format",
148
+ data: ptr(decodableSmallcaps),
149
+ request: types.QueryCapDataRequest{RemotableValueFormat: "foo"},
150
+ errCode: grpcCodes.InvalidArgument,
151
+ errContains: ptr("remotable_value_format"),
152
+ },
153
+ }...)
154
+
155
+ // Test formatting options against sufficiently complex CapData,
156
+ // deriving legacy encoding from smallcaps encoding to ensure equivalence
157
+ // and deriving expectations from marshalling to avoid spurious mismatches
158
+ // from Go's unpredictable field ordering (e.g., `{"a":0,"b":1}` vs. `{"b":1,"a":0}`).
159
+ slots := []any{"a"}
160
+ deepSmallcapsBody := `{"arr":[{"bigint":"+42","remotable":"$0.Alleged: Foo brand","ref2":"$0"}]}`
161
+ deepLegacyBody := deepSmallcapsBody
162
+ legacyFromSmallcaps := [][2]string{
163
+ [2]string{`"+42"`, `{"@qclass":"bigint","digits":"42"}`},
164
+ [2]string{`"$0.Alleged: Foo brand"`, `{"@qclass":"slot","index":0,"iface":"Alleged: Foo brand"}`},
165
+ [2]string{`"$0"`, `{"@qclass":"slot","index":0}`},
166
+ }
167
+ for _, pair := range legacyFromSmallcaps {
168
+ deepLegacyBody = strings.Replace(deepLegacyBody, pair[0], pair[1], -1)
169
+ }
170
+ cell := mustMarshalStreamCell("1", []string{
171
+ mustJsonMarshal(map[string]any{"body": "#" + deepSmallcapsBody, "slots": slots}),
172
+ mustJsonMarshal(map[string]any{"body": deepLegacyBody, "slots": slots}),
173
+ })
174
+ mustMarshalTwoLines := func(val any) string {
175
+ line := mustJsonMarshal(val)
176
+ return fmt.Sprintf("%s\n%s", line, line)
177
+ }
178
+ testCases = append(testCases, testCase{label: "remotables as strings",
179
+ data: ptr(cell),
180
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
181
+ expected: types.QueryCapDataResponse{
182
+ BlockHeight: "1",
183
+ Value: mustMarshalTwoLines(map[string]any{
184
+ "arr": []any{
185
+ map[string]any{
186
+ "bigint": "42",
187
+ "remotable": "[Alleged: Foo brand <a>]",
188
+ "ref2": "[Alleged: Foo brand <a>]",
189
+ },
190
+ },
191
+ }),
192
+ },
193
+ })
194
+ testCases = append(testCases, testCase{label: "remotables as strings, flat",
195
+ data: ptr(cell),
196
+ request: types.QueryCapDataRequest{ItemFormat: "flat", RemotableValueFormat: "string"},
197
+ expected: types.QueryCapDataResponse{
198
+ BlockHeight: "1",
199
+ Value: mustMarshalTwoLines(map[string]any{
200
+ "arr-0-bigint": "42",
201
+ "arr-0-remotable": "[Alleged: Foo brand <a>]",
202
+ "arr-0-ref2": "[Alleged: Foo brand <a>]",
203
+ }),
204
+ },
205
+ })
206
+ testCases = append(testCases, testCase{label: "remotables as objects",
207
+ data: ptr(cell),
208
+ request: types.QueryCapDataRequest{RemotableValueFormat: "object"},
209
+ expected: types.QueryCapDataResponse{
210
+ BlockHeight: "1",
211
+ Value: mustMarshalTwoLines(map[string]any{
212
+ "arr": []any{
213
+ map[string]any{
214
+ "bigint": "42",
215
+ "remotable": map[string]any{"id": "a", "allegedName": "Foo brand"},
216
+ "ref2": map[string]any{"id": "a", "allegedName": "Foo brand"},
217
+ },
218
+ },
219
+ }),
220
+ },
221
+ })
222
+ testCases = append(testCases, testCase{label: "remotables as objects, flat",
223
+ data: ptr(cell),
224
+ request: types.QueryCapDataRequest{ItemFormat: "flat", RemotableValueFormat: "object"},
225
+ expected: types.QueryCapDataResponse{
226
+ BlockHeight: "1",
227
+ Value: mustMarshalTwoLines(map[string]any{
228
+ "arr-0-bigint": "42",
229
+ "arr-0-remotable-id": "a",
230
+ "arr-0-remotable-allegedName": "Foo brand",
231
+ "arr-0-ref2-id": "a",
232
+ "arr-0-ref2-allegedName": "Foo brand",
233
+ }),
234
+ },
235
+ })
236
+
237
+ // Test errors from CapData that includes unsupported values.
238
+ expectNotImplemented := func(label, capdataBody string, slots []any) testCase {
239
+ if slots == nil {
240
+ slots = []any{}
241
+ }
242
+ serialized := mustJsonMarshal(map[string]any{
243
+ "body": capdataBody,
244
+ "slots": slots,
245
+ })
246
+ return testCase{
247
+ label: label,
248
+ data: ptr(serialized),
249
+ request: types.QueryCapDataRequest{RemotableValueFormat: "string"},
250
+ errCode: grpcCodes.FailedPrecondition,
251
+ errContains: ptr("not implemented"),
252
+ }
253
+ }
254
+ testCases = append(testCases, []testCase{
255
+ expectNotImplemented("smallcaps undefined", `#"#undefined"`, nil),
256
+ expectNotImplemented("smallcaps NaN", `#"#NaN"`, nil),
257
+ expectNotImplemented("smallcaps infinity", `#"#Infinity"`, nil),
258
+ expectNotImplemented("smallcaps negative infinity", `#"#-Infinity"`, nil),
259
+ expectNotImplemented("smallcaps symbol", `#"%foo"`, nil),
260
+ expectNotImplemented("smallcaps promise", `#"&0"`, []any{"a"}),
261
+ expectNotImplemented("smallcaps tagged", `#{"#tag":"copySet","payload":[]}`, nil),
262
+ expectNotImplemented("smallcaps error", `#{"#error":"foo","name":"Error"}`, nil),
263
+ expectNotImplemented("legacy undefined", `{"@qclass":"undefined"}`, nil),
264
+ expectNotImplemented("legacy NaN", `{"@qclass":"NaN"}`, nil),
265
+ expectNotImplemented("legacy infinity", `{"@qclass":"Infinity"}`, nil),
266
+ expectNotImplemented("legacy negative infinity", `{"@qclass":"-Infinity"}`, nil),
267
+ expectNotImplemented("legacy symbol", `{"@qclass":"symbol","name":"foo"}`, nil),
268
+ expectNotImplemented("smallcaps tagged", `{"@qclass":"tagged","tag":"copySet","payload":[]}`, nil),
269
+ expectNotImplemented("smallcaps error", `{"@qclass":"error","message":"foo","name":"Error"}`, nil),
270
+ expectNotImplemented("smallcaps Hilbert Hotel", `{"@qclass":"hilbert","original":"foo"}`, nil),
271
+ }...)
272
+ for _, desc := range testCases {
273
+ desc.request.Path = "key"
274
+ if desc.data == nil {
275
+ keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue(desc.request.Path))
276
+ } else {
277
+ keeper.SetStorage(ctx, agoric.NewKVEntry(desc.request.Path, *desc.data))
278
+ }
279
+ resp, err := querier.CapData(sdk.WrapSDKContext(ctx), &desc.request)
280
+ if desc.errCode == grpcCodes.OK {
281
+ if err != nil {
282
+ t.Errorf("%s: got unexpected error %v", desc.label, err)
283
+ } else if reflect.DeepEqual(resp, &desc.expected) {
284
+ continue
285
+ }
286
+ if resp.Value != desc.expected.Value {
287
+ lines := strings.Split(resp.Value, "\n")
288
+ t.Errorf("%s: wrong result value lines: %#q", desc.label, lines)
289
+ } else {
290
+ t.Errorf("%s: wrong result: %#v", desc.label, resp)
291
+ }
292
+ } else if err == nil {
293
+ t.Errorf("%s: got no error, want error %q", desc.label, *desc.errContains)
294
+ } else if code := grpcStatus.Code(err); code != desc.errCode {
295
+ t.Errorf("%s: got error code %q, want %q", desc.label, code, desc.errCode)
296
+ } else if desc.errContains != nil && !strings.Contains(err.Error(), *desc.errContains) {
297
+ t.Errorf("%s: got error %v, want error %q", desc.label, err, *desc.errContains)
298
+ }
299
+ }
300
+ }
@@ -4,6 +4,7 @@ import (
4
4
  "reflect"
5
5
  "testing"
6
6
 
7
+ agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
7
8
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
8
9
 
9
10
  "github.com/cosmos/cosmos-sdk/store"
@@ -30,7 +31,7 @@ func makeTestKit() testKit {
30
31
 
31
32
  db := dbm.NewMemDB()
32
33
  ms := store.NewCommitMultiStore(db)
33
- ms.MountStoreWithDB(vstorageStoreKey, sdk.StoreTypeIAVL, db)
34
+ ms.MountStoreWithDB(vstorageStoreKey, storetypes.StoreTypeIAVL, db)
34
35
  err := ms.LoadLatestVersion()
35
36
  if err != nil {
36
37
  panic(err)
@@ -57,19 +58,19 @@ func TestStorage(t *testing.T) {
57
58
  ctx, keeper := testKit.ctx, testKit.vstorageKeeper
58
59
 
59
60
  // Test that we can store and retrieve a value.
60
- keeper.SetStorage(ctx, types.NewStorageEntry("inited", "initValue"))
61
+ keeper.SetStorage(ctx, agoric.NewKVEntry("inited", "initValue"))
61
62
  if got := keeper.GetEntry(ctx, "inited").StringValue(); got != "initValue" {
62
63
  t.Errorf("got %q, want %q", got, "initValue")
63
64
  }
64
65
 
65
66
  // Test that unknown children return empty string.
66
- if got := keeper.GetEntry(ctx, "unknown"); got.HasData() || got.StringValue() != "" {
67
+ if got := keeper.GetEntry(ctx, "unknown"); got.HasValue() || got.StringValue() != "" {
67
68
  t.Errorf("got %q, want no value", got.StringValue())
68
69
  }
69
70
 
70
71
  // Test that we can store and retrieve an empty string value.
71
- keeper.SetStorage(ctx, types.NewStorageEntry("inited", ""))
72
- if got := keeper.GetEntry(ctx, "inited"); !got.HasData() || got.StringValue() != "" {
72
+ keeper.SetStorage(ctx, agoric.NewKVEntry("inited", ""))
73
+ if got := keeper.GetEntry(ctx, "inited"); !got.HasValue() || got.StringValue() != "" {
73
74
  t.Errorf("got %q, want empty string", got.StringValue())
74
75
  }
75
76
 
@@ -78,18 +79,18 @@ func TestStorage(t *testing.T) {
78
79
  t.Errorf("got %q children, want [inited]", got.Children)
79
80
  }
80
81
 
81
- keeper.SetStorage(ctx, types.NewStorageEntry("key1", "value1"))
82
+ keeper.SetStorage(ctx, agoric.NewKVEntry("key1", "value1"))
82
83
  if got := keeper.GetChildren(ctx, ""); !childrenEqual(got.Children, []string{"inited", "key1"}) {
83
84
  t.Errorf("got %q children, want [inited,key1]", got.Children)
84
85
  }
85
86
 
86
87
  // Check alphabetical.
87
- keeper.SetStorage(ctx, types.NewStorageEntry("alpha2", "value2"))
88
+ keeper.SetStorage(ctx, agoric.NewKVEntry("alpha2", "value2"))
88
89
  if got := keeper.GetChildren(ctx, ""); !childrenEqual(got.Children, []string{"alpha2", "inited", "key1"}) {
89
90
  t.Errorf("got %q children, want [alpha2,inited,key1]", got.Children)
90
91
  }
91
92
 
92
- keeper.SetStorage(ctx, types.NewStorageEntry("beta3", "value3"))
93
+ keeper.SetStorage(ctx, agoric.NewKVEntry("beta3", "value3"))
93
94
  if got := keeper.GetChildren(ctx, ""); !childrenEqual(got.Children, []string{"alpha2", "beta3", "inited", "key1"}) {
94
95
  t.Errorf("got %q children, want [alpha2,beta3,inited,key1]", got.Children)
95
96
  }
@@ -99,7 +100,7 @@ func TestStorage(t *testing.T) {
99
100
  }
100
101
 
101
102
  // Check adding children.
102
- keeper.SetStorage(ctx, types.NewStorageEntry("key1.child1", "value1child"))
103
+ keeper.SetStorage(ctx, agoric.NewKVEntry("key1.child1", "value1child"))
103
104
  if got := keeper.GetEntry(ctx, "key1.child1").StringValue(); got != "value1child" {
104
105
  t.Errorf("got %q, want %q", got, "value1child")
105
106
  }
@@ -109,7 +110,7 @@ func TestStorage(t *testing.T) {
109
110
  }
110
111
 
111
112
  // Add a grandchild.
112
- keeper.SetStorage(ctx, types.NewStorageEntry("key1.child1.grandchild1", "value1grandchild"))
113
+ keeper.SetStorage(ctx, agoric.NewKVEntry("key1.child1.grandchild1", "value1grandchild"))
113
114
  if got := keeper.GetEntry(ctx, "key1.child1.grandchild1").StringValue(); got != "value1grandchild" {
114
115
  t.Errorf("got %q, want %q", got, "value1grandchild")
115
116
  }
@@ -119,7 +120,7 @@ func TestStorage(t *testing.T) {
119
120
  }
120
121
 
121
122
  // Delete the child's contents.
122
- keeper.SetStorage(ctx, types.NewStorageEntryWithNoData("key1.child1"))
123
+ keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1.child1"))
123
124
  if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got.Children, []string{"child1"}) {
124
125
  t.Errorf("got %q children, want [child1]", got.Children)
125
126
  }
@@ -129,7 +130,7 @@ func TestStorage(t *testing.T) {
129
130
  }
130
131
 
131
132
  // Delete the grandchild's contents.
132
- keeper.SetStorage(ctx, types.NewStorageEntryWithNoData("key1.child1.grandchild1"))
133
+ keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1.child1.grandchild1"))
133
134
  if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got.Children, []string{}) {
134
135
  t.Errorf("got %q children, want []", got.Children)
135
136
  }
@@ -139,13 +140,13 @@ func TestStorage(t *testing.T) {
139
140
  }
140
141
 
141
142
  // See about deleting the parent.
142
- keeper.SetStorage(ctx, types.NewStorageEntryWithNoData("key1"))
143
+ keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1"))
143
144
  if got := keeper.GetChildren(ctx, ""); !childrenEqual(got.Children, []string{"alpha2", "beta3", "inited"}) {
144
145
  t.Errorf("got %q children, want [alpha2,beta3,inited]", got.Children)
145
146
  }
146
147
 
147
148
  // Do a deep set.
148
- keeper.SetStorage(ctx, types.NewStorageEntry("key2.child2.grandchild2", "value2grandchild"))
149
+ keeper.SetStorage(ctx, agoric.NewKVEntry("key2.child2.grandchild2", "value2grandchild"))
149
150
  if got := keeper.GetChildren(ctx, ""); !childrenEqual(got.Children, []string{"alpha2", "beta3", "inited", "key2"}) {
150
151
  t.Errorf("got %q children, want [alpha2,beta3,inited,key2]", got.Children)
151
152
  }
@@ -157,7 +158,7 @@ func TestStorage(t *testing.T) {
157
158
  }
158
159
 
159
160
  // Do another deep set.
160
- keeper.SetStorage(ctx, types.NewStorageEntry("key2.child2.grandchild2a", "value2grandchilda"))
161
+ keeper.SetStorage(ctx, agoric.NewKVEntry("key2.child2.grandchild2a", "value2grandchilda"))
161
162
  if got := keeper.GetChildren(ctx, "key2.child2"); !childrenEqual(got.Children, []string{"grandchild2", "grandchild2a"}) {
162
163
  t.Errorf("got %q children, want [grandchild2,grandchild2a]", got.Children)
163
164
  }
@@ -184,19 +185,37 @@ func TestStorage(t *testing.T) {
184
185
  t.Errorf("got export %q, want %q", got, expectedKey2Export)
185
186
  }
186
187
 
188
+ keeper.RemoveEntriesWithPrefix(ctx, "key2.child2")
189
+ if keeper.HasEntry(ctx, "key2") {
190
+ t.Errorf("got leftover entries for key2 after removal")
191
+ }
192
+ expectedRemainingExport := []*types.DataEntry{
193
+ {Path: "alpha2", Value: "value2"},
194
+ {Path: "beta3", Value: "value3"},
195
+ {Path: "inited", Value: ""},
196
+ }
197
+ gotRemainingExport := keeper.ExportStorage(ctx)
198
+ if !reflect.DeepEqual(gotRemainingExport, expectedRemainingExport) {
199
+ t.Errorf("got remaining export %q, want %q", expectedRemainingExport, expectedRemainingExport)
200
+ }
201
+
187
202
  keeper.ImportStorage(ctx, gotExport)
203
+ gotExport = keeper.ExportStorage(ctx)
204
+ if !reflect.DeepEqual(gotExport, expectedExport) {
205
+ t.Errorf("got export %q after import, want %q", gotExport, expectedExport)
206
+ }
188
207
  }
189
208
 
190
209
  func TestStorageNotify(t *testing.T) {
191
210
  tk := makeTestKit()
192
211
  ctx, keeper := tk.ctx, tk.vstorageKeeper
193
212
 
194
- keeper.SetStorageAndNotify(ctx, types.NewStorageEntry("notify.noLegacy", "noLegacyValue"))
195
- keeper.LegacySetStorageAndNotify(ctx, types.NewStorageEntry("notify.legacy", "legacyValue"))
196
- keeper.SetStorageAndNotify(ctx, types.NewStorageEntry("notify.noLegacy2", "noLegacyValue2"))
197
- keeper.SetStorageAndNotify(ctx, types.NewStorageEntry("notify.legacy2", "legacyValue2"))
198
- keeper.LegacySetStorageAndNotify(ctx, types.NewStorageEntry("notify.legacy2", "legacyValue2b"))
199
- keeper.SetStorageAndNotify(ctx, types.NewStorageEntry("notify.noLegacy2", "noLegacyValue2b"))
213
+ keeper.SetStorageAndNotify(ctx, agoric.NewKVEntry("notify.noLegacy", "noLegacyValue"))
214
+ keeper.LegacySetStorageAndNotify(ctx, agoric.NewKVEntry("notify.legacy", "legacyValue"))
215
+ keeper.SetStorageAndNotify(ctx, agoric.NewKVEntry("notify.noLegacy2", "noLegacyValue2"))
216
+ keeper.SetStorageAndNotify(ctx, agoric.NewKVEntry("notify.legacy2", "legacyValue2"))
217
+ keeper.LegacySetStorageAndNotify(ctx, agoric.NewKVEntry("notify.legacy2", "legacyValue2b"))
218
+ keeper.SetStorageAndNotify(ctx, agoric.NewKVEntry("notify.noLegacy2", "noLegacyValue2b"))
200
219
 
201
220
  // Check the batched events.
202
221
  expectedBeforeFlushEvents := sdk.Events{}
@@ -273,44 +292,3 @@ func TestStorageNotify(t *testing.T) {
273
292
  t.Errorf("got after second flush events %#v, want %#v", got, expectedAfterFlushEvents)
274
293
  }
275
294
  }
276
-
277
- func TestStorageMigrate(t *testing.T) {
278
- testKit := makeTestKit()
279
- ctx, keeper := testKit.ctx, testKit.vstorageKeeper
280
-
281
- // Simulate a pre-migration storage with empty string as placeholders
282
- keeper.SetStorage(ctx, types.NewStorageEntry("key1", "value1"))
283
- keeper.SetStorage(ctx, types.NewStorageEntry("key1.child1.grandchild1", "value1grandchild"))
284
- keeper.SetStorage(ctx, types.NewStorageEntry("key1.child1", ""))
285
-
286
- // Do a deep set.
287
- keeper.SetStorage(ctx, types.NewStorageEntry("key2.child2.grandchild2", "value2grandchild"))
288
- keeper.SetStorage(ctx, types.NewStorageEntry("key2.child2.grandchild2a", "value2grandchilda"))
289
- keeper.SetStorage(ctx, types.NewStorageEntry("key2.child2", ""))
290
- keeper.SetStorage(ctx, types.NewStorageEntry("key2", ""))
291
-
292
- keeper.MigrateNoDataPlaceholders(ctx)
293
-
294
- if keeper.HasStorage(ctx, "key1.child1") {
295
- t.Errorf("has key1.child1, want no value")
296
- }
297
- if keeper.HasStorage(ctx, "key2.child2") {
298
- t.Errorf("has key2.child2, want no value")
299
- }
300
- if keeper.HasStorage(ctx, "key2") {
301
- t.Errorf("has key2, want no value")
302
- }
303
-
304
- // Check the export.
305
- expectedExport := []*types.DataEntry{
306
- {Path: "key1", Value: "value1"},
307
- {Path: "key1.child1.grandchild1", Value: "value1grandchild"},
308
- {Path: "key2.child2.grandchild2", Value: "value2grandchild"},
309
- {Path: "key2.child2.grandchild2a", Value: "value2grandchilda"},
310
- }
311
- got := keeper.ExportStorage(ctx)
312
- if !reflect.DeepEqual(got, expectedExport) {
313
- t.Errorf("got export %q, want %q", got, expectedExport)
314
- }
315
- keeper.ImportStorage(ctx, got)
316
- }
@@ -1,10 +1,9 @@
1
1
  package keeper
2
2
 
3
3
  import (
4
- "strings"
5
-
6
4
  abci "github.com/tendermint/tendermint/abci/types"
7
5
 
6
+ sdkioerrors "cosmossdk.io/errors"
8
7
  "github.com/cosmos/cosmos-sdk/codec"
9
8
  sdk "github.com/cosmos/cosmos-sdk/types"
10
9
  sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -18,16 +17,42 @@ const (
18
17
  QueryChildren = "children"
19
18
  )
20
19
 
21
- // NewQuerier is the module level router for state queries
20
+ // getVstorageEntryPath validates that a request URL path represents a valid
21
+ // entry path with no extra data, and returns the path of that vstorage entry.
22
+ func getVstorageEntryPath(urlPathSegments []string) (string, error) {
23
+ if len(urlPathSegments) != 1 || types.ValidatePath(urlPathSegments[0]) != nil {
24
+ return "", sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid vstorage entry path")
25
+ }
26
+ return urlPathSegments[0], nil
27
+ }
28
+
29
+ // NewQuerier returns the function for handling queries routed to this module.
30
+ // It performs its own routing based on the first slash-separated URL path
31
+ // segment (e.g., URL path `/data/foo.bar` is a request for the value associated
32
+ // with vstorage path "foo.bar", and `/children/foo.bar` is a request for the
33
+ // child path segments immediately underneath vstorage path "foo.bar" which may
34
+ // be used to extend it to a vstorage path such as "foo.bar.baz").
22
35
  func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
23
- return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
24
- switch path[0] {
36
+ return func(ctx sdk.Context, urlPathSegments []string, req abci.RequestQuery) (res []byte, err error) {
37
+ var queryType string
38
+ if len(urlPathSegments) > 0 {
39
+ queryType = urlPathSegments[0]
40
+ }
41
+ switch queryType {
25
42
  case QueryData:
26
- return queryData(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
43
+ entryPath, entryPathErr := getVstorageEntryPath(urlPathSegments[1:])
44
+ if entryPathErr != nil {
45
+ return nil, entryPathErr
46
+ }
47
+ return queryData(ctx, entryPath, req, keeper, legacyQuerierCdc)
27
48
  case QueryChildren:
28
- return queryChildren(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
49
+ entryPath, entryPathErr := getVstorageEntryPath(urlPathSegments[1:])
50
+ if entryPathErr != nil {
51
+ return nil, entryPathErr
52
+ }
53
+ return queryChildren(ctx, entryPath, req, keeper, legacyQuerierCdc)
29
54
  default:
30
- return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown vstorage query endpoint")
55
+ return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown vstorage query path")
31
56
  }
32
57
  }
33
58
  }
@@ -35,13 +60,13 @@ func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
35
60
  // nolint: unparam
36
61
  func queryData(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
37
62
  entry := keeper.GetEntry(ctx, path)
38
- if !entry.HasData() {
39
- return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not get vstorage path")
63
+ if !entry.HasValue() {
64
+ return nil, sdkioerrors.Wrap(sdkerrors.ErrNotFound, "no data for vstorage path")
40
65
  }
41
66
 
42
- bz, err2 := codec.MarshalJSONIndent(legacyQuerierCdc, types.Data{Value: entry.StringValue()})
43
- if err2 != nil {
44
- return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err2.Error())
67
+ bz, marshalErr := codec.MarshalJSONIndent(legacyQuerierCdc, types.Data{Value: entry.StringValue()})
68
+ if marshalErr != nil {
69
+ return nil, sdkioerrors.Wrap(sdkerrors.ErrJSONMarshal, marshalErr.Error())
45
70
  }
46
71
 
47
72
  return bz, nil
@@ -58,7 +83,7 @@ func queryChildren(ctx sdk.Context, path string, req abci.RequestQuery, keeper K
58
83
 
59
84
  bz, err2 := codec.MarshalJSONIndent(legacyQuerierCdc, types.Children{Children: klist})
60
85
  if err2 != nil {
61
- return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err2.Error())
86
+ return nil, sdkioerrors.Wrap(sdkerrors.ErrJSONMarshal, err2.Error())
62
87
  }
63
88
 
64
89
  return bz, nil