-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add private arguments to contract
start
functions, via E(zoe)…
….startInstance (#3576) * feat: add ability to pass arguments privately to contract `start` function through `zoe.startInstance` * chore: add Swingset test * chore: assert copyRecord * chore: address PR comments * chore: address PR comments
- Loading branch information
1 parent
38dfe2d
commit f353e86
Showing
12 changed files
with
178 additions
and
5 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @ts-check | ||
|
||
import { E } from '@agoric/eventual-send'; | ||
import { Far } from '@agoric/marshal'; | ||
|
||
/** @type {ContractStartFn} */ | ||
const start = (_zcf, privateArgs) => { | ||
const creatorFacet = Far('creatorFacet', { | ||
usePrivateArgs: () => E(privateArgs.myArg).doTest(), | ||
}); | ||
return harden({ creatorFacet }); | ||
}; | ||
harden(start); | ||
export { start }; |
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,22 @@ | ||
import { E } from '@agoric/eventual-send'; | ||
import { Far } from '@agoric/marshal'; | ||
|
||
export function buildRootObject(vatPowers, vatParameters) { | ||
const { contractBundles: cb } = vatParameters; | ||
return Far('root', { | ||
async bootstrap(vats, devices) { | ||
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService( | ||
devices.vatAdmin, | ||
); | ||
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc); | ||
const installations = { | ||
privateArgsUsageContract: await E(zoe).install( | ||
cb.privateArgsUsageContract, | ||
), | ||
}; | ||
|
||
const aliceP = E(vats.alice).build(zoe, installations); | ||
await E(aliceP).privateArgsUsageTest(); | ||
}, | ||
}); | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/zoe/test/swingsetTests/privateArgs/test-privateArgs.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,76 @@ | ||
/* global __dirname */ | ||
|
||
// TODO Remove babel-standalone preinitialization | ||
// https://github.com/endojs/endo/issues/768 | ||
import '@agoric/babel-standalone'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@agoric/install-ses'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import test from 'ava'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { buildVatController, buildKernelBundles } from '@agoric/swingset-vat'; | ||
import bundleSource from '@agoric/bundle-source'; | ||
|
||
const CONTRACT_FILES = ['privateArgsUsageContract']; | ||
|
||
test.before(async t => { | ||
const start = Date.now(); | ||
const kernelBundles = await buildKernelBundles(); | ||
const step2 = Date.now(); | ||
const contractBundles = {}; | ||
await Promise.all( | ||
CONTRACT_FILES.map(async settings => { | ||
let bundleName; | ||
let contractPath; | ||
if (typeof settings === 'string') { | ||
bundleName = settings; | ||
contractPath = settings; | ||
} else { | ||
({ bundleName, contractPath } = settings); | ||
} | ||
const source = `${__dirname}/../../${contractPath}`; | ||
const bundle = await bundleSource(source); | ||
contractBundles[bundleName] = bundle; | ||
}), | ||
); | ||
const step3 = Date.now(); | ||
|
||
const vats = {}; | ||
await Promise.all( | ||
['alice', 'zoe'].map(async name => { | ||
const source = `${__dirname}/vat-${name}.js`; | ||
const bundle = await bundleSource(source); | ||
vats[name] = { bundle }; | ||
}), | ||
); | ||
const bootstrapSource = `${__dirname}/bootstrap.js`; | ||
vats.bootstrap = { | ||
bundle: await bundleSource(bootstrapSource), | ||
parameters: { contractBundles }, // argv will be added to this | ||
}; | ||
const config = { bootstrap: 'bootstrap', vats }; | ||
config.defaultManagerType = 'xs-worker'; | ||
|
||
const step4 = Date.now(); | ||
const ktime = `${(step2 - start) / 1000}s kernel`; | ||
const ctime = `${(step3 - step2) / 1000}s contracts`; | ||
const vtime = `${(step4 - step3) / 1000}s vats`; | ||
const ttime = `${(step4 - start) / 1000}s total`; | ||
console.log(`bundling: ${ktime}, ${ctime}, ${vtime}, ${ttime}`); | ||
|
||
t.context.data = { kernelBundles, config }; | ||
}); | ||
|
||
async function main(t, argv) { | ||
const { kernelBundles, config } = t.context.data; | ||
const controller = await buildVatController(config, argv, { kernelBundles }); | ||
await controller.run(); | ||
return controller.dump(); | ||
} | ||
|
||
const expected = ['privateArgs.myArg was accessed in the contract']; | ||
|
||
test.serial('private args usage', async t => { | ||
const dump = await main(t); | ||
t.deepEqual(dump.log, expected); | ||
}); |
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,29 @@ | ||
import { E } from '@agoric/eventual-send'; | ||
import { Far } from '@agoric/marshal'; | ||
|
||
const build = async (log, zoe, installations) => { | ||
return Far('build', { | ||
privateArgsUsageTest: async () => { | ||
const privateArgs = harden({ | ||
myArg: Far('arg', { | ||
doTest: () => 'privateArgs.myArg was accessed in the contract', | ||
}), | ||
}); | ||
const { creatorFacet } = await E(zoe).startInstance( | ||
installations.privateArgsUsageContract, | ||
undefined, | ||
undefined, | ||
privateArgs, | ||
); | ||
|
||
const testResult = await E(creatorFacet).usePrivateArgs(); | ||
log(testResult); | ||
}, | ||
}); | ||
}; | ||
|
||
export function buildRootObject(vatPowers) { | ||
return Far('root', { | ||
build: (...args) => build(vatPowers.testLog, ...args), | ||
}); | ||
} |
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,10 @@ | ||
import { Far } from '@agoric/marshal'; | ||
|
||
// noinspection ES6PreferShortImport | ||
import { makeZoe } from '../../../src/zoeService/zoe'; | ||
|
||
export function buildRootObject(_vatPowers) { | ||
return Far('root', { | ||
buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), | ||
}); | ||
} |