Skip to content

Commit

Permalink
test(internal): clarify fake vstorage append
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Feb 7, 2025
1 parent 83f9271 commit 418814c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/internal/src/storage-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { eventLoopIteration } from './testing-utils.js';

/**
* @import {TotalMap} from './types.js';
* @import {Marshaller, StorageEntry, StorageMessage, StorageNode} from './lib-chainStorage.js';
* @import {Marshaller, StorageEntry, StorageMessage, StorageNode, StreamCell} from './lib-chainStorage.js';
*/

const trace = makeTracer('StorTU', false);
Expand Down Expand Up @@ -174,8 +174,10 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
const newEntries = message.args;
for (const [key, value] of newEntries) {
value != null || Fail`attempt to append with no value`;
// In the absence of block boundaries, everything goes in a single StreamCell.
const oldVal = data.get(key);

/** @type {string | undefined} */
let oldVal = data.get(key);
/** @type {StreamCell | undefined} */
let streamCell;
if (oldVal != null) {
try {
Expand All @@ -184,14 +186,20 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
} catch (_err) {
streamCell = undefined;
}
// StreamCells reset at block boundaries.
if (
streamCell &&
Number(streamCell.blockHeight) !== currentBlockHeight
) {
streamCell = undefined;
oldVal = undefined;
}
}
if (
streamCell === undefined ||
Number(streamCell.blockHeight) !== currentBlockHeight
) {

if (streamCell === undefined) {
streamCell = {
blockHeight: String(currentBlockHeight),
values: !streamCell && oldVal != null ? [oldVal] : [],
values: oldVal != null ? [oldVal] : [],
};
}
streamCell.values.push(value);
Expand Down

0 comments on commit 418814c

Please sign in to comment.