From d232c8d104f349592b099b56f84c1abedff22ed2 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 16 Sep 2024 10:27:33 -0700 Subject: [PATCH] fixup to test without a new contract --- .../scripts/testing/fix-buggy-sendAnywhere.js | 2 +- .../testing/start-buggy-sendAnywhere.js | 22 +++- .../examples/buggy-sendAnywhere.contract.js | 110 ------------------ .../src/examples/send-anywhere.contract.js | 3 +- 4 files changed, 20 insertions(+), 117 deletions(-) delete mode 100644 packages/orchestration/src/examples/buggy-sendAnywhere.contract.js diff --git a/packages/builders/scripts/testing/fix-buggy-sendAnywhere.js b/packages/builders/scripts/testing/fix-buggy-sendAnywhere.js index 455fffb3f8d2..a6024d8a8bbe 100644 --- a/packages/builders/scripts/testing/fix-buggy-sendAnywhere.js +++ b/packages/builders/scripts/testing/fix-buggy-sendAnywhere.js @@ -17,7 +17,7 @@ import { E } from '@endo/far'; const trace = makeTracer('StartBuggySA', true); /** - * @import {start as StartFn} from '@agoric/orchestration/src/examples/buggy-sendAnywhere.contract.js'; + * @import {start as StartFn} from '@agoric/orchestration/src/examples/send-anywhere.contract.js'; */ /** diff --git a/packages/builders/scripts/testing/start-buggy-sendAnywhere.js b/packages/builders/scripts/testing/start-buggy-sendAnywhere.js index 7749b0db87f3..e726e3bf9eb1 100644 --- a/packages/builders/scripts/testing/start-buggy-sendAnywhere.js +++ b/packages/builders/scripts/testing/start-buggy-sendAnywhere.js @@ -7,7 +7,7 @@ import { makeTracer, NonNullish, } from '@agoric/internal'; -import { E } from '@endo/far'; +import { E, Far } from '@endo/far'; /// /** @@ -17,7 +17,7 @@ import { E } from '@endo/far'; const trace = makeTracer('StartBuggySA', true); /** - * @import {start as StartFn} from '@agoric/orchestration/src/examples/buggy-sendAnywhere.contract.js'; + * @import {start as StartFn} from '@agoric/orchestration/src/examples/send-anywhere.contract.js'; */ /** @@ -64,10 +64,22 @@ export const startSendAnywhere = async ({ }), ); + const agoricNamesHangs = Far('agoricNames that hangs', { + // ...privateArgs.agoricNames, + lookup: async () => { + trace('agoricNames.lookup being called that will never resolve'); + // BUG: this never resolves + return new Promise(() => {}); + }, + }); + const { instance } = await E(startUpgradable)({ label: 'sendAnywhere', installation: sendAnywhere, - privateArgs, + privateArgs: { + ...privateArgs, + agoricNames: agoricNamesHangs, + }, }); produceInstance.resolve(instance); trace('done'); @@ -75,7 +87,7 @@ export const startSendAnywhere = async ({ harden(startSendAnywhere); export const getManifestForValueVow = ({ restoreRef }, { sendAnywhereRef }) => { - console.log('sendAnywhereRef', sendAnywhereRef); + trace('sendAnywhereRef', sendAnywhereRef); return { manifest: { [startSendAnywhere.name]: { @@ -113,7 +125,7 @@ export const defaultProposalBuilder = async ({ publishRef, install }) => { sendAnywhereRef: publishRef( install( - '@agoric/orchestration/src/examples/buggy-sendAnywhere.contract.js', + '@agoric/orchestration/src/examples/send-anywhere.contract.js', ), ), }, diff --git a/packages/orchestration/src/examples/buggy-sendAnywhere.contract.js b/packages/orchestration/src/examples/buggy-sendAnywhere.contract.js deleted file mode 100644 index d0664b9f3889..000000000000 --- a/packages/orchestration/src/examples/buggy-sendAnywhere.contract.js +++ /dev/null @@ -1,110 +0,0 @@ -/** - * @file variation of sendAnywhere.contract.js that has a vow that never - * resolves, for use in testing replacing this with a working contract during - * in-flight offers - */ -import { makeSharedStateRecord } from '@agoric/async-flow'; -import { AmountShape } from '@agoric/ertp'; -import { InvitationShape } from '@agoric/zoe/src/typeGuards.js'; -import { Fail } from '@endo/errors'; -import { M } from '@endo/patterns'; -import { withOrchestration } from '../utils/start-helper.js'; -import * as orchestrationFns from './send-anywhere.flows.js'; -import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js'; - -/** - * @import {TimerService} from '@agoric/time'; - * @import {LocalChain} from '@agoric/vats/src/localchain.js'; - * @import {NameHub} from '@agoric/vats'; - * @import {Remote, Vow} from '@agoric/vow'; - * @import {Zone} from '@agoric/zone'; - * @import {VBankAssetDetail} from '@agoric/vats/tools/board-utils.js'; - * @import {CosmosInterchainService} from '@agoric/orchestration'; - * @import {OrchestrationTools} from '../utils/start-helper.js'; - */ - -/** - * @typedef {{ - * localchain: Remote; - * orchestrationService: Remote; - * storageNode: Remote; - * timerService: Remote; - * agoricNames: Remote; - * }} OrchestrationPowers - */ - -export const SingleAmountRecord = M.and( - M.recordOf(M.string(), AmountShape, { - numPropertiesLimit: 1, - }), - M.not(harden({})), -); -harden(SingleAmountRecord); - -/** - * Orchestration contract to be wrapped by withOrchestration for Zoe - * - * @param {ZCF} zcf - * @param {OrchestrationPowers & { - * marshaller: Marshaller; - * }} privateArgs - * @param {Zone} zone - * @param {OrchestrationTools} tools - */ -const contract = async ( - zcf, - privateArgs, - zone, - { chainHub, orchestrateAll, vowTools, zoeTools }, -) => { - const contractState = makeSharedStateRecord( - /** @type {{ localAccount: OrchestrationAccount | undefined }} */ { - localAccount: undefined, - }, - ); - - const creatorFacet = prepareChainHubAdmin(zone, chainHub); - - /** @type {(brand: Brand) => Vow} */ - const findBrandInVBank = vowTools.retriable( - zone, - 'findBrandInVBank', - /** @param {Brand} brand */ - async brand => { - // BUG: this never resolves - const assets = await new Promise(() => {}); - const it = assets.find(a => a.brand === brand); - it || Fail`brand ${brand} not in agoricNames.vbankAsset`; - return it; - }, - ); - - // orchestrate uses the names on orchestrationFns to do a "prepare" of the associated behavior - const orchFns = orchestrateAll(orchestrationFns, { - zcf, - contractState, - localTransfer: zoeTools.localTransfer, - findBrandInVBank, - }); - - const publicFacet = zone.exo( - 'Send PF', - M.interface('Send PF', { - makeSendInvitation: M.callWhen().returns(InvitationShape), - }), - { - makeSendInvitation() { - return zcf.makeInvitation( - orchFns.sendIt, - 'send', - undefined, - M.splitRecord({ give: SingleAmountRecord }), - ); - }, - }, - ); - return { creatorFacet, publicFacet }; -}; - -export const start = withOrchestration(contract); -harden(start); diff --git a/packages/orchestration/src/examples/send-anywhere.contract.js b/packages/orchestration/src/examples/send-anywhere.contract.js index ebe77f1af7df..493a6c982e21 100644 --- a/packages/orchestration/src/examples/send-anywhere.contract.js +++ b/packages/orchestration/src/examples/send-anywhere.contract.js @@ -29,7 +29,7 @@ harden(SingleAmountRecord); * @param {Zone} zone * @param {OrchestrationTools} tools */ -const contract = async ( +export const contract = async ( zcf, privateArgs, zone, @@ -69,6 +69,7 @@ const contract = async ( return { publicFacet, creatorFacet }; }; +harden(contract); export const start = withOrchestration(contract); harden(start);