-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve keysPaged * use db * update test * lint * cleanup
- Loading branch information
1 parent
31ecd6d
commit 345803f
Showing
17 changed files
with
584 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ dist | |
*.sqlite | ||
*.sqlite-journal | ||
*.wasm | ||
!packages/e2e/blobs/*.wasm | ||
*.db | ||
*.sqlite-shm | ||
*.sqlite-wal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
import { Api } from '../api.js' | ||
import { RemoteStorageLayer, StorageLayer, StorageValueKind } from './storage-layer.js' | ||
import { describe, expect, it, vi } from 'vitest' | ||
import _ from 'lodash' | ||
|
||
describe('getKeysPaged', () => { | ||
const hash = '0x1111111111111111111111111111111111111111111111111111111111111111' | ||
|
||
const allKeys = [ | ||
'0x0000000000000000000000000000000000000000000000000000000000000000_00', | ||
'0x0000000000000000000000000000000000000000000000000000000000000000_03', | ||
'0x0000000000000000000000000000000000000000000000000000000000000000_04', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_01', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_21', | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_23', | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_26', | ||
] | ||
|
||
Api.prototype['getKeysPaged'] = vi.fn(async (prefix, pageSize, startKey) => { | ||
const withPrefix = allKeys.filter((k) => k.startsWith(prefix) && k > startKey) | ||
const result = withPrefix.slice(0, pageSize) | ||
return result | ||
}) | ||
const mockApi = new Api(undefined!) | ||
|
||
const remoteLayer = new RemoteStorageLayer(mockApi, hash, undefined) | ||
const storageLayer = new StorageLayer(remoteLayer) | ||
|
||
it('mocked api works', async () => { | ||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
1, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
hash, | ||
), | ||
).toEqual(['0x1111111111111111111111111111111111111111111111111111111111111111_01']) | ||
|
||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x2222222222222222222222222222222222222222222222222222222222222222', | ||
4, | ||
'0x2222222222222222222222222222222222222222222222222222222222222222', | ||
hash, | ||
), | ||
).toEqual([ | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_21', | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_23', | ||
'0x2222222222222222222222222222222222222222222222222222222222222222_26', | ||
]) | ||
|
||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
hash, | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
2, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_04', | ||
hash, | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
2, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
hash, | ||
), | ||
).toEqual([]) | ||
}) | ||
|
||
it('remote layer works', async () => { | ||
expect( | ||
await remoteLayer.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
3, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_01', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
]) | ||
|
||
expect( | ||
await remoteLayer.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
}) | ||
|
||
it('storage layer works', async () => { | ||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
1, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
hash, | ||
), | ||
).toEqual(['0x1111111111111111111111111111111111111111111111111111111111111111_01']) | ||
|
||
expect( | ||
await mockApi.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
hash, | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
}) | ||
|
||
it('updated values', async () => { | ||
const layer2 = new StorageLayer(storageLayer) | ||
layer2.setAll([ | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_00', '0x00'], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_04', '0x04'], | ||
]) | ||
expect( | ||
await layer2.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_04', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
expect( | ||
await layer2.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_00', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_01', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_04', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
expect( | ||
await layer2.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_04', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
expect( | ||
await layer2.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
), | ||
).toEqual([]) | ||
|
||
const layer3 = new StorageLayer(layer2) | ||
layer3.setAll([ | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_03', '0x03'], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_04', null], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_06', '0x06'], | ||
]) | ||
|
||
expect( | ||
await layer3.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_03', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_06', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
]) | ||
|
||
const layer4 = new StorageLayer(layer3) | ||
layer4.setAll([ | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_03', null], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_04', '0x04'], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_06', null], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_08', '0x08'], | ||
]) | ||
|
||
expect( | ||
await layer4.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_02', | ||
), | ||
).toEqual([ | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_04', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_07', | ||
'0x1111111111111111111111111111111111111111111111111111111111111111_08', | ||
]) | ||
|
||
const layer5 = new StorageLayer(layer4) | ||
layer5.setAll([ | ||
['0x1111111111111111111111111111111111111111111111111111111111111111', StorageValueKind.DeletedPrefix], | ||
['0x1111111111111111111111111111111111111111111111111111111111111111_09', '0x09'], | ||
]) | ||
expect( | ||
await layer5.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
), | ||
).toEqual(['0x1111111111111111111111111111111111111111111111111111111111111111_09']) | ||
|
||
const layer6 = new StorageLayer(layer5) | ||
layer6.setAll([ | ||
['0x1111111111111111111111111111111111111111111111111111111111111111', StorageValueKind.DeletedPrefix], | ||
]) | ||
expect( | ||
await layer6.getKeysPaged( | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
10, | ||
'0x1111111111111111111111111111111111111111111111111111111111111111', | ||
), | ||
).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.