Skip to content

Commit

Permalink
test(cosmic-swingset): Smoke test the inquisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Feb 27, 2025
1 parent 66c226b commit 2f70223
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions packages/cosmic-swingset/test/inquisitor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import test from 'ava';

import { q, Fail } from '@endo/errors';

import { BridgeId, VBankAccount } from '@agoric/internal';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';

import { makeHelpers } from '../tools/inquisitor.mjs';
import { makeCosmicSwingsetTestKit } from '../tools/test-kit.js';

test('smoke test', async t => {
const fakeStorageKit = makeFakeStorageKit('');
const { toStorage: handleVstorage } = fakeStorageKit;
const receiveBridgeSend = (destPortName, msg) => {
switch (destPortName) {
case BridgeId.STORAGE: {
return handleVstorage(msg);
}
case BridgeId.BANK: {
if (msg.type === 'VBANK_GET_MODULE_ACCOUNT_ADDRESS') {
const matchesRequest = desc => desc.module === msg.moduleName;
const found = Object.values(VBankAccount).find(matchesRequest);
if (found) return found.address;
return { error: `module account ${msg.moduleName} not found` };
}
break;
}
default:
break;
}
Fail`port ${q(destPortName)} not implemented for message ${msg}`;
};
const env = {
...process.env,
CHAIN_BOOTSTRAP_VAT_CONFIG: '@agoric/vm-config/decentral-core-config.json',
};
const testKit = await makeCosmicSwingsetTestKit(receiveBridgeSend, { env });
const { pushCoreEval, runNextBlock, swingStore, shutdown } = testKit;
t.teardown(shutdown);

// To tickle some activity, run a couple of trivial blocks.
pushCoreEval(`${() => {}}`);
await runNextBlock();
pushCoreEval(`${() => {}}`);
await runNextBlock();

// Build and exercise the helpers.
const { db } = swingStore.internal;
// @ts-expect-error missing EV
const { stable: helpers } = makeHelpers({ db });
t.truthy(helpers.kvGet('vat.names'));
t.true(Array.isArray(helpers.kvGetJSON('vat.dynamicIDs')));
const vatAdmin = helpers.vatsByName.get('vatAdmin');
t.like(vatAdmin, { name: 'vatAdmin', isStatic: true }, 'vatAdmin');
{
const { vatID } = vatAdmin;
t.regex(vatID, /^v[1-9][0-9]*$/, 'vatAdmin vatID');

const rootVref = 'o+0';
const rootRefs = helpers.getRefs(rootVref, vatID);
t.true(rootRefs.length > 0, 'vatAdmin root object export');

const rootKref = rootRefs[0].kref;
const rootRefsByKref = helpers.getRefs(rootKref);
t.deepEqual(rootRefsByKref, rootRefs, 'vatAdmin root object kref');

const clist = helpers.kvGlob(`${vatID}.c.*`);
t.true(clist.length > 0);
const rootRow = clist.find(row => row.value === rootKref);
t.like(
rootRow,
{ key: `${vatID}.c.${rootVref}`, value: rootKref },
'kvGlob',
);
}
});
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/tools/inquisitor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const parseNumber = input => (input.match(/[0-9]/) ? Number(input) : NaN);
const storeExportAPI = ['getExportRecords', 'getArtifactNames'];

// TODO: getVatAdminNode('v112') # scan the vatAdmin vom v2.vs.vom.* vrefs for value matching /\b${vatID}\b/
const makeHelpers = ({ db, EV }) => {
export const makeHelpers = ({ db, EV }) => {
const sqlKVGet = db
.prepare('SELECT value FROM kvStore WHERE key = ?')
.pluck();
Expand Down

0 comments on commit 2f70223

Please sign in to comment.