Skip to content

Commit

Permalink
refactor(zoe)!: add method zcf.getInstance() (#3353)
Browse files Browse the repository at this point in the history
* refactor(zoe)!: add method zcf.getInstance()
  • Loading branch information
katelynsills authored Jun 18, 2021
1 parent 8447993 commit d8952c2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/zoe/src/contractFacet/zcfZygote.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const makeZCFZygote = (
addIssuerToInstanceRecord,
getTerms,
assertUniqueKeyword,
getInstanceRecord,
instantiate: instantiateInstanceRecordStorage,
} = makeInstanceRecordStorage();

Expand Down Expand Up @@ -243,6 +244,7 @@ export const makeZCFZygote = (
testJigSetter({ ...testFn(), zcf });
}
},
getInstance: () => getInstanceRecord().instance,
});

// handleOfferObject gives Zoe the ability to notify ZCF when a new seat is
Expand Down
3 changes: 3 additions & 0 deletions packages/zoe/src/instanceRecordStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,22 @@ export const makeInstanceRecordStorage = () => {
* Put together the instance record
*
* @param {Installation} installation
* @param {Instance} instance
* @param {Object} customTerms
* @param {IssuerKeywordRecord} issuers
* @param {BrandKeywordRecord} brands
* @returns {InstanceRecordManager}
*/
export const makeAndStoreInstanceRecord = (
installation,
instance,
customTerms,
issuers,
brands,
) => {
const instanceRecord = harden({
installation,
instance,
terms: {
...customTerms,
issuers,
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @typedef {object} InstanceRecord
* @property {Installation} installation
* @property {Instance} instance
* @property {Terms} terms - contract parameters
*
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/zoeService/zoeStorageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const makeZoeStorageManager = createZCFVat => {
// capabilities from the ZCF side.
const instanceRecordManager = makeAndStoreInstanceRecord(
installation,
instance,
customTerms,
issuers,
brands,
Expand Down
12 changes: 10 additions & 2 deletions packages/zoe/test/unitTests/test-instanceStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test('makeAndStoreInstanceRecord', async t => {
const { currencyKit, ticketKit } = setupIssuersForTest();
const bundle = await bundleSource(root);
const fakeInstallation = { getBundle: () => bundle };
const fakeInstance = /** @type {Instance} */ ({});
const customTerms = harden({ time: 2n });
const issuers = harden({
Currency: currencyKit.issuer,
Expand All @@ -48,13 +49,15 @@ test('makeAndStoreInstanceRecord', async t => {
assertUniqueKeyword,
} = makeAndStoreInstanceRecord(
fakeInstallation,
fakeInstance,
customTerms,
issuers,
brands,
);

t.deepEqual(getInstanceRecord(), {
installation: fakeInstallation,
instance: fakeInstance,
terms: { time: 2n, issuers, brands },
});

Expand All @@ -70,7 +73,8 @@ test('makeAndStoreInstanceRecord', async t => {
// Add currency again, but call it "money"
addIssuerToInstanceRecord(
'Money',
makeIssuerRecord(currencyKit.brand, currencyKit.issuer, AssetKind.NAT, {
makeIssuerRecord(currencyKit.brand, currencyKit.issuer, {
assetKind: AssetKind.NAT,
decimalPlaces: 18,
}),
);
Expand All @@ -82,6 +86,7 @@ test('makeInstanceRecordStorage', async t => {
const { currencyKit, ticketKit } = setupIssuersForTest();
const bundle = await bundleSource(root);
const fakeInstallation = { getBundle: () => bundle };
const fakeInstance = /** @type {Instance} */ ({});
const issuers = harden({
Currency: currencyKit.issuer,
Ticket: ticketKit.issuer,
Expand All @@ -101,11 +106,13 @@ test('makeInstanceRecordStorage', async t => {
} = makeInstanceRecordStorage();
instantiate({
installation: fakeInstallation,
instance: fakeInstance,
terms: { time: 2n, issuers, brands },
});

t.deepEqual(getInstanceRecord(), {
installation: fakeInstallation,
instance: fakeInstance,
terms: { time: 2n, issuers, brands },
});

Expand All @@ -121,7 +128,8 @@ test('makeInstanceRecordStorage', async t => {
// Add currency again, but call it "money"
addIssuerToInstanceRecord(
'Money',
makeIssuerRecord(currencyKit.brand, currencyKit.issuer, AssetKind.NAT, {
makeIssuerRecord(currencyKit.brand, currencyKit.issuer, {
assetKind: AssetKind.NAT,
decimalPlaces: 18,
}),
);
Expand Down
6 changes: 6 additions & 0 deletions packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ test(`zcf.getZoeService`, async t => {
t.is(await zoeService, zoe);
});

test(`zcf.getInstance`, async t => {
const { zcf, instance } = await setupZCFTest();
const instanceFromZCF = zcf.getInstance();
t.is(instance, instanceFromZCF);
});

test(`zcf.getInvitationIssuer`, async t => {
const { zoe, zcf } = await setupZCFTest();
const zcfInvitationIssuer = zcf.getInvitationIssuer();
Expand Down

0 comments on commit d8952c2

Please sign in to comment.