@agoric/casting 0.4.3-dev-803e785.0.803e785 → 0.4.3-dev-6727d47.0.6727d47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/casting",
3
- "version": "0.4.3-dev-803e785.0.803e785",
3
+ "version": "0.4.3-dev-6727d47.0.6727d47",
4
4
  "description": "Agoric's OCap broadcasting system",
5
5
  "type": "module",
6
6
  "main": "src/main.js",
@@ -22,9 +22,9 @@
22
22
  "author": "Agoric",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@agoric/internal": "0.3.3-dev-803e785.0.803e785",
26
- "@agoric/notifier": "0.6.3-dev-803e785.0.803e785",
27
- "@agoric/store": "0.9.3-dev-803e785.0.803e785",
25
+ "@agoric/internal": "0.3.3-dev-6727d47.0.6727d47",
26
+ "@agoric/notifier": "0.6.3-dev-6727d47.0.6727d47",
27
+ "@agoric/store": "0.9.3-dev-6727d47.0.6727d47",
28
28
  "@cosmjs/encoding": "^0.36.0",
29
29
  "@cosmjs/proto-signing": "^0.36.0",
30
30
  "@cosmjs/stargate": "^0.36.0",
@@ -37,7 +37,7 @@
37
37
  "@endo/promise-kit": "^1.1.13"
38
38
  },
39
39
  "devDependencies": {
40
- "@agoric/cosmic-proto": "0.4.1-dev-803e785.0.803e785",
40
+ "@agoric/cosmic-proto": "0.4.1-dev-6727d47.0.6727d47",
41
41
  "@endo/ses-ava": "^1.3.2",
42
42
  "ava": "^6.4.1",
43
43
  "c8": "^10.1.3",
@@ -45,6 +45,9 @@
45
45
  "tsd": "^0.33.0",
46
46
  "ws": "^7.2.0"
47
47
  },
48
+ "files": [
49
+ "src"
50
+ ],
48
51
  "publishConfig": {
49
52
  "access": "public"
50
53
  },
@@ -60,5 +63,5 @@
60
63
  "typeCoverage": {
61
64
  "atLeast": 89.19
62
65
  },
63
- "gitHead": "803e785954402887190ee2ebabd6e7980feed10f"
66
+ "gitHead": "6727d47e6970be1f992aa904cd964abdfef00a83"
64
67
  }
