diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index 48783bf3bec..5640f0cbb63 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -12,8 +12,7 @@ }, "scripts": { "build": "exit 0", - "test": "tap --no-coverage test/test-node-version.js && tap --no-coverage --jobs=1 --timeout 600 'test/**/test*.js'", - "test-nosort": "tape -r esm test/test-node-version.js && tape -r esm 'test/**/test*.js'", + "test": "ava", "pretty-fix": "prettier --write '**/*.js'", "pretty-check": "prettier --check '**/*.js'", "lint-fix": "yarn lint --fix", @@ -23,10 +22,7 @@ }, "devDependencies": { "@agoric/install-metering-and-ses": "^0.1.1", - "esm": "^3.2.5", - "tap": "^14.10.5", - "tape": "^4.13.2", - "tape-promise": "^4.0.0" + "ava": "^3.11.1" }, "dependencies": { "@agoric/assert": "^0.0.8", @@ -46,6 +42,7 @@ "@babel/core": "^7.5.0", "@babel/generator": "^7.6.4", "anylogger": "^0.21.0", + "esm": "^3.2.5", "netstring-stream": "^1.0.1", "re2": "^1.10.5", "rollup": "^1.23.1", @@ -72,5 +69,10 @@ }, "publishConfig": { "access": "public" + }, + "ava": { + "files": ["test/**/test-*.js"], + "require": ["esm"], + "timeout": "2m" } } diff --git a/packages/SwingSet/src/controller.js b/packages/SwingSet/src/controller.js index 5ac9cf7034b..4b44a09d304 100644 --- a/packages/SwingSet/src/controller.js +++ b/packages/SwingSet/src/controller.js @@ -312,8 +312,10 @@ export async function buildVatController( ); function makeNodeWorker() { + // TODO: after we move away from `-r esm` and use real ES6 modules, point + // this at nodeWorkerSupervisor.js instead of the CJS intermediate const supercode = require.resolve( - './kernel/vatManager/nodeWorkerSupervisor.js', + './kernel/vatManager/nodeWorkerSupervisorCJS.js', ); return new Worker(supercode); } diff --git a/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisorCJS.js b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisorCJS.js new file mode 100644 index 00000000000..88b2006efd4 --- /dev/null +++ b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisorCJS.js @@ -0,0 +1,12 @@ +// `tap` and `node -r esm` were able to allow the swingset process to create +// a thread (`new Worker()`) from the (ESM) supervisor file without problems, +// but for some reason AVA cannot. The file loaded into the new thread +// appears to lack the effects which `-r esm` had on the rest of the tree. +// This stub, written as CJS, exists to allow the real supervisor to be +// loaded under AVA. With luck, when we switch everything to use real ESM +// modules, and stop using `-r esm`, this should become unnecessary, and +// `controller.js` can point at `nodeWorkerSupervisor.js` instead. + +// eslint-disable-next-line no-global-assign +require = require('esm')(module); +module.exports = require('./nodeWorkerSupervisor'); diff --git a/packages/SwingSet/test/definition/test-vat-definition.js b/packages/SwingSet/test/definition/test-vat-definition.js index de1c9100692..aac74859f1a 100644 --- a/packages/SwingSet/test/definition/test-vat-definition.js +++ b/packages/SwingSet/test/definition/test-vat-definition.js @@ -1,6 +1,6 @@ /* global harden */ import '@agoric/install-ses'; -import tap from 'tap'; +import test from 'ava'; import { buildVatController } from '../../src/index'; const mUndefined = { '@qclass': 'undefined' }; @@ -13,7 +13,7 @@ function capargs(args, slots = []) { return capdata(JSON.stringify(args), slots); } -tap.test('create with setup and buildRootObject', async t => { +test('create with setup and buildRootObject', async t => { const config = { vats: { setup: { diff --git a/packages/SwingSet/test/message-patterns.js b/packages/SwingSet/test/message-patterns.js index f11b1183b5a..577a4f328b7 100644 --- a/packages/SwingSet/test/message-patterns.js +++ b/packages/SwingSet/test/message-patterns.js @@ -30,15 +30,6 @@ import { ignore } from './util'; // (which will only occur when using the comms layer, not in the // direct-to-kernel test). 'outPipelined' holds these alternate expectations. -// 'patterns' is used to track which tests should be skipped (or which should -// be the only test run at all). Each defined pattern must call test(name) to -// add it to the list. In addition, if you want to skip something, call -// 'test. skipLocal(name)' (without the space) and/or 'test. -// skipComms(name)'. To mark a test as the only one to run, call `test. -// onlyLocal(name)' or 'test. onlyComms(name)' (again without the space). (We -// insert a space in this description so a simple 'grep' can still accurately -// show the presence of skipped/only tests). - // Initial Conditions: vat A (which hosts objects 'alice' and 'amy'), and vat // B (hosting objects 'bob' and 'bert' and 'bill'). Initially alice has // access to amy/bob/bert but not bill. Bob has access to bert and bill. @@ -67,13 +58,7 @@ export function buildPatterns(log) { const out = {}; const outPipelined = {}; - // avoid dot-notation to preserve the utility of 'grep test(.)only' const test = name => patterns.set(name, { local: 'test', comms: 'test' }); - test['onlyLocal'] = n => patterns.set(n, { local: 'only', comms: 'test' }); - test['onlyComms'] = n => patterns.set(n, { local: 'test', comms: 'only' }); - test['skipLocal'] = n => patterns.set(n, { local: 'skip', comms: 'test' }); - test['skipComms'] = n => patterns.set(n, { local: 'test', comms: 'skip' }); - test['skipBoth'] = n => patterns.set(n, { local: 'skip', comms: 'skip' }); // bob!x() test('a10'); diff --git a/packages/SwingSet/test/metering/test-dynamic-vat-metered.js b/packages/SwingSet/test/metering/test-dynamic-vat-metered.js index ae589848d04..53205c7985b 100644 --- a/packages/SwingSet/test/metering/test-dynamic-vat-metered.js +++ b/packages/SwingSet/test/metering/test-dynamic-vat-metered.js @@ -2,7 +2,7 @@ import '@agoric/install-metering-and-ses'; import bundleSource from '@agoric/bundle-source'; -import tap from 'tap'; +import test from 'ava'; import { buildVatController } from '../../src/index'; import makeNextLog from '../make-nextlog'; @@ -14,7 +14,7 @@ function capargs(args, slots = []) { return capdata(JSON.stringify(args), slots); } -tap.test('metering dynamic vats', async t => { +test('metering dynamic vats', async t => { // we'll give this bundle to the loader vat, which will use it to create a // new (metered) dynamic vat const dynamicVatBundle = await bundleSource( @@ -73,6 +73,4 @@ tap.test('metering dynamic vats', async t => { ['run exploded: RangeError: Allocate meter exceeded'], 'stay dead', ); - - t.end(); }); diff --git a/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js b/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js index f39978d1de8..f81473af90f 100644 --- a/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js +++ b/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js @@ -2,7 +2,7 @@ import '@agoric/install-metering-and-ses'; import bundleSource from '@agoric/bundle-source'; -import tap from 'tap'; +import test from 'ava'; import { buildVatController } from '../../src/index'; import makeNextLog from '../make-nextlog'; @@ -17,7 +17,7 @@ function capargs(args, slots = []) { // This test checks that dynamic vats (which are metered) can import bundles, // and that those bundles are also metered. -tap.test('metering dynamic vat which imports bundle', async t => { +test('metering dynamic vat which imports bundle', async t => { // We first create a static vat with vat-load-dynamic.js const config = { bootstrap: 'bootstrap', @@ -96,6 +96,4 @@ tap.test('metering dynamic vat which imports bundle', async t => { ['run exploded: RangeError: Allocate meter exceeded'], 'whole dynamic vat is dead', ); - - t.end(); }); diff --git a/packages/SwingSet/test/metering/test-dynamic-vat-unmetered.js b/packages/SwingSet/test/metering/test-dynamic-vat-unmetered.js index c28cb60e6aa..c4e5e8af221 100644 --- a/packages/SwingSet/test/metering/test-dynamic-vat-unmetered.js +++ b/packages/SwingSet/test/metering/test-dynamic-vat-unmetered.js @@ -2,7 +2,7 @@ import '@agoric/install-metering-and-ses'; import bundleSource from '@agoric/bundle-source'; -import tap from 'tap'; +import test from 'ava'; import { buildVatController } from '../../src/index'; import makeNextLog from '../make-nextlog'; @@ -16,7 +16,7 @@ function capargs(args, slots = []) { // Dynamic vats can be created without metering -tap.test('unmetered dynamic vat', async t => { +test('unmetered dynamic vat', async t => { const config = { bootstrap: 'bootstrap', vats: { @@ -66,6 +66,4 @@ tap.test('unmetered dynamic vat', async t => { ); await c.run(); t.deepEqual(nextLog(), ['failed to explode'], 'metering disabled'); - - t.end(); }); diff --git a/packages/SwingSet/test/metering/test-metering.js b/packages/SwingSet/test/metering/test-metering.js index 62b5c2c9f62..499e215d875 100644 --- a/packages/SwingSet/test/metering/test-metering.js +++ b/packages/SwingSet/test/metering/test-metering.js @@ -9,7 +9,7 @@ import { importBundle } from '@agoric/import-bundle'; import { makeMeter, makeMeteringTransformer } from '@agoric/transform-metering'; import * as babelCore from '@babel/core'; import re2 from 're2'; -import tap from 'tap'; +import test from 'ava'; import { waitUntilQuiescent } from '../../src/waitUntilQuiescent'; // Run a function under the control of a meter. The function must not have @@ -90,7 +90,7 @@ async function meteredImportBundle(bundle, endowments) { }; } -tap.test('metering a single bundle', async function testSingleBundle(t) { +test('metering a single bundle', async function testSingleBundle(t) { const bundle = await bundleSource(require.resolve('./metered-code.js')); harden(Object.getPrototypeOf(console)); const endowments = { console }; @@ -106,18 +106,18 @@ tap.test('metering a single bundle', async function testSingleBundle(t) { let ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no')); t.deepEqual(log2, ['started', 'done'], 'computation completed'); log2.splice(0); - t.equal(ok, true, 'meter should not be exhausted'); + t.is(ok, true, 'meter should not be exhausted'); ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'compute')); t.deepEqual(log2, ['started'], 'computation started but halted'); log2.splice(0); - t.equal(ok, false, 'meter should be exhausted (compute)'); + t.is(ok, false, 'meter should be exhausted (compute)'); // Run the same code (without an infinite loop) against the old exhausted // meter. It should halt right away. ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no')); - t.equal(log2.length, 0, 'computation did not start'); - t.equal(ok, false, 'meter should be exhausted (still compute)'); + t.is(log2.length, 0, 'computation did not start'); + t.is(ok, false, 'meter should be exhausted (still compute)'); // Refill the meter, and the code should run again. // refillFacet.combined(10000000); @@ -126,13 +126,13 @@ tap.test('metering a single bundle', async function testSingleBundle(t) { ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no')); t.deepEqual(log2, ['started', 'done'], 'computation completed'); log2.splice(0); - t.equal(ok, true, 'meter should not be exhausted'); + t.is(ok, true, 'meter should not be exhausted'); // now check that metering catches infinite stack ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'stack')); t.deepEqual(log2, ['started'], 'computation started but halted'); log2.splice(0); - t.equal(ok, false, 'meter should be exhausted (stack)'); + t.is(ok, false, 'meter should be exhausted (stack)'); // Refill the meter, and the code should run again. // refillFacet.combined(10000000); @@ -141,18 +141,18 @@ tap.test('metering a single bundle', async function testSingleBundle(t) { ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no')); t.deepEqual(log2, ['started', 'done'], 'computation completed'); log2.splice(0); - t.equal(ok, true, 'meter should not be exhausted'); + t.is(ok, true, 'meter should not be exhausted'); // metering should catch primordial allocation too ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'allocate')); t.deepEqual(log2, ['started'], 'computation started but halted'); log2.splice(0); - t.equal(ok, false, 'meter should be exhausted (allocate)'); + t.is(ok, false, 'meter should be exhausted (allocate)'); // Refill the meter, and the code should run again. refillFacet.allocate(10000000); ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no')); t.deepEqual(log2, ['started', 'done'], 'computation completed'); log2.splice(0); - t.equal(ok, true, 'meter should not be exhausted'); + t.is(ok, true, 'meter should not be exhausted'); }); diff --git a/packages/SwingSet/test/metering/test-within-vat.js b/packages/SwingSet/test/metering/test-within-vat.js index 6ee537fb8c1..d6329923ed5 100644 --- a/packages/SwingSet/test/metering/test-within-vat.js +++ b/packages/SwingSet/test/metering/test-within-vat.js @@ -2,7 +2,7 @@ import '@agoric/install-metering-and-ses'; import bundleSource from '@agoric/bundle-source'; -import tap from 'tap'; +import test from 'ava'; import { buildVatController } from '../../src/index'; import makeNextLog from '../make-nextlog'; @@ -14,7 +14,7 @@ function capargs(args, slots = []) { return capdata(JSON.stringify(args), slots); } -tap.test('metering within a vat', async t => { +test('metering within a vat', async t => { // we'll give this bundle to the vat, which will import it under metering const bundle = await bundleSource(require.resolve('./metered-code.js')); const config = { @@ -143,6 +143,4 @@ tap.test('metering within a vat', async t => { ['run no', 'log2: started done', 'no exception'], 'compute meter refilled', ); - - t.end(); }); diff --git a/packages/SwingSet/test/test-comms.js b/packages/SwingSet/test/test-comms.js index 13cc962b51f..91eb4e4a32d 100644 --- a/packages/SwingSet/test/test-comms.js +++ b/packages/SwingSet/test/test-comms.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import buildCommsDispatch from '../src/vats/comms'; import { flipRemoteSlot } from '../src/vats/comms/parseRemoteSlot'; import { makeState } from '../src/vats/comms/state'; @@ -17,14 +17,12 @@ import { debugState } from '../src/vats/comms/dispatch'; test('mapOutbound', t => { const s = makeState(); const { remoteID } = addRemote(s, 'remote1', 'o-1'); - t.equal(mapOutbound(s, remoteID, 'o-4'), 'ro-20'); - t.equal(mapOutbound(s, remoteID, 'o-4'), 'ro-20'); - t.equal(mapOutbound(s, remoteID, 'o-5'), 'ro-21'); - t.throws( - () => mapOutbound(s, remoteID, 'o+5'), - /sending non-remote object o\+5 to remote machine/, - ); - t.end(); + t.is(mapOutbound(s, remoteID, 'o-4'), 'ro-20'); + t.is(mapOutbound(s, remoteID, 'o-4'), 'ro-20'); + t.is(mapOutbound(s, remoteID, 'o-5'), 'ro-21'); + t.throws(() => mapOutbound(s, remoteID, 'o+5'), { + message: /sending non-remote object o\+5 to remote machine/, + }); }); function mockSyscall() { @@ -62,7 +60,7 @@ test('transmit', t => { // now tell the comms vat to send a message to a remote machine, the // equivalent of bob!foo() d.deliver(bob, 'foo', capdata('argsbytes', []), null); - t.deepEquals(sends.shift(), [ + t.deepEqual(sends.shift(), [ transmitterID, 'transmit', encodeArgs('deliver:ro+23:foo:;argsbytes'), @@ -70,16 +68,16 @@ test('transmit', t => { // bob!bar(alice, bob) d.deliver(bob, 'bar', capdata('argsbytes', [alice, bob]), null); - t.deepEquals(sends.shift(), [ + t.deepEqual(sends.shift(), [ transmitterID, 'transmit', encodeArgs('deliver:ro+23:bar::ro-20:ro+23;argsbytes'), ]); // the outbound ro-20 should match an inbound ro+20, both represent 'alice' - t.equal(getInbound(state, remoteID, 'ro+20'), alice); + t.is(getInbound(state, remoteID, 'ro+20'), alice); // do it again, should use same values d.deliver(bob, 'bar', capdata('argsbytes', [alice, bob]), null); - t.deepEquals(sends.shift(), [ + t.deepEqual(sends.shift(), [ transmitterID, 'transmit', encodeArgs('deliver:ro+23:bar::ro-20:ro+23;argsbytes'), @@ -88,13 +86,11 @@ test('transmit', t => { // bob!cat(alice, bob, ayana) const ayana = 'o-11'; d.deliver(bob, 'cat', capdata('argsbytes', [alice, bob, ayana]), null); - t.deepEquals(sends.shift(), [ + t.deepEqual(sends.shift(), [ transmitterID, 'transmit', encodeArgs('deliver:ro+23:cat::ro-20:ro+23:ro-21;argsbytes'), ]); - - t.end(); }); test('receive', t => { @@ -108,7 +104,7 @@ test('receive', t => { const bob = 'o-10'; const { remoteID, receiverID } = addRemote(state, 'remote1', transmitterID); const remoteBob = flipRemoteSlot(mapOutbound(state, remoteID, bob)); - t.equal(remoteBob, 'ro+20'); + t.is(remoteBob, 'ro+20'); // now pretend the transport layer received a message from remote1, as if // the remote machine had performed bob!foo() @@ -118,7 +114,7 @@ test('receive', t => { encodeArgs(`deliver:${remoteBob}:foo:;argsbytes`), null, ); - t.deepEquals(sends.shift(), [bob, 'foo', capdata('argsbytes')]); + t.deepEqual(sends.shift(), [bob, 'foo', capdata('argsbytes')]); // bob!bar(alice, bob) d.deliver( @@ -127,13 +123,9 @@ test('receive', t => { encodeArgs(`deliver:${remoteBob}:bar::ro-20:${remoteBob};argsbytes`), null, ); - t.deepEquals(sends.shift(), [ - bob, - 'bar', - capdata('argsbytes', ['o+11', bob]), - ]); + t.deepEqual(sends.shift(), [bob, 'bar', capdata('argsbytes', ['o+11', bob])]); // if we were to send o+11, the other side should get ro+20, which is alice - t.equal(getOutbound(state, remoteID, 'o+11'), 'ro+20'); + t.is(getOutbound(state, remoteID, 'o+11'), 'ro+20'); // bob!bar(alice, bob) d.deliver( @@ -142,11 +134,7 @@ test('receive', t => { encodeArgs(`deliver:${remoteBob}:bar::ro-20:${remoteBob};argsbytes`), null, ); - t.deepEquals(sends.shift(), [ - bob, - 'bar', - capdata('argsbytes', ['o+11', bob]), - ]); + t.deepEqual(sends.shift(), [bob, 'bar', capdata('argsbytes', ['o+11', bob])]); // bob!cat(alice, bob, ayana) d.deliver( @@ -155,11 +143,9 @@ test('receive', t => { encodeArgs(`deliver:${remoteBob}:cat::ro-20:${remoteBob}:ro-21;argsbytes`), null, ); - t.deepEquals(sends.shift(), [ + t.deepEqual(sends.shift(), [ bob, 'cat', capdata('argsbytes', ['o+11', bob, 'o+12']), ]); - - t.end(); }); diff --git a/packages/SwingSet/test/test-controller.js b/packages/SwingSet/test/test-controller.js index 5637fe1648d..157dc4e1ffc 100644 --- a/packages/SwingSet/test/test-controller.js +++ b/packages/SwingSet/test/test-controller.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import path from 'path'; import { buildVatController, loadBasedir } from '../src/index'; import { checkKT } from './util'; @@ -24,8 +24,7 @@ test('load empty', async t => { const config = {}; const controller = await buildVatController(config); await controller.run(); - t.ok(true); - t.end(); + t.truthy(true); }); async function simpleCall(t) { @@ -77,9 +76,7 @@ async function simpleCall(t) { }); controller.log('2'); - t.equal(controller.dump().log[1], '2'); - - t.end(); + t.is(controller.dump().log[1], '2'); } test('simple call', async t => { @@ -95,7 +92,6 @@ test('bootstrap', async t => { // left[0].bootstrap const c = await buildVatController(config); t.deepEqual(c.dump().log, ['bootstrap called']); - t.end(); }); test('bootstrap export', async t => { @@ -259,6 +255,4 @@ test('bootstrap export', async t => { removeTriple(kt, barP, leftVatID, 'p+5'); // pruned promise checkKT(t, c, kt); t.deepEqual(c.dump().runQueue, []); - - t.end(); }); diff --git a/packages/SwingSet/test/test-demos-comms.js b/packages/SwingSet/test/test-demos-comms.js index 72ad85ae287..69ebbd173f1 100644 --- a/packages/SwingSet/test/test-demos-comms.js +++ b/packages/SwingSet/test/test-demos-comms.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildLoopbox } from '../src/devices/loopbox'; import { loadBasedir, buildVatController } from '../src/index'; @@ -29,12 +29,10 @@ const encouragementBotCommsGolden = [ test('run encouragementBotComms Demo', async t => { const dump = await main('demo/encouragementBotComms', []); - t.deepEquals(dump.log, encouragementBotCommsGolden); - t.end(); + t.deepEqual(dump.log, encouragementBotCommsGolden); }); test('run encouragementBotCommsWavyDot Demo', async t => { const dump = await main('demo/encouragementBotCommsWavyDot', []); - t.deepEquals(dump.log, encouragementBotCommsGolden); - t.end(); + t.deepEqual(dump.log, encouragementBotCommsGolden); }); diff --git a/packages/SwingSet/test/test-demos.js b/packages/SwingSet/test/test-demos.js index d2fd615e393..18d6e9cbfd7 100644 --- a/packages/SwingSet/test/test-demos.js +++ b/packages/SwingSet/test/test-demos.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildLoopbox } from '../src/devices/loopbox'; import { loadBasedir, buildVatController } from '../src/index'; @@ -22,6 +22,5 @@ const encouragementBotGolden = [ test('run encouragementBot Demo', async t => { const dump = await main('demo/encouragementBot', []); - t.deepEquals(dump.log, encouragementBotGolden); - t.end(); + t.deepEqual(dump.log, encouragementBotGolden); }); diff --git a/packages/SwingSet/test/test-device-bridge.js b/packages/SwingSet/test/test-device-bridge.js index 7b26551aa4f..de62677a222 100644 --- a/packages/SwingSet/test/test-device-bridge.js +++ b/packages/SwingSet/test/test-device-bridge.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { initSwingStore } from '@agoric/swing-store-simple'; import { buildVatController, buildBridge } from '../src/index'; @@ -105,8 +105,6 @@ test('bridge device', async t => { 'inbound', JSON.stringify([inboundArg2, inboundArg3]), ]); - - t.end(); }); test('bridge device can return undefined', async t => { @@ -139,6 +137,4 @@ test('bridge device can return undefined', async t => { t.deepEqual(outboundLog, argv); t.deepEqual(c.dump().log, ['outbound retval', '', 'true']); - - t.end(); }); diff --git a/packages/SwingSet/test/test-devices.js b/packages/SwingSet/test/test-devices.js index ecb31e95427..a2a788bac7f 100644 --- a/packages/SwingSet/test/test-devices.js +++ b/packages/SwingSet/test/test-devices.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { initSwingStore, getAllState } from '@agoric/swing-store-simple'; import { buildVatController } from '../src/index'; @@ -53,7 +53,6 @@ test('d0', async t => { 'd-70', 'd-71', ]); - t.end(); }); test('d1', async t => { @@ -86,7 +85,6 @@ test('d1', async t => { JSON.stringify(capargs({ ret: 3 })), ]); t.deepEqual(sharedArray, ['pushed']); - t.end(); }); async function test2(t, mode) { @@ -150,7 +148,6 @@ async function test2(t, mode) { 'ret done', ]); } - t.end(); } test('d2.1', async t => { @@ -196,8 +193,6 @@ test('device state', async t => { const s = getAllState(storage); t.deepEqual(JSON.parse(s[`${d3}.deviceState`]), capargs({ s: 'new' })); t.deepEqual(JSON.parse(s[`${d3}.o.nextID`]), 10); - - t.end(); }); test('mailbox outbound', async t => { @@ -236,8 +231,6 @@ test('mailbox outbound', async t => { const s2 = buildMailboxStateMap(); s2.populateFromData(s.exportToData()); t.deepEqual(s.exportToData(), s2.exportToData()); - - t.end(); }); test('mailbox inbound', async t => { @@ -265,7 +258,7 @@ test('mailbox inbound', async t => { ], 0, ); - t.ok(rc); + t.truthy(rc); await c.run(); t.deepEqual(c.dump().log, ['dm-peer1', 'm-1-msg1', 'm-2-msg2']); @@ -278,7 +271,7 @@ test('mailbox inbound', async t => { ], 3, ); - t.ok(rc); + t.truthy(rc); await c.run(); t.deepEqual(c.dump().log, ['dm-peer1', 'm-1-msg1', 'm-2-msg2', 'da-peer1-3']); @@ -291,7 +284,7 @@ test('mailbox inbound', async t => { ], 3, ); - t.notOk(rc); + t.falsy(rc); await c.run(); t.deepEqual(c.dump().log, ['dm-peer1', 'm-1-msg1', 'm-2-msg2', 'da-peer1-3']); @@ -305,7 +298,7 @@ test('mailbox inbound', async t => { ], 3, ); - t.ok(rc); + t.truthy(rc); await c.run(); t.deepEqual(c.dump().log, [ 'dm-peer1', @@ -326,7 +319,7 @@ test('mailbox inbound', async t => { ], 4, ); - t.ok(rc); + t.truthy(rc); await c.run(); t.deepEqual(c.dump().log, [ 'dm-peer1', @@ -339,7 +332,7 @@ test('mailbox inbound', async t => { ]); rc = mb.deliverInbound('peer2', [[4, 'msg4']], 5); - t.ok(rc); + t.truthy(rc); await c.run(); t.deepEqual(c.dump().log, [ 'dm-peer1', @@ -353,8 +346,6 @@ test('mailbox inbound', async t => { 'm-4-msg4', 'da-peer2-5', ]); - - t.end(); }); test('command broadcast', async t => { @@ -373,8 +364,6 @@ test('command broadcast', async t => { const c = await buildVatController(config, ['command1']); await c.run(); t.deepEqual(broadcasts, [{ hello: 'everybody' }]); - - t.end(); }); test('command deliver', async t => { @@ -408,6 +397,4 @@ test('command deliver', async t => { await c.run(); t.deepEqual(c.dump().log, ['handle-0-missing', 'handle-1-errory']); t.deepEqual(rejection, { response: 'body' }); - - t.end(); }); diff --git a/packages/SwingSet/test/test-exomessages.js b/packages/SwingSet/test/test-exomessages.js index 64b9aa8114e..f2457a6a285 100644 --- a/packages/SwingSet/test/test-exomessages.js +++ b/packages/SwingSet/test/test-exomessages.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildVatController } from '../src/index'; async function beginning(t, mode) { @@ -12,19 +12,18 @@ async function beginning(t, mode) { }, }; const controller = await buildVatController(config, [mode]); - t.equal(controller.bootstrapResult.status(), 'pending'); + t.is(controller.bootstrapResult.status(), 'pending'); return controller; } async function bootstrapSuccessfully(t, mode, body, slots) { const controller = await beginning(t, mode); await controller.run(); - t.equal(controller.bootstrapResult.status(), 'fulfilled'); + t.is(controller.bootstrapResult.status(), 'fulfilled'); t.deepEqual(controller.bootstrapResult.resolution(), { body, slots, }); - t.end(); } test('bootstrap returns data', async t => { @@ -57,15 +56,14 @@ async function testFailure(t) { await controller.run(); } catch (e) { failureHappened = true; - t.equal(e.message, 'kernel panic bootstrap failure'); + t.is(e.message, 'kernel panic bootstrap failure'); } - t.ok(failureHappened); - t.equal(controller.bootstrapResult.status(), 'rejected'); + t.truthy(failureHappened); + t.is(controller.bootstrapResult.status(), 'rejected'); t.deepEqual(controller.bootstrapResult.resolution(), { body: '{"@qclass":"error","name":"Error","message":"gratuitous error"}', slots: [], }); - t.end(); } test('bootstrap failure', async t => { @@ -84,12 +82,11 @@ async function extraMessage(t, mode, status, body, slots) { 'ignore', ); await controller.run(); - t.equal(extraResult.status(), status); + t.is(extraResult.status(), status); t.deepEqual(extraResult.resolution(), { body, slots, }); - t.end(); } test('extra message returns data', async t => { diff --git a/packages/SwingSet/test/test-kernel.js b/packages/SwingSet/test/test-kernel.js index b7388450ac0..ff6897350b1 100644 --- a/packages/SwingSet/test/test-kernel.js +++ b/packages/SwingSet/test/test-kernel.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; @@ -59,7 +59,6 @@ test('build kernel', async t => { const data = kernel.dump(); t.deepEqual(data.vatTables, []); t.deepEqual(data.kernelTable, []); - t.end(); }); test('simple call', async t => { @@ -98,14 +97,12 @@ test('simple call', async t => { t.deepEqual(log, [['o+1', 'foo', capdata('args')]]); data = kernel.dump(); - t.equal(data.log.length, 1); + t.is(data.log.length, 1); t.deepEqual(JSON.parse(data.log[0]), { facetID: 'o+1', method: 'foo', args: capdata('args'), }); - - t.end(); }); test('map inbound', async t => { @@ -154,8 +151,6 @@ test('map inbound', async t => { ['ko22', vat1, 'o+1'], ['kp40', vat1, 'p-60'], ]); - - t.end(); }); test('addImport', async t => { @@ -176,7 +171,6 @@ test('addImport', async t => { ['ko20', vat1, 'o-50'], ['ko20', vat2, 'o+5'], ]); - t.end(); }); test('outbound call', async t => { @@ -374,8 +368,6 @@ test('outbound call', async t => { queue: [], }, ]); - - t.end(); }); test('three-party', async t => { @@ -505,8 +497,6 @@ test('three-party', async t => { kt.push([carol, vatB, 'o-50']); kt.push(['kp42', vatB, 'p-60']); checkKT(t, kernel, kt); - - t.end(); }); test('transfer promise', async t => { @@ -609,8 +599,6 @@ test('transfer promise', async t => { t.deepEqual(logA, []); checkPromises(t, kernel, kp); checkKT(t, kernel, kt); - - t.end(); }); test('subscribe to promise', async t => { @@ -652,8 +640,6 @@ test('subscribe to promise', async t => { ]); t.deepEqual(kernel.dump().runQueue, []); t.deepEqual(log, []); - - t.end(); }); test('promise resolveToData', async t => { @@ -729,8 +715,6 @@ test('promise resolveToData', async t => { ]); } t.deepEqual(kernel.dump().runQueue, []); - - t.end(); }); test('promise resolveToPresence', async t => { @@ -810,7 +794,6 @@ test('promise resolveToPresence', async t => { ]); } t.deepEqual(kernel.dump().runQueue, []); - t.end(); }); test('promise reject', async t => { @@ -886,8 +869,6 @@ test('promise reject', async t => { ]); } t.deepEqual(kernel.dump().runQueue, []); - - t.end(); }); test('transcript', async t => { @@ -922,7 +903,7 @@ test('transcript', async t => { // the transcript records vat-specific import/export slots const tr = kernel.dump().vatTables[0].state.transcript; - t.equal(tr.length, 1); + t.is(tr.length, 1); t.deepEqual(tr[0], { d: [ 'deliver', @@ -939,8 +920,6 @@ test('transcript', async t => { ], crankNumber: 1, }); - - t.end(); }); // p1=x!foo(); p2=p1!bar(); p3=p2!urgh(); no pipelining. p1 will have a @@ -1057,8 +1036,6 @@ test('non-pipelined promise queueing', async t => { queue: [], }, ]); - - t.end(); }); // p1=x!foo(); p2=p1!bar(); p3=p2!urgh(); with pipelining. All three should @@ -1166,6 +1143,4 @@ test('pipelined promise queueing', async t => { queue: [], }, ]); - - t.end(); }); diff --git a/packages/SwingSet/test/test-liveslots.js b/packages/SwingSet/test/test-liveslots.js index a2cd2f82fad..a8ab3ccafdb 100644 --- a/packages/SwingSet/test/test-liveslots.js +++ b/packages/SwingSet/test/test-liveslots.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { E } from '@agoric/eventual-send'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import { makeLiveSlots } from '../src/kernel/liveSlots'; @@ -100,8 +100,6 @@ test('calls', async t => { t.deepEqual(log.shift(), ['rej', 'rejection']); // TODO: more calls, more slot types - - t.end(); }); test('liveslots pipelines to syscall.send', async t => { @@ -163,8 +161,6 @@ test('liveslots pipelines to syscall.send', async t => { resultSlot: p3, }); t.deepEqual(log.shift(), { type: 'subscribe', target: p3 }); - - t.end(); }); test('liveslots pipeline/non-pipeline calls', async t => { @@ -239,8 +235,6 @@ test('liveslots pipeline/non-pipeline calls', async t => { // and nonpipe3() wants a result t.deepEqual(log.shift(), { type: 'subscribe', target: 'p+7' }); t.deepEqual(log, []); - - t.end(); }); async function doOutboundPromise(t, mode) { @@ -340,8 +334,6 @@ async function doOutboundPromise(t, mode) { t.deepEqual(log.shift(), fulfillmentSyscall); t.deepEqual(log, []); - - t.end(); } test('liveslots does not retire outbound promise IDs after fulfillToPresence', async t => { @@ -458,8 +450,6 @@ async function doResultPromise(t, mode) { // #823 fails here for the non-presence cases: we expect no syscalls, but // instead we get a send to p+5 t.deepEqual(log, []); - - t.end(); } test('liveslots does not retire result promise IDs after fulfillToPresence', async t => { diff --git a/packages/SwingSet/test/test-marshal.js b/packages/SwingSet/test/test-marshal.js index a1c1aac5933..11b3257c4ef 100644 --- a/packages/SwingSet/test/test-marshal.js +++ b/packages/SwingSet/test/test-marshal.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { makePromiseKit } from '@agoric/promise-kit'; import { makeMarshaller } from '../src/kernel/liveSlots'; @@ -36,8 +36,6 @@ test('serialize exports', t => { body: '[{"@qclass":"slot","index":0},{"@qclass":"slot","index":1}]', slots: ['o+2', 'o+1'], }); - - t.end(); }); test('deserialize imports', async t => { @@ -48,8 +46,8 @@ test('deserialize imports', async t => { slots: ['o-1'], }); // a should be a proxy/presence. For now these are obvious. - t.equal(a.toString(), '[Presence o-1]'); - t.ok(Object.isFrozen(a)); + t.is(a.toString(), '[Presence o-1]'); + t.truthy(Object.isFrozen(a)); // m now remembers the proxy const b = m.unserialize({ @@ -64,8 +62,6 @@ test('deserialize imports', async t => { slots: ['x', 'x', 'o-1'], }); t.is(a, c); - - t.end(); }); test('deserialize exports', t => { @@ -77,8 +73,6 @@ test('deserialize exports', t => { slots: ['o+1'], }); t.is(a, o1); - - t.end(); }); test('serialize imports', async t => { @@ -92,8 +86,6 @@ test('serialize imports', async t => { body: '{"@qclass":"slot","index":0}', slots: ['o-1'], }); - - t.end(); }); test('serialize promise', async t => { @@ -129,8 +121,6 @@ test('serialize promise', async t => { setImmediate(() => pauseRes()); await pauseP; t.deepEqual(log, [{ result: 'p+5', data: { body: '5', slots: [] } }]); - - t.end(); }); test('unserialize promise', async t => { @@ -148,7 +138,5 @@ test('unserialize promise', async t => { slots: ['p-1'], }); t.deepEqual(log, ['subscribe-p-1']); - t.ok(p instanceof Promise); - - t.end(); + t.truthy(p instanceof Promise); }); diff --git a/packages/SwingSet/test/test-message-patterns.js b/packages/SwingSet/test/test-message-patterns.js index 0a8c4ad8c81..5b80cb326e4 100644 --- a/packages/SwingSet/test/test-message-patterns.js +++ b/packages/SwingSet/test/test-message-patterns.js @@ -3,7 +3,7 @@ /* eslint object-shorthand: "off" */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import path from 'path'; import { buildVatController, loadBasedir } from '../src/index'; import { buildLoopbox } from '../src/devices/loopbox'; @@ -11,15 +11,9 @@ import { buildPatterns } from './message-patterns'; // This exercises all the patterns in 'message-patterns.js' twice (once with // vatA/vatB connected directly through the kernel, and a second time with -// comms vats in the path). To enable/disable specific tests, edit the -// entries in that file. - -// use test['only'] so 'grep test(.)only' won't have false matches -const modes = { - test: test, - only: test['only'], - skip: test['skip'], -}; +// comms vats in the path). To enable/disable specific tests, run with e.g. +// 'yarn test test/test-message-patterns.js -m "test pattern a72 local"' +// or '-m "*a72 local"' // eslint-disable-next-line no-unused-vars async function runWithTrace(c) { @@ -56,18 +50,15 @@ export async function runVatsLocally(t, name) { return c.dump().log; } -function testLocalPatterns() { - const bp = buildPatterns(); - for (const name of Array.from(bp.patterns.keys()).sort()) { - const mode = bp.patterns.get(name).local; - modes[mode](`test pattern ${name} locally`, async t => { - const logs = await runVatsLocally(t, name); - t.deepEqual(logs, bp.expected[name]); - t.end(); - }); - } +const bp = buildPatterns(); +async function testLocalPattern(t, name) { + const logs = await runVatsLocally(t, name); + t.deepEqual(logs, bp.expected[name]); +} +testLocalPattern.title = (_, name) => `test pattern ${name} local`; +for (const name of Array.from(bp.patterns.keys()).sort()) { + test('local patterns', testLocalPattern, name); } -testLocalPatterns(); const commsSourcePath = require.resolve('../src/vats/comms'); const vatTPSourcePath = require.resolve('../src/vats/vat-tp'); @@ -108,20 +99,18 @@ export async function runVatsInComms(t, enablePipelining, name) { return c.dump().log; } -function testCommsPatterns() { +async function testCommsPattern(t, name) { const enablePipelining = true; - const bp = buildPatterns(); - for (const name of Array.from(bp.patterns.keys()).sort()) { - const mode = bp.patterns.get(name).comms; - modes[mode](`test pattern ${name} locally`, async t => { - const logs = await runVatsInComms(t, enablePipelining, name); - let expected = bp.expected[name]; - if (enablePipelining && name in bp.expected_pipelined) { - expected = bp.expected_pipelined[name]; - } - t.deepEqual(logs, expected); - t.end(); - }); + const logs = await runVatsInComms(t, enablePipelining, name); + let expected; + if (enablePipelining && name in bp.expected_pipelined) { + expected = bp.expected_pipelined[name]; + } else { + expected = bp.expected[name]; } + t.deepEqual(logs, expected); +} +testCommsPattern.title = (_, name) => `test pattern ${name} comms`; +for (const name of Array.from(bp.patterns.keys()).sort()) { + test('comms patterns', testCommsPattern, name); } -testCommsPatterns(); diff --git a/packages/SwingSet/test/test-network.js b/packages/SwingSet/test/test-network.js index fa31ea134f9..40ab2709b26 100644 --- a/packages/SwingSet/test/test-network.js +++ b/packages/SwingSet/test/test-network.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; // adds 'harden' to global -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { makePromiseKit } from '@agoric/promise-kit'; import { @@ -63,7 +63,7 @@ const makeProtocolHandler = t => { async onListenRemove(port, localAddr, listenHandler) { t.assert(port, `port is tracked in onListen`); t.assert(localAddr, `local address is supplied to onListen`); - t.equals(listenHandler, l, `listenHandler is tracked in onListenRemove`); + t.is(listenHandler, l, `listenHandler is tracked in onListenRemove`); l = undefined; lp = undefined; log('port done listening', port.getLocalAddress()); @@ -77,323 +77,261 @@ const makeProtocolHandler = t => { }; test('handled protocol', async t => { - try { - const protocol = makeNetworkProtocol(makeProtocolHandler(t)); + const protocol = makeNetworkProtocol(makeProtocolHandler(t)); - const closed = makePromiseKit(); - const port = await protocol.bind('/ibc/*/ordered'); - await port.connect( - '/ibc/*/ordered/echo', - harden({ - async onOpen(connection, _localAddr, _remoteAddr) { + const closed = makePromiseKit(); + const port = await protocol.bind('/ibc/*/ordered'); + await port.connect( + '/ibc/*/ordered/echo', + harden({ + async onOpen(connection, _localAddr, _remoteAddr) { + const ack = await connection.send('ping'); + // log(ack); + t.is(`${ack}`, 'ping', 'received pong'); + connection.close(); + }, + async onClose(_connection, reason) { + t.is(reason, undefined, 'no close reason'); + closed.resolve(); + }, + async onReceive(_connection, bytes) { + t.is(`${bytes}`, 'ping'); + return 'pong'; + }, + }), + ); + await closed.promise; + await port.revoke(); +}); + +test('protocol connection listen', async t => { + const protocol = makeNetworkProtocol(makeProtocolHandler(t)); + + const closed = makePromiseKit(); + + const port = await protocol.bind('/net/ordered/ordered/some-portname'); + + /** + * @type {import('../src/vats/network').ListenHandler} + */ + const listener = harden({ + async onListen(p, listenHandler) { + t.is(p, port, `port is tracked in onListen`); + t.assert(listenHandler, `listenHandler is tracked in onListen`); + }, + async onAccept(p, localAddr, remoteAddr, listenHandler) { + t.assert(localAddr, `local address is passed to onAccept`); + t.assert(remoteAddr, `remote address is passed to onAccept`); + t.is(p, port, `port is tracked in onAccept`); + t.is(listenHandler, listener, `listenHandler is tracked in onAccept`); + let handler; + return harden({ + async onOpen(connection, _localAddr, _remoteAddr, connectionHandler) { + t.assert(connectionHandler, `connectionHandler is tracked in onOpen`); + handler = connectionHandler; const ack = await connection.send('ping'); - // log(ack); - t.equals(`${ack}`, 'ping', 'received pong'); + t.is(`${ack}`, 'ping', 'received pong'); connection.close(); }, - async onClose(_connection, reason) { - t.equals(reason, undefined, 'no close reason'); + async onClose(c, reason, connectionHandler) { + t.is( + connectionHandler, + handler, + `connectionHandler is tracked in onClose`, + ); + handler = undefined; + t.assert(c, 'connection is passed to onClose'); + t.is(reason, undefined, 'no close reason'); closed.resolve(); }, - async onReceive(_connection, bytes) { - t.equals(`${bytes}`, 'ping'); + async onReceive(c, packet, connectionHandler) { + t.is( + connectionHandler, + handler, + `connectionHandler is tracked in onReceive`, + ); + t.assert(c, 'connection is passed to onReceive'); + t.is(`${packet}`, 'ping', 'expected ping'); return 'pong'; }, - }), - ); - await closed.promise; - await port.revoke(); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); - -test('protocol connection listen', async t => { - try { - const protocol = makeNetworkProtocol(makeProtocolHandler(t)); - - const closed = makePromiseKit(); + }); + }, + async onError(p, rej, listenHandler) { + t.is(p, port, `port is tracked in onError`); + t.is(listenHandler, listener, `listenHandler is tracked in onError`); + t.isNot(rej, rej, 'unexpected error'); + }, + async onRemove(p, listenHandler) { + t.is(listenHandler, listener, `listenHandler is tracked in onRemove`); + t.is(p, port, `port is passed to onReset`); + }, + }); - const port = await protocol.bind('/net/ordered/ordered/some-portname'); + await port.addListener(listener); - /** - * @type {import('../src/vats/network').ListenHandler} - */ - const listener = harden({ - async onListen(p, listenHandler) { - t.equals(p, port, `port is tracked in onListen`); - t.assert(listenHandler, `listenHandler is tracked in onListen`); - }, - async onAccept(p, localAddr, remoteAddr, listenHandler) { - t.assert(localAddr, `local address is passed to onAccept`); - t.assert(remoteAddr, `remote address is passed to onAccept`); - t.equals(p, port, `port is tracked in onAccept`); - t.equals( - listenHandler, - listener, - `listenHandler is tracked in onAccept`, - ); - let handler; - return harden({ - async onOpen(connection, _localAddr, _remoteAddr, connectionHandler) { - t.assert( - connectionHandler, - `connectionHandler is tracked in onOpen`, - ); - handler = connectionHandler; - const ack = await connection.send('ping'); - t.equals(`${ack}`, 'ping', 'received pong'); - connection.close(); - }, - async onClose(c, reason, connectionHandler) { - t.equals( - connectionHandler, - handler, - `connectionHandler is tracked in onClose`, - ); - handler = undefined; - t.assert(c, 'connection is passed to onClose'); - t.equals(reason, undefined, 'no close reason'); - closed.resolve(); - }, - async onReceive(c, packet, connectionHandler) { - t.equals( - connectionHandler, - handler, - `connectionHandler is tracked in onReceive`, - ); - t.assert(c, 'connection is passed to onReceive'); - t.equals(`${packet}`, 'ping', 'expected ping'); - return 'pong'; - }, - }); - }, - async onError(p, rej, listenHandler) { - t.equals(p, port, `port is tracked in onError`); - t.equals( - listenHandler, - listener, - `listenHandler is tracked in onError`, - ); - t.isNot(rej, rej, 'unexpected error'); - }, - async onRemove(p, listenHandler) { - t.equals( - listenHandler, - listener, - `listenHandler is tracked in onRemove`, - ); - t.equals(p, port, `port is passed to onReset`); + const port2 = await protocol.bind('/net/ordered'); + const connectionHandler = makeEchoConnectionHandler(); + await port2.connect( + '/net/ordered/ordered/some-portname', + harden({ + ...connectionHandler, + async onOpen(connection, localAddr, remoteAddr, c) { + if (connectionHandler.onOpen) { + await connectionHandler.onOpen(connection, localAddr, remoteAddr, c); + } + connection.send('ping'); }, - }); - - await port.addListener(listener); - - const port2 = await protocol.bind('/net/ordered'); - const connectionHandler = makeEchoConnectionHandler(); - await port2.connect( - '/net/ordered/ordered/some-portname', - harden({ - ...connectionHandler, - async onOpen(connection, localAddr, remoteAddr, c) { - if (connectionHandler.onOpen) { - await connectionHandler.onOpen( - connection, - localAddr, - remoteAddr, - c, - ); - } - connection.send('ping'); - }, - }), - ); + }), + ); - await closed.promise; + await closed.promise; - await port.removeListener(listener); - await port.revoke(); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + await port.removeListener(listener); + await port.revoke(); }); test('loopback protocol', async t => { - try { - const protocol = makeNetworkProtocol(makeLoopbackProtocolHandler()); + const protocol = makeNetworkProtocol(makeLoopbackProtocolHandler()); - const closed = makePromiseKit(); + const closed = makePromiseKit(); - const port = await protocol.bind('/loopback/foo'); - - /** - * @type {import('../src/vats/network').ListenHandler} - */ - const listener = harden({ - async onAccept(_p, _localAddr, _remoteAddr, _listenHandler) { - return harden({ - async onReceive(c, packet, _connectionHandler) { - t.equals(`${packet}`, 'ping', 'expected ping'); - return 'pingack'; - }, - }); - }, - }); - await port.addListener(listener); + const port = await protocol.bind('/loopback/foo'); - const port2 = await protocol.bind('/loopback/bar'); - await port2.connect( - port.getLocalAddress(), - harden({ - async onOpen(c, _localAddr, _remoteAddr, _connectionHandler) { - t.equals(`${await c.send('ping')}`, 'pingack', 'expected pingack'); - closed.resolve(); + /** + * @type {import('../src/vats/network').ListenHandler} + */ + const listener = harden({ + async onAccept(_p, _localAddr, _remoteAddr, _listenHandler) { + return harden({ + async onReceive(c, packet, _connectionHandler) { + t.is(`${packet}`, 'ping', 'expected ping'); + return 'pingack'; }, - }), - ); + }); + }, + }); + await port.addListener(listener); - await closed.promise; + const port2 = await protocol.bind('/loopback/bar'); + await port2.connect( + port.getLocalAddress(), + harden({ + async onOpen(c, _localAddr, _remoteAddr, _connectionHandler) { + t.is(`${await c.send('ping')}`, 'pingack', 'expected pingack'); + closed.resolve(); + }, + }), + ); - await port.removeListener(listener); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + await closed.promise; + + await port.removeListener(listener); }); test('routing', async t => { - try { - const router = makeRouter(); - t.deepEquals(router.getRoutes('/if/local'), [], 'get routes matches none'); - router.register('/if/', 'a'); - t.deepEquals( - router.getRoutes('/if/foo'), - [['/if/', 'a']], - 'get routes matches prefix', - ); - router.register('/if/foo', 'b'); - t.deepEquals( - router.getRoutes('/if/foo'), - [ - ['/if/foo', 'b'], - ['/if/', 'a'], - ], - 'get routes matches all', - ); - t.deepEquals( - router.getRoutes('/if/foob'), - [['/if/', 'a']], - 'get routes needs separator', - ); - router.register('/ibc/*/ordered', 'c'); - t.deepEquals( - router.getRoutes('/if/foo'), - [ - ['/if/foo', 'b'], - ['/if/', 'a'], - ], - 'get routes avoids nonmatching paths', - ); - t.deepEquals( - router.getRoutes('/ibc/*/ordered'), - [['/ibc/*/ordered', 'c']], - 'direct match', - ); - t.deepEquals( - router.getRoutes('/ibc/*/ordered/zot'), - [['/ibc/*/ordered', 'c']], - 'prefix matches', - ); - t.deepEquals(router.getRoutes('/ibc/*/barfo'), [], 'no match'); + const router = makeRouter(); + t.deepEqual(router.getRoutes('/if/local'), [], 'get routes matches none'); + router.register('/if/', 'a'); + t.deepEqual( + router.getRoutes('/if/foo'), + [['/if/', 'a']], + 'get routes matches prefix', + ); + router.register('/if/foo', 'b'); + t.deepEqual( + router.getRoutes('/if/foo'), + [ + ['/if/foo', 'b'], + ['/if/', 'a'], + ], + 'get routes matches all', + ); + t.deepEqual( + router.getRoutes('/if/foob'), + [['/if/', 'a']], + 'get routes needs separator', + ); + router.register('/ibc/*/ordered', 'c'); + t.deepEqual( + router.getRoutes('/if/foo'), + [ + ['/if/foo', 'b'], + ['/if/', 'a'], + ], + 'get routes avoids nonmatching paths', + ); + t.deepEqual( + router.getRoutes('/ibc/*/ordered'), + [['/ibc/*/ordered', 'c']], + 'direct match', + ); + t.deepEqual( + router.getRoutes('/ibc/*/ordered/zot'), + [['/ibc/*/ordered', 'c']], + 'prefix matches', + ); + t.deepEqual(router.getRoutes('/ibc/*/barfo'), [], 'no match'); - t.throws( - () => router.unregister('/ibc/*/ordered', 'a'), - /Router is not registered/, - 'unregister fails for no match', - ); - router.unregister('/ibc/*/ordered', 'c'); - t.deepEquals( - router.getRoutes('/ibc/*/ordered'), - [], - 'no match after unregistration', - ); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + t.throws( + () => router.unregister('/ibc/*/ordered', 'a'), + { message: /Router is not registered/ }, + 'unregister fails for no match', + ); + router.unregister('/ibc/*/ordered', 'c'); + t.deepEqual( + router.getRoutes('/ibc/*/ordered'), + [], + 'no match after unregistration', + ); }); test('multiaddr', async t => { - try { - t.deepEquals(parse('/if/local'), [['if', 'local']]); - t.deepEquals(parse('/zot'), [['zot']]); - t.deepEquals(parse('/zot/foo/bar/baz/bot'), [ - ['zot', 'foo'], - ['bar', 'baz'], - ['bot'], - ]); - for (const str of ['', 'foobar']) { - t.throws( - () => parse(str), - /Error parsing Multiaddr/, - `expected failure of ${str}`, - ); - } - for (const str of [ - '/', - '//', - '/foo', - '/foobib/bar', - '/k1/v1/k2/v2/k3/v3', - ]) { - t.equals( - unparse(parse(str)), - str, - `round-trip of ${JSON.stringify(str)} matches`, - ); - } - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); + t.deepEqual(parse('/if/local'), [['if', 'local']]); + t.deepEqual(parse('/zot'), [['zot']]); + t.deepEqual(parse('/zot/foo/bar/baz/bot'), [ + ['zot', 'foo'], + ['bar', 'baz'], + ['bot'], + ]); + for (const str of ['', 'foobar']) { + t.throws( + () => parse(str), + { message: /Error parsing Multiaddr/ }, + `expected failure of ${str}`, + ); + } + for (const str of ['/', '//', '/foo', '/foobib/bar', '/k1/v1/k2/v2/k3/v3']) { + t.is( + unparse(parse(str)), + str, + `round-trip of ${JSON.stringify(str)} matches`, + ); } }); test('bytes conversions', t => { - try { - const insouts = [ - ['', ''], - ['f', 'Zg=='], - ['fo', 'Zm8='], - ['foo', 'Zm9v'], - ['foob', 'Zm9vYg=='], - ['fooba', 'Zm9vYmE='], - ['foobar', 'Zm9vYmFy'], - ]; - for (const [inp, outp] of insouts) { - t.equals(dataToBase64(inp), outp, `${inp} encodes`); - t.equals(base64ToBytes(outp), inp, `${outp} decodes`); - } - const inputs = [ - 'a', - 'ab', - 'abc', - 'Hello, world!', - '\x0d\x02\x09\xff\xfe', - 'other--+iadtedata', - ]; - for (const str of inputs) { - t.equals(base64ToBytes(dataToBase64(str)), str, `${str} round trips`); - } - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); + const insouts = [ + ['', ''], + ['f', 'Zg=='], + ['fo', 'Zm8='], + ['foo', 'Zm9v'], + ['foob', 'Zm9vYg=='], + ['fooba', 'Zm9vYmE='], + ['foobar', 'Zm9vYmFy'], + ]; + for (const [inp, outp] of insouts) { + t.is(dataToBase64(inp), outp, `${inp} encodes`); + t.is(base64ToBytes(outp), inp, `${outp} decodes`); + } + const inputs = [ + 'a', + 'ab', + 'abc', + 'Hello, world!', + '\x0d\x02\x09\xff\xfe', + 'other--+iadtedata', + ]; + for (const str of inputs) { + t.is(base64ToBytes(dataToBase64(str)), str, `${str} round trips`); } }); diff --git a/packages/SwingSet/test/test-node-version.js b/packages/SwingSet/test/test-node-version.js index 9b92bc4bba9..bfe077e0ed0 100644 --- a/packages/SwingSet/test/test-node-version.js +++ b/packages/SwingSet/test/test-node-version.js @@ -1,14 +1,13 @@ // eslint-disable-next-line no-redeclare /* global process */ import semver from 'semver'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; test('Node version for IO queue priority', t => { t.true( semver.satisfies(process.version, '>=11.0'), 'we need Node 11 where the IO queue is higher priority than the Promise queue', ); - t.end(); }); test('Node version', t => { @@ -16,5 +15,4 @@ test('Node version', t => { semver.satisfies(process.version, '>=12.14.1'), 'we only test against Node 12.14.1 (LTS)', ); - t.end(); }); diff --git a/packages/SwingSet/test/test-promises.js b/packages/SwingSet/test/test-promises.js index b2627b98339..15ca9ce60e0 100644 --- a/packages/SwingSet/test/test-promises.js +++ b/packages/SwingSet/test/test-promises.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import path from 'path'; import { buildVatController, loadBasedir } from '../src/index'; @@ -11,7 +11,6 @@ test('flush', async t => { // all promises should settle before c.step() fires await c.step(); t.deepEqual(c.dump().log, ['then1', 'then2']); - t.end(); }); test('E() resolve', async t => { @@ -25,7 +24,6 @@ test('E() resolve', async t => { 'b.resolved 3', 'left.then 4', ]); - t.end(); }); test('E(E(x).foo()).bar()', async t => { @@ -48,7 +46,6 @@ test('E(E(x).foo()).bar()', async t => { 'left.call3 2', 'b.resolved 3', ]); - t.end(); }); test('E(Promise.resolve(presence)).foo()', async t => { @@ -62,7 +59,6 @@ test('E(Promise.resolve(presence)).foo()', async t => { 'left.call3 2', 'b.resolved 3', ]); - t.end(); }); test('E(local).foo()', async t => { @@ -71,7 +67,6 @@ test('E(local).foo()', async t => { await c.run(); t.deepEqual(c.dump().log, ['b.local1.finish', 'local.foo 1', 'b.resolved 2']); - t.end(); }); test('resolve-to-local', async t => { @@ -85,7 +80,6 @@ test('resolve-to-local', async t => { 'local.foo 2', 'b.resolved 3', ]); - t.end(); }); test('send-promise-resolve-to-local', async t => { @@ -100,7 +94,6 @@ test('send-promise-resolve-to-local', async t => { 'local.foo 1', 'b.resolved 4', ]); - t.end(); }); test('send-harden-promise-1', async t => { @@ -122,7 +115,6 @@ test('send-harden-promise-1', async t => { 'o1 frozen true', 'b.harden-promise-1.finish', ]); - t.end(); }); test('circular promise resolution data', async t => { @@ -162,5 +154,4 @@ test('circular promise resolution data', async t => { }); } t.deepEqual(c.dump().promises, expectedPromises); - t.end(); }); diff --git a/packages/SwingSet/test/test-queue-priority.js b/packages/SwingSet/test/test-queue-priority.js index d9210a4eedb..33f7c9c9b38 100644 --- a/packages/SwingSet/test/test-queue-priority.js +++ b/packages/SwingSet/test/test-queue-priority.js @@ -1,6 +1,6 @@ // eslint-disable-next-line no-redeclare /* global setImmediate setTimeout */ -import { test } from 'tape-promise/tape'; +import test from 'ava'; test('Promise queue should be higher priority than IO/timer queue', async t => { const log = []; @@ -19,5 +19,4 @@ test('Promise queue should be higher priority than IO/timer queue', async t => { await p; t.deepEqual(log, [1, 2, 3, 4, 5, 6]); - return t.end(); }); diff --git a/packages/SwingSet/test/test-state.js b/packages/SwingSet/test/test-state.js index 69c53c42aca..18bc192c635 100644 --- a/packages/SwingSet/test/test-state.js +++ b/packages/SwingSet/test/test-state.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { initSwingStore, getAllState, @@ -36,12 +36,12 @@ function checkState(t, getState, expected) { } function testStorage(t, s, getState, commit) { - t.notOk(s.has('missing')); - t.equal(s.get('missing'), undefined); + t.falsy(s.has('missing')); + t.is(s.get('missing'), undefined); s.set('foo', 'f'); - t.ok(s.has('foo')); - t.equal(s.get('foo'), 'f'); + t.truthy(s.has('foo')); + t.is(s.get('foo'), 'f'); s.set('foo2', 'f2'); s.set('foo1', 'f1'); @@ -50,8 +50,8 @@ function testStorage(t, s, getState, commit) { t.deepEqual(Array.from(s.getKeys('foo1', 'foo4')), ['foo1', 'foo2', 'foo3']); s.delete('foo2'); - t.notOk(s.has('foo2')); - t.equal(s.get('foo2'), undefined); + t.falsy(s.has('foo2')); + t.is(s.get('foo2'), undefined); t.deepEqual(Array.from(s.getKeys('foo1', 'foo4')), ['foo1', 'foo3']); if (commit) { @@ -68,7 +68,6 @@ function testStorage(t, s, getState, commit) { test('storageInMemory', t => { const { storage } = initSwingStore(); testStorage(t, storage, () => getAllState(storage), null); - t.end(); }); function buildHostDBAndGetState() { @@ -80,12 +79,12 @@ function buildHostDBAndGetState() { test('hostDBInMemory', t => { const { hostDB, getState } = buildHostDBAndGetState(); - t.notOk(hostDB.has('missing')); - t.equal(hostDB.get('missing'), undefined); + t.falsy(hostDB.has('missing')); + t.is(hostDB.get('missing'), undefined); hostDB.applyBatch([{ op: 'set', key: 'foo', value: 'f' }]); - t.ok(hostDB.has('foo')); - t.equal(hostDB.get('foo'), 'f'); + t.truthy(hostDB.has('foo')); + t.is(hostDB.get('foo'), 'f'); hostDB.applyBatch([ { op: 'set', key: 'foo2', value: 'f2' }, @@ -100,8 +99,8 @@ test('hostDBInMemory', t => { ]); hostDB.applyBatch([{ op: 'delete', key: 'foo2' }]); - t.notOk(hostDB.has('foo2')); - t.equal(hostDB.get('foo2'), undefined); + t.falsy(hostDB.has('foo2')); + t.is(hostDB.get('foo2'), undefined); t.deepEqual(Array.from(hostDB.getKeys('foo1', 'foo4')), ['foo1', 'foo3']); checkState(t, getState, [ @@ -109,28 +108,24 @@ test('hostDBInMemory', t => { ['foo1', 'f1'], ['foo3', 'f3'], ]); - t.end(); }); test('blockBuffer fulfills storage API', t => { const { hostDB, getState } = buildHostDBAndGetState(); const { blockBuffer, commitBlock } = buildBlockBuffer(hostDB); testStorage(t, blockBuffer, getState, commitBlock); - t.end(); }); test('guardStorage fulfills storage API', t => { const { storage } = initSwingStore(); const guardedHostStorage = guardStorage(storage); testStorage(t, guardedHostStorage, () => getAllState(storage), null); - t.end(); }); test('crankBuffer fulfills storage API', t => { const { storage } = initSwingStore(); const { crankBuffer, commitCrank } = buildCrankBuffer(storage); testStorage(t, crankBuffer, () => getAllState(storage), commitCrank); - t.end(); }); test('crankBuffer can abortCrank', t => { @@ -141,8 +136,8 @@ test('crankBuffer can abortCrank', t => { ); s.set('foo', 'f'); - t.ok(s.has('foo')); - t.equal(s.get('foo'), 'f'); + t.truthy(s.has('foo')); + t.is(s.get('foo'), 'f'); s.set('foo2', 'f2'); s.set('foo1', 'f1'); @@ -151,8 +146,8 @@ test('crankBuffer can abortCrank', t => { t.deepEqual(Array.from(s.getKeys('foo1', 'foo4')), ['foo1', 'foo2', 'foo3']); s.delete('foo2'); - t.notOk(s.has('foo2')); - t.equal(s.get('foo2'), undefined); + t.falsy(s.has('foo2')); + t.is(s.get('foo2'), undefined); t.deepEqual(Array.from(s.getKeys('foo1', 'foo4')), ['foo1', 'foo3']); commitBlock(); @@ -186,8 +181,6 @@ test('crankBuffer can abortCrank', t => { ['foo3', 'f3'], ['foo5', 'f5'], ]); - - t.end(); }); test('storage helpers', t => { @@ -228,18 +221,16 @@ test('storage helpers', t => { t.deepEqual(Array.from(s.getPrefixedValues('foo.', 1)), ['f1', 'f2', 'f3']); s.deletePrefixedKeys('foo.', 1); - t.ok(s.has('foo.0')); - t.notOk(s.has('foo.1')); - t.notOk(s.has('foo.2')); - t.notOk(s.has('foo.3')); - t.notOk(s.has('foo.4')); - t.ok(s.has('foo.5')); + t.truthy(s.has('foo.0')); + t.falsy(s.has('foo.1')); + t.falsy(s.has('foo.2')); + t.falsy(s.has('foo.3')); + t.falsy(s.has('foo.4')); + t.truthy(s.has('foo.5')); checkState(t, () => getAllState(storage), [ ['foo.0', 'f0'], ['foo.5', 'f5'], ]); - - t.end(); }); function buildKeeperStorageInMemory() { @@ -262,7 +253,7 @@ function duplicateKeeper(getState) { test('kernel state', async t => { const { kstorage, getState, commitCrank } = buildKeeperStorageInMemory(); const k = makeKernelKeeper(kstorage); - t.ok(!k.getInitialized()); + t.truthy(!k.getInitialized()); k.createStartingKernelState(); k.setInitialized(); @@ -280,7 +271,6 @@ test('kernel state', async t => { ['kd.nextID', '30'], ['kp.nextID', '40'], ]); - t.end(); }); test('kernelKeeper vat names', async t => { @@ -290,8 +280,8 @@ test('kernelKeeper vat names', async t => { const v1 = k.allocateVatIDForNameIfNeeded('vatname5'); const v2 = k.allocateVatIDForNameIfNeeded('Frank'); - t.equal(v1, 'v1'); - t.equal(v2, 'v2'); + t.is(v1, 'v1'); + t.is(v2, 'v2'); commitCrank(); checkState(t, getState, [ @@ -309,14 +299,13 @@ test('kernelKeeper vat names', async t => { ['vat.name.Frank', 'v2'], ]); t.deepEqual(k.getAllVatNames(), ['Frank', 'vatname5']); - t.equal(k.getVatIDForName('Frank'), v2); - t.equal(k.allocateVatIDForNameIfNeeded('Frank'), v2); + t.is(k.getVatIDForName('Frank'), v2); + t.is(k.allocateVatIDForNameIfNeeded('Frank'), v2); const k2 = duplicateKeeper(getState); t.deepEqual(k2.getAllVatNames(), ['Frank', 'vatname5']); - t.equal(k2.getVatIDForName('Frank'), v2); - t.equal(k2.allocateVatIDForNameIfNeeded('Frank'), v2); - t.end(); + t.is(k2.getVatIDForName('Frank'), v2); + t.is(k2.allocateVatIDForNameIfNeeded('Frank'), v2); }); test('kernelKeeper device names', async t => { @@ -326,8 +315,8 @@ test('kernelKeeper device names', async t => { const d7 = k.allocateDeviceIDForNameIfNeeded('devicename5'); const d8 = k.allocateDeviceIDForNameIfNeeded('Frank'); - t.equal(d7, 'd7'); - t.equal(d8, 'd8'); + t.is(d7, 'd7'); + t.is(d8, 'd8'); commitCrank(); checkState(t, getState, [ @@ -345,14 +334,13 @@ test('kernelKeeper device names', async t => { ['device.name.Frank', 'd8'], ]); t.deepEqual(k.getAllDeviceNames(), ['Frank', 'devicename5']); - t.equal(k.getDeviceIDForName('Frank'), d8); - t.equal(k.allocateDeviceIDForNameIfNeeded('Frank'), d8); + t.is(k.getDeviceIDForName('Frank'), d8); + t.is(k.allocateDeviceIDForNameIfNeeded('Frank'), d8); const k2 = duplicateKeeper(getState); t.deepEqual(k2.getAllDeviceNames(), ['Frank', 'devicename5']); - t.equal(k2.getDeviceIDForName('Frank'), d8); - t.equal(k2.allocateDeviceIDForNameIfNeeded('Frank'), d8); - t.end(); + t.is(k2.getDeviceIDForName('Frank'), d8); + t.is(k2.allocateDeviceIDForNameIfNeeded('Frank'), d8); }); test('kernelKeeper runQueue', async t => { @@ -360,37 +348,35 @@ test('kernelKeeper runQueue', async t => { const k = makeKernelKeeper(kstorage); k.createStartingKernelState(); - t.ok(k.isRunQueueEmpty()); - t.equal(k.getRunQueueLength(), 0); + t.truthy(k.isRunQueueEmpty()); + t.is(k.getRunQueueLength(), 0); k.addToRunQueue({ type: 'send', stuff: 'awesome' }); - t.notOk(k.isRunQueueEmpty()); - t.equal(k.getRunQueueLength(), 1); + t.falsy(k.isRunQueueEmpty()); + t.is(k.getRunQueueLength(), 1); k.addToRunQueue({ type: 'notify', stuff: 'notifawesome' }); - t.notOk(k.isRunQueueEmpty()); - t.equal(k.getRunQueueLength(), 2); + t.falsy(k.isRunQueueEmpty()); + t.is(k.getRunQueueLength(), 2); commitCrank(); const k2 = duplicateKeeper(getState); t.deepEqual(k.getNextMsg(), { type: 'send', stuff: 'awesome' }); - t.notOk(k.isRunQueueEmpty()); - t.equal(k.getRunQueueLength(), 1); + t.falsy(k.isRunQueueEmpty()); + t.is(k.getRunQueueLength(), 1); t.deepEqual(k.getNextMsg(), { type: 'notify', stuff: 'notifawesome' }); - t.ok(k.isRunQueueEmpty()); - t.equal(k.getRunQueueLength(), 0); + t.truthy(k.isRunQueueEmpty()); + t.is(k.getRunQueueLength(), 0); t.deepEqual(k2.getNextMsg(), { type: 'send', stuff: 'awesome' }); - t.notOk(k2.isRunQueueEmpty()); - t.equal(k2.getRunQueueLength(), 1); + t.falsy(k2.isRunQueueEmpty()); + t.is(k2.getRunQueueLength(), 1); t.deepEqual(k2.getNextMsg(), { type: 'notify', stuff: 'notifawesome' }); - t.ok(k2.isRunQueueEmpty()); - t.equal(k2.getRunQueueLength(), 0); - - t.end(); + t.truthy(k2.isRunQueueEmpty()); + t.is(k2.getRunQueueLength(), 0); }); test('kernelKeeper promises', async t => { @@ -406,8 +392,8 @@ test('kernelKeeper promises', async t => { subscribers: [], decider: 'v4', }); - t.ok(k.hasKernelPromise(p1)); - t.notOk(k.hasKernelPromise('kp99')); + t.truthy(k.hasKernelPromise(p1)); + t.falsy(k.hasKernelPromise('kp99')); commitCrank(); let k2 = duplicateKeeper(getState); @@ -419,7 +405,7 @@ test('kernelKeeper promises', async t => { subscribers: [], decider: 'v4', }); - t.ok(k2.hasKernelPromise(p1)); + t.truthy(k2.hasKernelPromise(p1)); k.clearDecider(p1); t.deepEqual(k.getKernelPromise(p1), { @@ -477,7 +463,7 @@ test('kernelKeeper promises', async t => { refCount: 0, slot: 'ko44', }); - t.ok(k.hasKernelPromise(p1)); + t.truthy(k.hasKernelPromise(p1)); // all the subscriber/queue stuff should be gone commitCrank(); checkState(t, getState, [ @@ -495,7 +481,6 @@ test('kernelKeeper promises', async t => { ['kp40.state', 'fulfilledToPresence'], ['kp40.refCount', '0'], ]); - t.end(); }); test('kernelKeeper promise resolveToData', async t => { @@ -514,7 +499,6 @@ test('kernelKeeper promise resolveToData', async t => { slots: ['ko22', 'kp24', 'kd25'], }, }); - t.end(); }); test('kernelKeeper promise reject', async t => { @@ -533,7 +517,6 @@ test('kernelKeeper promise reject', async t => { slots: ['ko22', 'kp24', 'kd25'], }, }); - t.end(); }); test('vatKeeper', async t => { @@ -547,25 +530,23 @@ test('vatKeeper', async t => { const vatExport1 = 'o+4'; const kernelExport1 = vk.mapVatSlotToKernelSlot(vatExport1); - t.equal(kernelExport1, 'ko20'); - t.equal(vk.mapVatSlotToKernelSlot(vatExport1), kernelExport1); - t.equal(vk.mapKernelSlotToVatSlot(kernelExport1), vatExport1); + t.is(kernelExport1, 'ko20'); + t.is(vk.mapVatSlotToKernelSlot(vatExport1), kernelExport1); + t.is(vk.mapKernelSlotToVatSlot(kernelExport1), vatExport1); commitCrank(); let vk2 = duplicateKeeper(getState).allocateVatKeeperIfNeeded(v1); - t.equal(vk2.mapVatSlotToKernelSlot(vatExport1), kernelExport1); - t.equal(vk2.mapKernelSlotToVatSlot(kernelExport1), vatExport1); + t.is(vk2.mapVatSlotToKernelSlot(vatExport1), kernelExport1); + t.is(vk2.mapKernelSlotToVatSlot(kernelExport1), vatExport1); const kernelImport2 = 'ko25'; const vatImport2 = vk.mapKernelSlotToVatSlot(kernelImport2); - t.equal(vatImport2, 'o-50'); - t.equal(vk.mapKernelSlotToVatSlot(kernelImport2), vatImport2); - t.equal(vk.mapVatSlotToKernelSlot(vatImport2), kernelImport2); + t.is(vatImport2, 'o-50'); + t.is(vk.mapKernelSlotToVatSlot(kernelImport2), vatImport2); + t.is(vk.mapVatSlotToKernelSlot(vatImport2), kernelImport2); commitCrank(); vk2 = duplicateKeeper(getState).allocateVatKeeperIfNeeded(v1); - t.equal(vk2.mapKernelSlotToVatSlot(kernelImport2), vatImport2); - t.equal(vk2.mapVatSlotToKernelSlot(vatImport2), kernelImport2); - - t.end(); + t.is(vk2.mapKernelSlotToVatSlot(kernelImport2), vatImport2); + t.is(vk2.mapVatSlotToKernelSlot(vatImport2), kernelImport2); }); diff --git a/packages/SwingSet/test/test-tildot.js b/packages/SwingSet/test/test-tildot.js index 34636f3914e..ef0f462b590 100644 --- a/packages/SwingSet/test/test-tildot.js +++ b/packages/SwingSet/test/test-tildot.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildVatController } from '../src/index'; test('vat code can use tildot', async t => { @@ -19,5 +19,4 @@ test('vat code can use tildot', async t => { 'HandledPromise.applyMethod(x, "foo", [y]);', 'ok', ]); - t.end(); }); diff --git a/packages/SwingSet/test/test-timer-device.js b/packages/SwingSet/test/test-timer-device.js index 8f270159a4a..4cde19d759a 100644 --- a/packages/SwingSet/test/test-timer-device.js +++ b/packages/SwingSet/test/test-timer-device.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { makeTimerMap, curryPollFn } from '../src/devices/timer-src'; test('multiMap multi store', t => { @@ -7,24 +7,22 @@ test('multiMap multi store', t => { mm.add(3, 'threeA'); mm.add(3, 'threeB'); const threes = mm.removeEventsThrough(4); - t.equal(threes.length, 1); + t.is(threes.length, 1); t.deepEqual(threes[0], { time: 3, handlers: [{ handler: 'threeA' }, { handler: 'threeB' }], }); - t.equal(mm.removeEventsThrough(10).length, 0); - t.end(); + t.is(mm.removeEventsThrough(10).length, 0); }); test('multiMap store multiple keys', t => { const mm = makeTimerMap(); mm.add(3, 'threeA'); mm.add(13, 'threeB'); - t.equal(mm.removeEventsThrough(4).length, 1); - t.equal(mm.removeEventsThrough(10).length, 0); + t.is(mm.removeEventsThrough(4).length, 1); + t.is(mm.removeEventsThrough(10).length, 0); const thirteens = mm.removeEventsThrough(13); - t.equal(thirteens.length, 1, thirteens); - t.end(); + t.is(thirteens.length, 1, `${thirteens}`); }); test('multiMap remove key', t => { @@ -34,11 +32,10 @@ test('multiMap remove key', t => { t.deepEqual(mm.remove('not There'), []); t.deepEqual(mm.remove('threeA'), [3]); mm.remove(3, 'threeA'); - t.equal(mm.removeEventsThrough(10).length, 0); + t.is(mm.removeEventsThrough(10).length, 0); const thirteens = mm.removeEventsThrough(13); - t.equal(thirteens.length, 1); + t.is(thirteens.length, 1); t.deepEqual(thirteens[0], { time: 13, handlers: [{ handler: 'threeB' }] }); - t.end(); }); function fakeSO(o) { @@ -83,14 +80,13 @@ test('Timer schedule single event', t => { const fakeTimer = makeFakeTimer(1); const lastPolled = fakeTimer.getLastPolled; const poll = curryPollFn(fakeSO, [], schedule, lastPolled, _ => {}); - t.notOk(poll(1)); // false when nothing is woken + t.falsy(poll(1)); // false when nothing is woken const handler = makeHandler(); schedule.add(2, handler); - t.equals(fakeTimer.getLastPolled(), 1); - t.ok(poll(4)); - t.equals(handler.getCalls(), 1); - t.equals(handler.getArgs()[0], 2); - t.end(); + t.is(fakeTimer.getLastPolled(), 1); + t.truthy(poll(4)); + t.is(handler.getCalls(), 1); + t.is(handler.getArgs()[0], 2); }); test('Timer schedule multiple events', t => { @@ -98,19 +94,18 @@ test('Timer schedule multiple events', t => { const fakeTimer = makeFakeTimer(1); const lastPolled = fakeTimer.getLastPolled; const poll = curryPollFn(fakeSO, [], schedule, lastPolled, _ => {}); - t.notOk(poll(1)); // false when nothing is woken + t.falsy(poll(1)); // false when nothing is woken const handler1 = makeHandler(); const handler2 = makeHandler(); schedule.add(3, handler1); schedule.add(4, handler1); schedule.add(2, handler2); - t.equals(lastPolled(), 1); - t.ok(poll(4)); - t.equals(handler1.getCalls(), 2); - t.equals(handler2.getCalls(), 1); + t.is(lastPolled(), 1); + t.truthy(poll(4)); + t.is(handler1.getCalls(), 2); + t.is(handler2.getCalls(), 1); t.deepEqual(handler1.getArgs(), [3, 4]); t.deepEqual(handler2.getArgs(), [2]); - t.end(); }); test('Timer schedule repeated event first', t => { @@ -120,16 +115,15 @@ test('Timer schedule repeated event first', t => { const lastPolled = fakeTimer.getLastPolled; const repeater = { startTime: 3, interval: 4 }; const poll = curryPollFn(fakeSO, [repeater], schedule, lastPolled, _ => {}); - t.notOk(poll(1)); // false when nothing is woken + t.falsy(poll(1)); // false when nothing is woken const handler = makeHandler(); schedule.add(5, handler, repeaterIndex); - t.notOk(poll(4)); - t.ok(poll(5)); - t.equals(handler.getCalls(), 1); + t.falsy(poll(4)); + t.truthy(poll(5)); + t.is(handler.getCalls(), 1); t.deepEqual(handler.getArgs(), [5]); const expected = [{ time: 7, handlers: [{ handler, index: repeaterIndex }] }]; t.deepEqual(schedule.removeEventsThrough(8), expected); - t.end(); }); test('multiMap remove repeater key', t => { @@ -140,11 +134,10 @@ test('multiMap remove repeater key', t => { const lastPolled = fakeTimer.getLastPolled; const repeater = { startTime: 2, interval: 4 }; const poll = curryPollFn(fakeSO, [repeater], schedule, lastPolled, _ => {}); - t.notOk(poll(1)); // false when nothing is woken + t.falsy(poll(1)); // false when nothing is woken const handler = makeHandler(); schedule.add(scheduleTime, handler, repeaterIndex); t.deepEqual(schedule.remove(handler), [scheduleTime]); - t.end(); }); test('Timer schedule repeated event, repeatedly', t => { @@ -154,24 +147,23 @@ test('Timer schedule repeated event, repeatedly', t => { const lastPolled = fakeTimer.getLastPolled; const repeater = { startTime: 6, interval: 3 }; const poll = curryPollFn(fakeSO, [repeater], schedule, lastPolled, _ => {}); - t.notOk(poll(4)); // false when nothing is woken + t.falsy(poll(4)); // false when nothing is woken const handler = makeHandler(); schedule.add(9, handler, repeaterIndex); - t.equals(handler.getCalls(), 0); + t.is(handler.getCalls(), 0); fakeTimer.setTime(8); - t.notOk(poll(8)); - t.equals(handler.getCalls(), 0); + t.falsy(poll(8)); + t.is(handler.getCalls(), 0); fakeTimer.setTime(10); - t.ok(poll(10)); - t.equals(handler.getCalls(), 1); + t.truthy(poll(10)); + t.is(handler.getCalls(), 1); fakeTimer.setTime(12); - t.ok(poll(12)); - t.equals(handler.getCalls(), 2); - t.deepEquals(handler.getArgs(), [9, 12]); - t.end(); + t.truthy(poll(12)); + t.is(handler.getCalls(), 2); + t.deepEqual(handler.getArgs(), [9, 12]); }); test('Timer schedule multiple repeaters', t => { @@ -195,39 +187,38 @@ test('Timer schedule multiple repeaters', t => { fakeTimer.setTime(7); poll(7); - t.equals(handler0.getCalls(), 0); - t.equals(handler1.getCalls(), 0); - t.equals(handler2.getCalls(), 0); + t.is(handler0.getCalls(), 0); + t.is(handler1.getCalls(), 0); + t.is(handler2.getCalls(), 0); fakeTimer.setTime(10); - t.ok(poll(10)); - t.equals(handler0.getCalls(), 1); // 9; next is 12 - t.equals(handler1.getCalls(), 0); // first is 12 - t.equals(handler2.getCalls(), 1); // 9; next is 13 + t.truthy(poll(10)); + t.is(handler0.getCalls(), 1); // 9; next is 12 + t.is(handler1.getCalls(), 0); // first is 12 + t.is(handler2.getCalls(), 1); // 9; next is 13 repeaters[repeaterIndex0] = undefined; fakeTimer.setTime(12); - t.ok(poll(12)); - t.equals(handler0.getCalls(), 2); // 12; next won't happen - t.equals(handler1.getCalls(), 1); // 12; next is 17 - t.equals(handler2.getCalls(), 1); // next is 13 + t.truthy(poll(12)); + t.is(handler0.getCalls(), 2); // 12; next won't happen + t.is(handler1.getCalls(), 1); // 12; next is 17 + t.is(handler2.getCalls(), 1); // next is 13 fakeTimer.setTime(14); - t.ok(poll(14)); - t.equals(handler0.getCalls(), 2); // next is not scheduled - t.equals(handler1.getCalls(), 1); // next is 17 - t.equals(handler2.getCalls(), 2); // 13; next is 17 + t.truthy(poll(14)); + t.is(handler0.getCalls(), 2); // next is not scheduled + t.is(handler1.getCalls(), 1); // next is 17 + t.is(handler2.getCalls(), 2); // 13; next is 17 fakeTimer.setTime(16); - t.notOk(poll(16)); // false when nothing is woken - t.equals(handler0.getCalls(), 2); // next didn't happen - t.equals(handler1.getCalls(), 1); // next is 17 - t.equals(handler2.getCalls(), 2); // next is 17 + t.falsy(poll(16)); // false when nothing is woken + t.is(handler0.getCalls(), 2); // next didn't happen + t.is(handler1.getCalls(), 1); // next is 17 + t.is(handler2.getCalls(), 2); // next is 17 const h = [ { handler: handler1, index: repeaterIndex1 }, { handler: handler2, index: repeaterIndex2 }, ]; t.deepEqual(schedule.cloneSchedule(), [{ time: 17, handlers: h }]); - t.end(); }); diff --git a/packages/SwingSet/test/test-transcript-light.js b/packages/SwingSet/test/test-transcript-light.js index ca6c5f83303..4c7188c7180 100644 --- a/packages/SwingSet/test/test-transcript-light.js +++ b/packages/SwingSet/test/test-transcript-light.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import path from 'path'; import { initSwingStore, @@ -15,8 +15,8 @@ test('transcript-light load', async t => { const { storage } = initSwingStore(); const c = await buildVatController(config, ['one'], { hostStorage: storage }); const state0 = getAllState(storage); - t.equal(state0.initialized, 'true'); - t.notEqual(state0.runQueue, '[]'); + t.is(state0.initialized, 'true'); + t.not(state0.runQueue, '[]'); await c.step(); const state1 = getAllState(storage); @@ -94,6 +94,4 @@ test('transcript-light load', async t => { await c2.step(); t.deepEqual(state5, getAllState(storage2), `p14`); - - t.end(); }); diff --git a/packages/SwingSet/test/test-transcript.js b/packages/SwingSet/test/test-transcript.js index cdf24a4bed4..ead2dda0cca 100644 --- a/packages/SwingSet/test/test-transcript.js +++ b/packages/SwingSet/test/test-transcript.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import path from 'path'; // import fs from 'fs'; import { @@ -46,7 +46,6 @@ test('transcript-one save', async t => { states1.forEach((s, i) => { t.deepEqual(s, states2[i]); }); - t.end(); }); test('transcript-one load', async t => { @@ -76,5 +75,4 @@ test('transcript-one load', async t => { // JSON.stringify(newstates[j]))); t.deepEqual(states.slice(i), newstates); } - t.end(); }); diff --git a/packages/SwingSet/test/test-vattp.js b/packages/SwingSet/test/test-vattp.js index 65ad4343020..625ee1c564c 100644 --- a/packages/SwingSet/test/test-vattp.js +++ b/packages/SwingSet/test/test-vattp.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildVatController } from '../src/index'; import { buildMailboxStateMap, buildMailbox } from '../src/devices/mailbox'; @@ -20,7 +20,7 @@ test('vattp', async t => { await c.run(); t.deepEqual(s.exportToData(), {}); - t.equal( + t.is( mb.deliverInbound( 'remote1', [ @@ -39,7 +39,7 @@ test('vattp', async t => { ]); t.deepEqual(s.exportToData(), { remote1: { outbox: [], inboundAck: 2 } }); - t.equal( + t.is( mb.deliverInbound( 'remote1', [ @@ -52,8 +52,6 @@ test('vattp', async t => { ); await c.run(); t.deepEqual(s.exportToData(), { remote1: { outbox: [], inboundAck: 2 } }); - - t.end(); }); test('vattp 2', async t => { @@ -75,19 +73,19 @@ test('vattp 2', async t => { remote1: { outbox: [[1, 'out1']], inboundAck: 0 }, }); - t.equal(mb.deliverInbound('remote1', [], 1), true); + t.is(mb.deliverInbound('remote1', [], 1), true); await c.run(); t.deepEqual(c.dump().log, []); t.deepEqual(s.exportToData(), { remote1: { outbox: [], inboundAck: 0 } }); - t.equal(mb.deliverInbound('remote1', [[1, 'msg1']], 1), true); + t.is(mb.deliverInbound('remote1', [[1, 'msg1']], 1), true); await c.run(); t.deepEqual(c.dump().log, ['ch.receive msg1']); t.deepEqual(s.exportToData(), { remote1: { outbox: [], inboundAck: 1 } }); - t.equal(mb.deliverInbound('remote1', [[1, 'msg1']], 1), false); + t.is(mb.deliverInbound('remote1', [[1, 'msg1']], 1), false); - t.equal( + t.is( mb.deliverInbound( 'remote1', [ @@ -101,6 +99,4 @@ test('vattp 2', async t => { await c.run(); t.deepEqual(c.dump().log, ['ch.receive msg1', 'ch.receive msg2']); t.deepEqual(s.exportToData(), { remote1: { outbox: [], inboundAck: 2 } }); - - t.end(); }); diff --git a/packages/SwingSet/test/test-vpid-kernel.js b/packages/SwingSet/test/test-vpid-kernel.js index e08603e1b47..5e43a0190a4 100644 --- a/packages/SwingSet/test/test-vpid-kernel.js +++ b/packages/SwingSet/test/test-vpid-kernel.js @@ -2,7 +2,7 @@ /* global harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; @@ -249,7 +249,7 @@ async function doTest123(t, which, mode) { dataPromiseB = 'p-61'; syscallA.send(rootBvatA, 'one', capargs([slot0arg], [exportedP1VatA])); p1kernel = clistVatToKernel(kernel, vatA, exportedP1VatA); - t.equal(p1kernel, expectedP1kernel); + t.is(p1kernel, expectedP1kernel); await kernel.run(); t.deepEqual(logB.shift(), { @@ -264,7 +264,7 @@ async function doTest123(t, which, mode) { syscallB.subscribe(importedP1VatB); await kernel.run(); t.deepEqual(logB, []); - t.equal(inCList(kernel, vatB, p1kernel, importedP1VatB), true); + t.is(inCList(kernel, vatB, p1kernel, importedP1VatB), true); } else if (which === 2) { // 2: Bob sends a message to Alice, Alice resolves the result promise // B: alice~.one() @@ -325,7 +325,7 @@ async function doTest123(t, which, mode) { } // before resolution, A's c-list should have the promise - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), true); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), true); const targetsA = { target2: rootBvatA, @@ -345,15 +345,14 @@ async function doTest123(t, which, mode) { if (expectRetirement) { // after resolution, A's c-list should *not* have the promise - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), false); - t.equal(clistKernelToVat(kernel, vatA, p1kernel), undefined); - t.equal(clistVatToKernel(kernel, vatA, p1VatA), undefined); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), false); + t.is(clistKernelToVat(kernel, vatA, p1kernel), undefined); + t.is(clistVatToKernel(kernel, vatA, p1VatA), undefined); } else { - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), true); - t.equal(clistKernelToVat(kernel, vatA, p1kernel), p1VatA); - t.equal(clistVatToKernel(kernel, vatA, p1VatA), p1kernel); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), true); + t.is(clistKernelToVat(kernel, vatA, p1kernel), p1VatA); + t.is(clistVatToKernel(kernel, vatA, p1VatA), p1kernel); } - t.end(); } // uncomment this when debugging specific problems // test.only(`XX`, async t => { @@ -422,7 +421,7 @@ async function doTest4567(t, which, mode) { dataPromiseA = 'p-61'; syscallB.send(rootAvatB, 'one', capargs([slot0arg], [exportedP1VatB])); p1kernel = clistVatToKernel(kernel, vatB, exportedP1VatB); - t.equal(p1kernel, expectedP1kernel); + t.is(p1kernel, expectedP1kernel); await kernel.run(); t.deepEqual(logA.shift(), { @@ -518,7 +517,7 @@ async function doTest4567(t, which, mode) { } // before resolution, A's c-list should have the promise - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), true); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), true); // Now bob resolves it. We want to examine the kernel's c-lists at the // moment the notification is delivered to Alice. We only expect one @@ -530,7 +529,7 @@ async function doTest4567(t, which, mode) { }; onDispatchCallback = function odc1(d) { t.deepEqual(d, resolutionOf(p1VatA, mode, targetsA)); - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), !expectRetirement); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), !expectRetirement); }; const targetsB = { target2: rootAvatB, @@ -546,15 +545,14 @@ async function doTest4567(t, which, mode) { if (expectRetirement) { // after resolution, A's c-list should *not* have the promise - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), false); - t.equal(clistKernelToVat(kernel, vatA, p1kernel), undefined); - t.equal(clistVatToKernel(kernel, vatA, p1VatA), undefined); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), false); + t.is(clistKernelToVat(kernel, vatA, p1kernel), undefined); + t.is(clistVatToKernel(kernel, vatA, p1VatA), undefined); } else { - t.equal(inCList(kernel, vatA, p1kernel, p1VatA), true); - t.equal(clistKernelToVat(kernel, vatA, p1kernel), p1VatA); - t.equal(clistVatToKernel(kernel, vatA, p1VatA), p1kernel); + t.is(inCList(kernel, vatA, p1kernel, p1VatA), true); + t.is(clistKernelToVat(kernel, vatA, p1kernel), p1VatA); + t.is(clistVatToKernel(kernel, vatA, p1VatA), p1kernel); } - t.end(); } for (const caseNum of [4, 5, 6, 7]) { diff --git a/packages/SwingSet/test/test-vpid-liveslots.js b/packages/SwingSet/test/test-vpid-liveslots.js index 2b51f260f93..275f26ff8da 100644 --- a/packages/SwingSet/test/test-vpid-liveslots.js +++ b/packages/SwingSet/test/test-vpid-liveslots.js @@ -2,7 +2,7 @@ /* global setImmediate harden */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; @@ -261,8 +261,6 @@ async function doVatResolveCase1(t, mode) { t.deepEqual(log.shift(), resolutionOf(expectedP3, mode, targets)); } t.deepEqual(log, []); - - t.end(); } for (const mode of modes) { @@ -539,19 +537,17 @@ async function doVatResolveCase23(t, which, mode, stalls) { // assert that the vat saw the local promise being resolved too if (mode === 'presence') { - t.equal(resolutionOfP1.toString(), `[Presence ${target2}]`); + t.is(resolutionOfP1.toString(), `[Presence ${target2}]`); } else if (mode === 'data') { - t.equal(resolutionOfP1, 4); + t.is(resolutionOfP1, 4); } else if (mode === 'promise-data') { - t.equal(Array.isArray(resolutionOfP1), true); - t.equal(resolutionOfP1.length, 1); + t.is(Array.isArray(resolutionOfP1), true); + t.is(resolutionOfP1.length, 1); t.is(resolutionOfP1[0], Promise.resolve(resolutionOfP1[0])); t.is(resolutionOfP1[0], stashP1); } else if (mode === 'reject') { - t.equal(resolutionOfP1, 'rejected'); + t.is(resolutionOfP1, 'rejected'); } - - t.end(); } // uncomment this when debugging specific problems @@ -704,8 +700,6 @@ async function doVatResolveCase4(t, mode) { // if p1 rejects or resolves to data, the kernel never hears about four() t.deepEqual(log, []); - - t.end(); } for (const mode of modes) { diff --git a/packages/SwingSet/test/timer-device/test-device.js b/packages/SwingSet/test/timer-device/test-device.js index 7f051b305ab..ee37834138f 100644 --- a/packages/SwingSet/test/timer-device/test-device.js +++ b/packages/SwingSet/test/timer-device/test-device.js @@ -1,5 +1,5 @@ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { buildVatController } from '../../src/index'; import { buildTimer } from '../../src/devices/timer'; @@ -22,7 +22,6 @@ test('wake', async t => { timer.poll(5); await c.step(); t.deepEqual(c.dump().log, ['starting wake test', 'handler.wake()']); - t.end(); }); test('repeater', async t => { @@ -45,7 +44,6 @@ test('repeater', async t => { 'starting repeater test', 'handler.wake(3) called 1 times.', ]); - t.end(); }); test('repeater2', async t => { @@ -71,7 +69,6 @@ test('repeater2', async t => { 'handler.wake(3) called 1 times.', 'handler.wake(7) called 2 times.', ]); - t.end(); }); test('repeaterZero', async t => { @@ -112,5 +109,4 @@ test('repeaterZero', async t => { 'handler.wake(6) called 2 times.', 'handler.wake(9) called 3 times.', ]); - t.end(); }); diff --git a/packages/SwingSet/test/vat-admin/terminate/test-terminate.js b/packages/SwingSet/test/vat-admin/terminate/test-terminate.js index da58856b13a..d35a84d1e2a 100644 --- a/packages/SwingSet/test/vat-admin/terminate/test-terminate.js +++ b/packages/SwingSet/test/vat-admin/terminate/test-terminate.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-ses'; import path from 'path'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { initSwingStore, getAllState, @@ -25,9 +25,9 @@ test('terminate', async t => { const configPath = path.resolve(__dirname, 'swingset-terminate.json'); const config = loadSwingsetConfigFile(configPath); const controller = await buildVatController(config); - t.equal(controller.bootstrapResult.status(), 'pending'); + t.is(controller.bootstrapResult.status(), 'pending'); await controller.run(); - t.equal(controller.bootstrapResult.status(), 'fulfilled'); + t.is(controller.bootstrapResult.status(), 'fulfilled'); t.deepEqual( controller.bootstrapResult.resolution(), capargs('bootstrap done'), @@ -47,7 +47,6 @@ test('terminate', async t => { 'afterForeverP.catch vat terminated', 'done', ]); - t.end(); }); test('dispatches to the dead do not harm kernel', async t => { @@ -83,15 +82,13 @@ test('dispatches to the dead do not harm kernel', async t => { 'panic', ); await c2.run(); - t.equal(r2.status(), 'fulfilled'); + t.is(r2.status(), 'fulfilled'); t.deepEqual(c2.dump().log, [ 'b: p1b = I so resolve', 'b: p2b fails vat terminated', 'm: live 2 failed: unknown vat', ]); } - - t.end(); }); test('replay does not resurrect dead vat', async t => { @@ -120,6 +117,4 @@ test('replay does not resurrect dead vat', async t => { // ...which shouldn't run the second time through t.deepEqual(c2.dump().log, []); } - - t.end(); }); diff --git a/packages/SwingSet/test/vat-admin/test-innerVat.js b/packages/SwingSet/test/vat-admin/test-innerVat.js index d8aed23fe6d..d5239ba2f54 100644 --- a/packages/SwingSet/test/vat-admin/test-innerVat.js +++ b/packages/SwingSet/test/vat-admin/test-innerVat.js @@ -1,6 +1,6 @@ import '@agoric/install-metering-and-ses'; import path from 'path'; -import { test } from 'tape'; +import test from 'ava'; import { initSwingStore } from '@agoric/swing-store-simple'; import bundleSource from '@agoric/bundle-source'; import { buildVatController, loadBasedir } from '../../src'; @@ -29,7 +29,6 @@ test('VatAdmin inner vat creation', async t => { await c.step(); } t.deepEqual(c.dump().log, ['starting newVat test', '13']); - t.end(); }); test('VatAdmin counter test', async t => { @@ -37,7 +36,6 @@ test('VatAdmin counter test', async t => { await c.run(); await c.run(); t.deepEqual(c.dump().log, ['starting counter test', '4', '9', '2']); - t.end(); }); test('VatAdmin broken vat creation', async t => { @@ -47,7 +45,6 @@ test('VatAdmin broken vat creation', async t => { 'starting brokenVat test', 'yay, rejected: Error: Vat Creation Error: ReferenceError: missing is not defined', ]); - t.end(); }); test('error creating vat from non-bundle', async t => { @@ -58,7 +55,6 @@ test('error creating vat from non-bundle', async t => { 'yay, rejected: Error: Vat Creation Error: Error: createVatDynamically() requires bundle, not a plain string', ]); await c.run(); - t.end(); }); test('VatAdmin get vat stats', async t => { @@ -71,5 +67,4 @@ test('VatAdmin get vat stats', async t => { '{"objectCount":0,"promiseCount":2,"deviceCount":0,"transcriptCount":2}', ]); await c.run(); - t.end(); }); diff --git a/packages/SwingSet/test/vat-admin/test-replay.js b/packages/SwingSet/test/vat-admin/test-replay.js index 13d3d897613..30990a8aad8 100644 --- a/packages/SwingSet/test/vat-admin/test-replay.js +++ b/packages/SwingSet/test/vat-admin/test-replay.js @@ -1,7 +1,7 @@ /* global harden */ import '@agoric/install-metering-and-ses'; import path from 'path'; -import { test } from 'tape'; +import test from 'ava'; import bundleSource from '@agoric/bundle-source'; import { initSwingStore, @@ -73,7 +73,6 @@ test('replay bundleSource-based dynamic vat', async t => { await c2.run(); t.deepEqual(r2.resolution(), capargs('ok')); } - t.end(); }); test('replay bundleName-based dynamic vat', async t => { @@ -120,5 +119,4 @@ test('replay bundleName-based dynamic vat', async t => { await c2.run(); t.deepEqual(r2.resolution(), capargs('ok')); } - t.end(); }); diff --git a/packages/SwingSet/test/workers/test-worker.js b/packages/SwingSet/test/workers/test-worker.js index ad33af5b82f..c4cd0d889bc 100644 --- a/packages/SwingSet/test/workers/test-worker.js +++ b/packages/SwingSet/test/workers/test-worker.js @@ -1,29 +1,27 @@ import '@agoric/install-ses'; -import tap from 'tap'; +import test from 'ava'; import { loadBasedir, buildVatController } from '../../src/index'; -tap.test('nodeWorker vat manager', async t => { +test('nodeWorker vat manager', async t => { const config = await loadBasedir(__dirname); config.vats.target.creationOptions = { managerType: 'nodeWorker' }; const c = await buildVatController(config, []); await c.run(); - t.equal(c.bootstrapResult.status(), 'fulfilled'); + t.is(c.bootstrapResult.status(), 'fulfilled'); await c.shutdown(); - t.end(); }); /* // disabling for now due to possible buffering issue on MacOS -tap.test('node-subprocess vat manager', async t => { +test('node-subprocess vat manager', async t => { const config = await loadBasedir(__dirname); config.vats.target.creationOptions = { managerType: 'node-subprocess' }; const c = await buildVatController(config, []); await c.run(); - t.equal(c.bootstrapResult.status(), 'fulfilled'); + t.is(c.bootstrapResult.status(), 'fulfilled'); await c.shutdown(); - t.end(); }); */ diff --git a/packages/acorn-eventual-send/package.json b/packages/acorn-eventual-send/package.json index be3eeebbaba..7b1ff43704c 100644 --- a/packages/acorn-eventual-send/package.json +++ b/packages/acorn-eventual-send/package.json @@ -5,17 +5,15 @@ "main": "index.js", "scripts": { "build": "exit 0", - "test": "tape -r esm 'test/**/*.js'", + "test": "ava", "lint-fix": "eslint --fix '**/*.js'", "lint-check": "eslint '**/*.js'" }, "devDependencies": { "acorn": "^7.1.0", + "ava": "^3.11.1", "esm": "^3.2.25", - "rollup": "^1.16.7", - "tap-spec": "^5.0.0", - "tape": "^4.9.2", - "tape-promise": "^4.0.0" + "rollup": "^1.16.7" }, "keywords": [], "files": [ @@ -33,5 +31,13 @@ "homepage": "https://github.com/acorn-eventual-send#readme", "publishConfig": { "access": "public" + }, + "ava": { + "files": [ + "test/**/test-*.js" + ], + "require": [ + "esm" + ] } } diff --git a/packages/acorn-eventual-send/test/test-parser.js b/packages/acorn-eventual-send/test/test-parser.js new file mode 100644 index 00000000000..c067d0b036a --- /dev/null +++ b/packages/acorn-eventual-send/test/test-parser.js @@ -0,0 +1,23 @@ +import test from 'ava'; +import * as acorn from 'acorn'; +import eventualSend from '..'; + +test('parser', async t => { + const MyParser = acorn.Parser.extend(eventualSend(acorn)); + const parser = src => MyParser.parse(src); + + // FIXME: Compare parse trees. + t.truthy(parser('x ~. p(y, z, q)'), 'post'); + t.truthy(parser('x ~. [i](y, z)'), 'computed post'); + t.truthy(parser('x ~. (y, z)'), 'apply'); + t.truthy(parser('x ~. ()'), 'apply nothing'); + t.truthy(parser('x ~. p'), 'get'); + t.truthy(parser('x ~. [i]'), 'computed get'); + t.truthy(parser('x ~. p = v'), 'put'); + t.truthy(parser('x ~. [i] = v'), 'computed put'); + t.truthy(parser('delete x ~. p'), 'delete'); + t.truthy(parser('delete x ~.[p]'), 'computed delete'); + t.truthy(parser('x~.\n p'), 'no asi'); + t.truthy(parser('x\n /* foo */ ~.p'), 'no asi2'); + t.truthy(parser('x~.p~.()'), 'chained get/post'); +}); diff --git a/packages/acorn-eventual-send/test/test-rollup.js b/packages/acorn-eventual-send/test/test-rollup.js index 54d36d6e70f..27d27943556 100644 --- a/packages/acorn-eventual-send/test/test-rollup.js +++ b/packages/acorn-eventual-send/test/test-rollup.js @@ -1,20 +1,14 @@ -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { rollup } from 'rollup/dist/rollup.es'; import * as acorn from 'acorn'; import eventualSend from '..'; test('SwingSet bug', async t => { - try { - const bundle = await rollup({ - input: require.resolve('../encouragementBotCommsWavyDot/bootstrap.js'), - treeshake: false, - external: [], - acornInjectPlugins: [eventualSend(acorn)], - }); - t.ok(bundle); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + const bundle = await rollup({ + input: require.resolve('../encouragementBotCommsWavyDot/bootstrap.js'), + treeshake: false, + external: [], + acornInjectPlugins: [eventualSend(acorn)], + }); + t.truthy(bundle); }); diff --git a/packages/acorn-eventual-send/test/test.js b/packages/acorn-eventual-send/test/test.js deleted file mode 100644 index bba5661a4fd..00000000000 --- a/packages/acorn-eventual-send/test/test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { test } from 'tape-promise/tape'; -import * as acorn from 'acorn'; -import eventualSend from '..'; - -test('parser', async t => { - try { - const MyParser = acorn.Parser.extend(eventualSend(acorn)); - const parser = src => MyParser.parse(src); - - // FIXME: Compare parse trees. - t.ok(parser('x ~. p(y, z, q)'), 'post'); - t.ok(parser('x ~. [i](y, z)'), 'computed post'); - t.ok(parser('x ~. (y, z)'), 'apply'); - t.ok(parser('x ~. ()'), 'apply nothing'); - t.ok(parser('x ~. p'), 'get'); - t.ok(parser('x ~. [i]'), 'computed get'); - t.ok(parser('x ~. p = v'), 'put'); - t.ok(parser('x ~. [i] = v'), 'computed put'); - t.ok(parser('delete x ~. p'), 'delete'); - t.ok(parser('delete x ~.[p]'), 'computed delete'); - t.ok(parser('x~.\n p'), 'no asi'); - t.ok(parser('x\n /* foo */ ~.p'), 'no asi2'); - t.ok(parser('x~.p~.()'), 'chained get/post'); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/bundle-source/package.json b/packages/bundle-source/package.json index 5209c39b74d..e6cec562653 100644 --- a/packages/bundle-source/package.json +++ b/packages/bundle-source/package.json @@ -5,7 +5,7 @@ "main": "src/index.js", "scripts": { "build": "exit 0", - "test": "tap --no-coverage --jobs=1 'test/**/*.js'", + "test": "ava", "lint-fix": "eslint --fix '**/*.js'", "lint-check": "eslint '**/*.js'", "lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.js'", @@ -13,9 +13,7 @@ }, "devDependencies": { "@agoric/install-ses": "^0.2.0", - "tap": "^14.10.5", - "tape": "^4.11.0", - "tape-promise": "^4.0.0" + "ava": "^3.11.1" }, "dependencies": { "@agoric/acorn-eventual-send": "^2.0.6", @@ -46,5 +44,9 @@ "homepage": "https://github.com/Agoric/agoric-sdk#readme", "publishConfig": { "access": "public" + }, + "ava": { + "files": ["test/**/test-*.js"], + "require": ["esm"] } } diff --git a/packages/bundle-source/test/circular.js b/packages/bundle-source/test/circular.js deleted file mode 100644 index 79d24f227fe..00000000000 --- a/packages/bundle-source/test/circular.js +++ /dev/null @@ -1,34 +0,0 @@ -/* global Compartment */ - -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import bundleSource from '..'; - -function evaluate(src, endowments) { - const c = new Compartment(endowments, {}, {}); - return c.evaluate(src); -} - -test('circular export', async t => { - try { - const { source: src1, sourceMap: map1 } = await bundleSource( - `${__dirname}/../demo/circular/a.js`, - 'nestedEvaluate', - ); - - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate }); - }; - // console.log(src1); - const srcMap1 = `(${src1})\n${map1}`; - const ex1 = nestedEvaluate(srcMap1)(); - - // console.log(err.stack); - t.equals(ex1.default, 'Foo', `circular export is Foo`); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/bundle-source/test/sanity.js b/packages/bundle-source/test/sanity.js deleted file mode 100644 index f5e7c9ceba8..00000000000 --- a/packages/bundle-source/test/sanity.js +++ /dev/null @@ -1,153 +0,0 @@ -/* global Compartment */ - -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import bundleSource from '..'; - -function evaluate(src, endowments) { - const c = new Compartment(endowments, {}, {}); - return c.evaluate(src); -} - -test('nestedEvaluate', async t => { - try { - const { - moduleFormat: mf1, - source: src1, - sourceMap: map1, - } = await bundleSource(`${__dirname}/../demo/dir1`, 'nestedEvaluate'); - - const srcMap1 = `(${src1})\n${map1}`; - - // console.log(srcMap1); - - t.equal(mf1, 'nestedEvaluate', 'module format is nestedEvaluate'); - - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate }); - }; - const ex1 = nestedEvaluate(srcMap1)(); - - const bundle = ex1.default(); - const err = bundle.makeError('foo'); - // console.log(err.stack); - t.assert( - err.stack.indexOf('(/bundled-source/encourage.js:3:') >= 0, - 'bundled source is in stack trace with correct line number', - ); - - const err2 = bundle.makeError2('bar'); - t.assert( - err2.stack.indexOf('(/bundled-source/index.js:10:') >= 0, - 'bundled source is in second stack trace with correct line number', - ); - - const { - moduleFormat: mf2, - source: src2, - sourceMap: map2, - } = await bundleSource( - `${__dirname}/../demo/dir1/encourage.js`, - 'nestedEvaluate', - ); - t.equal(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate'); - - const srcMap2 = `(${src2})\n${map2}`; - - const ex2 = nestedEvaluate(srcMap2)(); - t.equal(ex2.message, `You're great!`, 'exported message matches'); - t.equal( - ex2.encourage('Nick'), - `Hey Nick! You're great!`, - 'exported encourage matches', - ); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); - -test('getExport', async t => { - try { - const { - moduleFormat: mf1, - source: src1, - sourceMap: map1, - } = await bundleSource(`${__dirname}/../demo/dir1`, 'getExport'); - - const srcMap1 = `(${src1})\n${map1}`; - - // console.log(srcMap1); - - t.equal(mf1, 'getExport', 'module format is getExport'); - - // eslint-disable-next-line no-eval - const ex1 = eval(`${srcMap1}`)(); - - const bundle = ex1.default(); - const err = bundle.makeError('foo'); - t.assert( - err.stack.indexOf('(/bundled-source/encourage.js:') < 0, - 'bundled source is not in stack trace', - ); - - const { - moduleFormat: mf2, - source: src2, - sourceMap: map2, - } = await bundleSource(`${__dirname}/../demo/dir1/encourage.js`); - t.equal(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate'); - - const srcMap2 = `(${src2})\n${map2}`; - - const nestedEvaluate = src => { - // console.log('========== evaluating', src, '\n========='); - return evaluate(src, { nestedEvaluate }); - }; - // eslint-disable-next-line no-eval - const ex2 = nestedEvaluate(srcMap2)(); - t.equal(ex2.message, `You're great!`, 'exported message matches'); - t.equal( - ex2.encourage('Nick'), - `Hey Nick! You're great!`, - 'exported encourage matches', - ); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); - -test('babel-parser types', async t => { - // Once upon a time, bundleSource mangled: - // function createBinop(name, binop) { - // return new TokenType(name, { - // beforeExpr, - // binop - // }); - // } - // into: - // function createBinop(name, binop) { return new TokenType(name, { beforeExpr,; binop });}; - // - // Make sure it's ok now. The function in question came - // from @agoric/babel-parser/lib/tokenizer/types.js - - try { - const { source: src1 } = await bundleSource( - `${__dirname}/../demo/babel-parser-mangling.js`, - 'getExport', - ); - - t.assert(!src1.match(/beforeExpr,;/), 'source is not mangled that one way'); - // the mangled form wasn't syntactically valid, do a quick check - // eslint-disable-next-line no-eval - (1, eval)(`(${src1})`); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/bundle-source/test/test-circular.js b/packages/bundle-source/test/test-circular.js new file mode 100644 index 00000000000..f64c2f74c98 --- /dev/null +++ b/packages/bundle-source/test/test-circular.js @@ -0,0 +1,28 @@ +/* global Compartment */ + +import '@agoric/install-ses'; +import test from 'ava'; +import bundleSource from '..'; + +function evaluate(src, endowments) { + const c = new Compartment(endowments, {}, {}); + return c.evaluate(src); +} + +test('circular export', async t => { + const { source: src1, sourceMap: map1 } = await bundleSource( + `${__dirname}/../demo/circular/a.js`, + 'nestedEvaluate', + ); + + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate }); + }; + // console.log(src1); + const srcMap1 = `(${src1})\n${map1}`; + const ex1 = nestedEvaluate(srcMap1)(); + + // console.log(err.stack); + t.is(ex1.default, 'Foo', `circular export is Foo`); +}); diff --git a/packages/bundle-source/test/test-comment.js b/packages/bundle-source/test/test-comment.js index 1272a528db2..43b1be57b4c 100644 --- a/packages/bundle-source/test/test-comment.js +++ b/packages/bundle-source/test/test-comment.js @@ -1,6 +1,6 @@ /* global Compartment */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import bundleSource from '..'; function evaluate(src, endowments) { @@ -9,77 +9,55 @@ function evaluate(src, endowments) { } test('trailing comment', async t => { - try { - const { source: src1 } = await bundleSource( - `${__dirname}/../demo/comments/trailing-comment.js`, - 'nestedEvaluate', - ); - - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate }); - }; - // console.log(src1); - const srcMap1 = `(${src1})`; - const ex1 = nestedEvaluate(srcMap1)(); - - // console.log(err.stack); - t.equals( - typeof ex1.buildRootObject, - 'function', - `buildRootObject is exported`, - ); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + const { source: src1 } = await bundleSource( + `${__dirname}/../demo/comments/trailing-comment.js`, + 'nestedEvaluate', + ); + + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate }); + }; + // console.log(src1); + const srcMap1 = `(${src1})`; + const ex1 = nestedEvaluate(srcMap1)(); + + // console.log(err.stack); + t.is(typeof ex1.buildRootObject, 'function', `buildRootObject is exported`); }); test('comment block opener', async t => { - try { - t.plan(1); - const { source: src1 } = await bundleSource( - `${__dirname}/../demo/comments/block-opener.js`, - 'nestedEvaluate', - ); - - const success = () => t.pass('body runs correctly'); - - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate, success }); - }; - // console.log(src1); - const srcMap1 = `(${src1})`; - nestedEvaluate(srcMap1)(); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + t.plan(1); + const { source: src1 } = await bundleSource( + `${__dirname}/../demo/comments/block-opener.js`, + 'nestedEvaluate', + ); + + const success = () => t.pass('body runs correctly'); + + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate, success }); + }; + // console.log(src1); + const srcMap1 = `(${src1})`; + nestedEvaluate(srcMap1)(); }); test('comment block closer', async t => { - try { - t.plan(1); - const { source: src1 } = await bundleSource( - `${__dirname}/../demo/comments/block-closer.js`, - 'nestedEvaluate', - ); - - const success = () => t.pass('body runs correctly'); - - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate, success }); - }; - // console.log(src1); - const srcMap1 = `(${src1})`; - nestedEvaluate(srcMap1)(); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + t.plan(1); + const { source: src1 } = await bundleSource( + `${__dirname}/../demo/comments/block-closer.js`, + 'nestedEvaluate', + ); + + const success = () => t.pass('body runs correctly'); + + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate, success }); + }; + // console.log(src1); + const srcMap1 = `(${src1})`; + nestedEvaluate(srcMap1)(); }); diff --git a/packages/bundle-source/test/test-external-fs.js b/packages/bundle-source/test/test-external-fs.js index e6d25d416c7..8936886b7f7 100644 --- a/packages/bundle-source/test/test-external-fs.js +++ b/packages/bundle-source/test/test-external-fs.js @@ -1,6 +1,6 @@ /* global Compartment */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import bundleSource from '..'; function evaluate(src, endowments) { @@ -9,25 +9,19 @@ function evaluate(src, endowments) { } test(`external require('fs')`, async t => { - try { - t.plan(1); - const { source: src1 } = await bundleSource( - `${__dirname}/../demo/external-fs.js`, - 'nestedEvaluate', - ); + t.plan(1); + const { source: src1 } = await bundleSource( + `${__dirname}/../demo/external-fs.js`, + 'nestedEvaluate', + ); - const myRequire = mod => t.equals(mod, 'fs', 'required fs module'); + const myRequire = mod => t.is(mod, 'fs', 'required fs module'); - const nestedEvaluate = src => { - // console.log('========== evaluating', src); - return evaluate(src, { nestedEvaluate, require: myRequire }); - }; - // console.log(src1); - const srcMap1 = `(${src1})`; - nestedEvaluate(srcMap1)(); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate, require: myRequire }); + }; + // console.log(src1); + const srcMap1 = `(${src1})`; + nestedEvaluate(srcMap1)(); }); diff --git a/packages/bundle-source/test/test-sanity.js b/packages/bundle-source/test/test-sanity.js new file mode 100644 index 00000000000..5bba3b9a0a2 --- /dev/null +++ b/packages/bundle-source/test/test-sanity.js @@ -0,0 +1,135 @@ +/* global Compartment */ + +import '@agoric/install-ses'; +import test from 'ava'; +import bundleSource from '..'; + +function evaluate(src, endowments) { + const c = new Compartment(endowments, {}, {}); + return c.evaluate(src); +} + +test('nestedEvaluate', async t => { + const { + moduleFormat: mf1, + source: src1, + sourceMap: map1, + } = await bundleSource(`${__dirname}/../demo/dir1`, 'nestedEvaluate'); + + const srcMap1 = `(${src1})\n${map1}`; + + // console.log(srcMap1); + + t.is(mf1, 'nestedEvaluate', 'module format is nestedEvaluate'); + + const nestedEvaluate = src => { + // console.log('========== evaluating', src); + return evaluate(src, { nestedEvaluate }); + }; + const ex1 = nestedEvaluate(srcMap1)(); + + const bundle = ex1.default(); + const err = bundle.makeError('foo'); + // console.log(err.stack); + t.assert( + err.stack.indexOf('(/bundled-source/encourage.js:3:') >= 0, + 'bundled source is in stack trace with correct line number', + ); + + const err2 = bundle.makeError2('bar'); + t.assert( + err2.stack.indexOf('(/bundled-source/index.js:10:') >= 0, + 'bundled source is in second stack trace with correct line number', + ); + + const { + moduleFormat: mf2, + source: src2, + sourceMap: map2, + } = await bundleSource( + `${__dirname}/../demo/dir1/encourage.js`, + 'nestedEvaluate', + ); + t.is(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate'); + + const srcMap2 = `(${src2})\n${map2}`; + + const ex2 = nestedEvaluate(srcMap2)(); + t.is(ex2.message, `You're great!`, 'exported message matches'); + t.is( + ex2.encourage('Nick'), + `Hey Nick! You're great!`, + 'exported encourage matches', + ); +}); + +test('getExport', async t => { + const { + moduleFormat: mf1, + source: src1, + sourceMap: map1, + } = await bundleSource(`${__dirname}/../demo/dir1`, 'getExport'); + + const srcMap1 = `(${src1})\n${map1}`; + + // console.log(srcMap1); + + t.is(mf1, 'getExport', 'module format is getExport'); + + // eslint-disable-next-line no-eval + const ex1 = eval(`${srcMap1}`)(); + + const bundle = ex1.default(); + const err = bundle.makeError('foo'); + t.assert( + err.stack.indexOf('(/bundled-source/encourage.js:') < 0, + 'bundled source is not in stack trace', + ); + + const { + moduleFormat: mf2, + source: src2, + sourceMap: map2, + } = await bundleSource(`${__dirname}/../demo/dir1/encourage.js`); + t.is(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate'); + + const srcMap2 = `(${src2})\n${map2}`; + + const nestedEvaluate = src => { + // console.log('========== evaluating', src, '\n========='); + return evaluate(src, { nestedEvaluate }); + }; + // eslint-disable-next-line no-eval + const ex2 = nestedEvaluate(srcMap2)(); + t.is(ex2.message, `You're great!`, 'exported message matches'); + t.is( + ex2.encourage('Nick'), + `Hey Nick! You're great!`, + 'exported encourage matches', + ); +}); + +test('babel-parser types', async t => { + // Once upon a time, bundleSource mangled: + // function createBinop(name, binop) { + // return new TokenType(name, { + // beforeExpr, + // binop + // }); + // } + // into: + // function createBinop(name, binop) { return new TokenType(name, { beforeExpr,; binop });}; + // + // Make sure it's ok now. The function in question came + // from @agoric/babel-parser/lib/tokenizer/types.js + + const { source: src1 } = await bundleSource( + `${__dirname}/../demo/babel-parser-mangling.js`, + 'getExport', + ); + + t.truthy(!src1.match(/beforeExpr,;/), 'source is not mangled that one way'); + // the mangled form wasn't syntactically valid, do a quick check + // eslint-disable-next-line no-eval + (1, eval)(`(${src1})`); +}); diff --git a/packages/bundle-source/test/test-tildot-transform.js b/packages/bundle-source/test/test-tildot-transform.js new file mode 100644 index 00000000000..d50524ddeb2 --- /dev/null +++ b/packages/bundle-source/test/test-tildot-transform.js @@ -0,0 +1,22 @@ +import '@agoric/install-ses'; +import test from 'ava'; +import bundleSource from '..'; + +test('tildot transform', async t => { + const bundle = await bundleSource(`${__dirname}/../demo/tildot`, 'getExport'); + // console.log(bundle.source); + t.is(bundle.source.indexOf('~.'), -1); + // this is overspecified (whitespace, choice of quotation marks), sorry + t.not( + bundle.source.indexOf( + `HandledPromise.applyMethod(bob, "foo", [arg1, arg2])`, + ), + -1, + ); + t.not( + bundle.source.indexOf( + `HandledPromise.applyMethod(carol, "bar", [message])`, + ), + -1, + ); +}); diff --git a/packages/bundle-source/test/tildot-transform.js b/packages/bundle-source/test/tildot-transform.js deleted file mode 100644 index fa006135e18..00000000000 --- a/packages/bundle-source/test/tildot-transform.js +++ /dev/null @@ -1,31 +0,0 @@ -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import bundleSource from '..'; - -test('tildot transform', async t => { - try { - const bundle = await bundleSource( - `${__dirname}/../demo/tildot`, - 'getExport', - ); - // console.log(bundle.source); - t.equal(bundle.source.indexOf('~.'), -1); - // this is overspecified (whitespace, choice of quotation marks), sorry - t.notEqual( - bundle.source.indexOf( - `HandledPromise.applyMethod(bob, "foo", [arg1, arg2])`, - ), - -1, - ); - t.notEqual( - bundle.source.indexOf( - `HandledPromise.applyMethod(carol, "bar", [message])`, - ), - -1, - ); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/captp/package.json b/packages/captp/package.json index 2ec27eba760..c44eebb23f7 100644 --- a/packages/captp/package.json +++ b/packages/captp/package.json @@ -25,7 +25,7 @@ }, "scripts": { "build": "exit 0", - "test": "tape -r esm 'test/**/*.js'", + "test": "ava", "lint-fix": "eslint --fix '**/*.js'", "lint-check": "eslint 'lib/*.js'", "lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.js'", @@ -33,9 +33,7 @@ }, "devDependencies": { "@agoric/install-ses": "^0.2.0", - "tap-spec": "^5.0.0", - "tape": "^4.11.0", - "tape-promise": "^4.0.0" + "ava": "^3.11.1" }, "dependencies": { "@agoric/eventual-send": "^0.9.3", @@ -49,5 +47,10 @@ }, "publishConfig": { "access": "public" + }, + "ava": { + "files": ["test/**/test-*.js"], + "require": ["esm"], + "timeout": "2m" } } diff --git a/packages/captp/test/crosstalk.js b/packages/captp/test/crosstalk.js deleted file mode 100644 index 9a74ac89959..00000000000 --- a/packages/captp/test/crosstalk.js +++ /dev/null @@ -1,53 +0,0 @@ -/* global harden */ - -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import { makeCapTP, E } from '../lib/captp'; - -test('prevent crosstalk', async t => { - try { - const debug = false; - let rightDispatch; - const { dispatch: leftDispatch, getBootstrap: leftBootstrap } = makeCapTP( - 'left', - obj => { - if (debug) { - console.log('toRight', obj); - } - rightDispatch(obj); - }, - ); - ({ dispatch: rightDispatch } = makeCapTP( - 'right', - obj => { - if (debug) { - console.log('toLeft', obj); - } - leftDispatch(obj); - }, - harden({ - isSide(objP, side) { - return E(objP) - .side() - .then(s => t.equal(s, side, `obj.side() is ${side}`)); - }, - side() { - return 'right'; - }, - }), - )); - const rightRef = leftBootstrap(); - - await E(rightRef).isSide(rightRef, 'right'); - const leftRef = harden({ - side() { - return 'left'; - }, - }); - await E(rightRef).isSide(leftRef, 'left'); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/captp/test/disco.js b/packages/captp/test/disco.js deleted file mode 100644 index da4f775a198..00000000000 --- a/packages/captp/test/disco.js +++ /dev/null @@ -1,54 +0,0 @@ -/* global harden */ - -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import { E, makeCapTP } from '../lib/captp'; - -test('try disconnecting captp', async t => { - try { - const objs = []; - const rejected = []; - const { getBootstrap, abort } = makeCapTP( - 'us', - obj => objs.push(obj), - () => - harden({ - method() { - return 'hello'; - }, - }), - { - onReject(e) { - rejected.push(e); - }, - }, - ); - t.deepEqual(objs, [], 'expected no messages'); - const bs = getBootstrap(); - const ps = []; - ps.push(t.rejects(E.G(bs).prop, Error, 'rejected get after disconnect')); - ps.push( - t.rejects(E(bs).method(), Error, 'rejected method after disconnect'), - ); - t.deepEqual( - objs, - [{ type: 'CTP_BOOTSTRAP', questionID: 1 }], - 'expected bootstrap messages', - ); - ps.push(t.rejects(bs, Error, 'rejected after disconnect')); - const abortMsg = { type: 'CTP_ABORT', exception: Error('disconnect') }; - abort(abortMsg.exception); - await t.rejects(getBootstrap(), Error, 'rejected disconnected bootstrap'); - t.deepEqual( - objs, - [{ type: 'CTP_BOOTSTRAP', questionID: 1 }, abortMsg], - 'expected disconnect messages', - ); - await ps; - t.deepEqual(rejected, [abortMsg.exception], 'exactly one disconnect error'); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/captp/test/loopback.js b/packages/captp/test/loopback.js deleted file mode 100644 index ce9f786a347..00000000000 --- a/packages/captp/test/loopback.js +++ /dev/null @@ -1,66 +0,0 @@ -/* global harden */ - -import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; -import { E, makeCapTP } from '../lib/captp'; - -test('try loopback captp', async t => { - try { - const debug = false; - let rightDispatch; - const { dispatch: leftDispatch, getBootstrap: leftBootstrap } = makeCapTP( - 'left', - obj => { - if (debug) { - console.log('toRight', obj); - } - rightDispatch(obj); - }, - ); - const pr = {}; - pr.p = new Promise((resolve, reject) => { - pr.res = resolve; - pr.rej = reject; - }); - ({ dispatch: rightDispatch } = makeCapTP( - 'right', - obj => { - if (debug) { - console.log('toLeft', obj); - } - leftDispatch(obj); - }, - harden({ - promise: pr.p, - encourager: { - encourage(name) { - const bang = new Promise(resolve => { - setTimeout( - () => - resolve({ - trigger() { - return `${name} BANG!`; - }, - }), - 200, - ); - }); - return { comment: `good work, ${name}`, bang }; - }, - }, - }), - )); - const rightRef = leftBootstrap(); - const { comment, bang } = await E(E.G(rightRef).encourager).encourage( - 'buddy', - ); - t.equal(comment, 'good work, buddy', 'got encouragement'); - t.equal(await E(bang).trigger(), 'buddy BANG!', 'called on promise'); - pr.res('resolution'); - t.equal(await E.G(rightRef).promise, 'resolution', 'get resolution'); - } catch (e) { - t.isNot(e, e, 'unexpected exception'); - } finally { - t.end(); - } -}); diff --git a/packages/captp/test/test-crosstalk.js b/packages/captp/test/test-crosstalk.js new file mode 100644 index 00000000000..cfe2d14ef33 --- /dev/null +++ b/packages/captp/test/test-crosstalk.js @@ -0,0 +1,47 @@ +/* global harden */ + +import '@agoric/install-ses'; +import test from 'ava'; +import { makeCapTP, E } from '../lib/captp'; + +test('prevent crosstalk', async t => { + const debug = false; + let rightDispatch; + const { dispatch: leftDispatch, getBootstrap: leftBootstrap } = makeCapTP( + 'left', + obj => { + if (debug) { + console.log('toRight', obj); + } + rightDispatch(obj); + }, + ); + ({ dispatch: rightDispatch } = makeCapTP( + 'right', + obj => { + if (debug) { + console.log('toLeft', obj); + } + leftDispatch(obj); + }, + harden({ + isSide(objP, side) { + return E(objP) + .side() + .then(s => t.is(s, side, `obj.side() is ${side}`)); + }, + side() { + return 'right'; + }, + }), + )); + const rightRef = leftBootstrap(); + + await E(rightRef).isSide(rightRef, 'right'); + const leftRef = harden({ + side() { + return 'left'; + }, + }); + await E(rightRef).isSide(leftRef, 'left'); +}); diff --git a/packages/captp/test/test-disco.js b/packages/captp/test/test-disco.js new file mode 100644 index 00000000000..bf9903a85b8 --- /dev/null +++ b/packages/captp/test/test-disco.js @@ -0,0 +1,64 @@ +/* global harden */ + +import '@agoric/install-ses'; +import test from 'ava'; +import { E, makeCapTP } from '../lib/captp'; + +test('try disconnecting captp', async t => { + const objs = []; + const rejected = []; + const { getBootstrap, abort } = makeCapTP( + 'us', + obj => objs.push(obj), + () => + harden({ + method() { + return 'hello'; + }, + }), + { + onReject(e) { + rejected.push(e); + }, + }, + ); + t.deepEqual(objs, [], 'expected no messages'); + const bs = getBootstrap(); + const ps = []; + ps.push( + t.throwsAsync( + E.G(bs).prop, + { instanceOf: Error }, + 'rejected get after disconnect', + ), + ); + ps.push( + t.throwsAsync( + E(bs).method(), + { instanceOf: Error }, + 'rejected method after disconnect', + ), + ); + t.deepEqual( + objs, + [{ type: 'CTP_BOOTSTRAP', questionID: 1 }], + 'expected bootstrap messages', + ); + ps.push( + t.throwsAsync(bs, { instanceOf: Error }, 'rejected after disconnect'), + ); + const abortMsg = { type: 'CTP_ABORT', exception: Error('disconnect') }; + abort(abortMsg.exception); + await t.throwsAsync( + getBootstrap(), + { instanceOf: Error }, + 'rejected disconnected bootstrap', + ); + t.deepEqual( + objs, + [{ type: 'CTP_BOOTSTRAP', questionID: 1 }, abortMsg], + 'expected disconnect messages', + ); + await ps; + t.deepEqual(rejected, [abortMsg.exception], 'exactly one disconnect error'); +}); diff --git a/packages/captp/test/test-loopback.js b/packages/captp/test/test-loopback.js new file mode 100644 index 00000000000..1420591bb64 --- /dev/null +++ b/packages/captp/test/test-loopback.js @@ -0,0 +1,60 @@ +/* global harden */ + +import '@agoric/install-ses'; +import test from 'ava'; +import { E, makeCapTP } from '../lib/captp'; + +test('try loopback captp', async t => { + const debug = false; + let rightDispatch; + const { dispatch: leftDispatch, getBootstrap: leftBootstrap } = makeCapTP( + 'left', + obj => { + if (debug) { + console.log('toRight', obj); + } + rightDispatch(obj); + }, + ); + const pr = {}; + pr.p = new Promise((resolve, reject) => { + pr.res = resolve; + pr.rej = reject; + }); + ({ dispatch: rightDispatch } = makeCapTP( + 'right', + obj => { + if (debug) { + console.log('toLeft', obj); + } + leftDispatch(obj); + }, + harden({ + promise: pr.p, + encourager: { + encourage(name) { + const bang = new Promise(resolve => { + setTimeout( + () => + resolve({ + trigger() { + return `${name} BANG!`; + }, + }), + 200, + ); + }); + return { comment: `good work, ${name}`, bang }; + }, + }, + }), + )); + const rightRef = leftBootstrap(); + const { comment, bang } = await E(E.G(rightRef).encourager).encourage( + 'buddy', + ); + t.is(comment, 'good work, buddy', 'got encouragement'); + t.is(await E(bang).trigger(), 'buddy BANG!', 'called on promise'); + pr.res('resolution'); + t.is(await E.G(rightRef).promise, 'resolution', 'get resolution'); +}); diff --git a/packages/import-bundle/package.json b/packages/import-bundle/package.json index 1ef627a2bc3..251745aa529 100644 --- a/packages/import-bundle/package.json +++ b/packages/import-bundle/package.json @@ -8,7 +8,7 @@ "node": ">=10.15.1" }, "scripts": { - "test": "tap --no-coverage --jobs=1 'test/**/test*.js'", + "test": "ava", "build": "exit 0", "lint-fix": "eslint --fix '**/*.js'", "lint-check": "eslint '**/*.js'" @@ -16,8 +16,8 @@ "devDependencies": { "@agoric/bundle-source": "^1.1.6", "@agoric/install-ses": "^0.2.0", - "esm": "^3.2.5", - "tap": "^14.10.5" + "ava": "^3.11.1", + "esm": "^3.2.5" }, "peerDependencies": { "ses": "^0.10.1" @@ -79,5 +79,14 @@ }, "dependencies": { "ses": "^0.10.1" + }, + "ava": { + "files": [ + "test/**/test-*.js" + ], + "require": [ + "esm" + ], + "timeout": "2m" } } diff --git a/packages/import-bundle/test/test-compartment-wrapper.js b/packages/import-bundle/test/test-compartment-wrapper.js index f6eaf7cf1e5..46096a831c3 100644 --- a/packages/import-bundle/test/test-compartment-wrapper.js +++ b/packages/import-bundle/test/test-compartment-wrapper.js @@ -1,10 +1,8 @@ /* global Compartment */ import '@agoric/install-ses'; -import tap from 'tap'; +import test from 'ava'; import { wrapInescapableCompartment } from '../src/compartment-wrapper.js'; -const { test } = tap; - // We build a transform that allows oldSrc to increment the odometer, but not // read it. Note, of course, that SES provides a far easier way to accomplish // this (pass in a hardened `addMilage` endowment), but there are metering @@ -72,55 +70,55 @@ const attemptResetByTransform = `() => { }`; function check(t, c, odometer, n) { - t.equal(odometer.read(), 0, `${n}.start`); + t.is(odometer.read(), 0, `${n}.start`); c.evaluate(doAdd); - t.equal(odometer.read(), 1, `${n}.doAdd`); + t.is(odometer.read(), 1, `${n}.doAdd`); odometer.reset(); c.evaluate(doAddInChild)(doAdd); - t.equal(odometer.read(), 1, `${n}.doAddInChild`); + t.is(odometer.read(), 1, `${n}.doAddInChild`); odometer.reset(); odometer.add(5); t.throws( () => c.evaluate(attemptReset)(), - /forbidden access/, + { message: /forbidden access/ }, `${n}.attemptReset`, ); - t.equal(odometer.read(), 5, `${n} not reset`); + t.is(odometer.read(), 5, `${n} not reset`); t.throws( () => c.evaluate(attemptResetInChild)(attemptReset), - /forbidden access/, + { message: /forbidden access/ }, `${n}.attemptResetInChild`, ); - t.equal(odometer.read(), 5, `${n} not reset`); + t.is(odometer.read(), 5, `${n} not reset`); odometer.reset(); const fakeCalled = c.evaluate(attemptResetByShadow)(doAdd); - t.notOk(fakeCalled, `${n}.attemptResetByShadow`); - t.equal(odometer.read(), 1, `${n} called anyway`); + t.falsy(fakeCalled, `${n}.attemptResetByShadow`); + t.is(odometer.read(), 1, `${n} called anyway`); odometer.reset(); odometer.add(5); t.throws( () => c.evaluate(attemptResetByTransform)(), - /forbidden access/, + { message: /forbidden access/ }, `${n}.attemptResetByTransform`, ); - t.equal(odometer.read(), 5, `${n} not reset`); + t.is(odometer.read(), 5, `${n} not reset`); odometer.reset(); - t.equal( - c.evaluate('Compartment.name'), - 'Compartment', - `${n}.Compartment.name`, - ); + t.is(c.evaluate('Compartment.name'), 'Compartment', `${n}.Compartment.name`); - t.ok(c instanceof Compartment, `${n} instanceof`); + t.truthy(c instanceof Compartment, `${n} instanceof`); const Con = Object.getPrototypeOf(c.globalThis.Compartment).constructor; - t.throws(() => new Con(), /Not available/, `${n} .constructor is tamed`); + t.throws( + () => new Con(), + { message: /Not available/ }, + `${n} .constructor is tamed`, + ); } test('wrap', t => { @@ -145,6 +143,4 @@ test('wrap', t => { const c3 = c2.evaluate(createChild)(); check(t, c3, odometer, 'c3'); - - t.end(); }); diff --git a/packages/import-bundle/test/test-import-bundle.js b/packages/import-bundle/test/test-import-bundle.js index d76750b8210..7f242277fe6 100644 --- a/packages/import-bundle/test/test-import-bundle.js +++ b/packages/import-bundle/test/test-import-bundle.js @@ -2,7 +2,7 @@ import '@agoric/install-ses'; import bundleSource from '@agoric/bundle-source'; -import tap from 'tap'; +import test from 'ava'; import { importBundle } from '../src/index.js'; function transform1(src) { @@ -11,29 +11,25 @@ function transform1(src) { .replace('two foot wide', 'sixty feet wide'); } -async function testBundle1(b1, mode, ew) { +async function testBundle1(t, b1, mode, ew) { const ns1 = await importBundle(b1, { endowments: ew }); - tap.equal(ns1.f1(1), 2, `ns1.f1 ${mode} ok`); - tap.equal(ns1.f2(1), 3, `ns1.f2 ${mode} ok`); + t.is(ns1.f1(1), 2, `ns1.f1 ${mode} ok`); + t.is(ns1.f2(1), 3, `ns1.f2 ${mode} ok`); const endowments = { endow1: 3, ...ew }; const ns2 = await importBundle(b1, { endowments }); - tap.equal(ns2.f3(1), 4, `ns2.f1 ${mode} ok`); + t.is(ns2.f3(1), 4, `ns2.f1 ${mode} ok`); // untransformed - tap.equal( - ns2.f4('is unreplaced'), - 'replaceme is unreplaced', - `ns2.f4 ${mode} ok`, - ); - tap.equal( + t.is(ns2.f4('is unreplaced'), 'replaceme is unreplaced', `ns2.f4 ${mode} ok`); + t.is( ns2.f5('the bed'), 'Mr. Lambert says the bed is two foot wide', `ns2.f5 ${mode} ok`, ); const ns3 = await importBundle(b1, { endowments, transforms: [transform1] }); - tap.equal(ns3.f4('is ok'), 'substitution is ok', `ns3.f4 ${mode} ok`); - tap.equal( + t.is(ns3.f4('is ok'), 'substitution is ok', `ns3.f4 ${mode} ok`); + t.is( ns3.f5('the bed'), 'Mr. Lambert says the bed is sixty feet wide', `ns3.f5 ${mode} ok`, @@ -41,18 +37,18 @@ async function testBundle1(b1, mode, ew) { const endowments4 = { sneakyChannel: 3, ...ew }; const ns4 = await importBundle(b1, { endowments: endowments4 }); - tap.equal(ns4.f6ReadGlobal(), 3, `ns3.f6 ${mode} ok`); - tap.equal(ns4.f8ReadGlobalSubmodule(), 3, `ns3.f8 ${mode} ok`); - tap.throws( + t.is(ns4.f6ReadGlobal(), 3, `ns3.f6 ${mode} ok`); + t.is(ns4.f8ReadGlobalSubmodule(), 3, `ns3.f8 ${mode} ok`); + t.throws( () => ns4.f7WriteGlobal(5), - 'Cannot assign to read only property', + { message: /Cannot assign to read only property/ }, `ns4.f7 ${mode} ok`, ); - tap.equal(ns4.f6ReadGlobal(), 3, `ns4.f6 ${mode} ok`); - tap.equal(ns4.f8ReadGlobalSubmodule(), 3, `ns3.f8 ${mode} ok`); + t.is(ns4.f6ReadGlobal(), 3, `ns4.f6 ${mode} ok`); + t.is(ns4.f8ReadGlobalSubmodule(), 3, `ns3.f8 ${mode} ok`); } -tap.test('test import', async function testImport(t) { +test('test import', async function testImport(t) { // nestedEvaluate requires a 'require' endowment, but doesn't call it function req(what) { console.log(`require(${what})`); @@ -69,19 +65,17 @@ tap.test('test import', async function testImport(t) { require.resolve('./bundle1.js'), 'getExport', ); - await testBundle1(b1getExport, 'getExport', endowments); + await testBundle1(t, b1getExport, 'getExport', endowments); } const b1NestedEvaluate = await bundleSource( require.resolve('./bundle1.js'), 'nestedEvaluate', ); - await testBundle1(b1NestedEvaluate, 'nestedEvaluate', endowments); - - t.end(); + await testBundle1(t, b1NestedEvaluate, 'nestedEvaluate', endowments); }); -tap.test('test missing sourceMap', async function testImport(t) { +test('test missing sourceMap', async function testImport(t) { function req(what) { console.log(`require(${what})`); } @@ -94,11 +88,10 @@ tap.test('test missing sourceMap', async function testImport(t) { ); delete b1.sourceMap; const ns1 = await importBundle(b1, { endowments }); - tap.equal(ns1.f1(1), 2, `missing sourceMap ns.f1 ok`); - t.end(); + t.is(ns1.f1(1), 2, `missing sourceMap ns.f1 ok`); }); -tap.test('inescapable transforms', async function testInescapableTransforms(t) { +test('inescapable transforms', async function testInescapableTransforms(t) { const b1 = await bundleSource( require.resolve('./bundle1.js'), 'nestedEvaluate', @@ -113,29 +106,23 @@ tap.test('inescapable transforms', async function testInescapableTransforms(t) { endowments, inescapableTransforms: [transform1], }); - tap.equal(ns.f4('is ok'), 'substitution is ok', `iT ns.f4 ok`); - t.end(); + t.is(ns.f4('is ok'), 'substitution is ok', `iT ns.f4 ok`); }); -tap.test( - 'inescapable globalLexicals', - async function testInescapableGlobalLexicals(t) { - const b1 = await bundleSource( - require.resolve('./bundle1.js'), - 'nestedEvaluate', - ); - function req(what) { - console.log(`require(${what})`); - } - harden(Object.getPrototypeOf(console)); - const endowments = { require: req, console }; - - const ns = await importBundle(b1, { - endowments, - inescapableGlobalLexicals: { endow1: 3 }, - }); - tap.equal(ns.f3(1), 4, `iGL ns.f3 ok`); +test('inescapable globalLexicals', async function testInescapableGlobalLexicals(t) { + const b1 = await bundleSource( + require.resolve('./bundle1.js'), + 'nestedEvaluate', + ); + function req(what) { + console.log(`require(${what})`); + } + harden(Object.getPrototypeOf(console)); + const endowments = { require: req, console }; - t.end(); - }, -); + const ns = await importBundle(b1, { + endowments, + inescapableGlobalLexicals: { endow1: 3 }, + }); + t.is(ns.f3(1), 4, `iGL ns.f3 ok`); +}); diff --git a/packages/marshal/package.json b/packages/marshal/package.json index 0b5d78e1167..2f547733ef1 100644 --- a/packages/marshal/package.json +++ b/packages/marshal/package.json @@ -8,7 +8,7 @@ }, "scripts": { "build": "exit 0", - "test": "tape -r esm 'test/**/test*.js' | tap-spec", + "test": "ava", "pretty-fix": "prettier --write '**/*.js'", "pretty-check": "prettier --check '**/*.js'", "lint-fix": "yarn lint --fix", @@ -35,13 +35,20 @@ "@agoric/promise-kit": "^0.1.3" }, "devDependencies": { - "esm": "^3.2.25", "@agoric/install-ses": "^0.2.0", - "tap-spec": "^5.0.0", - "tape": "^4.10.2", - "tape-promise": "^4.0.0" + "ava": "^3.11.1", + "esm": "^3.2.25" }, "publishConfig": { "access": "public" + }, + "ava": { + "files": [ + "test/**/test-*.js" + ], + "require": [ + "esm" + ], + "timeout": "2m" } } diff --git a/packages/marshal/test/test-marshal.js b/packages/marshal/test/test-marshal.js index 3a41741572a..f37db44b5d7 100644 --- a/packages/marshal/test/test-marshal.js +++ b/packages/marshal/test/test-marshal.js @@ -1,7 +1,7 @@ /* global harden BigInt */ import '@agoric/install-ses'; -import { test } from 'tape-promise/tape'; +import test from 'ava'; import { Remotable, getInterfaceOf, @@ -14,7 +14,9 @@ import { test('serialize static data', t => { const m = makeMarshal(); const ser = val => m.serialize(val); - t.throws(() => ser([1, 2]), /Cannot pass non-frozen objects like/); + t.throws(() => ser([1, 2]), { + message: /Cannot pass non-frozen objects like/, + }); t.deepEqual(ser(harden([1, 2])), { body: '[1,2]', slots: [] }); t.deepEqual(ser(harden({ foo: 1 })), { body: '{"foo":1}', slots: [] }); t.deepEqual(ser(true), { body: 'true', slots: [] }); @@ -38,11 +40,11 @@ test('serialize static data', t => { slots: [], }); // registered symbols - t.throws(() => ser(Symbol.for('sym1')), /Cannot pass symbols/); + t.throws(() => ser(Symbol.for('sym1')), { message: /Cannot pass symbols/ }); // unregistered symbols - t.throws(() => ser(Symbol('sym2')), /Cannot pass symbols/); + t.throws(() => ser(Symbol('sym2')), { message: /Cannot pass symbols/ }); // well known symbols - t.throws(() => ser(Symbol.iterator), /Cannot pass symbols/); + t.throws(() => ser(Symbol.iterator), { message: /Cannot pass symbols/ }); let bn; try { bn = BigInt(4); @@ -81,22 +83,20 @@ test('serialize static data', t => { }); const cd = ser(harden([1, 2])); - t.equal(Object.isFrozen(cd), true); - t.equal(Object.isFrozen(cd.slots), true); - - t.end(); + t.is(Object.isFrozen(cd), true); + t.is(Object.isFrozen(cd.slots), true); }); test('unserialize static data', t => { const m = makeMarshal(); const uns = body => m.unserialize({ body, slots: [] }); - t.equal(uns('1'), 1); - t.equal(uns('"abc"'), 'abc'); - t.equal(uns('false'), false); + t.is(uns('1'), 1); + t.is(uns('"abc"'), 'abc'); + t.is(uns('false'), false); // JS primitives that aren't natively representable by JSON t.deepEqual(uns('{"@qclass":"undefined"}'), undefined); - t.ok(Object.is(uns('{"@qclass":"NaN"}'), NaN)); + t.truthy(Object.is(uns('{"@qclass":"NaN"}'), NaN)); t.deepEqual(uns('{"@qclass":"Infinity"}'), Infinity); t.deepEqual(uns('{"@qclass":"-Infinity"}'), -Infinity); @@ -118,17 +118,17 @@ test('unserialize static data', t => { const em1 = uns( '{"@qclass":"error","name":"ReferenceError","message":"msg"}', ); - t.ok(em1 instanceof ReferenceError); - t.equal(em1.message, 'msg'); - t.ok(Object.isFrozen(em1)); + t.truthy(em1 instanceof ReferenceError); + t.is(em1.message, 'msg'); + t.truthy(Object.isFrozen(em1)); const em2 = uns('{"@qclass":"error","name":"TypeError","message":"msg2"}'); - t.ok(em2 instanceof TypeError); - t.equal(em2.message, 'msg2'); + t.truthy(em2 instanceof TypeError); + t.is(em2.message, 'msg2'); const em3 = uns('{"@qclass":"error","name":"Unknown","message":"msg3"}'); - t.ok(em3 instanceof Error); - t.equal(em3.message, 'msg3'); + t.truthy(em3 instanceof Error); + t.is(em3.message, 'msg3'); t.deepEqual(uns('[1,2]'), [1, 2]); t.deepEqual(uns('{"a":1,"b":2}'), { a: 1, b: 2 }); @@ -136,14 +136,12 @@ test('unserialize static data', t => { // should be frozen const arr = uns('[1,2]'); - t.ok(Object.isFrozen(arr)); + t.truthy(Object.isFrozen(arr)); const a = uns('{"b":{"c":{"d": []}}}'); - t.ok(Object.isFrozen(a)); - t.ok(Object.isFrozen(a.b)); - t.ok(Object.isFrozen(a.b.c)); - t.ok(Object.isFrozen(a.b.c.d)); - - t.end(); + t.truthy(Object.isFrozen(a)); + t.truthy(Object.isFrozen(a.b)); + t.truthy(Object.isFrozen(a.b.c)); + t.truthy(Object.isFrozen(a.b.c.d)); }); test('serialize ibid cycle', t => { @@ -157,71 +155,67 @@ test('serialize ibid cycle', t => { body: '["a",{"@qclass":"ibid","index":0},"c"]', slots: [], }); - t.end(); }); test('forbid ibid cycle', t => { const m = makeMarshal(); const uns = body => m.unserialize({ body, slots: [] }); - t.throws( - () => uns('["a",{"@qclass":"ibid","index":0},"c"]'), - /Ibid cycle at 0/, - ); - t.end(); + t.throws(() => uns('["a",{"@qclass":"ibid","index":0},"c"]'), { + message: /Ibid cycle at 0/, + }); }); test('unserialize ibid cycle', t => { const m = makeMarshal(); const uns = body => m.unserialize({ body, slots: [] }, 'warnOfCycles'); const cycle = uns('["a",{"@qclass":"ibid","index":0},"c"]'); - t.ok(Object.is(cycle[1], cycle)); - t.end(); + t.truthy(Object.is(cycle[1], cycle)); }); test('null cannot be pass-by-presence', t => { - t.throws(() => mustPassByPresence(null), /null cannot be pass-by-remote/); - t.end(); + t.throws(() => mustPassByPresence(null), { + message: /null cannot be pass-by-remote/, + }); }); test('mal-formed @qclass', t => { const m = makeMarshal(); const uns = body => m.unserialize({ body, slots: [] }); - t.throws(() => uns('{"@qclass": 0}'), /invalid qclass/); - t.end(); + t.throws(() => uns('{"@qclass": 0}'), { message: /invalid qclass/ }); }); test('Remotable/getInterfaceOf', t => { t.throws( () => Remotable({ bar: 29 }), - /unimplemented/, + { message: /unimplemented/ }, 'object ifaces are not implemented', ); t.throws( () => Remotable('MyHandle', { foo: 123 }), - /cannot serialize/, + { message: /cannot serialize/ }, 'non-function props are not implemented', ); t.throws( () => Remotable('MyHandle', {}, a => a + 1), - /cannot serialize/, + { message: /cannot serialize/ }, 'function presences are not implemented', ); - t.equals(getInterfaceOf('foo'), undefined, 'string, no interface'); - t.equals(getInterfaceOf(null), undefined, 'null, no interface'); - t.equals( + t.is(getInterfaceOf('foo'), undefined, 'string, no interface'); + t.is(getInterfaceOf(null), undefined, 'null, no interface'); + t.is( getInterfaceOf(a => a + 1), undefined, 'function, no interface', ); - t.equals(getInterfaceOf(123), undefined, 'number, no interface'); + t.is(getInterfaceOf(123), undefined, 'number, no interface'); // Check that a handle can be created. const p = Remotable('MyHandle'); harden(p); // console.log(p); - t.equals(getInterfaceOf(p), 'MyHandle', `interface is MyHandle`); - t.equals(`${p}`, '[MyHandle]', 'stringify is [MyHandle]'); + t.is(getInterfaceOf(p), 'MyHandle', `interface is MyHandle`); + t.is(`${p}`, '[MyHandle]', 'stringify is [MyHandle]'); const p2 = Remotable('Thing', { name() { @@ -231,8 +225,7 @@ test('Remotable/getInterfaceOf', t => { return now - 64; }, }); - t.equals(getInterfaceOf(p2), 'Thing', `interface is Thing`); - t.equals(p2.name(), 'cretin', `name() method is presence`); - t.equals(p2.birthYear(2020), 1956, `birthYear() works`); - t.end(); + t.is(getInterfaceOf(p2), 'Thing', `interface is Thing`); + t.is(p2.name(), 'cretin', `name() method is presence`); + t.is(p2.birthYear(2020), 1956, `birthYear() works`); });