-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(orchestration): ZCFTools #10057
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mhofman marked this conversation as resolved.
Show resolved
Hide resolved
|
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>} | ||
*/ | ||
turadg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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/, | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nb: the usage here somewhat abuses the "map" idea. Kind of a
deepAssert
orvisitObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite