agoric 0.21.2-other-dev-1f26562.0 → 0.21.2-other-dev-3eb1a1d.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/package.json +53 -39
- package/src/anylogger-agoric.js +31 -16
- package/src/bin-agops.js +8 -10
- package/src/chain-config.js +33 -14
- package/src/commands/auction.js +17 -18
- package/src/commands/{ec.js → gov.js} +211 -59
- package/src/commands/inter.js +45 -62
- package/src/commands/oracle.js +98 -61
- package/src/commands/perf.js +6 -6
- package/src/commands/psm.js +19 -20
- package/src/commands/reserve.js +8 -6
- package/src/commands/test-upgrade.js +16 -8
- package/src/commands/vaults.js +25 -18
- package/src/commands/wallet.js +105 -35
- package/src/cosmos.js +3 -3
- package/src/deploy.js +3 -4
- package/src/entrypoint.js +1 -3
- package/src/follow.js +6 -3
- package/src/helpers.js +9 -5
- package/src/init.js +2 -9
- package/src/install.js +17 -16
- package/src/lib/bundles.js +102 -0
- package/src/lib/chain.js +63 -12
- package/src/lib/format.js +28 -34
- package/src/lib/network-config.js +41 -0
- package/src/lib/wallet.js +43 -143
- package/src/main-publish.js +2 -3
- package/src/main.js +91 -89
- package/src/open.js +8 -10
- package/src/publish.js +4 -9
- package/src/scripts.js +13 -4
- package/src/sdk-package-names.js +13 -7
- package/src/set-defaults.js +2 -1
- package/src/start.js +59 -67
- package/tools/getting-started.js +254 -0
- package/tools/resm-plugin/deploy.js +18 -0
- package/tools/resm-plugin/package.json +12 -0
- package/tools/resm-plugin/src/output.js +1 -0
- package/tools/resm-plugin/src/plugin.js +17 -0
- package/CHANGELOG.md +0 -1069
- package/src/lib/rpc.js +0 -272
|
@@ -0,0 +1,254 @@
|
|
|
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
|
+
function yarn(args) {
|
|
112
|
+
return pspawnStdout('yarn', args, {
|
|
113
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
114
|
+
env: { ...process.env },
|
|
115
|
+
detached: true,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const olddir = process.cwd();
|
|
120
|
+
const { name } = tmp.dirSync({
|
|
121
|
+
unsafeCleanup: true,
|
|
122
|
+
prefix: 'agoric-cli-test-',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const finalizers = [];
|
|
126
|
+
const runFinalizers = sig => {
|
|
127
|
+
while (finalizers.length) {
|
|
128
|
+
const f = finalizers.shift();
|
|
129
|
+
try {
|
|
130
|
+
f();
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.log(e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (sig) {
|
|
136
|
+
// We're dying due to signal.
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
await null;
|
|
142
|
+
try {
|
|
143
|
+
process.on('SIGINT', runFinalizers);
|
|
144
|
+
process.on('exit', runFinalizers);
|
|
145
|
+
process.chdir(name);
|
|
146
|
+
|
|
147
|
+
// ==============
|
|
148
|
+
// agoric init dapp-foo
|
|
149
|
+
if (process.env.AGORIC_INIT_OPTIONS) {
|
|
150
|
+
const opts = JSON.parse(process.env.AGORIC_INIT_OPTIONS);
|
|
151
|
+
initOptions.push(...opts);
|
|
152
|
+
}
|
|
153
|
+
t.is(
|
|
154
|
+
await myMain(['init', ...initOptions, 'dapp-foo']),
|
|
155
|
+
0,
|
|
156
|
+
'init dapp-foo works',
|
|
157
|
+
);
|
|
158
|
+
process.chdir('dapp-foo');
|
|
159
|
+
|
|
160
|
+
if (AGORIC_INSTALL_DISTTAG && process.env.AGORIC_INSTALL_OPTIONS) {
|
|
161
|
+
// ==============
|
|
162
|
+
// agoric install $DISTTAG
|
|
163
|
+
const opts = JSON.parse(process.env.AGORIC_INSTALL_OPTIONS);
|
|
164
|
+
installOptions.push(...opts);
|
|
165
|
+
t.is(
|
|
166
|
+
await myMain(['install', ...installOptions]),
|
|
167
|
+
0,
|
|
168
|
+
'agoric install works',
|
|
169
|
+
);
|
|
170
|
+
} else {
|
|
171
|
+
// ==============
|
|
172
|
+
// yarn install
|
|
173
|
+
t.is(await yarn(['install', ...installOptions]), 0, 'yarn install works');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ==============
|
|
177
|
+
// yarn start:docker
|
|
178
|
+
t.is(await yarn(['start:docker']), 0, 'yarn start:docker works');
|
|
179
|
+
|
|
180
|
+
// ==============
|
|
181
|
+
// wait for the chain to start
|
|
182
|
+
let lastKnownBlockHeight = 2n;
|
|
183
|
+
for (;;) {
|
|
184
|
+
try {
|
|
185
|
+
const currentHeight = await getLatestBlockHeight(
|
|
186
|
+
'http://localhost:26657/status',
|
|
187
|
+
);
|
|
188
|
+
if (currentHeight > lastKnownBlockHeight) {
|
|
189
|
+
const earlierHeight = lastKnownBlockHeight;
|
|
190
|
+
lastKnownBlockHeight = currentHeight;
|
|
191
|
+
if (earlierHeight > 2n && currentHeight > earlierHeight) {
|
|
192
|
+
// We've had at least 3 blocks produced.
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {
|
|
197
|
+
console.error((e && e.message) || e);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Wait a bit and try again.
|
|
201
|
+
await new Promise(resolve =>
|
|
202
|
+
setTimeout(resolve, RETRY_BLOCKHEIGHT_SECONDS * 1_000),
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ==============
|
|
207
|
+
// yarn start:contract
|
|
208
|
+
t.is(await yarn(['start:contract']), 0, 'yarn start:contract works');
|
|
209
|
+
|
|
210
|
+
// ==============
|
|
211
|
+
// yarn start:ui
|
|
212
|
+
const startUiP = yarn(['start:ui']);
|
|
213
|
+
finalizers.push(() => pkill(startUiP.childProcess, 'SIGINT'));
|
|
214
|
+
const uiListening = makePromiseKit();
|
|
215
|
+
let retries = 0;
|
|
216
|
+
const ival = setInterval(() => {
|
|
217
|
+
try {
|
|
218
|
+
const resolve = status => {
|
|
219
|
+
clearInterval(ival);
|
|
220
|
+
uiListening.resolve(status);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
retries += 1;
|
|
224
|
+
if (retries > 8) {
|
|
225
|
+
resolve('too many retries');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const req = request('http://localhost:5173/', _res => {
|
|
230
|
+
resolve('listening');
|
|
231
|
+
});
|
|
232
|
+
req.setTimeout(SOCKET_TIMEOUT_SECONDS * 1_000);
|
|
233
|
+
req.on('error', err => {
|
|
234
|
+
if (!('code' in err) || err.code !== 'ECONNREFUSED') {
|
|
235
|
+
resolve(`Cannot connect to UI server: ${err}`);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
req.end();
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.error('cannot make request', e);
|
|
241
|
+
}
|
|
242
|
+
}, 3000);
|
|
243
|
+
t.is(
|
|
244
|
+
await Promise.race([startUiP, uiListening.promise]),
|
|
245
|
+
'listening',
|
|
246
|
+
`yarn start:ui succeeded`,
|
|
247
|
+
);
|
|
248
|
+
clearInterval(ival);
|
|
249
|
+
} finally {
|
|
250
|
+
runFinalizers();
|
|
251
|
+
process.off('SIGINT', runFinalizers);
|
|
252
|
+
process.chdir(olddir);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
@@ -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 @@
|
|
|
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
|
+
};
|