From e7a283b6e49b6e5cd1d57341cf615cf9da0043ac Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Thu, 5 Sep 2024 16:23:41 -0700 Subject: [PATCH] test: add the ability to find details for multiple vats --- .../synthetic-chain/src/lib/vat-status.js | 29 ++++++++++++++++++ .../test/snapshots/test-exports.ts.md | 1 + .../test/snapshots/test-exports.ts.snap | Bin 2256 -> 2276 bytes 3 files changed, 30 insertions(+) diff --git a/packages/synthetic-chain/src/lib/vat-status.js b/packages/synthetic-chain/src/lib/vat-status.js index 345a856b..dc15e950 100644 --- a/packages/synthetic-chain/src/lib/vat-status.js +++ b/packages/synthetic-chain/src/lib/vat-status.js @@ -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, }); }; @@ -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; +}; diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.md b/packages/synthetic-chain/test/snapshots/test-exports.ts.md index 05e608ff..44e233da 100644 --- a/packages/synthetic-chain/test/snapshots/test-exports.ts.md +++ b/packages/synthetic-chain/test/snapshots/test-exports.ts.md @@ -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 {}, diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.snap b/packages/synthetic-chain/test/snapshots/test-exports.ts.snap index dc736f9941c39759a2a5a7b55fdf70ebcdd51b2f..17997e702afe700f95505e977d08f00078056eb4 100644 GIT binary patch literal 2276 zcmV$q};!>*j}TuBkni=7V4lPg&Ym zT27swgCC0s00000000A(nM-UWM;XWeZO_~G*j{@*-h@}!ED2e>@0gL<;5Znx3BN=^A%e&tr)|0VHzV0|!;#{AzL6WNO8E>D!bW+@v~f)|ky5!?8%sDKYN6 z^s1&2PHsIM??oK#A0?q&TUCJT3cwZM6$SX20-WgqKHmep)&soL0}S*6&-Vha_X5A} z1^(0v^hbb4BEVt<*p2|-i2y&10KbU?0=83tlLGFffHzaXgB0-3 z6foEaWcz?CeSqBu-01^Glvr9(hLzYF(_E7d4GlpVfKq@mh!Le{ROy8h9ad8L?e(=6 zRxaOIU+b8nF5#>i;9^UK8~M#!oySCxROkfJwEz}hzM3!GD6DjzlWk5d5yJ|Ai7V?n zQ~8yZ&5mJ$=*%|MDN1uCd$QcJo26DRmuoG|%~flQ^V4QoZ>iNrt2SFR7xuc0Hr;Ks zhFvU8=jN$9eS2oMHeVy9g}uqya@lQ_XR1v%SI;d@FD!H!ZKm63E$w!*QJOC<=4Q(E z8ga}jxjk<#mZx3Qt>wrWtdg<3;xR;)Qvnk?_>?xJ1Ni)N#!nNZS- z@s4V|Q5?w_B|58#8Gb04Q=YkC@%AK#*X=3SnM%09td8|!m;7ffrqLIw-dp8lFYOvu z_F%H#OOwTfk7w^2IIt&niB;L6mWcXEN$KBpEzP7WloLZ_ksVdHm}{%S${Cfl;3{TL zw+b=DgyWB&R+Lwy*+*4ks;)^my-7@y@-0rdpzcdlS}jqvvdV0+$D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