Skip to content

Commit

Permalink
fix: getPublicFacet accepts promise for instance (#4328)
Browse files Browse the repository at this point in the history
* fix: getPublicFacet accepts promise for instance

* fix: add test
  • Loading branch information
erights authored Jan 21, 2022
1 parent 8a6875f commit f716199
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/zoe/src/zoeService/instanceAdminStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import { E } from '@agoric/eventual-send';
import { makeWeakStore } from '@agoric/store';

/**
Expand All @@ -10,9 +11,10 @@ export const makeInstanceAdminStorage = () => {
const instanceToInstanceAdmin = makeWeakStore('instance');

/** @type {GetPublicFacet} */
const getPublicFacet = async instance => {
return instanceToInstanceAdmin.get(instance).getPublicFacet();
};
const getPublicFacet = async instanceP =>
E.when(instanceP, instance =>
instanceToInstanceAdmin.get(instance).getPublicFacet(),
);

/** @type {GetBrands} */
const getBrands = async instance =>
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/zoeService/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

/**
* @callback GetPublicFacet
* @param {Instance} instance
* @param {ERef<Instance>} instanceP
* @returns {Promise<Object>}
*/

Expand Down
20 changes: 20 additions & 0 deletions packages/zoe/test/unitTests/test-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ test(`E(zoe).getPublicFacet`, async t => {
t.is(await E(zoe).getPublicFacet(instance), publicFacet);
});

test(`E(zoe).getPublicFacet promise for instance`, async t => {
const { zoe } = setup();
const contractPath = `${dirname}/../../src/contracts/automaticRefund`;
const bundle = await bundleSource(contractPath);
const installationP = E(zoe).install(bundle);
// Note that E.get does not currently pipeline
const { publicFacet: publicFacetP, instance: instanceP } = E.get(
E(zoe).startInstance(installationP),
);
const pfp = E(zoe).getPublicFacet(instanceP);
const offersCountP = E(publicFacetP).getOffersCount();
const [offersCount, publicFacet, pf] = await Promise.all([
offersCountP,
publicFacetP,
pfp,
]);
t.is(offersCount, 0n);
t.is(pf, publicFacet);
});

test(`E(zoe).getPublicFacet - no instance`, async t => {
const { zoe } = setup();
// @ts-ignore deliberate invalid arguments for testing
Expand Down

0 comments on commit f716199

Please sign in to comment.