Skip to content

Commit

Permalink
test(vats): vat-bank needs MapStore ocap insertion-order preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 7, 2023
1 parent 2b5214b commit d0c6811
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/vats/test/test-vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { fakeVomKit } from './setup-vat-data.js';
import { E } from '@endo/far';
import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { heapZone } from '@agoric/zone';
import { subscribeEach } from '@agoric/notifier';
import { buildRootObject } from '../src/vat-bank.js';

Expand All @@ -16,6 +17,40 @@ const provideBaggage = key => {
return zone.mapStore(`${key} baggage`);
};

test('provideAssetSubscription - MapStore insertion order preserved', async t => {
const zones = {
durableZone: makeDurableZone(provideBaggage('key order')),
heapZone,
};
for (const [name, zone] of Object.entries(zones)) {
const ids = harden(['a', 'b', 'c', 'd', 'e']);
const handleToId = new Map(
ids.map(id => [zone.exo(`${name} ${id} handle`, undefined, {}), id]),
);

const forwardMap = zone.mapStore(`${name} forward map`);
handleToId.forEach((id, h) => forwardMap.init(h, id));
const forwardMapIds = [...forwardMap.values()];

const reverseMap = zone.mapStore(`${name} reverse map`);
[...handleToId.entries()]
.reverse()
.forEach(([h, id]) => reverseMap.init(h, id));
const reverseMapIds = [...reverseMap.values()];

t.deepEqual(
forwardMapIds,
ids,
`${name} forward map insertion order preserved`,
);
t.deepEqual(
reverseMapIds,
[...ids].reverse(),
`${name} reverse map insertion order preserved`,
);
}
});

test('communication', async t => {
t.plan(32);
const baggage = provideBaggage('communication');
Expand Down

0 comments on commit d0c6811

Please sign in to comment.