|
| 1 | +/* global __dirname */ |
| 2 | + |
| 3 | +// TODO Remove babel-standalone preinitialization |
| 4 | +// https://github.com/endojs/endo/issues/768 |
| 5 | +import '@agoric/babel-standalone'; |
| 6 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 7 | +import '@agoric/install-ses'; |
| 8 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 9 | +import test from 'ava'; |
| 10 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 11 | +import { buildVatController, buildKernelBundles } from '@agoric/swingset-vat'; |
| 12 | +import bundleSource from '@agoric/bundle-source'; |
| 13 | + |
| 14 | +const CONTRACT_FILES = ['offerArgsUsageContract']; |
| 15 | + |
| 16 | +test.before(async t => { |
| 17 | + const start = Date.now(); |
| 18 | + const kernelBundles = await buildKernelBundles(); |
| 19 | + const step2 = Date.now(); |
| 20 | + const contractBundles = {}; |
| 21 | + await Promise.all( |
| 22 | + CONTRACT_FILES.map(async settings => { |
| 23 | + let bundleName; |
| 24 | + let contractPath; |
| 25 | + if (typeof settings === 'string') { |
| 26 | + bundleName = settings; |
| 27 | + contractPath = settings; |
| 28 | + } else { |
| 29 | + ({ bundleName, contractPath } = settings); |
| 30 | + } |
| 31 | + const source = `${__dirname}/../../${contractPath}`; |
| 32 | + const bundle = await bundleSource(source); |
| 33 | + contractBundles[bundleName] = bundle; |
| 34 | + }), |
| 35 | + ); |
| 36 | + const step3 = Date.now(); |
| 37 | + |
| 38 | + const vats = {}; |
| 39 | + await Promise.all( |
| 40 | + ['alice', 'zoe'].map(async name => { |
| 41 | + const source = `${__dirname}/vat-${name}.js`; |
| 42 | + const bundle = await bundleSource(source); |
| 43 | + vats[name] = { bundle }; |
| 44 | + }), |
| 45 | + ); |
| 46 | + const bootstrapSource = `${__dirname}/bootstrap.js`; |
| 47 | + vats.bootstrap = { |
| 48 | + bundle: await bundleSource(bootstrapSource), |
| 49 | + parameters: { contractBundles }, // argv will be added to this |
| 50 | + }; |
| 51 | + const config = { bootstrap: 'bootstrap', vats }; |
| 52 | + config.defaultManagerType = 'xs-worker'; |
| 53 | + |
| 54 | + const step4 = Date.now(); |
| 55 | + const ktime = `${(step2 - start) / 1000}s kernel`; |
| 56 | + const ctime = `${(step3 - step2) / 1000}s contracts`; |
| 57 | + const vtime = `${(step4 - step3) / 1000}s vats`; |
| 58 | + const ttime = `${(step4 - start) / 1000}s total`; |
| 59 | + console.log(`bundling: ${ktime}, ${ctime}, ${vtime}, ${ttime}`); |
| 60 | + |
| 61 | + t.context.data = { kernelBundles, config }; |
| 62 | +}); |
| 63 | + |
| 64 | +async function main(t, argv) { |
| 65 | + const { kernelBundles, config } = t.context.data; |
| 66 | + const controller = await buildVatController(config, argv, { kernelBundles }); |
| 67 | + await controller.run(); |
| 68 | + return controller.dump(); |
| 69 | +} |
| 70 | + |
| 71 | +const expected = ['offerArgs.myArg was accessed in the contract']; |
| 72 | + |
| 73 | +test.serial('private args usage', async t => { |
| 74 | + const dump = await main(t); |
| 75 | + t.deepEqual(dump.log, expected); |
| 76 | +}); |
0 commit comments