Skip to content

Commit 102a5b6

Browse files
authored
Merge pull request #5633 from Agoric/5628-double-define-bug
Throw error on attempt to reuse a kind handle
2 parents 23f0de1 + 5ac8cb1 commit 102a5b6

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

packages/SwingSet/src/liveslots/virtualObjectManager.js

+8
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ export function makeVirtualObjectManager(
833833
const durableKindDescriptor = kindDescriptors.get(kindHandle);
834834
assert(durableKindDescriptor);
835835
const { kindID, tag } = durableKindDescriptor;
836+
assert(
837+
!definedDurableKinds.has(kindID),
838+
`redefinition of durable kind "${tag}"`,
839+
);
836840
const maker = defineKindInternal(
837841
kindID,
838842
tag,
@@ -850,6 +854,10 @@ export function makeVirtualObjectManager(
850854
const durableKindDescriptor = kindDescriptors.get(kindHandle);
851855
assert(durableKindDescriptor);
852856
const { kindID, tag } = durableKindDescriptor;
857+
assert(
858+
!definedDurableKinds.has(kindID),
859+
`redefinition of durable kind "${tag}"`,
860+
);
853861
const maker = defineKindInternal(
854862
kindID,
855863
tag,

packages/SwingSet/test/test-vat-env.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ test('kind makers are in the test environment', t => {
3232
const dthing = makeDThing('dthing');
3333
t.is(dthing.ping(), 4);
3434

35+
const kind2 = VatData.makeKindHandle('thing2');
3536
const makeDMThing = VatData.defineDurableKindMulti(
36-
kind,
37+
kind2,
3738
null,
3839
multiThingBehavior,
3940
);

packages/SwingSet/test/virtualObjects/test-virtualObjectManager.js

+11
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,17 @@ test('virtual object cycles using the finish function', t => {
513513
t.is(thing.getOtherThing().getFirstThing(), thing);
514514
});
515515

516+
test('durable kind IDs cannot be reused', t => {
517+
const { vom } = makeFakeVirtualStuff();
518+
const { makeKindHandle, defineDurableKind } = vom;
519+
520+
const kindHandle = makeKindHandle('testkind');
521+
defineDurableKind(kindHandle, initThing, thingBehavior);
522+
t.throws(() => defineDurableKind(kindHandle, initThing, thingBehavior), {
523+
message: 'redefinition of durable kind "testkind"',
524+
});
525+
});
526+
516527
test('durable kind IDs can be reanimated', t => {
517528
const log = [];
518529
const { vom, vrm, cm, fakeStuff } = makeFakeVirtualStuff({

packages/zoe/test/minimalMakeKindContract.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const start = _zcf => {
55
VatData.defineKindMulti('x', () => {}, { x: {}, y: {} });
66
const kh = VatData.makeKindHandle();
77
VatData.defineDurableKind(kh, () => {}, {});
8-
VatData.defineDurableKindMulti(kh, () => {}, { x: {}, y: {} });
8+
const kh2 = VatData.makeKindHandle();
9+
VatData.defineDurableKindMulti(kh2, () => {}, { x: {}, y: {} });
910
VatData.makeScalarBigMapStore();
1011
VatData.makeScalarBigWeakMapStore();
1112
VatData.makeScalarBigSetStore();

packages/zoe/test/unitTests/test-makeKind.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ test('defineKind non-swingset', async t => {
2626
t.notThrows(() => VatData.makeKindHandle());
2727
const kh = VatData.makeKindHandle();
2828
t.notThrows(() => VatData.defineDurableKind(kh, () => {}, {}));
29+
const kh2 = VatData.makeKindHandle();
2930
t.notThrows(() =>
30-
VatData.defineDurableKindMulti(kh, () => {}, { x: {}, y: {} }),
31+
VatData.defineDurableKindMulti(kh2, () => {}, { x: {}, y: {} }),
3132
);
3233
t.notThrows(() => VatData.makeScalarBigMapStore());
3334
t.notThrows(() => VatData.makeScalarBigWeakMapStore());

packages/zoe/test/unitTests/test-zoe-env.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test('(mock) kind makers from SwingSet are in the zoe contract environment', t =
1313
VatData.defineKindMulti('x', () => {}, { x: {}, y: {} });
1414
const kh = VatData.makeKindHandle();
1515
VatData.defineDurableKind(kh, () => {}, {});
16-
VatData.defineDurableKindMulti(kh, () => {}, { x: {}, y: {} });
16+
const kh2 = VatData.makeKindHandle();
17+
VatData.defineDurableKindMulti(kh2, () => {}, { x: {}, y: {} });
1718
t.pass();
1819
});
1920

0 commit comments

Comments
 (0)