@fireproof/core-test 0.23.0 → 0.23.1-dev-issue-1057
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/blockstore/interceptor-gateway.test.js.map +1 -1
- package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
- package/blockstore/keyed-crypto.test.js.map +1 -1
- package/blockstore/loader.test.js.map +1 -1
- package/blockstore/standalone.test.js.map +1 -1
- package/blockstore/store.test.js.map +1 -1
- package/blockstore/transaction.test.js.map +1 -1
- package/fireproof/all-gateway.test.js.map +1 -1
- package/fireproof/attachable.test.js.map +1 -1
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js.map +1 -1
- package/fireproof/charwise-boolean.test.js.map +1 -1
- package/fireproof/compact-strategy.test.js.map +1 -1
- package/fireproof/concurrent.test.js.map +1 -1
- package/fireproof/crdt.test.js.map +1 -1
- package/fireproof/database.test.js.map +1 -1
- package/fireproof/deleted-docs-handling.test.js.map +1 -1
- package/fireproof/fireproof.test.fixture.js.map +1 -1
- package/fireproof/fireproof.test.js.map +1 -1
- package/fireproof/hello.test.js.map +1 -1
- package/fireproof/indexer.test.js.map +1 -1
- package/fireproof/multiple-ledger.test.js.map +1 -1
- package/fireproof/query-docs.test.js.map +1 -1
- package/fireproof/query-limit-issue.test.js.map +1 -1
- package/fireproof/query-property-inconsistency.test.js.map +1 -1
- package/fireproof/query-result-properties.test.js.map +1 -1
- package/fireproof/stable-cid.test.js.map +1 -1
- package/fireproof/utils.test.js.map +1 -1
- package/gateway/file/loader-config.test.js.map +1 -1
- package/gateway/indexeddb/create-db-on-write.test.js.map +1 -1
- package/gateway/indexeddb/loader-config.test.js.map +1 -1
- package/global-setup.js.map +1 -1
- package/helpers.js.map +1 -1
- package/package.json +19 -19
- package/protocols/cloud/msger.test.js.map +1 -1
- package/runtime/fp-envelope-serialize.test.js.map +1 -1
- package/runtime/key-bag.test.js.map +1 -1
- package/runtime/meta-key-hack.test.js.map +1 -1
- package/setup.file.js.map +1 -1
- package/setup.indexeddb.js.map +1 -1
- package/setup.memory.js.map +1 -1
- package/vitest.config.js.map +1 -1
- package/vitest.file.config.js.map +1 -1
- package/vitest.indexeddb.config.js.map +1 -1
- package/vitest.memory.config.js.map +1 -1
- package/blockstore/fp-envelope.test.ts-off +0 -65
- package/blockstore/fragment-gateway.test.ts-off +0 -106
- package/blockstore/interceptor-gateway.test.ts +0 -259
- package/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -134
- package/blockstore/keyed-crypto.test.ts +0 -381
- package/blockstore/loader.test.ts +0 -313
- package/blockstore/standalone.test.ts +0 -156
- package/blockstore/store.test.ts +0 -199
- package/blockstore/transaction.test.ts +0 -132
- package/fireproof/all-gateway.test.ts +0 -477
- package/fireproof/attachable.test.ts +0 -677
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
- package/fireproof/charwise-boolean.test.ts +0 -68
- package/fireproof/compact-strategy.test.ts +0 -40
- package/fireproof/concurrent.test.ts +0 -37
- package/fireproof/crdt.test.ts +0 -572
- package/fireproof/database.test.ts +0 -772
- package/fireproof/deleted-docs-handling.test.ts +0 -112
- package/fireproof/fireproof.test.fixture.ts +0 -133
- package/fireproof/fireproof.test.ts +0 -767
- package/fireproof/hello.test.ts +0 -75
- package/fireproof/indexer.test.ts +0 -459
- package/fireproof/multiple-ledger.test.ts +0 -67
- package/fireproof/query-docs.test.ts +0 -117
- package/fireproof/query-limit-issue.test.ts +0 -147
- package/fireproof/query-property-inconsistency.test.ts +0 -90
- package/fireproof/query-result-properties.test.ts +0 -43
- package/fireproof/stable-cid.test.ts +0 -72
- package/fireproof/utils.test.ts +0 -137
- package/gateway/file/loader-config.test.ts +0 -309
- package/gateway/indexeddb/create-db-on-write.test.ts +0 -202
- package/gateway/indexeddb/loader-config.test.ts +0 -80
- package/global-setup.ts +0 -11
- package/helpers.ts +0 -177
- package/protocols/cloud/msger.test.ts +0 -559
- package/runtime/fp-envelope-serialize.test.ts +0 -266
- package/runtime/key-bag.test.ts +0 -243
- package/runtime/meta-key-hack.test.ts +0 -103
- package/setup.file.ts +0 -1
- package/setup.indexeddb.ts +0 -0
- package/setup.memory.ts +0 -2
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -8
- package/vitest.file.config.ts +0 -11
- package/vitest.indexeddb.config.ts +0 -34
- package/vitest.memory.config.ts +0 -24
package/fireproof/crdt.test.ts
DELETED
|
@@ -1,572 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CRDT,
|
|
3
|
-
defaultWriteQueueOpts,
|
|
4
|
-
LedgerOpts,
|
|
5
|
-
toStoreURIRuntime,
|
|
6
|
-
CRDTImpl,
|
|
7
|
-
CRDTMeta,
|
|
8
|
-
DocValue,
|
|
9
|
-
Index,
|
|
10
|
-
index,
|
|
11
|
-
} from "@fireproof/core";
|
|
12
|
-
import { tracer } from "../helpers.js";
|
|
13
|
-
import { AppContext } from "@adviser/cement";
|
|
14
|
-
import { ensureSuperThis } from "@fireproof/core-runtime";
|
|
15
|
-
import { describe, afterEach, beforeEach, it, expect, assert } from "vitest";
|
|
16
|
-
import { ensureStoreEnDeFile, Loader, EncryptedBlockstore, parseCarFile } from "@fireproof/core-blockstore";
|
|
17
|
-
import { defaultKeyBagOpts } from "@fireproof/core-keybag";
|
|
18
|
-
import { AnyBlock, isCarBlockItemReady } from "@fireproof/core-types-blockstore";
|
|
19
|
-
|
|
20
|
-
describe("Fresh crdt", function () {
|
|
21
|
-
let crdt: CRDT;
|
|
22
|
-
const sthis = ensureSuperThis();
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await crdt.close();
|
|
25
|
-
await crdt.destroy();
|
|
26
|
-
});
|
|
27
|
-
beforeEach(async () => {
|
|
28
|
-
await sthis.start();
|
|
29
|
-
const dbOpts: LedgerOpts = {
|
|
30
|
-
name: "test-crdt",
|
|
31
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
32
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
33
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
|
34
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
35
|
-
ctx: new AppContext(),
|
|
36
|
-
tracer,
|
|
37
|
-
};
|
|
38
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
39
|
-
await crdt.ready();
|
|
40
|
-
});
|
|
41
|
-
it("should have an empty head", async () => {
|
|
42
|
-
const head = crdt.clock.head;
|
|
43
|
-
expect(head.length).toBe(0);
|
|
44
|
-
});
|
|
45
|
-
it("should accept put and return results", async () => {
|
|
46
|
-
const didPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
|
|
47
|
-
const head = didPut.head;
|
|
48
|
-
expect(head.length).toBe(1);
|
|
49
|
-
});
|
|
50
|
-
it("should accept multi-put and return results", async () => {
|
|
51
|
-
const didPut = await crdt.bulk([
|
|
52
|
-
{ id: "ace", value: { points: 11 } },
|
|
53
|
-
{ id: "king", value: { points: 10 } },
|
|
54
|
-
]);
|
|
55
|
-
const head = didPut.head;
|
|
56
|
-
expect(head.length).toBe(1);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("CRDT with one record", function () {
|
|
61
|
-
interface CRDTTestType {
|
|
62
|
-
readonly hello: string;
|
|
63
|
-
readonly nice: string;
|
|
64
|
-
}
|
|
65
|
-
let crdt: CRDT;
|
|
66
|
-
let firstPut: CRDTMeta;
|
|
67
|
-
const sthis = ensureSuperThis();
|
|
68
|
-
|
|
69
|
-
afterEach(async () => {
|
|
70
|
-
await crdt.close();
|
|
71
|
-
await crdt.destroy();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
beforeEach(async () => {
|
|
75
|
-
await sthis.start();
|
|
76
|
-
const dbOpts: LedgerOpts = {
|
|
77
|
-
name: "test-crdt",
|
|
78
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
79
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
80
|
-
storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId().str}`),
|
|
81
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
82
|
-
ctx: new AppContext(),
|
|
83
|
-
tracer,
|
|
84
|
-
};
|
|
85
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
86
|
-
firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
|
|
87
|
-
});
|
|
88
|
-
it("should have a one-element head", async () => {
|
|
89
|
-
const head = crdt.clock.head;
|
|
90
|
-
expect(head.length).toBe(1);
|
|
91
|
-
});
|
|
92
|
-
it("should return the head", async () => {
|
|
93
|
-
expect(firstPut.head.length).toBe(1);
|
|
94
|
-
});
|
|
95
|
-
it("return the record on get", async () => {
|
|
96
|
-
const got = (await crdt.get("hello")) as DocValue<CRDTTestType>;
|
|
97
|
-
expect(got).toBeTruthy();
|
|
98
|
-
expect(got.doc.hello).toBe("world");
|
|
99
|
-
});
|
|
100
|
-
it("should accept another put and return results", async () => {
|
|
101
|
-
const didPut = await crdt.bulk([{ id: "nice", value: { nice: "data" } }]);
|
|
102
|
-
const head = didPut.head;
|
|
103
|
-
expect(head.length).toBe(1);
|
|
104
|
-
const { doc } = (await crdt.get("nice")) as DocValue<CRDTTestType>;
|
|
105
|
-
expect(doc.nice).toBe("data");
|
|
106
|
-
});
|
|
107
|
-
it("should allow for a delete", async () => {
|
|
108
|
-
const didDel = await crdt.bulk([{ id: "hello", del: true }]);
|
|
109
|
-
expect(didDel.head).toBeTruthy();
|
|
110
|
-
const got = await crdt.get("hello");
|
|
111
|
-
expect(got).toBeFalsy();
|
|
112
|
-
});
|
|
113
|
-
it("should offer changes", async () => {
|
|
114
|
-
const { result } = await crdt.changes<Partial<CRDTTestType>>([]);
|
|
115
|
-
expect(result.length).toBe(1);
|
|
116
|
-
expect(result[0].id).toBe("hello");
|
|
117
|
-
expect(result[0].value?.hello).toBe("world");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("CRDT with a multi-write", function () {
|
|
122
|
-
interface CRDTTestType {
|
|
123
|
-
readonly points: number;
|
|
124
|
-
}
|
|
125
|
-
let crdt: CRDT;
|
|
126
|
-
let firstPut: CRDTMeta;
|
|
127
|
-
const sthis = ensureSuperThis();
|
|
128
|
-
|
|
129
|
-
afterEach(async () => {
|
|
130
|
-
await crdt.close();
|
|
131
|
-
await crdt.destroy();
|
|
132
|
-
});
|
|
133
|
-
beforeEach(async () => {
|
|
134
|
-
await sthis.start();
|
|
135
|
-
const dbOpts: LedgerOpts = {
|
|
136
|
-
name: "test-crdt",
|
|
137
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
138
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
139
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
|
140
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
141
|
-
ctx: new AppContext(),
|
|
142
|
-
tracer,
|
|
143
|
-
};
|
|
144
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
145
|
-
firstPut = await crdt.bulk([
|
|
146
|
-
{ id: "ace", value: { points: 11 } },
|
|
147
|
-
{ id: "king", value: { points: 10 } },
|
|
148
|
-
]);
|
|
149
|
-
});
|
|
150
|
-
it("should have a one-element head", async () => {
|
|
151
|
-
const head = crdt.clock.head;
|
|
152
|
-
expect(head.length).toBe(1);
|
|
153
|
-
expect(firstPut.head.length).toBe(1);
|
|
154
|
-
});
|
|
155
|
-
it("return the records on get", async () => {
|
|
156
|
-
const { doc } = (await crdt.get("ace")) as DocValue<CRDTTestType>;
|
|
157
|
-
expect(doc.points).toBe(11);
|
|
158
|
-
|
|
159
|
-
const got2 = (await crdt.get("king")) as DocValue<CRDTTestType>;
|
|
160
|
-
expect(got2).toBeTruthy();
|
|
161
|
-
expect(got2.doc.points).toBe(10);
|
|
162
|
-
});
|
|
163
|
-
it("should accept another put and return results", async () => {
|
|
164
|
-
const didPut = await crdt.bulk([{ id: "queen", value: { points: 10 } }]);
|
|
165
|
-
const head = didPut.head;
|
|
166
|
-
expect(head.length).toBe(1);
|
|
167
|
-
const got = (await crdt.get("queen")) as DocValue<CRDTTestType>;
|
|
168
|
-
expect(got).toBeTruthy();
|
|
169
|
-
expect(got.doc.points).toBe(10);
|
|
170
|
-
});
|
|
171
|
-
it("should offer changes", async () => {
|
|
172
|
-
const { result } = await crdt.changes<CRDTTestType>([]);
|
|
173
|
-
expect(result.length).toBe(2);
|
|
174
|
-
expect(result[0].id).toBe("ace");
|
|
175
|
-
expect(result[0].value?.points).toBe(11);
|
|
176
|
-
expect(result[1].id).toBe("king");
|
|
177
|
-
});
|
|
178
|
-
it("should offer changes since", async () => {
|
|
179
|
-
/** @type {CRDTMeta} */
|
|
180
|
-
const secondPut = await crdt.bulk([
|
|
181
|
-
{ id: "queen", value: { points: 10 } },
|
|
182
|
-
{ id: "jack", value: { points: 10 } },
|
|
183
|
-
]);
|
|
184
|
-
expect(secondPut.head).toBeTruthy();
|
|
185
|
-
const { result: r2, head: h2 } = await crdt.changes<CRDTTestType>();
|
|
186
|
-
expect(r2.length).toBe(4);
|
|
187
|
-
const { result: r3 } = await crdt.changes(firstPut.head);
|
|
188
|
-
expect(r3.length).toBe(2);
|
|
189
|
-
const { result: r4 } = await crdt.changes(h2);
|
|
190
|
-
expect(r4.length).toBe(0);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
interface CRDTTestType {
|
|
195
|
-
readonly points: number;
|
|
196
|
-
}
|
|
197
|
-
describe("CRDT with two multi-writes", function () {
|
|
198
|
-
let crdt: CRDT;
|
|
199
|
-
let firstPut: CRDTMeta;
|
|
200
|
-
let secondPut: CRDTMeta;
|
|
201
|
-
const sthis = ensureSuperThis();
|
|
202
|
-
afterEach(async () => {
|
|
203
|
-
await crdt.close();
|
|
204
|
-
await crdt.destroy();
|
|
205
|
-
});
|
|
206
|
-
beforeEach(async () => {
|
|
207
|
-
await sthis.start();
|
|
208
|
-
const dbOpts: LedgerOpts = {
|
|
209
|
-
name: "test-crdt",
|
|
210
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
211
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
212
|
-
storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId().str}`),
|
|
213
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
214
|
-
ctx: new AppContext(),
|
|
215
|
-
tracer,
|
|
216
|
-
};
|
|
217
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
218
|
-
firstPut = await crdt.bulk([
|
|
219
|
-
{ id: "ace", value: { points: 11 } },
|
|
220
|
-
{ id: "king", value: { points: 10 } },
|
|
221
|
-
]);
|
|
222
|
-
secondPut = await crdt.bulk([
|
|
223
|
-
{ id: "queen", value: { points: 10 } },
|
|
224
|
-
{ id: "jack", value: { points: 10 } },
|
|
225
|
-
]);
|
|
226
|
-
});
|
|
227
|
-
it("should have a one-element head", async () => {
|
|
228
|
-
const head = crdt.clock.head;
|
|
229
|
-
expect(head.length).toBe(1);
|
|
230
|
-
expect(firstPut.head.length).toBe(1);
|
|
231
|
-
expect(secondPut.head.length).toBe(1);
|
|
232
|
-
expect(firstPut.head[0]).not.toBe(secondPut.head[0]);
|
|
233
|
-
});
|
|
234
|
-
it("return the records on get", async () => {
|
|
235
|
-
const ret = await crdt.get("ace");
|
|
236
|
-
expect(ret).not.toBeNull();
|
|
237
|
-
const { doc } = ret as DocValue<CRDTTestType>;
|
|
238
|
-
expect(doc.points).toBe(11);
|
|
239
|
-
|
|
240
|
-
for (const key of ["king", "queen", "jack"]) {
|
|
241
|
-
const { doc } = (await crdt.get(key)) as DocValue<CRDTTestType>;
|
|
242
|
-
expect(doc.points).toBe(10);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
it("should offer changes", async () => {
|
|
246
|
-
const { result } = await crdt.changes<CRDTTestType>();
|
|
247
|
-
expect(result.length).toBe(4);
|
|
248
|
-
expect(result[0].id).toBe("ace");
|
|
249
|
-
expect(result[0].value?.points).toBe(11);
|
|
250
|
-
expect(result[1].id).toBe("king");
|
|
251
|
-
expect(result[2].id).toBe("queen");
|
|
252
|
-
expect(result[3].id).toBe("jack");
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe("Compact a named CRDT with writes", function () {
|
|
257
|
-
let crdt: CRDT;
|
|
258
|
-
const sthis = ensureSuperThis();
|
|
259
|
-
afterEach(async () => {
|
|
260
|
-
await crdt.close();
|
|
261
|
-
await crdt.destroy();
|
|
262
|
-
});
|
|
263
|
-
beforeEach(async () => {
|
|
264
|
-
await sthis.start();
|
|
265
|
-
// sthis.env.set(
|
|
266
|
-
// "FP_STORAGE_URL",
|
|
267
|
-
// BuildURI.from(sthis.env.get("FP_STORAGE_URL")).setParam(PARAM.STORE_KEY, "insecure").toString(),
|
|
268
|
-
// );
|
|
269
|
-
// console.log("FP_STORAGE_URL", sthis.env.get("FP_STORAGE_URL"));
|
|
270
|
-
const dbOpts: LedgerOpts = {
|
|
271
|
-
name: "test-crdt",
|
|
272
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
273
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
274
|
-
storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction-${sthis.nextId().str}`),
|
|
275
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
276
|
-
ctx: new AppContext(),
|
|
277
|
-
tracer,
|
|
278
|
-
};
|
|
279
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
280
|
-
for (let i = 0; i < 10; i++) {
|
|
281
|
-
const bulk = [
|
|
282
|
-
{ id: "ace", value: { points: 11 } },
|
|
283
|
-
{ id: "king", value: { points: 10 } },
|
|
284
|
-
];
|
|
285
|
-
await crdt.bulk(bulk);
|
|
286
|
-
}
|
|
287
|
-
// await sleep(1000);
|
|
288
|
-
});
|
|
289
|
-
it("has data", async () => {
|
|
290
|
-
const got = (await crdt.get("ace")) as DocValue<CRDTTestType>;
|
|
291
|
-
expect(got.doc).toBeTruthy();
|
|
292
|
-
expect(got.doc.points).toBe(11);
|
|
293
|
-
});
|
|
294
|
-
it("should start with blocks", async () => {
|
|
295
|
-
const blz: AnyBlock[] = [];
|
|
296
|
-
for await (const blk of crdt.blockstore.entries()) {
|
|
297
|
-
blz.push(blk);
|
|
298
|
-
}
|
|
299
|
-
// expect(blz.map((i) => sthis.txt.decode(i.bytes) + "\n=================\n")).toEqual([
|
|
300
|
-
//
|
|
301
|
-
// ])
|
|
302
|
-
expect(blz.map((i) => i.cid.toString())).toEqual([
|
|
303
|
-
"bafyreicuomyooryb747esregkhooc4phr656tocowyo6dwcocq22h7qdhu",
|
|
304
|
-
"bafyreig5jhovaiocwk3vfafzdspgtwinftjygyghjzigkc554muhdmp5ba",
|
|
305
|
-
"bafyreiegj7yumreue7llzqroebigscedyzrkeir3zneg5q7zia77itowy4",
|
|
306
|
-
"bafyreihobual6tt3hgdfve4h5uzt7fey62se3dfecbuj6f4ndkkwquke4u",
|
|
307
|
-
"bafyreibqqcs3r6mhpr3525na6jtqnjcf6dmgskk27x4a2jb3r2qveqgexm",
|
|
308
|
-
"bafyreibr7udlekt4xgavn54i4zfsdlrmi4r76iq6gh3bdq4xh52px6to3e",
|
|
309
|
-
"bafyreidg2eyas62nvwvi6ggq44tsldj4kwmupyk2xtwmxbwf77g3noqtp4",
|
|
310
|
-
"bafyreigbzxzj4eh7ljfvzlc7smdextuuk7gvep5mpnb3igaj5r2qzjlfye",
|
|
311
|
-
"bafyreicr7takuntpofvk52xerdcoiq7wdt73ef54acoya2geig2ywkqlsi",
|
|
312
|
-
"bafyreihmmgm5sufvnsgjic4fbizkdbajpy2yrklyieadstbtegfr4qko2m",
|
|
313
|
-
"bafyreibnu44uyu3ggqwgmnlxodw6dyta3qg7e5qldsjq7bkbv452ova6oa",
|
|
314
|
-
"bafyreieh4nlzg7enfczmj4z7uxvgrnykh7ajw7crxjrncqfrzj47ip6t6m",
|
|
315
|
-
"bafyreigqqrccymfvvdfetjd2twsdzjwxbb6cn6tedqntvpgp5vboky2ol4",
|
|
316
|
-
"bafyreid6kkobhgdmce2cyroepyos3jwumtdrfuzi6suldlxzjsgagc3fvi",
|
|
317
|
-
"bafyreibo2d56wo5ldey24hygtmsfhdxsqgdpmtne5oitehxjppipru33ma",
|
|
318
|
-
"bafyreifjv6havcza3is7w6ii345f5akba7e34xqcxwoqozmsnihkivykum",
|
|
319
|
-
"bafyreig6eroqeg3y7am4bnrun3yzbvd656epzxjyivdpzwqo3j3vpuwysi",
|
|
320
|
-
"bafyreibpsnfsducp7refempcyqnte54j7ueh4ysdlabggihclbddfnuzxm",
|
|
321
|
-
"bafyreicfkkygbzz5zawr3xbfah2gy3e7w4opzysew4tini7xnksujj4gf4",
|
|
322
|
-
"bafyreiddjm5xkpfa5vmyhoj5opocrwo6zbdnmqyhouc5ttfxoilmaf25bm",
|
|
323
|
-
"bafyreibp7vlgfexaknaoxpemnnwadyfa4cfuc3euzlkslskks2n44wwspu",
|
|
324
|
-
"bafyreichwj7izzpxeyjkhwl26pq45m4hnhxcgzqfk5ffeqkscafleiwfzm",
|
|
325
|
-
"bafyreidzjjqou36q2ghqdue4buq7536w4sl5aejni6tw25mzsusl26gtwu",
|
|
326
|
-
"bafyreibxibqhi6wh5klrje7ne4htffeqyyqfd6y7x2no6wnhid4nixizau",
|
|
327
|
-
"bafyreidnvv4mwvweup5w52ddre2sl4syhvczm6ejqsmuekajowdl2cf2q4",
|
|
328
|
-
"bafyreihh6nbfbhgkf5lz7hhsscjgiquw426rxzr3fprbgonekzmyvirrhe",
|
|
329
|
-
"bafyreiejg3twlaxr7gfvvhtxrhvwaydytdv4guidmtvaz5dskm6gp73ryi",
|
|
330
|
-
"bafyreiblui55o25dopc5faol3umsnuohb5carto7tot4kicnkfc37he4h4",
|
|
331
|
-
]);
|
|
332
|
-
// expect(blz.length).toBe(13);
|
|
333
|
-
}, 1000000);
|
|
334
|
-
it("should start with changes", async () => {
|
|
335
|
-
const { result } = await crdt.changes();
|
|
336
|
-
expect(result.length).toBe(2);
|
|
337
|
-
expect(result[0].id).toBe("ace");
|
|
338
|
-
});
|
|
339
|
-
it.skip("should have fewer blocks after compact", async () => {
|
|
340
|
-
await crdt.compact();
|
|
341
|
-
const blz: AnyBlock[] = [];
|
|
342
|
-
for await (const blk of crdt.blockstore.entries()) {
|
|
343
|
-
blz.push(blk);
|
|
344
|
-
}
|
|
345
|
-
expect(blz.length).toBe(23);
|
|
346
|
-
});
|
|
347
|
-
it("should have data after compact", async () => {
|
|
348
|
-
await crdt.compact();
|
|
349
|
-
const got = (await crdt.get("ace")) as DocValue<CRDTTestType>;
|
|
350
|
-
expect(got.doc).toBeTruthy();
|
|
351
|
-
expect(got.doc.points).toBe(11);
|
|
352
|
-
});
|
|
353
|
-
it("should have changes after compact", async () => {
|
|
354
|
-
const chs = await crdt.changes();
|
|
355
|
-
expect(chs.result[0].id).toBe("ace");
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
describe("CRDT with an index", function () {
|
|
360
|
-
let crdt: CRDT;
|
|
361
|
-
let idx: Index<CRDTTestType, number>;
|
|
362
|
-
const sthis = ensureSuperThis();
|
|
363
|
-
afterEach(async () => {
|
|
364
|
-
await crdt.close();
|
|
365
|
-
await crdt.destroy();
|
|
366
|
-
});
|
|
367
|
-
beforeEach(async () => {
|
|
368
|
-
await sthis.start();
|
|
369
|
-
const dbOpts: LedgerOpts = {
|
|
370
|
-
name: "test-crdt",
|
|
371
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
372
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
373
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
|
374
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
375
|
-
ctx: new AppContext(),
|
|
376
|
-
tracer,
|
|
377
|
-
};
|
|
378
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
379
|
-
await crdt.bulk([
|
|
380
|
-
{ id: "ace", value: { points: 11 } },
|
|
381
|
-
{ id: "king", value: { points: 10 } },
|
|
382
|
-
]);
|
|
383
|
-
idx = await index<CRDTTestType, number>(crdt, "points");
|
|
384
|
-
});
|
|
385
|
-
it("should query the data", async () => {
|
|
386
|
-
const got = await idx.query({ range: [9, 12] });
|
|
387
|
-
expect(got.rows.length).toBe(2);
|
|
388
|
-
expect(got.rows[0].id).toBe("king");
|
|
389
|
-
expect(got.rows[0].key).toBe(10);
|
|
390
|
-
});
|
|
391
|
-
it("should register the index", async () => {
|
|
392
|
-
const rIdx = await index<CRDTTestType, number>(crdt, "points");
|
|
393
|
-
expect(rIdx).toBeTruthy();
|
|
394
|
-
expect(rIdx.name).toBe("points");
|
|
395
|
-
const got = await rIdx.query({ range: [9, 12] });
|
|
396
|
-
expect(got.rows.length).toBe(2);
|
|
397
|
-
expect(got.rows[0].id).toBe("king");
|
|
398
|
-
expect(got.rows[0].key).toBe(10);
|
|
399
|
-
});
|
|
400
|
-
it.skip("creating a different index with same name should not work", async () => {
|
|
401
|
-
const e = await index(crdt, "points", (doc) => doc._id)
|
|
402
|
-
.query()
|
|
403
|
-
.catch((err) => err);
|
|
404
|
-
expect(e.message).toMatch(/cannot apply/);
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
describe("Loader with a committed transaction", function () {
|
|
409
|
-
let loader: Loader;
|
|
410
|
-
let blockstore: EncryptedBlockstore;
|
|
411
|
-
let crdt: CRDT;
|
|
412
|
-
let done: CRDTMeta;
|
|
413
|
-
const dbname = "test-loader";
|
|
414
|
-
const sthis = ensureSuperThis();
|
|
415
|
-
afterEach(async () => {
|
|
416
|
-
await crdt.close();
|
|
417
|
-
await crdt.destroy();
|
|
418
|
-
});
|
|
419
|
-
beforeEach(async () => {
|
|
420
|
-
await sthis.start();
|
|
421
|
-
const dbOpts: LedgerOpts = {
|
|
422
|
-
name: "test-crdt",
|
|
423
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
424
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
425
|
-
storeUrls: toStoreURIRuntime(sthis, dbname),
|
|
426
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
427
|
-
ctx: new AppContext(),
|
|
428
|
-
tracer,
|
|
429
|
-
};
|
|
430
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
431
|
-
blockstore = crdt.blockstore as EncryptedBlockstore;
|
|
432
|
-
expect(blockstore.loader).toBeTruthy();
|
|
433
|
-
loader = blockstore.loader as Loader;
|
|
434
|
-
done = await crdt.bulk([{ id: "foo", value: { foo: "bar" } }]);
|
|
435
|
-
});
|
|
436
|
-
// it("should have a name", function () {
|
|
437
|
-
// expect(loader.ebOpts.storeUrls).toEqual({
|
|
438
|
-
// data: "file://./dist/fp-dir-file?name=test-loader&store=data&storekey=%40test-loader-data%40&suffix=.car&urlGen=fromEnv",
|
|
439
|
-
// file: "file://./dist/fp-dir-file?name=test-loader&store=data&storekey=%40test-loader-data%40&urlGen=fromEnv",
|
|
440
|
-
// meta: "file://./dist/fp-dir-file?name=test-loader&store=meta&storekey=%40test-loader-meta%40&urlGen=fromEnv",
|
|
441
|
-
// wal: "file://./dist/fp-dir-file?name=test-loader&store=wal&storekey=%40test-loader-wal%40&urlGen=fromEnv",
|
|
442
|
-
// });
|
|
443
|
-
// });
|
|
444
|
-
it("should commit a transaction", function () {
|
|
445
|
-
expect(done.head).toBeTruthy();
|
|
446
|
-
// expect(done.cars).toBeTruthy();
|
|
447
|
-
expect(loader.carLog.length).toBe(1 + 1 /* genesis */);
|
|
448
|
-
});
|
|
449
|
-
it("can load the car", async () => {
|
|
450
|
-
const blk = loader.carLog.asArray()[0][0];
|
|
451
|
-
expect(blk).toBeTruthy();
|
|
452
|
-
const reader = await loader.loadCar(blk, loader.attachedStores.local());
|
|
453
|
-
expect(reader).toBeTruthy();
|
|
454
|
-
assert(isCarBlockItemReady(reader));
|
|
455
|
-
const parsed = await parseCarFile<CRDTMeta>(reader, loader.logger);
|
|
456
|
-
expect(parsed.cars).toBeTruthy();
|
|
457
|
-
expect(parsed.cars.length).toBe(0 + 1 /* genesis */);
|
|
458
|
-
expect(parsed.meta).toBeTruthy();
|
|
459
|
-
expect(parsed.meta.head).toBeTruthy();
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
describe("Loader with two committed transactions", function () {
|
|
464
|
-
let loader: Loader;
|
|
465
|
-
let crdt: CRDT;
|
|
466
|
-
let blockstore: EncryptedBlockstore;
|
|
467
|
-
let done1: CRDTMeta;
|
|
468
|
-
let done2: CRDTMeta;
|
|
469
|
-
const sthis = ensureSuperThis();
|
|
470
|
-
afterEach(async () => {
|
|
471
|
-
await crdt.close();
|
|
472
|
-
await crdt.destroy();
|
|
473
|
-
});
|
|
474
|
-
beforeEach(async () => {
|
|
475
|
-
await sthis.start();
|
|
476
|
-
const dbOpts: LedgerOpts = {
|
|
477
|
-
name: "test-crdt",
|
|
478
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
479
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
480
|
-
storeUrls: toStoreURIRuntime(sthis, "test-loader"),
|
|
481
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
482
|
-
ctx: new AppContext(),
|
|
483
|
-
tracer,
|
|
484
|
-
};
|
|
485
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
486
|
-
blockstore = crdt.blockstore as EncryptedBlockstore;
|
|
487
|
-
expect(blockstore.loader).toBeTruthy();
|
|
488
|
-
loader = blockstore.loader as Loader;
|
|
489
|
-
done1 = await crdt.bulk([{ id: "apple", value: { foo: "bar" } }]);
|
|
490
|
-
done2 = await crdt.bulk([{ id: "orange", value: { foo: "bar" } }]);
|
|
491
|
-
});
|
|
492
|
-
it("should commit two transactions", function () {
|
|
493
|
-
expect(done1.head).toBeTruthy();
|
|
494
|
-
// expect(done1.cars).toBeTruthy();
|
|
495
|
-
expect(done2.head).toBeTruthy();
|
|
496
|
-
// expect(done2.cars).toBeTruthy();
|
|
497
|
-
expect(done1.head).not.toBe(done2.head);
|
|
498
|
-
// expect(done1.cars).not.toBe(done2.cars);
|
|
499
|
-
// expect(blockstore.transactions.size).toBe(2);
|
|
500
|
-
expect(loader.carLog.length).toBe(2 + 1 /* genesis */);
|
|
501
|
-
// expect(loader.carLog.indexOf(done1.cars)).toBe(1);
|
|
502
|
-
// expect(loader.carLog.map((cs) => cs.toString()).indexOf(done1.cars.toString())).toBe(1);
|
|
503
|
-
// expect(loader.carLog.indexOf(done2.cars)).toBe(0);
|
|
504
|
-
// expect(loader.carLog.map((cs) => cs.toString()).indexOf(done2.cars.toString())).toBe(0);
|
|
505
|
-
});
|
|
506
|
-
it("can load the car", async () => {
|
|
507
|
-
const blk = loader.carLog.asArray()[0][0];
|
|
508
|
-
expect(blk).toBeTruthy();
|
|
509
|
-
const reader = await loader.loadCar(blk, loader.attachedStores.local());
|
|
510
|
-
expect(reader).toBeTruthy();
|
|
511
|
-
assert(isCarBlockItemReady(reader));
|
|
512
|
-
const parsed = await parseCarFile<CRDTMeta>(reader, loader.logger);
|
|
513
|
-
expect(parsed.cars).toBeTruthy();
|
|
514
|
-
expect(parsed.cars.length).toBe(1 + 1 /* genesis */);
|
|
515
|
-
expect(parsed.meta).toBeTruthy();
|
|
516
|
-
expect(parsed.meta.head).toBeTruthy();
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe("Loader with many committed transactions", function () {
|
|
521
|
-
let loader: Loader;
|
|
522
|
-
let blockstore: EncryptedBlockstore;
|
|
523
|
-
let crdt: CRDT;
|
|
524
|
-
let dones: CRDTMeta[];
|
|
525
|
-
const count = 10;
|
|
526
|
-
const sthis = ensureSuperThis();
|
|
527
|
-
afterEach(async () => {
|
|
528
|
-
await crdt.close();
|
|
529
|
-
await crdt.destroy();
|
|
530
|
-
});
|
|
531
|
-
beforeEach(async () => {
|
|
532
|
-
await sthis.start();
|
|
533
|
-
const dbOpts: LedgerOpts = {
|
|
534
|
-
name: "test-crdt",
|
|
535
|
-
writeQueue: defaultWriteQueueOpts({}),
|
|
536
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
537
|
-
storeUrls: toStoreURIRuntime(sthis, "test-loader-many"),
|
|
538
|
-
storeEnDe: ensureStoreEnDeFile({}),
|
|
539
|
-
ctx: new AppContext(),
|
|
540
|
-
tracer,
|
|
541
|
-
};
|
|
542
|
-
crdt = new CRDTImpl(sthis, dbOpts);
|
|
543
|
-
blockstore = crdt.blockstore as EncryptedBlockstore;
|
|
544
|
-
expect(blockstore.loader).toBeTruthy();
|
|
545
|
-
loader = blockstore.loader as Loader;
|
|
546
|
-
dones = [];
|
|
547
|
-
for (let i = 0; i < count; i++) {
|
|
548
|
-
const did = await crdt.bulk([{ id: `apple${i}`, value: { foo: "bar" } }]);
|
|
549
|
-
dones.push(did);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
it("should commit many transactions", function () {
|
|
553
|
-
for (const done of dones) {
|
|
554
|
-
expect(done.head).toBeTruthy();
|
|
555
|
-
// expect(done.cars).toBeTruthy();
|
|
556
|
-
}
|
|
557
|
-
expect(blockstore.transactions.size).toBe(0); // cleaned up on commit
|
|
558
|
-
expect(loader.carLog.length).toBe(count + 1 /* genesis */);
|
|
559
|
-
});
|
|
560
|
-
it("can load the car", async () => {
|
|
561
|
-
const blk = loader.carLog.asArray()[2][0];
|
|
562
|
-
// expect(dones[5].cars).toBeTruthy();
|
|
563
|
-
const reader = await loader.loadCar(blk, loader.attachedStores.local());
|
|
564
|
-
expect(reader).toBeTruthy();
|
|
565
|
-
assert(isCarBlockItemReady(reader));
|
|
566
|
-
const parsed = await parseCarFile<CRDTMeta>(reader, loader.logger);
|
|
567
|
-
expect(parsed.cars).toBeTruthy();
|
|
568
|
-
expect(parsed.cars.length).toBe(7 + 1 /* genesis */);
|
|
569
|
-
expect(parsed.meta).toBeTruthy();
|
|
570
|
-
expect(parsed.meta.head).toBeTruthy();
|
|
571
|
-
});
|
|
572
|
-
});
|