agoric 0.21.2-other-dev-8f8782b.0 → 0.21.2-other-dev-fbe72e7.0.fbe72e7

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 (44) hide show
  1. package/README.md +0 -73
  2. package/package.json +60 -43
  3. package/src/anylogger-agoric.js +31 -16
  4. package/src/bin-agops.js +8 -12
  5. package/src/chain-config.js +42 -16
  6. package/src/commands/auction.js +22 -19
  7. package/src/commands/gov.js +475 -0
  8. package/src/commands/inter.js +44 -62
  9. package/src/commands/oracle.js +144 -87
  10. package/src/commands/perf.js +20 -16
  11. package/src/commands/psm.js +29 -26
  12. package/src/commands/reserve.js +13 -6
  13. package/src/commands/test-upgrade.js +15 -8
  14. package/src/commands/vaults.js +31 -18
  15. package/src/commands/wallet.js +121 -48
  16. package/src/cosmos.js +3 -3
  17. package/src/deploy.js +10 -5
  18. package/src/entrypoint.js +2 -5
  19. package/src/follow.js +14 -10
  20. package/src/helpers.js +10 -5
  21. package/src/init.js +2 -9
  22. package/src/install.js +18 -25
  23. package/src/lib/bundles.js +102 -0
  24. package/src/lib/chain.js +71 -35
  25. package/src/lib/format.js +28 -34
  26. package/src/lib/index.js +7 -0
  27. package/src/lib/packageManager.js +24 -0
  28. package/src/lib/wallet.js +44 -144
  29. package/src/main-publish.js +2 -3
  30. package/src/main.js +95 -125
  31. package/src/open.js +8 -10
  32. package/src/publish.js +4 -9
  33. package/src/scripts.js +14 -32
  34. package/src/sdk-package-names.js +22 -9
  35. package/src/set-defaults.js +2 -1
  36. package/src/start.js +59 -68
  37. package/tools/getting-started.js +272 -0
  38. package/tools/resm-plugin/deploy.js +18 -0
  39. package/tools/resm-plugin/package.json +12 -0
  40. package/tools/resm-plugin/src/output.js +1 -0
  41. package/tools/resm-plugin/src/plugin.js +17 -0
  42. package/CHANGELOG.md +0 -1069
  43. package/src/commands/ec.js +0 -314
  44. package/src/lib/rpc.js +0 -272
