Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(zoe): teach fakeVatAdmin to createVatByName(zcf)
Zoe needs a way to create a new ZCF vat to host each contract instance. Inside swingset, zoe uses `vatAdminService`, and this is used from unit tests (zoe and other packages that use zoe) when they are willing to take the time to run a full swingset environment. Unit tests that use zoe, but not swingset, use `tools/fakeVatAdmin.js` as a replacement, which implements `createVat(bundle)` but not `createVatByName(name)`. This is used to evaluate the ZCF bundle in a new Compartment (using `importBundle` and `evalContractBundle`). The primary export of `@agoric/zoe` is `makeZoeKit()`, which is called with `vatAdminService` and an optional `zcfBundleName`. This function runs `setupCreateZCFVat(vatAdminService)` to attenuate the vat-making power into one that can only create ZCF vats. Previously, `setupCreateZCFVat` closed over a copy of the ZCF bundle, and passed it to `vatAdminService~.createVat(zcfBundle)`. This hides the existence of the ZCF bundle from other packages that just want to use Zoe. However, to remove these large code bundles from userspace messages (#4372), we need the ZCF bundle to be installed "off to the side", by the code that prepares the swingset environment (usually as `config.bundles.zcf=`). This commit changes `fakeVatAdmin.js` to implement `createVatByName('zcf')`, and to move the copy of the zcfBundle out of `makeZoeKit()` and into `fakeVatAdmin.js` . In addition, it changes `createZCFVat.js` to provide a default bundle name of 'zcf'. Any unit test that uses `fakeVatAdmin.js` can continue to do so without changes, and the fake service will magically know how to create Zoe's ZCF vat without any additional configuration. Unit tests that use swingset, however, need to be updated to install the ZCF bundle into the kernel, with something like: ``` import zcfBundle from `@agoric/zoe/bundles/bundle-contractFacet.js`; ... config.bundles.zcf = { bundle: zcfBundle }; ``` Note: if we used `{ sourceSpec: '@agoric/zoe/contractFacet.js' }`, then we would not depend upon a recent `cd packages/zoe && yarn build`, and each kernel instance would bundle its own copy. This would be slower, but perhaps less prone to stale-bundle surprises, and might be a nicer export commitment. refs #4487
- Loading branch information