@agoric/internal 0.3.3-dev-dc89345.0.dc89345 → 0.3.3-dev-32665e4.0.32665e4
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 +4 -4
- package/src/testing-utils.d.ts +4 -0
- package/src/testing-utils.d.ts.map +1 -1
- package/src/testing-utils.js +81 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-32665e4.0.32665e4",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:types": "yarn run -T tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-32665e4.0.32665e4",
|
|
24
24
|
"@endo/cache-map": "^1.1.0",
|
|
25
25
|
"@endo/common": "^1.2.13",
|
|
26
26
|
"@endo/compartment-mapper": "^1.6.3",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"jessie.js": "^0.3.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
41
|
+
"@agoric/cosmic-proto": "0.4.1-dev-32665e4.0.32665e4",
|
|
42
42
|
"@endo/exo": "^1.5.12",
|
|
43
43
|
"@endo/init": "^1.1.12",
|
|
44
44
|
"@endo/ses-ava": "^1.3.2",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"typeCoverage": {
|
|
67
67
|
"atLeast": 92.89
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "32665e40a7d223b050640771695ac47bb2a450f5"
|
|
70
70
|
}
|
package/src/testing-utils.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export function eventLoopIteration(): Promise<any>;
|
|
2
2
|
export function inspectMapStore(store: MapStore): object;
|
|
3
|
+
export function testInterruptedSteps<Context = unknown>(t: AvaT<Context>, allSteps: readonly TestStep[], doInterrupt: (t: AvaT<Context>) => ERef<void>): Promise<void>;
|
|
4
|
+
export type TestStep = readonly [stepName: string, fn: (input: any, label: string) => unknown];
|
|
3
5
|
import type { MapStore } from '@agoric/store';
|
|
6
|
+
import type { ExecutionContext as AvaT } from 'ava';
|
|
7
|
+
import type { ERef } from '@endo/eventual-send';
|
|
4
8
|
//# sourceMappingURL=testing-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"AAmBO,mDACwC;AAgBxC,uCAHI,QAAQ,GACN,MAAM,CAsBlB;AAmBM,qCALO,OAAO,eACV,KAAK,OAAO,CAAC,YACb,SAAS,QAAQ,EAAE,eACnB,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC,iBA2D1C;uBAxEY,SAAS,CACjB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAC3C;8BAxDuB,eAAe;8CACC,KAAK;0BACzB,qBAAqB"}
|
package/src/testing-utils.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* https://github.com/Agoric/agoric-sdk/issues/7503
|
|
5
5
|
*/
|
|
6
6
|
/* global setImmediate */
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @import {MapStore} from '@agoric/store';
|
|
9
|
+
* @import {ExecutionContext as AvaT} from 'ava';
|
|
10
|
+
* @import {ERef} from '@endo/eventual-send';
|
|
11
|
+
*/
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* A workaround for some issues with fake time in tests.
|
|
@@ -52,3 +56,79 @@ export const inspectMapStore = store => {
|
|
|
52
56
|
return obj;
|
|
53
57
|
};
|
|
54
58
|
harden(inspectMapStore);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {readonly [
|
|
62
|
+
* stepName: string,
|
|
63
|
+
* fn: (input: any, label: string) => unknown,
|
|
64
|
+
* ]} TestStep
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* For each step, run to just before that point and pause for continuation after
|
|
69
|
+
* interrupt.
|
|
70
|
+
*
|
|
71
|
+
* @template [Context=unknown]
|
|
72
|
+
* @param {AvaT<Context>} t
|
|
73
|
+
* @param {readonly TestStep[]} allSteps
|
|
74
|
+
* @param {(t: AvaT<Context>) => ERef<void>} doInterrupt
|
|
75
|
+
*/
|
|
76
|
+
export const testInterruptedSteps = async (t, allSteps, doInterrupt) => {
|
|
77
|
+
/**
|
|
78
|
+
* @typedef {{
|
|
79
|
+
* label: string;
|
|
80
|
+
* accum?: unknown;
|
|
81
|
+
* }} RunState
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {string} label
|
|
86
|
+
* @param {readonly TestStep[]} steps
|
|
87
|
+
* @param {RunState} [runState]
|
|
88
|
+
* @returns {Promise<RunState>}
|
|
89
|
+
*/
|
|
90
|
+
const runSteps = async (label, steps, runState = { label }) => {
|
|
91
|
+
await null;
|
|
92
|
+
let accum = runState.accum;
|
|
93
|
+
const runLabel = runState.label;
|
|
94
|
+
for (const [stepName, fn] of steps) {
|
|
95
|
+
await t.notThrowsAsync(async () => {
|
|
96
|
+
accum = await fn(accum, runLabel);
|
|
97
|
+
}, `${label} ${stepName} must complete successfully`);
|
|
98
|
+
}
|
|
99
|
+
return { label: runLabel, accum };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Sanity check
|
|
103
|
+
await runSteps('pre-interrupt', allSteps);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @type {{
|
|
107
|
+
* runState: RunState;
|
|
108
|
+
* remainingSteps: readonly TestStep[];
|
|
109
|
+
* }[]}
|
|
110
|
+
*/
|
|
111
|
+
const pausedRuns = [];
|
|
112
|
+
for (let i = 0; i < allSteps.length; i += 1) {
|
|
113
|
+
const [beforeStepName] = allSteps[i];
|
|
114
|
+
const runState = await runSteps(
|
|
115
|
+
`pre-${beforeStepName}`,
|
|
116
|
+
allSteps.slice(0, i),
|
|
117
|
+
{ label: `pause-before-${beforeStepName}` },
|
|
118
|
+
);
|
|
119
|
+
pausedRuns.push({ runState, remainingSteps: allSteps.slice(i) });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Run the user code that interrupts the steps.
|
|
123
|
+
await doInterrupt(t);
|
|
124
|
+
|
|
125
|
+
// Verify a complete run post-interrupt.
|
|
126
|
+
await runSteps('post-interrupt', allSteps);
|
|
127
|
+
|
|
128
|
+
// Verify completion of each paused step.
|
|
129
|
+
for (const { runState, remainingSteps } of pausedRuns) {
|
|
130
|
+
const [beforeStepName] = remainingSteps[0];
|
|
131
|
+
await runSteps(`resumed-${beforeStepName}`, remainingSteps, runState);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
harden(testInterruptedSteps);
|