@@ -0,0 +1,272 @@
1
+ // @ts-check
2
+ /* eslint-env node */
3
+
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import tmp from 'tmp';
7
+ import { makePromiseKit } from '@endo/promise-kit';
8
+ import { request } from 'http';
9
+
10
+ import { spawn } from 'child_process';
11
+
12
+ import { makePspawn } from '../src/helpers.js';
13
+
14
+ const RETRY_BLOCKHEIGHT_SECONDS = 3;
15
+ const SOCKET_TIMEOUT_SECONDS = 2;
16
+
17
+ // TODO: Set this to `true` when `agoric install $DISTTAG` properly updates the
18
+ // getting-started workflow's dependencies to current `@endo/*` and Agoric SDK
19
+ // from the local registry.
20
+ const AGORIC_INSTALL_DISTTAG = false;
21
+
22
+ const dirname = new URL('./', import.meta.url).pathname;
23
+
24
+ // To keep in sync with https://docs.agoric.com/guides/getting-started/
25
+
26
+ // Note that we currently only test:
27
+ // agoric init dapp-foo
28
+ // yarn install (or agoric install $DISTTAG)
29
+ // yarn start:docker
30
+ // yarn start:contract
31
+ // yarn start:ui
32
+
33
+ /**
34
+ * @param {string} url
35
+ * @returns {Promise<bigint>}
36
+ */
37
+ const getLatestBlockHeight = url =>
38
+ new Promise((resolve, reject) => {
39
+ const req = request(url, res => {
40
+ if (!res) {
41
+ reject(Error('no result'));
42
+ return;
43
+ }
44
+ const bodyChunks = [];
45
+ res
46
+ .on('data', chunk => bodyChunks.push(chunk))
47
+ .on('end', () => {
48
+ const body = Buffer.concat(bodyChunks).toString('utf8');
49
+ const { statusCode = 0 } = res;
50
+ if (statusCode >= 200 && statusCode < 300) {
51
+ const { result: { sync_info: sync = {} } = {} } = JSON.parse(body);
52
+ if (sync.catching_up === false) {
53
+ resolve(BigInt(sync.latest_block_height));
54
+ return;
55
+ }
56
+ }
57
+ reject(Error(`Cannot get block height: ${statusCode} ${body}`));
58
+ });
59
+ });
60
+ req.setTimeout(SOCKET_TIMEOUT_SECONDS * 1_000);
61
+ req.on('error', reject);
62
+ req.end();
63
+ });
64
+
65
+ /**
66
+ * Test the "getting started" workflow. Note that this function may be imported
67
+ * by external repositories.
68
+ *
69
+ * @param {import('ava').ExecutionContext} t
70
+ * @param {{ init?: string[], install?: string[] }} [options]
71
+ */
72
+ export const gettingStartedWorkflowTest = async (t, options = {}) => {
73
+ const { init: initOptions = [], install: installOptions = [] } = options;
74
+ const pspawn = makePspawn({ spawn });
75
+
76
+ // Kill an entire process group.
77
+ const pkill = (cp, signal = 'SIGINT') => process.kill(-cp.pid, signal);
78
+
79
+ /** @param {Parameters<typeof pspawn>} args */
80
+ function pspawnStdout(...args) {
81
+ const ps = pspawn(...args);
82
+ const { stdout } = ps.childProcess;
83
+ if (stdout) {
84
+ stdout.on('data', chunk => {
85
+ process.stdout.write(chunk);
86
+ });
87
+ }
88
+ // ps.childProcess.unref();
89
+ return ps;
90
+ }
91
+
92
+ const defaultAgoricCmd = () => {
93
+ // Run all main programs with the '--sdk' flag if we are in agoric-sdk.
94
+ const extraArgs = fs.existsSync(`${dirname}/../../cosmic-swingset`)
95
+ ? ['--sdk']
96
+ : [];
97
+ const localCli = path.join(dirname, '..', 'bin', 'agoric');
98
+ return [localCli, ...extraArgs];
99
+ };
100
+ const { AGORIC_CMD = JSON.stringify(defaultAgoricCmd()) } = process.env;
101
+ const agoricCmd = JSON.parse(AGORIC_CMD);
102
+ function myMain(args, opts = {}) {
103
+ return pspawnStdout(agoricCmd[0], [...agoricCmd.slice(1), ...args], {
104
+ stdio: ['ignore', 'pipe', 'inherit'],
105
+ env: { ...process.env, DEBUG: 'agoric:debug' },
106
+ detached: true,
107
+ ...opts,
108
+ });
109
+ }
110
+
111
+ /**
112
+ * @param {string[]} args
113
+ * @returns {{childProcess?: import('child_process').ChildProcess} & Promise<void>}
114
+ */
115
+ function yarn(...args) {
116
+ const ps = pspawnStdout('yarn', args, {
117
+ stdio: ['ignore', 'pipe', 'inherit'],
118
+ env: { ...process.env },
119
+ detached: true,
120
+ });
121
+ /** @type {{childProcess?: import('child_process').ChildProcess} & Promise<void>} */
122
+ const p = new Promise((resolve, reject) => {
123
+ ps.then(code => {
124
+ if (code !== 0) {
125
+ reject(
126
+ new Error(`yarn ${args.join(' ')} failed with exit code ${code}`),
127
+ );
128
+ } else {
129
+ resolve();
130
+ }
131
+ }).catch(reject);
132
+ });
133
+ p.childProcess = ps.childProcess;
134
+ return p;
135
+ }
136
+
137
+ const olddir = process.cwd();
138
+ const { name } = tmp.dirSync({
139
+ unsafeCleanup: true,
140
+ prefix: 'agoric-cli-test-',
141
+ });
142
+
143
+ const finalizers = [];
144
+ const runFinalizers = sig => {
145
+ while (finalizers.length) {
146
+ const f = finalizers.shift();
147
+ try {
148
+ f();
149
+ } catch (e) {
150
+ console.log(e);
151
+ }
152
+ }
153
+ if (sig) {
154
+ // We're dying due to signal.
155
+ process.exit(1);
156
+ }
157
+ };
158
+
159
+ await null;
160
+ try {
161
+ process.on('SIGINT', runFinalizers);
162
+ process.on('exit', runFinalizers);
163
+ process.chdir(name);
164
+
165
+ // ==============
166
+ // agoric init dapp-foo
167
+ if (process.env.AGORIC_INIT_OPTIONS) {
168
+ const opts = JSON.parse(process.env.AGORIC_INIT_OPTIONS);
169
+ initOptions.push(...opts);
170
+ }
171
+ t.is(
172
+ await myMain(['init', ...initOptions, 'dapp-foo']),
173
+ 0,
174
+ 'init dapp-foo works',
175
+ );
176
+ process.chdir('dapp-foo');
177
+
178
+ if (AGORIC_INSTALL_DISTTAG && process.env.AGORIC_INSTALL_OPTIONS) {
179
+ // ==============
180
+ // agoric install $DISTTAG
181
+ const opts = JSON.parse(process.env.AGORIC_INSTALL_OPTIONS);
182
+ installOptions.push(...opts);
183
+ t.is(
184
+ await myMain(['install', ...installOptions]),
185
+ 0,
186
+ 'agoric install works',
187
+ );
188
+ } else {
189
+ // ==============
190
+ // yarn install
191
+ await yarn('install', ...installOptions);
192
+ }
193
+
194
+ // ==============
195
+ // yarn start:docker
196
+ await yarn('start:docker');
197
+
198
+ // ==============
199
+ // wait for the chain to start
200
+ let lastKnownBlockHeight = 2n;
201
+ for (;;) {
202
+ try {
203
+ const currentHeight = await getLatestBlockHeight(
204
+ 'http://localhost:26657/status',
205
+ );
206
+ if (currentHeight > lastKnownBlockHeight) {
207
+ const earlierHeight = lastKnownBlockHeight;
208
+ lastKnownBlockHeight = currentHeight;
209
+ if (earlierHeight > 2n && currentHeight > earlierHeight) {
210
+ // We've had at least 3 blocks produced.
211
+ break;
212
+ }
213
+ }
214
+ } catch (e) {
215
+ console.error((e && e.message) || e);
216
+ }
217
+
218
+ // Wait a bit and try again.
219
+ await new Promise(resolve =>
220
+ setTimeout(resolve, RETRY_BLOCKHEIGHT_SECONDS * 1_000),
221
+ );
222
+ }
223
+
224
+ // ==============
225
+ // yarn start:contract
226
+ await yarn('start:contract');
227
+
228
+ // ==============
229
+ // yarn start:ui
230
+ const startUiP = yarn('start:ui');
231
+ finalizers.push(() => pkill(startUiP.childProcess, 'SIGINT'));
232
+ const uiListening = makePromiseKit();
233
+ let retries = 0;
234
+ const ival = setInterval(() => {
235
+ try {
236
+ const resolve = status => {
237
+ clearInterval(ival);
238
+ uiListening.resolve(status);
239
+ };
240
+
241
+ retries += 1;
242
+ if (retries > 8) {
243
+ resolve('too many retries');
244
+ return;
245
+ }
246
+
247
+ const req = request('http://localhost:5173/', _res => {
248
+ resolve('listening');
249
+ });
250
+ req.setTimeout(SOCKET_TIMEOUT_SECONDS * 1_000);
251
+ req.on('error', err => {
252
+ if (!('code' in err) || err.code !== 'ECONNREFUSED') {
253
+ resolve(`Cannot connect to UI server: ${err}`);
254
+ }
255
+ });
256
+ req.end();
257
+ } catch (e) {
258
+ console.error('cannot make request', e);
259
+ }
260
+ }, 3000);
261
+ t.is(
262
+ await Promise.race([startUiP, uiListening.promise]),
263
+ 'listening',
264
+ `yarn start:ui succeeded`,
265
+ );
266
+ clearInterval(ival);
267
+ } finally {
268
+ runFinalizers();
269
+ process.off('SIGINT', runFinalizers);
270
+ process.chdir(olddir);
271
+ }
272
+ };
@@ -0,0 +1,18 @@
1
+ /* globals setTimeout */
2
+ import { E } from '@endo/eventual-send';
3
+
4
+ const PONG_TIMEOUT = 10_000;
5
+
6
+ export default async function deployPlugin(
7
+ homePromise,
8
+ { installUnsafePlugin },
9
+ ) {
10
+ const plugin = await installUnsafePlugin('./src/plugin.js', {});
11
+ const result = await Promise.race([
12
+ E(plugin).ping(),
13
+ new Promise(resolve => setTimeout(resolve, PONG_TIMEOUT, 'timeout')),
14
+ ]);
15
+ if (result !== 'pong') {
16
+ throw Error(`ping failed ${result}`);
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@agoric/test-resm-plugin",
3
+ "version": "1.0.0",
4
+ "type": "commonjs",
5
+ "dependencies": {
6
+ "@endo/eventual-send": "^0.17.2",
7
+ "@endo/marshal": "^0.8.5"
8
+ },
9
+ "typeCoverage": {
10
+ "atLeast": 0
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export const start = 'Started plugin';
@@ -0,0 +1,17 @@
1
+ // @jessie-check
2
+
3
+ import { Far } from '@endo/marshal';
4
+ import { start } from './output.js';
5
+
6
+ export const bootPlugin = () => {
7
+ return Far('plugin', {
8
+ start(_opts) {
9
+ console.log(start);
10
+ return Far('plugin start', {
11
+ async ping() {
12
+ return 'pong';
13
+ },
14
+ });
15
+ },
16
+ });
17
+ };