-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestration): ZCFTools (#10057)
closes: #9773 ## Description Provide selected ZCF APIs for use in orchestration flows. For example: use vows for resumable promises. ### Security Considerations nothing new ### Scaling Considerations n/a ### Documentation Considerations - [x] reference docs for attenuated ZCF ### Testing Considerations - [x] unit tests - [x] a bit of integration with one of the examples ### Upgrade Considerations n/a
- Loading branch information
Showing
15 changed files
with
175 additions
and
12 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
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,35 @@ | ||
/** | ||
* @import {HostInterface} from '@agoric/async-flow'; | ||
* @import {VowTools} from '@agoric/vow'; | ||
* @import {ZcfTools} from '../types.js'; | ||
*/ | ||
|
||
import { M, mustMatch } from '@endo/patterns'; | ||
|
||
const HandlerShape = M.remotable('OfferHandler'); | ||
|
||
/** | ||
* @param {ZCF} zcf | ||
* @param {VowTools} vowTools | ||
* @returns {HostInterface<ZcfTools>} | ||
*/ | ||
export const makeZcfTools = (zcf, vowTools) => | ||
harden({ | ||
makeInvitation(offerHandler, description, customDetails, proposalShape) { | ||
mustMatch(offerHandler, HandlerShape); | ||
return vowTools.watch( | ||
zcf.makeInvitation( | ||
offerHandler, | ||
description, | ||
customDetails, | ||
proposalShape, | ||
), | ||
); | ||
}, | ||
atomicRearrange(transfers) { | ||
zcf.atomicRearrange(transfers); | ||
}, | ||
assertUniqueKeyword(keyword) { | ||
zcf.assertUniqueKeyword(keyword); | ||
}, | ||
}); |
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
Binary file modified
BIN
+158 Bytes
(120%)
packages/orchestration/test/examples/snapshots/unbond.contract.test.ts.snap
Binary file not shown.
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
20 changes: 20 additions & 0 deletions
20
packages/orchestration/test/fixtures/zcfTester.contract.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,20 @@ | ||
import { Far } from '@endo/far'; | ||
|
||
/** | ||
* Tests ZCF | ||
* | ||
* @param {ZCF} zcf | ||
*/ | ||
export const start = async zcf => { | ||
// make the `zcf` and `instance` available to the tests | ||
const instance = zcf.getInstance(); | ||
zcf.setTestJig(() => harden({ instance })); | ||
|
||
const publicFacet = Far('public facet', { | ||
makeInvitation: () => zcf.makeInvitation(() => 17, 'simple'), | ||
}); | ||
|
||
return { publicFacet }; | ||
}; | ||
|
||
harden(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
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 @@ | ||
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { AmountMath, makeIssuerKit } from '@agoric/ertp'; | ||
import { prepareSwingsetVowTools } from '@agoric/vow'; | ||
import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; | ||
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js'; | ||
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js'; | ||
import { E, Far } from '@endo/far'; | ||
import type { TestFn } from 'ava'; | ||
import { createRequire } from 'node:module'; | ||
import { makeZcfTools } from '../../src/utils/zcf-tools.js'; | ||
import { provideDurableZone } from '../supports.js'; | ||
|
||
const nodeRequire = createRequire(import.meta.url); | ||
const contractEntry = nodeRequire.resolve('../fixtures/zcfTester.contract.js'); | ||
|
||
const makeTestContext = async () => { | ||
let testJig; | ||
const setJig = jig => (testJig = jig); | ||
const fakeVatAdmin = makeFakeVatAdmin(setJig); | ||
const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest( | ||
fakeVatAdmin.admin, | ||
); | ||
|
||
const bundleCache = await makeNodeBundleCache('bundles', {}, s => import(s)); | ||
const contractBundle = await bundleCache.load(contractEntry); | ||
|
||
fakeVatAdmin.vatAdminState.installBundle('b1-contract', contractBundle); | ||
const installation = await E(zoe).installBundleID('b1-contract'); | ||
|
||
const stuff = makeIssuerKit('Stuff'); | ||
await E(zoe).startInstance(installation, { Stuff: stuff.issuer }); | ||
assert(testJig, 'startInstance did not call back to setTestJig'); | ||
|
||
const zcf: ZCF = testJig.zcf; | ||
|
||
const zone = provideDurableZone('root'); | ||
const vt = prepareSwingsetVowTools(zone); | ||
const zcfTools = makeZcfTools(zcf, vt); | ||
return { zoe, zcf, stuff, feeMintAccess, zcfTools, vt }; | ||
}; | ||
|
||
type TestContext = Awaited<ReturnType<typeof makeTestContext>>; | ||
|
||
const test = anyTest as TestFn<TestContext>; | ||
|
||
test.before('set up context', async t => (t.context = await makeTestContext())); | ||
|
||
test('unchanged: atomicRearrange(), assertUniqueKeyword()', async t => { | ||
const { zcf, zcfTools } = t.context; | ||
|
||
t.notThrows(() => zcfTools.atomicRearrange([])); | ||
|
||
t.notThrows(() => zcfTools.assertUniqueKeyword('K1')); | ||
t.throws(() => zcfTools.assertUniqueKeyword('Stuff')); | ||
}); | ||
|
||
test('changed: makeInvitation: watch promise', async t => { | ||
const { zoe, zcf, zcfTools, vt } = t.context; | ||
|
||
const handler = Far('Trade', { handle: seat => {} }); | ||
const toTradeVow = zcfTools.makeInvitation(handler, 'trade'); | ||
|
||
const toTrade = await vt.when(toTradeVow); | ||
const amt = await E(E(zoe).getInvitationIssuer()).getAmountOf(toTrade); | ||
t.like(amt, { value: [{ description: 'trade' }] }); | ||
}); | ||
|
||
test('removed: makeInvitation: non-passable handler', async t => { | ||
const { zcfTools } = t.context; | ||
|
||
const handler = harden(_seat => {}); | ||
t.throws(() => zcfTools.makeInvitation(handler, 'trade'), { | ||
message: /Remotables must be explicitly declared/, | ||
}); | ||
}); |