diff --git a/packages/SwingSet/src/blockBuffer.js b/packages/SwingSet/src/blockBuffer.js index 607f5354278b..455ed222de26 100644 --- a/packages/SwingSet/src/blockBuffer.js +++ b/packages/SwingSet/src/blockBuffer.js @@ -43,7 +43,7 @@ export function buildBlockBuffer(hostDB) { keys.delete(k); } for (const k of Array.from(keys).sort()) { - if (start <= k && k < end) { + if ((start === '' || start <= k) && (end === '' || k < end)) { yield k; } } diff --git a/packages/SwingSet/src/kernel/state/storageWrapper.js b/packages/SwingSet/src/kernel/state/storageWrapper.js index 5295ac96d279..c57a72713f04 100644 --- a/packages/SwingSet/src/kernel/state/storageWrapper.js +++ b/packages/SwingSet/src/kernel/state/storageWrapper.js @@ -121,6 +121,8 @@ export function buildCrankBuffer(kvStore) { }, *getKeys(start, end) { + assert.typeof(start, 'string'); + assert.typeof(end, 'string'); const keys = new Set(kvStore.getKeys(start, end)); for (const k of additions.keys()) { keys.add(k); @@ -129,13 +131,14 @@ export function buildCrankBuffer(kvStore) { keys.delete(k); } for (const k of Array.from(keys).sort()) { - if (start <= k && k < end) { + if ((start === '' || start <= k) && (end === '' || k < end)) { yield k; } } }, get(key) { + assert.typeof(key, 'string'); if (additions.has(key)) { return additions.get(key); } @@ -146,11 +149,14 @@ export function buildCrankBuffer(kvStore) { }, set(key, value) { + assert.typeof(key, 'string'); + assert.typeof(value, 'string'); additions.set(key, value); deletions.delete(key); }, delete(key) { + assert.typeof(key, 'string'); additions.delete(key); deletions.add(key); }, diff --git a/packages/SwingSet/test/test-state.js b/packages/SwingSet/test/test-state.js index be9550385a76..3184646d9f3d 100644 --- a/packages/SwingSet/test/test-state.js +++ b/packages/SwingSet/test/test-state.js @@ -47,6 +47,9 @@ function testStorage(t, s, getState, commit) { s.set('foo3', 'f3'); t.deepEqual(Array.from(s.getKeys('foo1', 'foo3')), ['foo1', 'foo2']); t.deepEqual(Array.from(s.getKeys('foo1', 'foo4')), ['foo1', 'foo2', 'foo3']); + t.deepEqual(Array.from(s.getKeys('', '')), ['foo', 'foo1', 'foo2', 'foo3']); + t.deepEqual(Array.from(s.getKeys('foo1', '')), ['foo1', 'foo2', 'foo3']); + t.deepEqual(Array.from(s.getKeys('', 'foo2')), ['foo', 'foo1']); s.delete('foo2'); t.falsy(s.has('foo2')); @@ -250,21 +253,15 @@ function duplicateKeeper(getState) { } test('hostStorage param guards', async t => { - const { kstorage, commitCrank } = buildKeeperStorageInMemory(); - kstorage.set('foo', true); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.set(true, 'foo'); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.has(true); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.getKeys('foo', true); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.getKeys(true, 'foo'); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.get(true); - t.throws(commitCrank, { message: /must be a string/ }); - kstorage.delete(true); - t.throws(commitCrank, { message: /must be a string/ }); + const { kstorage } = buildKeeperStorageInMemory(); + const exp = { message: /true must be a string/ }; + t.throws(() => kstorage.set('foo', true), exp); + t.throws(() => kstorage.set(true, 'foo'), exp); + t.throws(() => kstorage.has(true), exp); + t.throws(() => Array.from(kstorage.getKeys('foo', true)), exp); + t.throws(() => Array.from(kstorage.getKeys(true, 'foo')), exp); + t.throws(() => kstorage.get(true), exp); + t.throws(() => kstorage.delete(true), exp); }); test('kernel state', async t => {