Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test updating instances in promiseSpace updates agoricNames #9989

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/vats/test/name-hub-published.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import { makeHandle } from '@agoric/zoe/src/makeHandle.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeTracer } from '@agoric/internal';
import {
agoricNamesReserved,
makeAgoricNamesAccess,
makePromiseSpaceForNameHub,
makeWellKnownSpaces,
} from '../src/core/utils.js';
import { makePromiseSpace } from '../src/core/promise-space.js';
import {
Expand Down Expand Up @@ -58,3 +61,30 @@ test('promise space reserves non-well-known names', async t => {

t.is(await nameHub.lookup('thing1'), true);
});

test('promise space reset instance to change a value', async t => {
const { nameAdmin, nameHub: agoricNames } = makeNameHubKit();

const tracer = makeTracer('test NS');
const space = await makeWellKnownSpaces(
nameAdmin,
tracer,
Object.keys(agoricNamesReserved),
);

const auctionInstance1 = makeHandle('instance1');
const instanceLookup = await agoricNames.lookup('instance');

// @ts-expect-error storing fake instance
space.instance.produce.auctioneer.resolve(auctionInstance1);
// @ts-expect-error expecting instance
t.is(await space.instance.consume.auctioneer, auctionInstance1);
Comment on lines +75 to +81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving the error to where auctionInstance1 is declared:

Suggested change
const auctionInstance1 = makeHandle('instance1');
const instanceLookup = await agoricNames.lookup('instance');
// @ts-expect-error storing fake instance
space.instance.produce.auctioneer.resolve(auctionInstance1);
// @ts-expect-error expecting instance
t.is(await space.instance.consume.auctioneer, auctionInstance1);
/** @type { Instance } */
// @ts-expect-error mock
const auctionInstance1 = makeHandle('instance1');
const instanceLookup = await agoricNames.lookup('instance');
space.instance.produce.auctioneer.resolve(auctionInstance1);
t.is(await space.instance.consume.auctioneer, auctionInstance1);

t.is(await instanceLookup.lookup('auctioneer'), auctionInstance1);

const auctionInstance2 = makeHandle('instance2');
await space.instance.produce.auctioneer.reset();
// @ts-expect-error fake instance
await space.instance.produce.auctioneer.resolve(auctionInstance2);

t.is(await instanceLookup.lookup('auctioneer'), auctionInstance2);
});
Loading