-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(swingset): createVatDynamically option to disable metering
refs #1307
- Loading branch information
Showing
5 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/SwingSet/test/metering/test-unmetered-dynamic-vat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* global harden */ | ||
|
||
import '@agoric/install-metering-and-ses'; | ||
import bundleSource from '@agoric/bundle-source'; | ||
import tap from 'tap'; | ||
import { buildVatController } from '../../src/index'; | ||
import makeNextLog from '../make-nextlog'; | ||
|
||
function capdata(body, slots = []) { | ||
return harden({ body, slots }); | ||
} | ||
|
||
function capargs(args, slots = []) { | ||
return capdata(JSON.stringify(args), slots); | ||
} | ||
|
||
// Dynamic vats can be created without metering | ||
|
||
tap.test('unmetered dynamic vat', async t => { | ||
const config = { | ||
vats: new Map(), | ||
bootstrapIndexJS: require.resolve('./vat-load-dynamic.js'), | ||
}; | ||
const c = await buildVatController(config, []); | ||
const nextLog = makeNextLog(c); | ||
|
||
// let the vatAdminService get wired up before we create any new vats | ||
await c.run(); | ||
|
||
// we'll give this bundle to the loader vat, which will use it to create a | ||
// new (unmetered) dynamic vat | ||
const dynamicVatBundle = await bundleSource( | ||
require.resolve('./metered-dynamic-vat.js'), | ||
); | ||
|
||
// 'createVat' will import the bundle | ||
c.queueToVatExport( | ||
'_bootstrap', | ||
'o+0', | ||
'createVat', | ||
capargs([dynamicVatBundle, { metered: false }]), | ||
); | ||
await c.run(); | ||
t.deepEqual(nextLog(), ['created'], 'first create'); | ||
|
||
// First, send a message to the dynamic vat that runs normally | ||
c.queueToVatExport('_bootstrap', 'o+0', 'run', capargs([])); | ||
await c.run(); | ||
|
||
t.deepEqual(nextLog(), ['did run'], 'first run ok'); | ||
|
||
// Tell the dynamic vat to call `Array(4e9)`. If metering was in place, | ||
// this would be rejected. Without metering, it's harmless (Arrays are | ||
// lazy). | ||
c.queueToVatExport('_bootstrap', 'o+0', 'explode', capargs(['allocate'])); | ||
await c.run(); | ||
t.deepEqual(nextLog(), ['failed to explode'], 'metering disabled'); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters