All files / kernel-test/src/vats revocation-target-vat.ts

0% Statements 0/14
0% Branches 0/4
0% Functions 0/6
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                                                                     
import { E } from '@endo/eventual-send';
import { makeDefaultExo } from '@metamask/kernel-utils/exo';
 
import type { TestPowers } from '../test-powers.ts';
 
/**
 * Build function for a vat that exports two objects — a revocable target and an
 * unrelated bystander — so cross-kernel revocation tests can check both sides.
 *
 * @param vatPowers - Special powers granted to this vat.
 * @param vatPowers.logger - The logger for the vat.
 * @param parameters - Initialization parameters from the vat's config object.
 * @param parameters.name - The name of the vat.
 * @param _baggage - Root of vat's persistent state (not used here).
 * @returns The root object for the new vat.
 */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function buildRootObject(
  { logger }: TestPowers,
  parameters: { name?: string } = {},
  _baggage: unknown = null,
) {
  const name = parameters?.name ?? 'RevocationTarget';
  logger.log(`buildRootObject "${name}"`);
 
  const target = makeDefaultExo('target', {
    ping() {
      return `pong from ${name} target`;
    },
  });
 
  const bystander = makeDefaultExo('bystander', {
    ping() {
      return `pong from ${name} bystander`;
    },
  });
 
  return makeDefaultExo('root', {
    async bootstrap(
      _vats: unknown,
      services: { ocapURLIssuerService?: unknown },
    ) {
      logger.log(`vat ${name} is bootstrap`);
      const issuerService = services.ocapURLIssuerService;
      const targetURL = await E(issuerService).issue(target);
      const bystanderURL = await E(issuerService).issue(bystander);
      return harden({ targetURL, bystanderURL });
    },
 
    getTarget() {
      return target;
    },
 
    getBystander() {
      return bystander;
    },
  });
}