@agoric/swing-store 0.9.2-dev-c6d8a27.0 → 0.9.2-dev-479a1a0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/test/exports.js +99 -0
- package/test/test-import.js +9 -102
- package/test/test-repair-metadata.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/swing-store",
|
|
3
|
-
"version": "0.9.2-dev-
|
|
3
|
+
"version": "0.9.2-dev-479a1a0.0+479a1a0",
|
|
4
4
|
"description": "Persistent storage for SwingSet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"lint:eslint": "eslint ."
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agoric/assert": "0.6.1-dev-
|
|
25
|
-
"@agoric/internal": "0.3.3-dev-
|
|
24
|
+
"@agoric/assert": "0.6.1-dev-479a1a0.0+479a1a0",
|
|
25
|
+
"@agoric/internal": "0.3.3-dev-479a1a0.0+479a1a0",
|
|
26
26
|
"@endo/base64": "^0.2.32",
|
|
27
27
|
"@endo/bundle-source": "^2.5.2",
|
|
28
28
|
"@endo/check-bundle": "^0.2.19",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
],
|
|
46
46
|
"timeout": "2m"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "479a1a02a362144acf30cb9ca956dc05f6cfb5ea"
|
|
49
49
|
}
|
package/test/exports.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { makeB0ID } from './util.js';
|
|
3
|
+
|
|
4
|
+
export const snapshotData = 'snapshot data';
|
|
5
|
+
// this snapHash was computed manually
|
|
6
|
+
export const snapHash =
|
|
7
|
+
'e7dee7266896538616b630a5da40a90e007726a383e005a9c9c5dd0c2daf9329';
|
|
8
|
+
|
|
9
|
+
/** @type {import('../src/bundleStore.js').Bundle} */
|
|
10
|
+
export const bundle0 = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
11
|
+
export const bundle0ID = makeB0ID(bundle0);
|
|
12
|
+
|
|
13
|
+
export function buildData() {
|
|
14
|
+
// build an export manually
|
|
15
|
+
const exportData = new Map();
|
|
16
|
+
const artifacts = new Map();
|
|
17
|
+
|
|
18
|
+
// shadow kvStore
|
|
19
|
+
exportData.set('kv.key1', 'value1');
|
|
20
|
+
|
|
21
|
+
// now add artifacts and metadata in pairs
|
|
22
|
+
|
|
23
|
+
artifacts.set(`bundle.${bundle0ID}`, JSON.stringify(bundle0));
|
|
24
|
+
exportData.set(`bundle.${bundle0ID}`, bundle0ID);
|
|
25
|
+
|
|
26
|
+
const sbase = { vatID: 'v1', hash: snapHash, inUse: 0 };
|
|
27
|
+
const tbase = { vatID: 'v1', startPos: 0, isCurrent: 0, incarnation: 1 };
|
|
28
|
+
const addTS = (key, obj) =>
|
|
29
|
+
exportData.set(key, JSON.stringify({ ...tbase, ...obj }));
|
|
30
|
+
const t0hash =
|
|
31
|
+
'5bee0f44eca02f23eab03703e84ed2647d5d117fed99e1c30a3b424b7f082ab9';
|
|
32
|
+
const t2hash =
|
|
33
|
+
'57152efdd7fdf75c03371d2b4f1088d5bf3eae7fe643babce527ff81df38998c';
|
|
34
|
+
const t5hash =
|
|
35
|
+
'1947001e78e01bd1e773feb22b4ffc530447373b9de9274d5d5fbda3f23dbf2b';
|
|
36
|
+
const t8hash =
|
|
37
|
+
'e6b42c6a3fb94285a93162f25a9fc0145fd4c5bb144917dc572c50ae2d02ee69';
|
|
38
|
+
|
|
39
|
+
addTS(`transcript.v1.0`, { incarnation: 0, endPos: 2, hash: t0hash });
|
|
40
|
+
artifacts.set(`transcript.v1.0.2`, 'start-worker\nshutdown-worker\n');
|
|
41
|
+
|
|
42
|
+
addTS(`transcript.v1.2`, { startPos: 2, endPos: 5, hash: t2hash });
|
|
43
|
+
artifacts.set(
|
|
44
|
+
`transcript.v1.2.5`,
|
|
45
|
+
'start-worker\ndelivery1\nsave-snapshot\n',
|
|
46
|
+
);
|
|
47
|
+
exportData.set(`snapshot.v1.4`, JSON.stringify({ ...sbase, snapPos: 4 }));
|
|
48
|
+
artifacts.set(`snapshot.v1.4`, snapshotData);
|
|
49
|
+
|
|
50
|
+
addTS(`transcript.v1.5`, { startPos: 5, endPos: 8, hash: t5hash });
|
|
51
|
+
artifacts.set(
|
|
52
|
+
'transcript.v1.5.8',
|
|
53
|
+
'load-snapshot\ndelivery2\nsave-snapshot\n',
|
|
54
|
+
);
|
|
55
|
+
exportData.set(
|
|
56
|
+
`snapshot.v1.7`,
|
|
57
|
+
JSON.stringify({ ...sbase, snapPos: 7, inUse: 1 }),
|
|
58
|
+
);
|
|
59
|
+
artifacts.set(`snapshot.v1.7`, snapshotData);
|
|
60
|
+
|
|
61
|
+
artifacts.set('transcript.v1.8.10', 'load-snapshot\ndelivery3\n');
|
|
62
|
+
exportData.set(`snapshot.v1.current`, 'snapshot.v1.7');
|
|
63
|
+
addTS(`transcript.v1.current`, {
|
|
64
|
+
startPos: 8,
|
|
65
|
+
endPos: 10,
|
|
66
|
+
isCurrent: 1,
|
|
67
|
+
hash: t8hash,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return { exportData, artifacts, t0hash, t2hash, t5hash, t8hash };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param { Map<string, string | null> } exportData
|
|
75
|
+
* @param { Map<string, string> } artifacts
|
|
76
|
+
*/
|
|
77
|
+
export function makeExporter(exportData, artifacts) {
|
|
78
|
+
return {
|
|
79
|
+
async *getExportData() {
|
|
80
|
+
for (const [key, value] of exportData.entries()) {
|
|
81
|
+
/** @type { import('../src/exporter.js').KVPair } */
|
|
82
|
+
const pair = [key, value];
|
|
83
|
+
yield pair;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
async *getArtifactNames() {
|
|
87
|
+
for (const name of artifacts.keys()) {
|
|
88
|
+
yield name;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async *getArtifact(name) {
|
|
92
|
+
const data = artifacts.get(name);
|
|
93
|
+
assert(data, `missing artifact ${name}`);
|
|
94
|
+
yield Buffer.from(data);
|
|
95
|
+
},
|
|
96
|
+
// eslint-disable-next-line no-empty-function
|
|
97
|
+
async close() {},
|
|
98
|
+
};
|
|
99
|
+
}
|
package/test/test-import.js
CHANGED
|
@@ -14,7 +14,15 @@ import { decodeBase64 } from '@endo/base64';
|
|
|
14
14
|
import { buffer } from '../src/util.js';
|
|
15
15
|
import { importSwingStore, makeSwingStoreExporter } from '../src/index.js';
|
|
16
16
|
|
|
17
|
-
import { tmpDir
|
|
17
|
+
import { tmpDir } from './util.js';
|
|
18
|
+
import {
|
|
19
|
+
buildData,
|
|
20
|
+
bundle0,
|
|
21
|
+
bundle0ID,
|
|
22
|
+
makeExporter,
|
|
23
|
+
snapHash,
|
|
24
|
+
snapshotData,
|
|
25
|
+
} from './exports.js';
|
|
18
26
|
|
|
19
27
|
const rank = {
|
|
20
28
|
operational: 1,
|
|
@@ -23,15 +31,6 @@ const rank = {
|
|
|
23
31
|
debug: 4,
|
|
24
32
|
};
|
|
25
33
|
|
|
26
|
-
const snapshotData = 'snapshot data';
|
|
27
|
-
// this snapHash was computed manually
|
|
28
|
-
const snapHash =
|
|
29
|
-
'e7dee7266896538616b630a5da40a90e007726a383e005a9c9c5dd0c2daf9329';
|
|
30
|
-
|
|
31
|
-
/** @type {import('../src/bundleStore.js').Bundle} */
|
|
32
|
-
const bundle0 = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
33
|
-
const bundle0ID = makeB0ID(bundle0);
|
|
34
|
-
|
|
35
34
|
function convert(orig) {
|
|
36
35
|
const bundles = Object.fromEntries(
|
|
37
36
|
Object.entries(orig.bundles).map(([bundleID, encBundle]) => {
|
|
@@ -44,38 +43,6 @@ function convert(orig) {
|
|
|
44
43
|
return { ...orig, bundles };
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
/**
|
|
48
|
-
* @typedef { import('../src/exporter').KVPair } KVPair
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param { Map<string, string | null> } exportData
|
|
53
|
-
* @param { Map<string, string> } artifacts
|
|
54
|
-
*/
|
|
55
|
-
export function makeExporter(exportData, artifacts) {
|
|
56
|
-
return {
|
|
57
|
-
async *getExportData() {
|
|
58
|
-
for (const [key, value] of exportData.entries()) {
|
|
59
|
-
/** @type { KVPair } */
|
|
60
|
-
const pair = [key, value];
|
|
61
|
-
yield pair;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
async *getArtifactNames() {
|
|
65
|
-
for (const name of artifacts.keys()) {
|
|
66
|
-
yield name;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
async *getArtifact(name) {
|
|
70
|
-
const data = artifacts.get(name);
|
|
71
|
-
assert(data, `missing artifact ${name}`);
|
|
72
|
-
yield Buffer.from(data);
|
|
73
|
-
},
|
|
74
|
-
// eslint-disable-next-line no-empty-function
|
|
75
|
-
async close() {},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
46
|
test('import empty', async t => {
|
|
80
47
|
const [dbDir, cleanup] = await tmpDir('testdb');
|
|
81
48
|
t.teardown(cleanup);
|
|
@@ -91,66 +58,6 @@ test('import empty', async t => {
|
|
|
91
58
|
});
|
|
92
59
|
});
|
|
93
60
|
|
|
94
|
-
export function buildData() {
|
|
95
|
-
// build an export manually
|
|
96
|
-
const exportData = new Map();
|
|
97
|
-
const artifacts = new Map();
|
|
98
|
-
|
|
99
|
-
// shadow kvStore
|
|
100
|
-
exportData.set('kv.key1', 'value1');
|
|
101
|
-
|
|
102
|
-
// now add artifacts and metadata in pairs
|
|
103
|
-
|
|
104
|
-
artifacts.set(`bundle.${bundle0ID}`, JSON.stringify(bundle0));
|
|
105
|
-
exportData.set(`bundle.${bundle0ID}`, bundle0ID);
|
|
106
|
-
|
|
107
|
-
const sbase = { vatID: 'v1', hash: snapHash, inUse: 0 };
|
|
108
|
-
const tbase = { vatID: 'v1', startPos: 0, isCurrent: 0, incarnation: 1 };
|
|
109
|
-
const addTS = (key, obj) =>
|
|
110
|
-
exportData.set(key, JSON.stringify({ ...tbase, ...obj }));
|
|
111
|
-
const t0hash =
|
|
112
|
-
'5bee0f44eca02f23eab03703e84ed2647d5d117fed99e1c30a3b424b7f082ab9';
|
|
113
|
-
const t2hash =
|
|
114
|
-
'57152efdd7fdf75c03371d2b4f1088d5bf3eae7fe643babce527ff81df38998c';
|
|
115
|
-
const t5hash =
|
|
116
|
-
'1947001e78e01bd1e773feb22b4ffc530447373b9de9274d5d5fbda3f23dbf2b';
|
|
117
|
-
const t8hash =
|
|
118
|
-
'e6b42c6a3fb94285a93162f25a9fc0145fd4c5bb144917dc572c50ae2d02ee69';
|
|
119
|
-
|
|
120
|
-
addTS(`transcript.v1.0`, { incarnation: 0, endPos: 2, hash: t0hash });
|
|
121
|
-
artifacts.set(`transcript.v1.0.2`, 'start-worker\nshutdown-worker\n');
|
|
122
|
-
|
|
123
|
-
addTS(`transcript.v1.2`, { startPos: 2, endPos: 5, hash: t2hash });
|
|
124
|
-
artifacts.set(
|
|
125
|
-
`transcript.v1.2.5`,
|
|
126
|
-
'start-worker\ndelivery1\nsave-snapshot\n',
|
|
127
|
-
);
|
|
128
|
-
exportData.set(`snapshot.v1.4`, JSON.stringify({ ...sbase, snapPos: 4 }));
|
|
129
|
-
artifacts.set(`snapshot.v1.4`, snapshotData);
|
|
130
|
-
|
|
131
|
-
addTS(`transcript.v1.5`, { startPos: 5, endPos: 8, hash: t5hash });
|
|
132
|
-
artifacts.set(
|
|
133
|
-
'transcript.v1.5.8',
|
|
134
|
-
'load-snapshot\ndelivery2\nsave-snapshot\n',
|
|
135
|
-
);
|
|
136
|
-
exportData.set(
|
|
137
|
-
`snapshot.v1.7`,
|
|
138
|
-
JSON.stringify({ ...sbase, snapPos: 7, inUse: 1 }),
|
|
139
|
-
);
|
|
140
|
-
artifacts.set(`snapshot.v1.7`, snapshotData);
|
|
141
|
-
|
|
142
|
-
artifacts.set('transcript.v1.8.10', 'load-snapshot\ndelivery3\n');
|
|
143
|
-
exportData.set(`snapshot.v1.current`, 'snapshot.v1.7');
|
|
144
|
-
addTS(`transcript.v1.current`, {
|
|
145
|
-
startPos: 8,
|
|
146
|
-
endPos: 10,
|
|
147
|
-
isCurrent: 1,
|
|
148
|
-
hash: t8hash,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return { exportData, artifacts, t0hash, t2hash, t5hash, t8hash };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
61
|
const importTest = test.macro(async (t, mode) => {
|
|
155
62
|
/** @typedef {import('../src/internal.js').ArtifactMode} ArtifactMode */
|
|
156
63
|
const artifactMode = /** @type {ArtifactMode} */ (mode);
|
|
@@ -8,7 +8,7 @@ import sqlite3 from 'better-sqlite3';
|
|
|
8
8
|
|
|
9
9
|
import { importSwingStore } from '../src/index.js';
|
|
10
10
|
|
|
11
|
-
import { makeExporter, buildData } from './
|
|
11
|
+
import { makeExporter, buildData } from './exports.js';
|
|
12
12
|
import { tmpDir } from './util.js';
|
|
13
13
|
|
|
14
14
|
test('repair metadata', async t => {
|