Skip to content

Commit

Permalink
test: add the ability to find details for multiple vats
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Sep 5, 2024
1 parent 643068f commit e7a283b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/synthetic-chain/src/lib/vat-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ const makeSwingstore = db => {
if (!targetVat) throw Error(`vat not found: ${vatName}`);
return targetVat;
},
/** @param {string} vatName */
findVats: vatName => {
/** @type {string[]} */
const dynamicIDs = kvGetJSON('vat.dynamicIDs');
return dynamicIDs.filter(vatID =>
lookupVat(vatID).options().name.includes(vatName),
);
},
lookupVat,
});
};
Expand Down Expand Up @@ -92,3 +100,24 @@ export const getIncarnation = async vatName => {

return details.incarnation;
};

/** @param {string} vatName */
export const getDetailsMatchingVats = async vatName => {
const fullPath = swingstorePath.replace(/^~/, NonNullish(HOME));

const db = dbOpenAmbient(fullPath, { readonly: true });
const kStore = makeSwingstore(db);

const vatIDs = kStore.findVats(vatName);
const infos = [];
for (const vatID of vatIDs) {
const vatInfo = kStore.lookupVat(vatID);
const name = vatInfo.options().name;
const source = vatInfo.source();
// @ts-expect-error cast
const { incarnation } = vatInfo.currentSpan();
infos.push({ vatName: name, vatID, incarnation, ...source });
}

return infos;
};
1 change: 1 addition & 0 deletions packages/synthetic-chain/test/snapshots/test-exports.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Generated by [AVA](https://avajs.dev).
generateOracleMap: Function generateOracleMap {},
getAuctionCollateral: AsyncFunction {},
getContractInfo: AsyncFunction {},
getDetailsMatchingVats: AsyncFunction {},
getISTBalance: AsyncFunction {},
getIncarnation: AsyncFunction {},
getInstanceBoardId: AsyncFunction {},
Expand Down
Binary file modified packages/synthetic-chain/test/snapshots/test-exports.ts.snap
Binary file not shown.

0 comments on commit e7a283b

Please sign in to comment.