-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathtest-contractHost.js
53 lines (48 loc) · 1.58 KB
/
test-contractHost.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* global __dirname */
// TODO Remove babel-standalone preinitialization
// https://github.com/endojs/endo/issues/768
import '@agoric/babel-standalone';
import '@agoric/install-ses';
import test from 'ava';
import path from 'path';
import bundleSource from '@agoric/bundle-source';
import {
buildKernelBundles,
buildVatController,
loadBasedir,
} from '@agoric/swingset-vat';
test.before(async t => {
const kernelBundles = await buildKernelBundles();
const trivialFn = path.resolve(__dirname, 'trivial.js');
const trivialBundle = await bundleSource(trivialFn);
t.context.data = { kernelBundles, trivialBundle };
});
async function main(t, mode, defaultManagerType = 'local') {
const config = await loadBasedir(__dirname);
config.defaultManagerType = defaultManagerType;
const { kernelBundles, trivialBundle } = t.context.data;
const argv = [mode, trivialBundle];
const controller = await buildVatController(config, argv, { kernelBundles });
await controller.run();
return controller.dump();
}
const contractTrivialGolden = [
'starting trivialContractTest',
'terms are: terms were: terms are provided',
'eight is: 8',
'++ DONE',
];
test('trivial', async t => {
const dump = await main(t, 'trivial');
t.deepEqual(dump.log, contractTrivialGolden);
});
const contractExhaustedGolden = [
'starting exhaustedContractTest',
'loop1 failed: Error: vat terminated',
'loop2: spawned without error',
'loop2 dead: Error: vat terminated',
];
test('exhaustion', async t => {
const dump = await main(t, 'exhaust', 'xs-worker');
t.deepEqual(dump.log, contractExhaustedGolden);
});