@fireproof/core-test 0.22.0-keybag → 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/LICENSE.md +197 -228
- package/README.md +269 -0
- package/blockstore/interceptor-gateway.test.js.map +1 -1
- package/blockstore/keyed-crypto-indexeddb-file.test.js +1 -0
- package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
- package/blockstore/keyed-crypto.test.js +1 -0
- 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 +1 -1
- package/fireproof/concurrent.test.js.map +1 -1
- package/fireproof/crdt.test.js +1 -0
- 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.d.ts +3 -3
- package/fireproof/fireproof.test.fixture.js.map +1 -1
- package/fireproof/fireproof.test.js +1 -0
- 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 +2 -2
- package/gateway/file/loader-config.test.js.map +1 -1
- package/gateway/indexeddb/create-db-on-write.test.d.ts +1 -0
- package/gateway/indexeddb/create-db-on-write.test.js +145 -0
- package/gateway/indexeddb/create-db-on-write.test.js.map +1 -0
- 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 +21 -22
- 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 -38
- 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/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
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { BuildURI, runtimeFn, URI } from "@adviser/cement";
|
|
2
|
-
import { Link } from "multiformats";
|
|
3
|
-
import { stripper } from "@adviser/cement/utils";
|
|
4
|
-
import pLimit from "@fireproof/vendor/p-limit";
|
|
5
|
-
import { ensureSuperThis, sleep } from "@fireproof/core-runtime";
|
|
6
|
-
import { CRDT, PARAM, LedgerOpts } from "@fireproof/core-types-base";
|
|
7
|
-
import { describe, it, vi, expect, beforeEach, afterEach } from "vitest";
|
|
8
|
-
import { Loader } from "@fireproof/core-blockstore";
|
|
9
|
-
import { CRDTImpl, fireproof } from "@fireproof/core-base";
|
|
10
|
-
|
|
11
|
-
describe("standalone", () => {
|
|
12
|
-
const sthis = ensureSuperThis();
|
|
13
|
-
|
|
14
|
-
describe("howto-loader", () => {
|
|
15
|
-
// beforeAll(async () => {
|
|
16
|
-
// const db = fireproof("howto-loader", {
|
|
17
|
-
// storeUrls: {
|
|
18
|
-
// base: "file://dist/how-to-loader?store-key=insecure",
|
|
19
|
-
// },
|
|
20
|
-
// });
|
|
21
|
-
// for (let cid = 0; cid < 1; cid++) {
|
|
22
|
-
// const blk = new Array(3)
|
|
23
|
-
// .fill(0)
|
|
24
|
-
// .map((_, peer) => ({ _id: `test-${cid}:peer-${peer}`, value: { cid: `test-${cid}`, peer: `peer-${peer}` } }));
|
|
25
|
-
// await db.bulk(blk);
|
|
26
|
-
// }
|
|
27
|
-
// // await db.compact()
|
|
28
|
-
// await db.close();
|
|
29
|
-
// });
|
|
30
|
-
|
|
31
|
-
it("understand the writer", async () => {
|
|
32
|
-
const db = fireproof("howto-writer", {
|
|
33
|
-
storeUrls: {
|
|
34
|
-
base: "memory://how-to-writer",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
await db.put({ _id: "test-1", value: { cid: "test-1", peer: "peer-1" } });
|
|
38
|
-
await db.close();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it.skip("understand loader", async () => {
|
|
42
|
-
const db = fireproof("howto-loader", {
|
|
43
|
-
storeUrls: {
|
|
44
|
-
base: "file://dist/how-to-loader?store-key=insecure",
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
const fn = vi.fn();
|
|
48
|
-
const loader = db.ledger.crdt.blockstore.loader as Loader;
|
|
49
|
-
loader.cidCache.onSet(fn);
|
|
50
|
-
expect(fn).toHaveBeenCalledTimes(0);
|
|
51
|
-
await db.ready();
|
|
52
|
-
expect(
|
|
53
|
-
loader.cidCache.values().map((i) => {
|
|
54
|
-
const v = i.value.Ok();
|
|
55
|
-
return {
|
|
56
|
-
type: v.item.type,
|
|
57
|
-
cid: v.cid,
|
|
58
|
-
value: stripper(/(type|cid)/, v.item),
|
|
59
|
-
};
|
|
60
|
-
}),
|
|
61
|
-
).toEqual([]);
|
|
62
|
-
// let last = 0
|
|
63
|
-
// for (let i = 0; i < 100; i++) {
|
|
64
|
-
// if (last !== fn.mock.calls.length) {
|
|
65
|
-
// console.log("fn", i, fn.mock.calls.length);
|
|
66
|
-
// last = fn.mock.calls.length
|
|
67
|
-
// }
|
|
68
|
-
// await sleep(10);
|
|
69
|
-
// }
|
|
70
|
-
const ret = await db.allDocs();
|
|
71
|
-
expect(ret.rows.length).toBe(100);
|
|
72
|
-
expect(fn).toHaveBeenCalledTimes(109393);
|
|
73
|
-
await db.close();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe("test-plimit", () => {
|
|
78
|
-
it("should work with plimit", async () => {
|
|
79
|
-
const limiter = pLimit(2);
|
|
80
|
-
let concurrent = 0;
|
|
81
|
-
const ret = await Promise.all(
|
|
82
|
-
Array(10)
|
|
83
|
-
.fill(0)
|
|
84
|
-
.map((_, i) => {
|
|
85
|
-
return limiter(async () => {
|
|
86
|
-
concurrent++;
|
|
87
|
-
expect(concurrent).toBeLessThanOrEqual(2);
|
|
88
|
-
await sleep(100);
|
|
89
|
-
concurrent--;
|
|
90
|
-
return i;
|
|
91
|
-
});
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
expect(ret).toEqual(Array.from(Array(10).keys()));
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe.skip("crdt-stack", () => {
|
|
99
|
-
let crdt: CRDT;
|
|
100
|
-
beforeEach(async () => {
|
|
101
|
-
let uri: URI;
|
|
102
|
-
switch (true) {
|
|
103
|
-
case runtimeFn().isBrowser:
|
|
104
|
-
uri = BuildURI.from("indexeddb://standalone-peer-log").setParam(PARAM.NAME, "peer-log").URI();
|
|
105
|
-
break;
|
|
106
|
-
default:
|
|
107
|
-
uri = BuildURI.from("file://dist/standalone")
|
|
108
|
-
.setParam(PARAM.NAME, "peer-log")
|
|
109
|
-
.setParam(PARAM.STORE_KEY, "insecure")
|
|
110
|
-
.URI();
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
// console.log("uri", uri.toString());
|
|
114
|
-
crdt = new CRDTImpl(sthis, {
|
|
115
|
-
name: "peer-log",
|
|
116
|
-
writeQueue: { chunkSize: 32 },
|
|
117
|
-
storeUrls: {
|
|
118
|
-
data: {
|
|
119
|
-
meta: uri.build().setParam(PARAM.STORE, "meta").setParam(PARAM.STORE_KEY, "insecure").URI(),
|
|
120
|
-
car: uri.build().setParam(PARAM.STORE, "car").setParam(PARAM.STORE_KEY, "insecure").URI(),
|
|
121
|
-
file: uri.build().setParam(PARAM.STORE, "file").setParam(PARAM.STORE_KEY, "insecure").URI(),
|
|
122
|
-
wal: uri.build().setParam(PARAM.STORE, "wal").setParam(PARAM.STORE_KEY, "insecure").URI(),
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
} as LedgerOpts);
|
|
126
|
-
await crdt.ready();
|
|
127
|
-
});
|
|
128
|
-
afterEach(async () => {
|
|
129
|
-
await crdt.close();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it.each(new Array(10).fill(0).map((_, i) => ({ cid: i })))("write:$cid", async ({ cid }) => {
|
|
133
|
-
const peers = new Array(10).fill(0).map((_, peer) => {
|
|
134
|
-
return { id: `test-${cid}:peer-${peer}`, value: { cid: `test-${cid}`, peer: `peer-${peer}` } };
|
|
135
|
-
});
|
|
136
|
-
await crdt.bulk(peers);
|
|
137
|
-
});
|
|
138
|
-
it("read", async () => {
|
|
139
|
-
for (let cid = 0; cid < 10; cid++) {
|
|
140
|
-
for (let peer = 0; peer < 10; peer++) {
|
|
141
|
-
const id = `test-${cid}:peer-${peer}`;
|
|
142
|
-
const res = (await crdt.get(id)) as unknown as { cid: Link; doc: { cid: string; peer: string } };
|
|
143
|
-
expect(res.doc).toEqual({ cid: `test-${cid}`, peer: `peer-${peer}` });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
// for (let cid = 0; cid < 10; cid++) {
|
|
148
|
-
// const gte = `test-${cid}`;
|
|
149
|
-
// const ret = [];
|
|
150
|
-
// for await (const [key, link] of entries(blk, root, { gte })) {
|
|
151
|
-
// ret.push([key, link]);
|
|
152
|
-
// }
|
|
153
|
-
// expect(ret.length).toEqual(10);
|
|
154
|
-
// }
|
|
155
|
-
});
|
|
156
|
-
});
|
package/blockstore/store.test.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { CID } from "multiformats";
|
|
2
|
-
import { Result } from "@adviser/cement";
|
|
3
|
-
import { mockLoader, noopUrl } from "../helpers.js";
|
|
4
|
-
import { ensureSuperThis } from "@fireproof/core-runtime";
|
|
5
|
-
import { PARAM, NotFoundError, DbMeta } from "@fireproof/core-types-base";
|
|
6
|
-
import { describe, afterEach, beforeEach, it, expect } from "vitest";
|
|
7
|
-
import { createAttachedStores } from "@fireproof/core-blockstore";
|
|
8
|
-
import { CarStore, Loadable, AnyBlock, MetaStore, FPEnvelopeMeta } from "@fireproof/core-types-blockstore";
|
|
9
|
-
import { fpDeserialize } from "@fireproof/core-gateways-base";
|
|
10
|
-
|
|
11
|
-
// function runtime(sthis: SuperThis) {
|
|
12
|
-
// return toStoreRuntime(sthis);
|
|
13
|
-
// }
|
|
14
|
-
|
|
15
|
-
// async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFactoryItem> {
|
|
16
|
-
// const url = noopUrl(name);
|
|
17
|
-
// return {
|
|
18
|
-
// // sthis,
|
|
19
|
-
// url: url,
|
|
20
|
-
// loader:
|
|
21
|
-
// };
|
|
22
|
-
// }
|
|
23
|
-
|
|
24
|
-
describe("CarStore", function () {
|
|
25
|
-
let store: CarStore;
|
|
26
|
-
const sthis = ensureSuperThis();
|
|
27
|
-
|
|
28
|
-
let loader: Loadable;
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
await store.close();
|
|
32
|
-
await store.destroy();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
beforeEach(async () => {
|
|
36
|
-
loader = mockLoader(sthis);
|
|
37
|
-
await sthis.start();
|
|
38
|
-
const at = await createAttachedStores(noopUrl("test"), loader);
|
|
39
|
-
store = at.stores.car;
|
|
40
|
-
await store.start(at.stores);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should have a name", function () {
|
|
44
|
-
expect(store.url().getParam(PARAM.NAME)).toEqual("test");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should save a car", async () => {
|
|
48
|
-
const car: AnyBlock = {
|
|
49
|
-
cid: "cidKey" as unknown as CID,
|
|
50
|
-
bytes: new Uint8Array([55, 56, 57]),
|
|
51
|
-
};
|
|
52
|
-
await store.save(car);
|
|
53
|
-
const data = (await store.realGateway.getPlain({ loader }, store.url(), car.cid.toString())).Ok();
|
|
54
|
-
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("CarStore with a saved car", function () {
|
|
59
|
-
let store: CarStore;
|
|
60
|
-
let car: AnyBlock;
|
|
61
|
-
let loader: Loadable;
|
|
62
|
-
|
|
63
|
-
const sthis = ensureSuperThis();
|
|
64
|
-
|
|
65
|
-
afterEach(async () => {
|
|
66
|
-
await store.close();
|
|
67
|
-
await store.destroy();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
beforeEach(async () => {
|
|
71
|
-
loader = mockLoader(sthis);
|
|
72
|
-
await sthis.start();
|
|
73
|
-
|
|
74
|
-
const at = await createAttachedStores(noopUrl("test2"), loader);
|
|
75
|
-
store = at.stores.car;
|
|
76
|
-
await store.start(at.stores);
|
|
77
|
-
car = {
|
|
78
|
-
cid: "cid" as unknown as CID,
|
|
79
|
-
bytes: new Uint8Array([55, 56, 57, 80]),
|
|
80
|
-
};
|
|
81
|
-
await store.save(car);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("should have a car", async () => {
|
|
85
|
-
const data = (await store.realGateway.getPlain({ loader }, store.url(), car.cid.toString())).Ok();
|
|
86
|
-
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should load a car", async () => {
|
|
90
|
-
const loaded = await store.load(car.cid);
|
|
91
|
-
expect(loaded.cid).toEqual(car.cid);
|
|
92
|
-
expect(loaded.bytes.constructor.name).toEqual("Uint8Array");
|
|
93
|
-
expect(loaded.bytes.toString()).toEqual(car.bytes.toString());
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should remove a car", async () => {
|
|
97
|
-
await store.remove(car.cid);
|
|
98
|
-
const { e: error } = (await store.load(car.cid).catch((e: Error) => ({ e }))) as { e: NotFoundError };
|
|
99
|
-
expect(error).toBeTruthy();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("MetaStore", function () {
|
|
104
|
-
let store: MetaStore;
|
|
105
|
-
const sthis = ensureSuperThis();
|
|
106
|
-
let loader: Loadable;
|
|
107
|
-
|
|
108
|
-
afterEach(async () => {
|
|
109
|
-
await store.close();
|
|
110
|
-
await store.destroy();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
beforeEach(async () => {
|
|
114
|
-
loader = mockLoader(sthis);
|
|
115
|
-
await sthis.start();
|
|
116
|
-
const at = await createAttachedStores(noopUrl("test"), loader);
|
|
117
|
-
store = at.stores.meta;
|
|
118
|
-
await store.start(at.stores);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("should have a name", function () {
|
|
122
|
-
expect(store.url().getParam(PARAM.NAME)).toEqual("test");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("should save a header", async () => {
|
|
126
|
-
const cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
|
127
|
-
const h: DbMeta = {
|
|
128
|
-
cars: [cid],
|
|
129
|
-
// key: undefined,
|
|
130
|
-
};
|
|
131
|
-
await store.save(h);
|
|
132
|
-
const file = await store.realGateway.getPlain({ loader }, store.url(), "main");
|
|
133
|
-
const blockMeta = (await fpDeserialize(sthis, store.url(), file)) as Result<FPEnvelopeMeta>;
|
|
134
|
-
expect(blockMeta.Ok()).toBeTruthy();
|
|
135
|
-
expect(blockMeta.Ok().payload.length).toEqual(1);
|
|
136
|
-
const decodedHeader = blockMeta.Ok().payload[0].dbMeta;
|
|
137
|
-
expect(decodedHeader).toBeTruthy();
|
|
138
|
-
expect(decodedHeader.cars).toBeTruthy();
|
|
139
|
-
expect(decodedHeader.cars[0].toString()).toEqual(cid.toString());
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("MetaStore with a saved header", function () {
|
|
144
|
-
let store: MetaStore;
|
|
145
|
-
let cid: CID;
|
|
146
|
-
const sthis = ensureSuperThis();
|
|
147
|
-
let loader: Loadable;
|
|
148
|
-
|
|
149
|
-
afterEach(async () => {
|
|
150
|
-
await store.close();
|
|
151
|
-
await store.destroy();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
beforeEach(async () => {
|
|
155
|
-
loader = mockLoader(sthis);
|
|
156
|
-
await sthis.start();
|
|
157
|
-
const at = await createAttachedStores(noopUrl("test3-meta"), loader);
|
|
158
|
-
store = at.stores.meta;
|
|
159
|
-
await store.start(at.stores);
|
|
160
|
-
cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
|
161
|
-
await store.save({ cars: [cid] /*, key: undefined */ });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// it("should load", async () =>{
|
|
165
|
-
// expect(onload).toBeTruthy();
|
|
166
|
-
// expect(onload?.length).toEqual(1);
|
|
167
|
-
// expect(onload?.[0].cars.toString()).toEqual(cid.toString());
|
|
168
|
-
// });
|
|
169
|
-
|
|
170
|
-
it("should have a header", async () => {
|
|
171
|
-
const bytes = await store.realGateway.getPlain({ loader }, store.url(), "main");
|
|
172
|
-
const data = sthis.txt.decode(bytes.Ok());
|
|
173
|
-
expect(data).toMatch(/parents/);
|
|
174
|
-
const header = JSON.parse(data)[0];
|
|
175
|
-
expect(header).toBeDefined();
|
|
176
|
-
expect(header.parents).toBeDefined();
|
|
177
|
-
// const [blockMeta] = await store.handleByteHeads(bytes);
|
|
178
|
-
|
|
179
|
-
const blockMeta = (await fpDeserialize(sthis, store.url(), bytes)) as Result<FPEnvelopeMeta>;
|
|
180
|
-
expect(blockMeta.Ok()).toBeTruthy();
|
|
181
|
-
expect(blockMeta.Ok().payload.length).toEqual(1);
|
|
182
|
-
const decodedHeader = blockMeta.Ok().payload[0].dbMeta;
|
|
183
|
-
expect(decodedHeader).toBeDefined();
|
|
184
|
-
expect(decodedHeader.cars).toBeDefined();
|
|
185
|
-
expect(decodedHeader.cars[0].toString()).toEqual(cid.toString());
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("should load a header", async () => {
|
|
189
|
-
const metaStream = store.stream().getReader();
|
|
190
|
-
while (true) {
|
|
191
|
-
const { done, value: cars } = await metaStream.read();
|
|
192
|
-
if (done) break;
|
|
193
|
-
// expect(loaded).toBeTruthy();
|
|
194
|
-
expect(cars).toBeTruthy();
|
|
195
|
-
expect(cars.map((i) => i.cars.map((i) => i.toString())).flat(2)).toEqual([cid.toString()]);
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { CID } from "multiformats";
|
|
2
|
-
import { simpleBlockOpts } from "../helpers.js";
|
|
3
|
-
import { to_uint8 } from "@adviser/cement";
|
|
4
|
-
import { anyBlock2FPBlock, BaseBlockstoreImpl, CarTransactionImpl, EncryptedBlockstore } from "@fireproof/core-blockstore";
|
|
5
|
-
import { ensureSuperThis } from "@fireproof/core-runtime";
|
|
6
|
-
import { BaseBlockstore, CarTransaction } from "@fireproof/core-types-base";
|
|
7
|
-
import { describe, beforeEach, it, expect, assert } from "vitest";
|
|
8
|
-
import { AnyAnyLink, AnyBlock, AnyLink } from "@fireproof/core-types-blockstore";
|
|
9
|
-
|
|
10
|
-
describe("Fresh TransactionBlockstore", function () {
|
|
11
|
-
let blocks: BaseBlockstore;
|
|
12
|
-
const sthis = ensureSuperThis();
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
blocks = new BaseBlockstoreImpl(simpleBlockOpts(sthis));
|
|
15
|
-
await blocks.ready();
|
|
16
|
-
});
|
|
17
|
-
// it("should not have a name", function () {
|
|
18
|
-
// expect(blocks.name).toBeFalsy();
|
|
19
|
-
// });
|
|
20
|
-
// it("should not have a loader", function () {
|
|
21
|
-
// expect(blocks.loader).toBeFalsy();
|
|
22
|
-
// });
|
|
23
|
-
it("should not put", async () => {
|
|
24
|
-
const value = sthis.txt.encode("value");
|
|
25
|
-
const e = await blocks.put(await anyBlock2FPBlock({ cid: "key" as unknown as AnyLink, bytes: value })).catch((e) => e);
|
|
26
|
-
expect(e.message).toMatch(/transaction/g);
|
|
27
|
-
});
|
|
28
|
-
it("should yield a transaction", async () => {
|
|
29
|
-
const txR = await blocks.transaction(async (tblocks) => {
|
|
30
|
-
expect(tblocks).toBeTruthy();
|
|
31
|
-
expect(tblocks instanceof CarTransactionImpl).toBeTruthy();
|
|
32
|
-
return { head: [] };
|
|
33
|
-
});
|
|
34
|
-
expect(txR).toBeTruthy();
|
|
35
|
-
expect(txR.t).toBeTruthy();
|
|
36
|
-
expect(txR.meta).toEqual({ head: [] });
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("TransactionBlockstore with name", function () {
|
|
41
|
-
let blocks: EncryptedBlockstore;
|
|
42
|
-
const sthis = ensureSuperThis();
|
|
43
|
-
beforeEach(async () => {
|
|
44
|
-
blocks = new EncryptedBlockstore(sthis, simpleBlockOpts(sthis));
|
|
45
|
-
await blocks.ready();
|
|
46
|
-
});
|
|
47
|
-
// it("should have a name", function () {
|
|
48
|
-
// expect(blocks.name).toEqual("test");
|
|
49
|
-
// });
|
|
50
|
-
it("should have a loader", function () {
|
|
51
|
-
expect(blocks.loader).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
it("should get from loader", async () => {
|
|
54
|
-
const bytes = sthis.txt.encode("bytes");
|
|
55
|
-
expect(blocks.loader).toBeTruthy();
|
|
56
|
-
blocks.loader.getBlock = async (cid) => {
|
|
57
|
-
return anyBlock2FPBlock({ cid, bytes });
|
|
58
|
-
};
|
|
59
|
-
const value = await blocks.get("key" as unknown as AnyAnyLink);
|
|
60
|
-
expect(value).toEqual({ cid: "key" as unknown as AnyAnyLink, bytes });
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("A transaction", function () {
|
|
65
|
-
let tblocks: CarTransaction;
|
|
66
|
-
let blocks: EncryptedBlockstore;
|
|
67
|
-
const sthis = ensureSuperThis();
|
|
68
|
-
beforeEach(async () => {
|
|
69
|
-
blocks = new EncryptedBlockstore(sthis, simpleBlockOpts(sthis, "test"));
|
|
70
|
-
tblocks = new CarTransactionImpl(blocks);
|
|
71
|
-
blocks.transactions.add(tblocks);
|
|
72
|
-
});
|
|
73
|
-
it("should put and get", async () => {
|
|
74
|
-
const cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
|
75
|
-
const bytes = sthis.txt.encode("bytes");
|
|
76
|
-
await tblocks.put(await anyBlock2FPBlock({ cid, bytes }));
|
|
77
|
-
expect(blocks.transactions.has(tblocks)).toBeTruthy();
|
|
78
|
-
const got = await tblocks.get(cid);
|
|
79
|
-
assert(got, "missing block");
|
|
80
|
-
expect(got.cid).toEqual(cid);
|
|
81
|
-
expect(got.bytes).toEqual(bytes);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// function asUInt8Array(str: string, sthis: SuperThis) {
|
|
86
|
-
// return sthis.txt.encode(str);
|
|
87
|
-
// }
|
|
88
|
-
|
|
89
|
-
describe("TransactionBlockstore with a completed transaction", function () {
|
|
90
|
-
let blocks: BaseBlockstore;
|
|
91
|
-
let cid: CID;
|
|
92
|
-
let cid2: CID;
|
|
93
|
-
const sthis = ensureSuperThis();
|
|
94
|
-
|
|
95
|
-
beforeEach(async () => {
|
|
96
|
-
cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
|
97
|
-
cid2 = CID.parse("bafybeibgouhn5ktecpjuovt52zamzvm4dlve5ak7x6d5smms3itkhplnhm");
|
|
98
|
-
|
|
99
|
-
blocks = new BaseBlockstoreImpl(simpleBlockOpts(sthis));
|
|
100
|
-
await blocks.transaction(async (tblocks) => {
|
|
101
|
-
await tblocks.put(await anyBlock2FPBlock({ cid, bytes: to_uint8("value") }));
|
|
102
|
-
await tblocks.put(await anyBlock2FPBlock({ cid, bytes: to_uint8("value") }));
|
|
103
|
-
return { head: [] };
|
|
104
|
-
});
|
|
105
|
-
await blocks.transaction(async (tblocks) => {
|
|
106
|
-
await tblocks.put(await anyBlock2FPBlock({ cid, bytes: to_uint8("value") }));
|
|
107
|
-
await tblocks.put(await anyBlock2FPBlock({ cid: cid2, bytes: to_uint8("value2") }));
|
|
108
|
-
return { head: [] };
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it("should have transactions", async () => {
|
|
112
|
-
const ts = blocks.transactions;
|
|
113
|
-
expect(ts.size).toEqual(2);
|
|
114
|
-
});
|
|
115
|
-
it("should get", async () => {
|
|
116
|
-
const value = (await blocks.get(cid)) as AnyBlock;
|
|
117
|
-
expect(value.cid).toEqual(cid);
|
|
118
|
-
expect(value.bytes.toString()).toEqual(to_uint8("value").toString());
|
|
119
|
-
|
|
120
|
-
const value2 = (await blocks.get(cid2)) as AnyBlock;
|
|
121
|
-
expect(value2.bytes.toString()).toEqual(to_uint8("value2").toString());
|
|
122
|
-
});
|
|
123
|
-
it("should yield entries", async () => {
|
|
124
|
-
const blz = [];
|
|
125
|
-
for await (const blk of blocks.entries()) {
|
|
126
|
-
blz.push(blk);
|
|
127
|
-
}
|
|
128
|
-
expect(blz.length).toEqual(2);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// test compact
|