Sequential use of smallCaps.ref for the same object omits its boardID in capData Slots #10218
-
ContextI’d like to bring up an issue I encountered while working on test cases running in the Although this might not be relevant for everyone, it could be useful for anyone facing a similar issue in the future. Here's a summary of the situation. The export const smallCapsContext = () => {
const slots = [] as string[]; // XXX global mutable state
const smallCaps = {
Nat: (n: number | bigint) => `+${n}`,
// XXX mutates obj
ref: (obj: any) => {
if (obj.ix) return obj.ix;
const ix = slots.length;
slots.push(obj.boardID);
obj.ix = `$${ix}.Alleged: ${obj.iface}`;
return obj.ix;
},
};
const toCapData = (body: unknown) => {
const capData = { body: `#${JSON.stringify(body)}`, slots };
return JSON.stringify(capData);
};
return { smallCaps, toCapData };
}; The ProblemWhen making multiple sequential offers using the same The issue arises because the It is important to highlight that I have failed to noticed the comment present on the smallCapsContext function that clearly specified that smallCaps.ref mutates the object. SolutionThis occurs because the same reference to the
To illustrate this behavior more clearly, I’ve created a simple test that demonstrates the issue in detail: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm a little surprised that |
Beta Was this translation helpful? Give feedback.
smallCapsContext
is a kludge - it's a partial implementation of@agoric/marshal
. If you run into limitations, I suggest using the real toCapData function.I'm a little surprised that
smallCapsContext
is exported from any package. It was originally written to be used in a constrained context where such limitations aren't relevant. If you're working on acceptance testing, I suggest adding@deprecated
tosmallCapsContext
.