package/CHANGELOG.md DELETED
@@ -1,122 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ### [0.4.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.4.1...@agoric/casting@0.4.2) (2023-06-02)
7
-
8
- **Note:** Version bump only for package @agoric/casting
9
-
10
-
11
-
12
-
13
-
14
- ### [0.4.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.4.0...@agoric/casting@0.4.1) (2023-05-24)
15
-
16
- **Note:** Version bump only for package @agoric/casting
17
-
18
-
19
-
20
-
21
-
22
- ## [0.4.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.3.2...@agoric/casting@0.4.0) (2023-05-19)
23
-
24
-
25
- ### ⚠ BREAKING CHANGES
26
-
27
- * emit smallcaps-format data in all marshallers
28
- * **AMM:** remove the AMM and cleanup bootstrap etc. dependencies (#7074)
29
- * rename 'fit' to 'mustMatch'
30
-
31
- ### Features
32
-
33
- * **internal:** makeFakeStorageKit supports "get" and "entries" ([6a69aab](https://github.com/Agoric/agoric-sdk/commit/6a69aab5cb54faae5af631bbc2281e4fc4ede8e0))
34
- * emit smallcaps-format data in all marshallers ([1753df8](https://github.com/Agoric/agoric-sdk/commit/1753df83465785b5ee71b250770c9b012d750ffc)), closes [#6822](https://github.com/Agoric/agoric-sdk/issues/6822)
35
- * **AMM:** remove the AMM and cleanup bootstrap etc. dependencies ([#7074](https://github.com/Agoric/agoric-sdk/issues/7074)) ([ed5ee58](https://github.com/Agoric/agoric-sdk/commit/ed5ee58a276fce3c55f19e4f6f662ed579896c2c)), closes [#7047](https://github.com/Agoric/agoric-sdk/issues/7047)
36
- * **casting:** handle noData value encoding ([530bc41](https://github.com/Agoric/agoric-sdk/commit/530bc41854cc7f5e5749e97e87fabc6163a17864))
37
- * assertNetworkConfig ([9762b19](https://github.com/Agoric/agoric-sdk/commit/9762b19b25ebcb4678faa389d39c4bab91e0c25c))
38
- * getEachIterable skip height fetch ([77b1bb5](https://github.com/Agoric/agoric-sdk/commit/77b1bb589e90462bc7514347b8c62c236d72922e))
39
- * getLatestIterable skip height fetch ([aff3354](https://github.com/Agoric/agoric-sdk/commit/aff335417d9553182d50a5b84a4aa7c7fb6ae430))
40
- * getReverseIterable skip height fetch ([edbc8ec](https://github.com/Agoric/agoric-sdk/commit/edbc8ec2fab4a71e2675f5cc608f25d27b43b524))
41
- * vstorageKeySpecToPath ([9db1fbb](https://github.com/Agoric/agoric-sdk/commit/9db1fbb1328c28282db972b3e130e2ee3515b87d))
42
-
43
-
44
- ### Bug Fixes
45
-
46
- * **casting:** use new subscriber tools ([cb1f739](https://github.com/Agoric/agoric-sdk/commit/cb1f739c36c28befa2ab097bfc9b86686dbe57c3))
47
- * require chainName ([5c5e661](https://github.com/Agoric/agoric-sdk/commit/5c5e661f444add3e1544c931c475a3a266a080de))
48
-
49
-
50
- ### Miscellaneous Chores
51
-
52
- * rename 'fit' to 'mustMatch' ([9fa3232](https://github.com/Agoric/agoric-sdk/commit/9fa32324f84bfb85de9e99e0c9ad277b8017b50e)), closes [#6844](https://github.com/Agoric/agoric-sdk/issues/6844)
53
-
54
-
55
-
56
- ### [0.3.4](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.3.3...@agoric/casting@0.3.4) (2023-02-17)
57
-
58
- **Note:** Version bump only for package @agoric/casting
59
-
60
-
61
-
62
-
63
-
64
- ### [0.3.3](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.3.2...@agoric/casting@0.3.3) (2022-12-14)
65
-
66
- **Note:** Version bump only for package @agoric/casting
67
-
68
-
69
-
70
-
71
-
72
- ### [0.3.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.3.1...@agoric/casting@0.3.2) (2022-10-18)
73
-
74
- **Note:** Version bump only for package @agoric/casting
75
-
76
-
77
-
78
-
79
-
80
- ### [0.3.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.3.0...@agoric/casting@0.3.1) (2022-10-08)
81
-
82
- **Note:** Version bump only for package @agoric/casting
83
-
84
-
85
-
86
-
87
-
88
- ## [0.3.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/casting@0.2.0...@agoric/casting@0.3.0) (2022-10-05)
89
-
90
-
91
- ### Features
92
-
93
- * **cli:** show status of invitations ([8506e6d](https://github.com/Agoric/agoric-sdk/commit/8506e6d87ef331e781c9d2e2251fdcf48e784e04))
94
-
95
-
96
-
97
- ## 0.2.0 (2022-09-20)
98
-
99
-
100
- ### ⚠ BREAKING CHANGES
101
-
102
- * **casting:** enable an implicit default follower of the local chain
103
-
104
- ### Features
105
-
106
- * **casting:** enable an implicit default follower of the local chain ([41d4c0c](https://github.com/Agoric/agoric-sdk/commit/41d4c0c0326ec71ede4a6a5b101ae5c8a4339aa0))
107
- * **casting:** provide reverse iteration ([65906f5](https://github.com/Agoric/agoric-sdk/commit/65906f553908ae5200a96307e78ec505060cb43b))
108
- * **casting:** Update to consume stream cells ([35db0da](https://github.com/Agoric/agoric-sdk/commit/35db0daed7f8315222fa87cbf9c50e4e2ee8d225)), closes [#5366](https://github.com/Agoric/agoric-sdk/issues/5366)
109
- * **wallet:** some feedback when no smart wallet ([8057c35](https://github.com/Agoric/agoric-sdk/commit/8057c35d2a89b9d80d31c1da10279c248b3c6e68))
110
- * **wallet-connection:** Connect dapp directly to wallet UI ([#5750](https://github.com/Agoric/agoric-sdk/issues/5750)) ([1dd584b](https://github.com/Agoric/agoric-sdk/commit/1dd584b195212705b1f74a8c89b7f3f121640e41))
111
- * contract for single on-chain wallet ([0184a89](https://github.com/Agoric/agoric-sdk/commit/0184a89403a3719f21dc61de37865512cdc819ae))
112
-
113
-
114
- ### Bug Fixes
115
-
116
- * **casting:** Align cosmjs deps ([0ba7a1f](https://github.com/Agoric/agoric-sdk/commit/0ba7a1f7a18d4f83afa04b3637f432fdd72f3cd8))
117
- * **casting:** correct backoff timer logic ([1b41ef5](https://github.com/Agoric/agoric-sdk/commit/1b41ef56bec54f89296376a0677c421f66baabba))
118
- * **casting:** implement getReverseIterable ([7f5a791](https://github.com/Agoric/agoric-sdk/commit/7f5a79170a11560567406ebb02234dbef20ca07a))
119
- * **casting:** iterateLatest erroneously adapted getEachIterable ([b1937cf](https://github.com/Agoric/agoric-sdk/commit/b1937cf8fbd8685b5078ad5d312b4aa1b173a9ae))
120
- * **casting:** Update each and latest iterators for stream cells. ([231d37c](https://github.com/Agoric/agoric-sdk/commit/231d37c4cd87785c20b70eb270384a50e010b3b7))
121
- * avoid relying on bound `E` proxy methods ([#5998](https://github.com/Agoric/agoric-sdk/issues/5998)) ([497d157](https://github.com/Agoric/agoric-sdk/commit/497d157d29cc8dda58eca9e07c24b57731647074))
122
- * makePublishKit ([#5435](https://github.com/Agoric/agoric-sdk/issues/5435)) ([d8228d2](https://github.com/Agoric/agoric-sdk/commit/d8228d272cfe18aa2fba713fb5acc4e84eaa1e39))
package/test/deploy.js DELETED
@@ -1,35 +0,0 @@
1
- import { E } from '@endo/far';
2
- import { iterateLatest, makeFollower } from '../src/main.js';
3
-
4
- const COLLATERAL = 'ATOM';
5
- const getVaultManagerMetrics = async (homeP, { cache, lookup }) => {
6
- const zoe = E.get(homeP).zoe;
7
- const publicFacet = cache(`publicFacet.vault`, () =>
8
- E(zoe).getPublicFacet(lookup('agoricNames', 'instance', 'VaultFactory')),
9
- );
10
- const brand = await cache(`brand.${COLLATERAL}`, () =>
11
- lookup('agoricNames', 'brand', COLLATERAL),
12
- );
13
- const manager = cache([`vault.manager`, brand], () =>
14
- E(publicFacet).getCollateralManager(brand),
15
- );
16
- const subscription = cache([`subscription`, brand], () =>
17
- E(manager).getMetrics(),
18
- );
19
- return cache([`subscription.key2`, brand], () =>
20
- E(subscription).getStoreKey(),
21
- );
22
- };
23
-
24
- export default async (homeP, { cache, lookup, makeDefaultLeader }) => {
25
- // const storeKey = getStoreKeyFromCache(homeP, { cache, lookup });
26
- const storeKey = getVaultManagerMetrics(homeP, { cache, lookup });
27
-
28
- console.log('storeKey', await storeKey);
29
-
30
- const leader = makeDefaultLeader();
31
- const follower = makeFollower(storeKey, leader);
32
- for await (const { value } of iterateLatest(follower)) {
33
- console.log(`here's a value`, value);
34
- }
35
- };
@@ -1,310 +0,0 @@
1
- import { Buffer } from 'buffer';
2
- import './lockdown.js';
3
-
4
- import { makeMarshal } from '@endo/marshal';
5
-
6
- import express from 'express';
7
- // import morgan from 'morgan';
8
-
9
- import { toAscii, toBase64 } from '@cosmjs/encoding';
10
-
11
- /**
12
- * @import {ExecutionContext} from 'ava';
13
- */
14
-
15
- const chainName = 'fakeChain';
16
-
17
- let lastPort = 8989;
18
-
19
- /**
20
- * @param {number} min
21
- * @param {number} max
22
- * @param {number} n
23
- */
24
- const clamp = (min, max, n) => Math.max(min, Math.min(max, n));
25
-
26
- const fakeStatusResult = {
27
- node_info: {
28
- protocol_version: {
29
- p2p: '7',
30
- block: '10',
31
- app: '0',
32
- },
33
- id: '5576458aef205977e18fd50b274e9b5d9014525a',
34
- listen_addr: 'tcp://0.0.0.0:26656',
35
- network: 'cosmoshub-2',
36
- version: '0.32.1',
37
- channels: '4020212223303800',
38
- moniker: 'moniker-node',
39
- other: {
40
- tx_index: 'on',
41
- rpc_address: 'tcp://0.0.0.0:26657',
42
- },
43
- },
44
- sync_info: {
45
- latest_block_hash:
46
- '790BA84C3545FCCC49A5C629CEE6EA58A6E875C3862175BDC11EE7AF54703501',
47
- latest_app_hash:
48
- 'C9AEBB441B787D9F1D846DE51F3826F4FD386108B59B08239653ABF59455C3F8',
49
- latest_block_height: '1262196',
50
- latest_block_time: '2019-08-01T11:52:22.818762194Z',
51
- earliest_block_hash:
52
- '790BA84C3545FCCC49A5C629CEE6EA58A6E875C3862175BDC11EE7AF54703501',
53
- earliest_app_hash:
54
- 'C9AEBB441B787D9F1D846DE51F3826F4FD386108B59B08239653ABF59455C3F8',
55
- earliest_block_height: '1262196',
56
- earliest_block_time: '2019-08-01T11:52:22.818762194Z',
57
- max_leader_block_height: '1262196',
58
- catching_up: false,
59
- total_synced_time: '1000000000',
60
- remaining_time: '0',
61
- total_snapshots: '10',
62
- chunk_process_avg_time: '1000000000',
63
- snapshot_height: '1262196',
64
- snapshot_chunks_count: '10',
65
- snapshot_chunks_total: '100',
66
- backfilled_blocks: '10',
67
- backfill_blocks_total: '100',
68
- },
69
- validator_info: {
70
- address: '5D6A51A8E9899C44079C6AF90618BA0369070E6E',
71
- pub_key: {
72
- type: 'tendermint/PubKeyEd25519',
73
- value: 'A6DoBUypNtUAyEHWtQ9bFjfNg8Bo9CrnkUGl6k6OHN4=',
74
- },
75
- voting_power: '0',
76
- },
77
- };
78
-
79
- /** @typedef {Partial<ExecutionContext<{cleanups: Array<() => void>}>> & {context}} FakeServerTestContext */
80
- /**
81
- * @param {FakeServerTestContext} t
82
- * @param {Array<{any}>} fakeValues
83
- * @param {object} [options]
84
- * @param {Marshaller} [options.marshaller]
85
- * @param {number} [options.batchSize] count of stream-cell results per response, or 0/absent to return lone naked values
86
- */
87
- export const startFakeServer = (t, fakeValues, options = {}) => {
88
- const { log = console.log } = t;
89
- lastPort += 1;
90
- const PORT = lastPort;
91
- const { marshaller = makeMarshal(), batchSize = 0 } = options;
92
- return new Promise(resolve => {
93
- log('starting http server on port', PORT);
94
- const app = express();
95
- // app.use(morgan());
96
- app.use((req, _res, next) => {
97
- log('request', req.method, req.url);
98
- next();
99
- });
100
- app.use(express.json());
101
- app.get('/bad-network-config', (req, res) => {
102
- res.json({
103
- chainName,
104
- rpcAddrs: 'not an array',
105
- });
106
- });
107
- app.get('/network-config', (req, res) => {
108
- res.json({
109
- chainName,
110
- rpcAddrs: [`http://localhost:${PORT}/tendermint-rpc`],
111
- });
112
- });
113
-
114
- const dataPrefix = new Uint8Array([0]);
115
- const encode = obj => {
116
- const str = JSON.stringify(obj);
117
- const ascii = toAscii(str);
118
- const buf = new Uint8Array(dataPrefix.length + ascii.length);
119
- buf.set(dataPrefix);
120
- buf.set(ascii, dataPrefix.length);
121
- return toBase64(buf);
122
- };
123
- const fakeBlocksStartHeight = 74863;
124
- let blockHeight = fakeBlocksStartHeight;
125
- app.post('/tendermint-rpc', (req, res) => {
126
- log('received', req.path, req.body, req.params);
127
- const reply = result => {
128
- log('response', result);
129
- res.json({
130
- jsonrpc: '2.0',
131
- id: req.body.id,
132
- result,
133
- });
134
- };
135
- log('req.body', req.body);
136
- switch (req.body.method) {
137
- case 'status': {
138
- reply(fakeStatusResult);
139
- break;
140
- }
141
- case 'abci_info': {
142
- const result = {
143
- response: {
144
- data: 'agoric',
145
- version: '0.32.1',
146
- last_block_height: blockHeight,
147
- last_block_app_hash: '',
148
- },
149
- };
150
- reply(result);
151
- break;
152
- }
153
- case 'abci_query': {
154
- const desiredHeight = req.body.height ?? blockHeight;
155
- const values = [];
156
- for (
157
- let batchIndex = 0;
158
- batchIndex < Math.max(1, batchSize);
159
- batchIndex += 1
160
- ) {
161
- const fakeIndex = clamp(
162
- 0,
163
- fakeValues.length - 1,
164
- desiredHeight - fakeBlocksStartHeight + batchIndex,
165
- );
166
- values.push(fakeValues[fakeIndex]);
167
- }
168
- let responseValue;
169
- if (batchSize > 0) {
170
- // Return a JSON stream cell.
171
- const serializedValues = values.map(val =>
172
- JSON.stringify(marshaller.toCapData(val)),
173
- );
174
- responseValue = {
175
- blockHeight: String(desiredHeight - 1),
176
- values: serializedValues,
177
- };
178
- } else {
179
- // Return a single naked value.
180
- responseValue = marshaller.toCapData(values[0]);
181
- }
182
- const responseValueBase64 = encode(responseValue);
183
- const result = {
184
- response: {
185
- code: 0,
186
- log: '',
187
- info: '',
188
- index: '0',
189
- key: Buffer.from(
190
- 'swingset/data:mailbox.agoric1foobarbaz',
191
- ).toString('base64'),
192
- value: responseValueBase64,
193
- proofOps: null,
194
- height: String(blockHeight),
195
- codespace: '',
196
- },
197
- };
198
- reply(result);
199
- break;
200
- }
201
- default: {
202
- res.sendStatus(400);
203
- }
204
- }
205
- });
206
- const controller = {
207
- advance(offset) {
208
- blockHeight += offset;
209
- },
210
- };
211
- const listener = app.listen(PORT, () => {
212
- log('started http server on', PORT);
213
- const cleanup = () => {
214
- log('shutting down http server on', PORT);
215
- listener.close();
216
- };
217
- t.context.cleanups.push(cleanup);
218
- resolve({ controller, PORT });
219
- });
220
- });
221
- };
222
-
223
- export const jsonPairs = harden([
224
- // Justin is the same as the JSON encoding but without unnecessary quoting
225
- ['[1,2]', '[1,2]'],
226
- ['{"foo":1}', '{foo:1}'],
227
- ['{"a":1,"b":2}', '{a:1,b:2}'],
228
- ['{"a":1,"b":{"c":3}}', '{a:1,b:{c:3}}'],
229
- ['true', 'true'],
230
- ['1', '1'],
231
- ['"abc"', '"abc"'],
232
- ['null', 'null'],
233
-
234
- // Primitives not representable in JSON
235
- ['{"@qclass":"undefined"}', 'undefined'],
236
- ['{"@qclass":"NaN"}', 'NaN'],
237
- ['{"@qclass":"Infinity"}', 'Infinity'],
238
- ['{"@qclass":"-Infinity"}', '-Infinity'],
239
- ['{"@qclass":"bigint","digits":"4"}', '4n'],
240
- ['{"@qclass":"bigint","digits":"9007199254740993"}', '9007199254740993n'],
241
- ['{"@qclass":"symbol","name":"@@asyncIterator"}', 'Symbol.asyncIterator'],
242
- ['{"@qclass":"symbol","name":"@@match"}', 'Symbol.match'],
243
- ['{"@qclass":"symbol","name":"foo"}', 'Symbol.for("foo")'],
244
- ['{"@qclass":"symbol","name":"@@@@foo"}', 'Symbol.for("@@foo")'],
245
-
246
- // Arrays and objects
247
- ['[{"@qclass":"undefined"}]', '[undefined]'],
248
- ['{"foo":{"@qclass":"undefined"}}', '{foo:undefined}'],
249
- ['{"@qclass":"error","message":"","name":"Error"}', 'Error("")'],
250
- [
251
- '{"@qclass":"error","message":"msg","name":"ReferenceError"}',
252
- 'ReferenceError("msg")',
253
- ],
254
-
255
- // The one case where JSON is not a semantic subset of JS
256
- ['{"__proto__":8}', '{["__proto__"]:8}'],
257
-
258
- // The Hilbert Hotel is always tricky
259
- ['{"@qclass":"hilbert","original":8}', '{"@qclass":8}'],
260
- ['{"@qclass":"hilbert","original":"@qclass"}', '{"@qclass":"@qclass"}'],
261
- [
262
- '{"@qclass":"hilbert","original":{"@qclass":"hilbert","original":8}}',
263
- '{"@qclass":{"@qclass":8}}',
264
- ],
265
- [
266
- '{"@qclass":"hilbert","original":{"@qclass":"hilbert","original":8,"rest":{"foo":"foo1"}},"rest":{"bar":{"@qclass":"hilbert","original":{"@qclass":"undefined"}}}}',
267
- '{"@qclass":{"@qclass":8,foo:"foo1"},bar:{"@qclass":undefined}}',
268
- ],
269
-
270
- // tagged
271
- ['{"@qclass":"tagged","tag":"x","payload":8}', 'makeTagged("x",8)'],
272
- [
273
- '{"@qclass":"tagged","tag":"x","payload":{"@qclass":"undefined"}}',
274
- 'makeTagged("x",undefined)',
275
- ],
276
-
277
- // Slots
278
- [
279
- '[{"@qclass":"slot","iface":"Alleged: for testing Justin","index":0}]',
280
- '[slot(0,"Alleged: for testing Justin")]',
281
- ],
282
- // Tests https://github.com/endojs/endo/issues/1185 fix
283
- [
284
- '[{"@qclass":"slot","iface":"Alleged: for testing Justin","index":0},{"@qclass":"slot","index":0}]',
285
- '[slot(0,"Alleged: for testing Justin"),slot(0)]',
286
- ],
287
- ]);
288
-
289
- export const develop = async () => {
290
- const { unserialize } = makeMarshal();
291
- const fakeValues = harden(
292
- jsonPairs.map(([jsonMarshalled]) =>
293
- unserialize({ body: jsonMarshalled, slots: [] }),
294
- ),
295
- );
296
- const mockT = /** @type {FakeServerTestContext} */ (
297
- /** @type {unknown} */ ({
298
- log: console.log,
299
- context: { cleanups: [] },
300
- })
301
- );
302
- const { PORT } = await startFakeServer(mockT, [...fakeValues]);
303
- console.log(
304
- `Try this in another terminal:
305
- agoric follow :fake.path --bootstrap=http://localhost:${PORT}/network-config --sleep=0.5 --proof=none`,
306
- );
307
- console.warn(`Control-C to interrupt...`);
308
- // Wait forever.
309
- await new Promise(() => {});
310
- };
@@ -1,123 +0,0 @@
1
- // @ts-check
2
- /* global globalThis */
3
- import anyTest from 'ava';
4
- import {
5
- createProtobufRpcClient,
6
- QueryClient,
7
- setupBankExtension,
8
- } from '@cosmjs/stargate';
9
- import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
10
- import {
11
- QueryChildrenRequest,
12
- QueryChildrenResponse,
13
- } from '@agoric/cosmic-proto/vstorage/query.js';
14
-
15
- import { makeTendermintRpcClient } from '../src/makeHttpClient.js';
16
- import { captureIO, replayIO, web1, web2 } from './net-access-fixture.js';
17
-
18
- /**
19
- * @import {EReturn} from '@endo/far';
20
- * @import {TestFn} from 'ava';
21
- */
22
-
23
- /** @type {TestFn<EReturn<typeof makeTestContext>>} */
24
- const test = /** @type {any} */ (anyTest);
25
-
26
- const RECORDING = false;
27
-
28
- const makeTestContext = async () => {
29
- return { fetch: globalThis.fetch };
30
- };
31
-
32
- test.before(async t => {
33
- t.context = await makeTestContext();
34
- });
35
-
36
- const scenario1 = {
37
- endpoint: 'https://emerynet.rpc.agoric.net/',
38
- request: {
39
- id: 1,
40
- method: 'no-such-method',
41
- params: [],
42
- },
43
- gov2: {
44
- addr: 'agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang',
45
- balance: { amount: '25050000', denom: 'uist' },
46
- },
47
- };
48
-
49
- test('interpose net access', async t => {
50
- const fetchMock = replayIO(web1);
51
- const rpcClient = makeTendermintRpcClient(scenario1.endpoint, fetchMock);
52
-
53
- t.log('raw JSON RPC');
54
- const res = await rpcClient.execute({
55
- ...scenario1.request,
56
- jsonrpc: '2.0',
57
- });
58
- t.like(res, { error: { message: 'Method not found' } });
59
-
60
- t.log('Cosmos SDK RPC: balance query');
61
- const tmClient = await Tendermint34Client.create(rpcClient);
62
- const qClient = new QueryClient(tmClient);
63
- const ext = setupBankExtension(qClient);
64
- const actual = await ext.bank.balance(
65
- scenario1.gov2.addr,
66
- scenario1.gov2.balance.denom,
67
- );
68
-
69
- t.deepEqual(actual, scenario1.gov2.balance);
70
- });
71
-
72
- const scenario2 = {
73
- endpoint: 'https://emerynet.rpc.agoric.net/',
74
- children: [
75
- 'activityhash',
76
- 'beansOwing',
77
- 'egress',
78
- 'highPrioritySenders',
79
- 'published',
80
- 'swingStore',
81
- ],
82
- };
83
-
84
- // XXX open code until https://github.com/Agoric/agoric-sdk/issues/9200
85
- class QueryClientImpl {
86
- rpc;
87
-
88
- service;
89
-
90
- constructor(rpc, opts) {
91
- this.service = opts?.service || 'agoric.vstorage.Query';
92
- this.rpc = rpc;
93
- }
94
-
95
- Children(request) {
96
- const reqData = QueryChildrenRequest.encode(request).finish();
97
- const promise = this.rpc.request(this.service, 'Children', reqData);
98
- return promise.then(respData => QueryChildrenResponse.decode(respData));
99
- }
100
- }
101
-
102
- test(`vstorage query: Children (RECORDING: ${RECORDING})`, async t => {
103
- const { context: io } = t;
104
-
105
- const { fetch: fetchMock, web } = io.recording
106
- ? captureIO(io.fetch)
107
- : { fetch: replayIO(web2), web: new Map() };
108
- const rpcClient = makeTendermintRpcClient(scenario2.endpoint, fetchMock);
109
-
110
- const tmClient = await Tendermint34Client.create(rpcClient);
111
- const qClient = new QueryClient(tmClient);
112
- const rpc = createProtobufRpcClient(qClient);
113
- const queryService = new QueryClientImpl(rpc);
114
-
115
- const children = await queryService.Children({ path: '' });
116
- if (io.recording) {
117
- t.snapshot(web);
118
- }
119
- t.deepEqual(children, {
120
- children: scenario2.children,
121
- pagination: undefined,
122
- });
123
- });
package/test/lockdown.js DELETED
@@ -1,2 +0,0 @@
1
- import '@endo/init/pre-remoting.js';
2
- import '@endo/init';
package/test/mvp.test.js DELETED
@@ -1,238 +0,0 @@
1
- // @ts-nocheck
2
-
3
- import './lockdown.js';
4
-
5
- import { makeMarshal } from '@endo/marshal';
6
- import { test } from './prepare-test-env-ava.js';
7
-
8
- import {
9
- iterateLatest,
10
- iterateEach,
11
- makeFollower,
12
- makeLeader,
13
- makeCastingSpec,
14
- } from '../src/main.js';
15
-
16
- import { delay } from '../src/defaults.js';
17
- import { startFakeServer } from './fake-rpc-server.js';
18
-
19
- /**
20
- * @import {LeaderOptions} from '../src/types.js';
21
- * @import {FollowerOptions} from '../src/types.js';
22
- */
23
-
24
- // TODO: Replace with test.macro({title, exec}).
25
- const testHappyPath = (label, ...input) => {
26
- // eslint-disable-next-line no-shadow
27
- const title = label => `happy path ${label}`;
28
- const makeExec =
29
- ({ fakeValues, iterate, start = 0, stride = 1, expectedValues, options }) =>
30
- async t => {
31
- const expected = expectedValues ?? [...fakeValues];
32
- t.plan(expected.length);
33
- const { controller, PORT } = await t.context.startFakeServer(
34
- t,
35
- fakeValues,
36
- options,
37
- );
38
- controller.advance(start);
39
- /** @type {LeaderOptions} */
40
- const lo = {
41
- retryCallback: null, // fail fast, no retries
42
- keepPolling: () => delay(1000).then(() => true), // poll really quickly
43
- jitter: null, // no jitter
44
- };
45
- /** @type {FollowerOptions} */
46
- const so = {
47
- proof: 'none',
48
- };
49
-
50
- // The rest of this test is taken almost verbatim from the README.md, with
51
- // some minor modifications (testLeaderOptions and deepEqual).
52
- const leader = makeLeader(`http://localhost:${PORT}/network-config`, lo);
53
- const castingSpec = makeCastingSpec(':mailbox.agoric1foobarbaz');
54
- const follower = await makeFollower(castingSpec, leader, so);
55
- for await (const { value } of iterate(follower)) {
56
- t.log(`here's a mailbox value`, value);
57
-
58
- // The rest here is to drive the test.
59
- t.deepEqual(value, expected.shift());
60
- if (expected.length === 0) {
61
- break;
62
- }
63
- controller.advance(stride);
64
- }
65
- };
66
- test(title(label), makeExec(...input));
67
- };
68
-
69
- testHappyPath('each legacy cells', {
70
- fakeValues: ['latest', 'later', 'done'],
71
- iterate: iterateEach,
72
- options: {},
73
- });
74
-
75
- testHappyPath('each stream cells batchSize=1', {
76
- fakeValues: ['latest', 'later', 'done'],
77
- iterate: iterateEach,
78
- options: { batchSize: 1 },
79
- });
80
-
81
- testHappyPath('each stream cells batchSize=2', {
82
- fakeValues: ['latest', 'later', 'done'],
83
- iterate: iterateEach,
84
- options: { batchSize: 2 },
85
- });
86
-
87
- testHappyPath('latest legacy cells', {
88
- fakeValues: ['latest', 'later', 'done'],
89
- iterate: iterateLatest,
90
- options: {},
91
- });
92
-
93
- testHappyPath('latest stream cells batchSize=1', {
94
- fakeValues: ['latest', 'later', 'done'],
95
- iterate: iterateLatest,
96
- options: { batchSize: 1 },
97
- });
98
-
99
- testHappyPath('latest stream cells batchSize=2', {
100
- fakeValues: ['latest', 'later', 'done'],
101
- expectedValues: [
102
- /* latest skipped because not final in batch */ 'later',
103
- 'done',
104
- ],
105
- iterate: iterateLatest,
106
- options: { batchSize: 2 },
107
- });
108
-
109
- testHappyPath('latest stream cells batchSize=2 stride=1', {
110
- fakeValues: ['a1', 'a2', 'b1', 'b2', 'c'],
111
- expectedValues: ['a2', 'b1', 'b2', 'c'],
112
- iterate: iterateLatest,
113
- options: { batchSize: 2 },
114
- });
115
-
116
- testHappyPath('latest stream cells batchSize=2 stride=2', {
117
- fakeValues: ['a1', 'a2', 'b1', 'b2', 'c'],
118
- expectedValues: ['a2', 'b2', 'c'],
119
- iterate: iterateLatest,
120
- stride: 2,
121
- options: { batchSize: 2 },
122
- });
123
-
124
- testHappyPath('latest legacy cells, start at 1', {
125
- fakeValues: ['latest', 'later', 'done'],
126
- expectedValues: ['later', 'done'],
127
- iterate: iterateLatest,
128
- start: 1,
129
- options: {},
130
- });
131
-
132
- testHappyPath('latest legacy cells, stride by 2', {
133
- fakeValues: ['latest', 'later', 'done'],
134
- expectedValues: ['latest', /* skip later */ 'done'],
135
- iterate: iterateLatest,
136
- stride: 2,
137
- options: {},
138
- });
139
-
140
- test('bad network config', async t => {
141
- const { PORT } = await t.context.startFakeServer(t, []);
142
- await t.throwsAsync(
143
- () =>
144
- makeLeader(`http://localhost:${PORT}/bad-network-config`, {
145
- retryCallback: null,
146
- jitter: null,
147
- }),
148
- {
149
- message: /rpcAddrs.*Must be a copyArray/,
150
- },
151
- );
152
- });
153
-
154
- test('missing rpc server', async t => {
155
- const { PORT } = await t.context.startFakeServer(t, []);
156
- await t.throwsAsync(
157
- () =>
158
- makeLeader(`http://localhost:${PORT}/missing-network-config`, {
159
- retryCallback: null,
160
- jitter: null,
161
- }),
162
- {
163
- message: /^Unexpected token/,
164
- },
165
- );
166
- });
167
-
168
- test('unrecognized proof', async t => {
169
- await t.throwsAsync(
170
- () =>
171
- makeFollower(makeCastingSpec(':activityhash'), {}, { proof: 'bother' }),
172
- {
173
- message: /unrecognized follower proof mode.*/,
174
- },
175
- );
176
- });
177
-
178
- test('yields error on bad capdata without terminating', async t => {
179
- const marshal = makeMarshal();
180
- const improperlyMarshalledData = { bad: 'data' };
181
- const properlyMarshalledData = { foo: 'bar' };
182
- const fakeValues = [
183
- improperlyMarshalledData,
184
- marshal.toCapData(harden(properlyMarshalledData)),
185
- ];
186
- t.plan(4);
187
- const options = { batchSize: 1, marshaller: { toCapData: data => data } };
188
- const { controller, PORT } = await t.context.startFakeServer(
189
- t,
190
- fakeValues,
191
- options,
192
- );
193
- controller.advance(0);
194
- /** @type {LeaderOptions} */
195
- const lo = {
196
- retryCallback: null, // fail fast, no retries
197
- keepPolling: () => delay(1000).then(() => true), // poll really quickly
198
- jitter: null, // no jitter
199
- };
200
- /** @type {FollowerOptions} */
201
- const so = {
202
- proof: 'none',
203
- };
204
-
205
- const leader = makeLeader(`http://localhost:${PORT}/network-config`, lo);
206
- const castingSpec = makeCastingSpec(':mailbox.agoric1foobarbaz');
207
- const follower = await makeFollower(castingSpec, leader, so);
208
- let i = 0;
209
-
210
- for await (const { value, error } of iterateEach(follower)) {
211
- if (i === 0) {
212
- t.log(`value from follower, should be undefined:`, value);
213
- t.log(`error from follower, should be defined:`, error);
214
-
215
- t.deepEqual(value, undefined);
216
- t.assert(typeof error === 'object');
217
-
218
- i += 1;
219
- controller.advance(1);
220
- } else if (i === 1) {
221
- t.log(`value from follower, should be defined:`, value);
222
- t.log(`error from follower, should be undefined:`, error);
223
-
224
- t.deepEqual(value, properlyMarshalledData);
225
- t.deepEqual(error, undefined);
226
- break;
227
- }
228
- }
229
- });
230
-
231
- test.before(t => {
232
- t.context.cleanups = [];
233
- t.context.startFakeServer = startFakeServer;
234
- });
235
-
236
- test.after(t => {
237
- t.context.cleanups.map(cleanup => cleanup());
238
- });
@@ -1,196 +0,0 @@
1
- const { stringify: jq } = JSON;
2
-
3
- /**
4
- * @file to regenerate
5
- * 1. set RECORDING=true in interpose-net-access.test.js
6
- * 2. run: yarn test test/interpose-net-access.test.js --update-snapshots
7
- * 3. for each map in interpose-net-access.test.js.md, copy it and
8
- * 4. replace all occurences of => with : and paste as args to Object.fromEntries()
9
- * 5. change RECORDING back to false
10
- */
11
- export const web1 = new Map([
12
- [
13
- jq([
14
- 'https://emerynet.rpc.agoric.net/',
15
- {
16
- method: 'POST',
17
- body: jq({
18
- id: 1208387614,
19
- method: 'no-such-method',
20
- params: [],
21
- jsonrpc: '2.0',
22
- }),
23
- headers: { 'Content-Type': 'application/json' },
24
- },
25
- ]),
26
- {
27
- error: {
28
- code: -32601,
29
- message: 'Method not found',
30
- },
31
- id: 1208387614,
32
- jsonrpc: '2.0',
33
- },
34
- ],
35
- [
36
- jq([
37
- 'https://emerynet.rpc.agoric.net/',
38
- {
39
- method: 'POST',
40
- body: jq({
41
- jsonrpc: '2.0',
42
- id: 797030719,
43
- method: 'abci_query',
44
- params: {
45
- path: '/cosmos.bank.v1beta1.Query/Balance',
46
- data: '0a2d61676f726963313430646d6b727a326534326572676a6a37677976656a687a6d6a7a7572767165713832616e67120475697374',
47
- prove: false,
48
- },
49
- }),
50
- headers: { 'Content-Type': 'application/json' },
51
- },
52
- ]),
53
- {
54
- id: 797030719,
55
- jsonrpc: '2.0',
56
- result: {
57
- response: {
58
- code: 0,
59
- codespace: '',
60
- height: '123985',
61
- index: '0',
62
- info: '',
63
- key: null,
64
- log: '',
65
- proofOps: null,
66
- value: 'ChAKBHVpc3QSCDI1MDUwMDAw',
67
- },
68
- },
69
- },
70
- ],
71
- ]);
72
-
73
- export const web2 = new Map([
74
- [
75
- jq([
76
- 'https://emerynet.rpc.agoric.net/',
77
- {
78
- method: 'POST',
79
- body: jq({
80
- jsonrpc: '2.0',
81
- id: 1757612624,
82
- method: 'abci_query',
83
- params: {
84
- path: '/agoric.vstorage.Query/Children',
85
- data: '',
86
- prove: false,
87
- },
88
- }),
89
- headers: { 'Content-Type': 'application/json' },
90
- },
91
- ]),
92
- {
93
- id: 1757612624,
94
- jsonrpc: '2.0',
95
- result: {
96
- response: {
97
- code: 0,
98
- codespace: '',
99
- height: '123985',
100
- index: '0',
101
- info: '',
102
- key: null,
103
- log: '',
104
- proofOps: null,
105
- value:
106
- 'CgxhY3Rpdml0eWhhc2gKCmJlYW5zT3dpbmcKBmVncmVzcwoTaGlnaFByaW9yaXR5U2VuZGVycwoJcHVibGlzaGVkCgpzd2luZ1N0b3Jl',
107
- },
108
- },
109
- },
110
- ],
111
- ]);
112
-
113
- /**
114
- * @param {string} str
115
- * ack: https://stackoverflow.com/a/7616484
116
- */
117
- const hashCode = str => {
118
- let hash = 0;
119
- let i;
120
- let chr;
121
- if (str.length === 0) return hash;
122
- for (i = 0; i < str.length; i += 1) {
123
- chr = str.charCodeAt(i);
124
- // eslint-disable-next-line no-bitwise
125
- hash = (hash << 5) - hash + chr;
126
- // eslint-disable-next-line no-bitwise
127
- hash |= 0; // Convert to 32bit integer
128
- }
129
- return hash;
130
- };
131
-
132
- /**
133
- * Normalize JSON RPC request ID
134
- *
135
- * tendermint-rpc generates ids using ambient access to Math.random()
136
- * So we normalize them to a hash of the rest of the JSON.
137
- *
138
- * Earlier, we tried a sequence number, but it was non-deterministic
139
- * with multiple interleaved requests.
140
- *
141
- * @param {string} argsKey
142
- */
143
- const normalizeID = argsKey => {
144
- // arbitrary string unlikely to occur in a request. from `pwgen 16 -1`
145
- const placeholder = 'Ajaz1chei7ohnguv';
146
-
147
- const noid = argsKey.replace(/\\"id\\":\d+/, `\\"id\\":${placeholder}`);
148
- const id = Math.abs(hashCode(noid));
149
- return noid.replace(placeholder, `${id}`);
150
- };
151
-
152
- /**
153
- * Wrap `fetch` to capture JSON RPC IO traffic.
154
- *
155
- * @param {typeof window.fetch} fetch
156
- * returns wraped fetch along with a .web map for use with {@link replayIO}
157
- */
158
- export const captureIO = fetch => {
159
- const web = new Map();
160
- /** @type {typeof window.fetch} */
161
- // @ts-expect-error mock
162
- const f = async (...args) => {
163
- const key = normalizeID(JSON.stringify(args));
164
- const resp = await fetch(...args);
165
- return {
166
- json: async () => {
167
- const data = await resp.json();
168
- web.set(key, data);
169
- return data;
170
- },
171
- };
172
- };
173
- return { fetch: f, web };
174
- };
175
-
176
- /**
177
- * Replay captured JSON RPC IO.
178
- *
179
- * @param {Map<string, any>} web map from
180
- * JSON-stringified fetch args to fetched JSON data.
181
- */
182
- export const replayIO = web => {
183
- /** @type {typeof window.fetch} */
184
- // @ts-expect-error mock
185
- const f = async (...args) => {
186
- const key = normalizeID(JSON.stringify(args));
187
- const data = web.get(key);
188
- if (!data) {
189
- throw Error(`no data for ${key}`);
190
- }
191
- return {
192
- json: async () => data,
193
- };
194
- };
195
- return f;
196
- };
@@ -1,52 +0,0 @@
1
- import { test } from './prepare-test-env-ava.js';
2
- import { assertNetworkConfig } from '../src/netconfig.js';
3
-
4
- /**
5
- * @import {NetworkConfig} from '@agoric/casting/src/netconfig.js';
6
- */
7
-
8
- test('https://main.agoric.net/network-config 2022-10-27', t => {
9
- /**
10
- * @type {NetworkConfig}
11
- */
12
- const specimen = {
13
- chainName: 'agoric-3',
14
- gci: 'edef208d407403e6f478bc33dcf7bb294febc5bc6a423c720f0c9c50da5176d5',
15
- peers: [
16
- 'a26158a5cbb1df581dd6843ac427191af76d6d5d@104.154.240.50:26656',
17
- '6e26a1b4afa6889f841d7957e8c2b5d50d32d485@95.216.53.26:26656',
18
- ],
19
- rpcAddrs: ['https://agoric-rpc.polkachu.com:443'],
20
- apiAddrs: ['https://agoric-api.polkachu.com:443'],
21
- // @ts-expect-error extraneous
22
- oldRpcAddrs: ['https://main.rpc.agoric.net:443'],
23
- seeds: [],
24
- };
25
- t.notThrows(() => assertNetworkConfig(harden(specimen)));
26
- });
27
-
28
- test('https://ollinet.agoric.net/network-config 2022-10-27', t => {
29
- /**
30
- * @type {NetworkConfig}
31
- */
32
- const specimen = {
33
- chainName: 'agoricollinet-44',
34
- gci: 'https://ollinet.rpc.agoric.net:443/genesis',
35
- peers: ['fb86a0993c694c981a28fa1ebd1fd692f345348b@34.67.167.8:26656'],
36
- rpcAddrs: ['https://ollinet.rpc.agoric.net:443'],
37
- seeds: ['0f04c4610b7511a64b8644944b907416db568590@34.172.146.145:26656'],
38
- };
39
- t.notThrows(() => assertNetworkConfig(harden(specimen)));
40
- });
41
-
42
- test('https://ollinet.agoric.net/network-config 2022-10-27 minus rpcAddrs', t => {
43
- const specimen = {
44
- chainName: 'agoricollinet-44',
45
- gci: 'https://ollinet.rpc.agoric.net:443/genesis',
46
- peers: ['fb86a0993c694c981a28fa1ebd1fd692f345348b@34.67.167.8:26656'],
47
- seeds: ['0f04c4610b7511a64b8644944b907416db568590@34.172.146.145:26656'],
48
- };
49
- t.throws(() => assertNetworkConfig(harden(specimen)), {
50
- message: /Must have missing properties \["rpcAddrs"\]/,
51
- });
52
- });
@@ -1,6 +0,0 @@
1
- import './lockdown.js';
2
- import { wrapTest } from '@endo/ses-ava';
3
- import rawTest from 'ava';
4
-
5
- /** @type {typeof rawTest} */
6
- export const test = wrapTest(rawTest);
@@ -1,31 +0,0 @@
1
- import { E } from '@endo/far';
2
- import { expectType } from 'tsd';
3
- import type { ValueFollower } from '../src/follower-cosmjs.js';
4
- import { makeFollower } from '../src/follower.js';
5
- import { iterateLatest } from '../src/iterable.js';
6
- import { makeLeader } from '../src/leader-netconfig.js';
7
- import type { ValueFollowerElement } from '../src/types.js';
8
-
9
- type ThePublishedDatum = { a: 1; b: 'two' };
10
- type TheFollowerElement = ValueFollowerElement<ThePublishedDatum>;
11
-
12
- const leader = makeLeader();
13
-
14
- {
15
- const f = makeFollower<ThePublishedDatum>('', leader, {});
16
- expectType<ValueFollower<ThePublishedDatum>>(await f);
17
-
18
- expectType<AsyncIterable<TheFollowerElement>>(await E(f).getLatestIterable());
19
-
20
- expectType<AsyncIterable<TheFollowerElement>>(await E(f).getLatestIterable());
21
-
22
- expectType<AsyncIterable<TheFollowerElement>>(
23
- await E(f).getReverseIterable(),
24
- );
25
-
26
- const iter = iterateLatest(f);
27
- for await (const { value } of iter) {
28
- assert(value, 'value undefined');
29
- expectType<ThePublishedDatum>(value);
30
- }
31
- }
@@ -1,6 +0,0 @@
1
- {
2
- "extends": [
3
- "./tsconfig.json",
4
- "../../tsconfig-build-options.json"
5
- ]
6
- }
@@ -1 +0,0 @@
1
- {"root":["./src/casting-spec.js","./src/change-follower.js","./src/defaults.js","./src/follower-cosmjs.js","./src/follower.js","./src/iterable.js","./src/leader-netconfig.js","./src/leader.js","./src/main.js","./src/makeHttpClient.js","./src/netconfig.js","./src/shuffle.js","./src/types.js"],"version":"5.9.3"}
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- // This file can contain .js-specific Typescript compiler config.
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {},
5
- "include": [
6
- "*.js",
7
- "public/**/*.js",
8
- "src",
9
- "test",
10
- ],
11
- }