cojson 0.13.16 → 0.13.18
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/dist/PeerState.d.ts +3 -0
- package/dist/PeerState.d.ts.map +1 -1
- package/dist/PeerState.js +9 -0
- package/dist/PeerState.js.map +1 -1
- package/dist/SyncStateManager.d.ts.map +1 -1
- package/dist/SyncStateManager.js +2 -3
- package/dist/SyncStateManager.js.map +1 -1
- package/dist/coValue.d.ts +6 -4
- package/dist/coValue.d.ts.map +1 -1
- package/dist/coValue.js +5 -4
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +143 -0
- package/dist/coValueCore/coValueCore.d.ts.map +1 -0
- package/dist/{coValueCore.js → coValueCore/coValueCore.js} +314 -246
- package/dist/coValueCore/coValueCore.js.map +1 -0
- package/dist/coValueCore/verifiedState.d.ts +65 -0
- package/dist/coValueCore/verifiedState.d.ts.map +1 -0
- package/dist/coValueCore/verifiedState.js +210 -0
- package/dist/coValueCore/verifiedState.js.map +1 -0
- package/dist/coValues/account.d.ts +8 -10
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/account.js +12 -13
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.d.ts +10 -6
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coList.js +41 -15
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.d.ts +4 -3
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coMap.js +5 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coPlainText.d.ts +2 -2
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/coPlainText.js +5 -5
- package/dist/coValues/coPlainText.js.map +1 -1
- package/dist/coValues/coStream.d.ts +5 -4
- package/dist/coValues/coStream.d.ts.map +1 -1
- package/dist/coValues/coStream.js +5 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.d.ts +7 -2
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +29 -26
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.d.ts +4 -3
- package/dist/coreToCoValue.d.ts.map +1 -1
- package/dist/coreToCoValue.js +10 -14
- package/dist/coreToCoValue.js.map +1 -1
- package/dist/exports.d.ts +6 -5
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +3 -4
- package/dist/exports.js.map +1 -1
- package/dist/localNode.d.ts +30 -24
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +153 -177
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.d.ts +2 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +15 -11
- package/dist/permissions.js.map +1 -1
- package/dist/priority.d.ts +1 -1
- package/dist/priority.d.ts.map +1 -1
- package/dist/sync.d.ts +2 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +86 -55
- package/dist/sync.js.map +1 -1
- package/dist/tests/coList.test.js +133 -13
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +43 -14
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coPlainText.test.js +9 -10
- package/dist/tests/coPlainText.test.js.map +1 -1
- package/dist/tests/coStream.test.js +49 -18
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/coValueCore.test.js +22 -28
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/coValueCoreLoadingState.test.d.ts +2 -0
- package/dist/tests/coValueCoreLoadingState.test.d.ts.map +1 -0
- package/dist/tests/coValueCoreLoadingState.test.js +227 -0
- package/dist/tests/coValueCoreLoadingState.test.js.map +1 -0
- package/dist/tests/group.test.js +42 -43
- package/dist/tests/group.test.js.map +1 -1
- package/dist/tests/messagesTestUtils.d.ts +2 -2
- package/dist/tests/messagesTestUtils.d.ts.map +1 -1
- package/dist/tests/messagesTestUtils.js +1 -1
- package/dist/tests/messagesTestUtils.js.map +1 -1
- package/dist/tests/permissions.test.js +224 -292
- package/dist/tests/permissions.test.js.map +1 -1
- package/dist/tests/priority.test.js +13 -14
- package/dist/tests/priority.test.js.map +1 -1
- package/dist/tests/sync.auth.test.d.ts +2 -0
- package/dist/tests/sync.auth.test.d.ts.map +1 -0
- package/dist/tests/sync.auth.test.js +141 -0
- package/dist/tests/sync.auth.test.js.map +1 -0
- package/dist/tests/sync.load.test.js +60 -2
- package/dist/tests/sync.load.test.js.map +1 -1
- package/dist/tests/sync.mesh.test.js +70 -10
- package/dist/tests/sync.mesh.test.js.map +1 -1
- package/dist/tests/sync.peerReconciliation.test.js +19 -19
- package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
- package/dist/tests/sync.storage.test.js +20 -13
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.test.js +32 -39
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js +126 -37
- package/dist/tests/sync.upload.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +24 -15
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +88 -61
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/expectGroup.js +1 -1
- package/dist/typeUtils/expectGroup.js.map +1 -1
- package/package.json +1 -1
- package/src/PeerState.ts +11 -0
- package/src/SyncStateManager.ts +2 -3
- package/src/coValue.ts +14 -8
- package/src/{coValueCore.ts → coValueCore/coValueCore.ts} +470 -413
- package/src/coValueCore/verifiedState.ts +376 -0
- package/src/coValues/account.ts +20 -25
- package/src/coValues/coList.ts +63 -29
- package/src/coValues/coMap.ts +13 -6
- package/src/coValues/coPlainText.ts +10 -8
- package/src/coValues/coStream.ts +12 -7
- package/src/coValues/group.ts +50 -28
- package/src/coreToCoValue.ts +14 -15
- package/src/exports.ts +9 -7
- package/src/localNode.ts +248 -283
- package/src/permissions.ts +18 -12
- package/src/priority.ts +1 -1
- package/src/sync.ts +96 -63
- package/src/tests/coList.test.ts +200 -12
- package/src/tests/coMap.test.ts +65 -14
- package/src/tests/coPlainText.test.ts +12 -9
- package/src/tests/coStream.test.ts +80 -17
- package/src/tests/coValueCore.test.ts +30 -27
- package/src/tests/coValueCoreLoadingState.test.ts +337 -0
- package/src/tests/group.test.ts +44 -68
- package/src/tests/messagesTestUtils.ts +3 -8
- package/src/tests/permissions.test.ts +283 -449
- package/src/tests/priority.test.ts +17 -13
- package/src/tests/sync.auth.test.ts +188 -0
- package/src/tests/sync.load.test.ts +79 -2
- package/src/tests/sync.mesh.test.ts +89 -9
- package/src/tests/sync.peerReconciliation.test.ts +25 -25
- package/src/tests/sync.storage.test.ts +20 -13
- package/src/tests/sync.test.ts +43 -43
- package/src/tests/sync.upload.test.ts +157 -37
- package/src/tests/testUtils.ts +120 -74
- package/src/typeUtils/expectGroup.ts +1 -1
- package/dist/CoValuesStore.d.ts +0 -14
- package/dist/CoValuesStore.d.ts.map +0 -1
- package/dist/CoValuesStore.js +0 -32
- package/dist/CoValuesStore.js.map +0 -1
- package/dist/coValueCore.d.ts +0 -141
- package/dist/coValueCore.d.ts.map +0 -1
- package/dist/coValueCore.js.map +0 -1
- package/dist/coValueState.d.ts +0 -34
- package/dist/coValueState.d.ts.map +0 -1
- package/dist/coValueState.js +0 -228
- package/dist/coValueState.js.map +0 -1
- package/dist/tests/coValueState.test.d.ts +0 -2
- package/dist/tests/coValueState.test.d.ts.map +0 -1
- package/dist/tests/coValueState.test.js +0 -344
- package/dist/tests/coValueState.test.js.map +0 -1
- package/src/CoValuesStore.ts +0 -41
- package/src/coValueState.ts +0 -300
- package/src/tests/coValueState.test.ts +0 -525
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
1
|
+
import { beforeEach, describe, expect, test } from "vitest";
|
|
2
2
|
import { expectStream } from "../coValue.js";
|
|
3
|
-
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
|
|
3
|
+
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore/coValueCore.js";
|
|
4
4
|
import {
|
|
5
5
|
BinaryStreamItem,
|
|
6
6
|
CoStreamItem,
|
|
@@ -10,12 +10,22 @@ import {
|
|
|
10
10
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
11
11
|
import { SessionID } from "../ids.js";
|
|
12
12
|
import { LocalNode } from "../localNode.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
loadCoValueOrFail,
|
|
15
|
+
nodeWithRandomAgentAndSessionID,
|
|
16
|
+
randomAgentAndSessionID,
|
|
17
|
+
setupTestNode,
|
|
18
|
+
waitFor,
|
|
19
|
+
} from "./testUtils.js";
|
|
14
20
|
|
|
15
21
|
const Crypto = await WasmCrypto.create();
|
|
16
22
|
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
setupTestNode({ isSyncServer: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
17
27
|
test("Empty CoStream works", () => {
|
|
18
|
-
const node =
|
|
28
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
19
29
|
|
|
20
30
|
const coValue = node.createCoValue({
|
|
21
31
|
type: "costream",
|
|
@@ -32,7 +42,7 @@ test("Empty CoStream works", () => {
|
|
|
32
42
|
});
|
|
33
43
|
|
|
34
44
|
test("Can push into CoStream", () => {
|
|
35
|
-
const node =
|
|
45
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
36
46
|
|
|
37
47
|
const coValue = node.createCoValue({
|
|
38
48
|
type: "costream",
|
|
@@ -58,7 +68,7 @@ test("Can push into CoStream", () => {
|
|
|
58
68
|
});
|
|
59
69
|
|
|
60
70
|
test("Empty RawBinaryCoStream works", () => {
|
|
61
|
-
const node =
|
|
71
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
62
72
|
|
|
63
73
|
const coValue = node.createCoValue({
|
|
64
74
|
type: "costream",
|
|
@@ -84,7 +94,7 @@ test("Empty RawBinaryCoStream works", () => {
|
|
|
84
94
|
});
|
|
85
95
|
|
|
86
96
|
test("Can push into RawBinaryCoStream", () => {
|
|
87
|
-
const node =
|
|
97
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
88
98
|
|
|
89
99
|
const coValue = node.createCoValue({
|
|
90
100
|
type: "costream",
|
|
@@ -120,7 +130,7 @@ test("Can push into RawBinaryCoStream", () => {
|
|
|
120
130
|
});
|
|
121
131
|
|
|
122
132
|
test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature every time we reach MAX_RECOMMENDED_TX_SIZE and split up newContentSince accordingly", () => {
|
|
123
|
-
const node =
|
|
133
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
124
134
|
|
|
125
135
|
const coValue = node.createCoValue({
|
|
126
136
|
type: "costream",
|
|
@@ -152,7 +162,11 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
152
162
|
|
|
153
163
|
content.endBinaryStream("trusting");
|
|
154
164
|
|
|
155
|
-
|
|
165
|
+
if (!coValue.isAvailable()) {
|
|
166
|
+
throw new Error("CoValue is not available");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
|
|
156
170
|
expect(sessionEntry.transactions.length).toEqual(12);
|
|
157
171
|
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
158
172
|
expect(sessionEntry.signatureAfter[1]).not.toBeDefined();
|
|
@@ -167,7 +181,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
167
181
|
expect(sessionEntry.signatureAfter[10]).not.toBeDefined();
|
|
168
182
|
expect(sessionEntry.signatureAfter[11]).not.toBeDefined();
|
|
169
183
|
|
|
170
|
-
const newContent = coValue.newContentSince({
|
|
184
|
+
const newContent = coValue.verified.newContentSince({
|
|
171
185
|
id: coValue.id,
|
|
172
186
|
header: false,
|
|
173
187
|
sessions: {},
|
|
@@ -190,7 +204,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
190
204
|
});
|
|
191
205
|
|
|
192
206
|
test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature after every large transaction and split up newContentSince accordingly", () => {
|
|
193
|
-
const node =
|
|
207
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
194
208
|
|
|
195
209
|
const coValue = node.createCoValue({
|
|
196
210
|
type: "costream",
|
|
@@ -222,7 +236,11 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
222
236
|
|
|
223
237
|
content.endBinaryStream("trusting");
|
|
224
238
|
|
|
225
|
-
|
|
239
|
+
if (!coValue.isAvailable()) {
|
|
240
|
+
throw new Error("CoValue is not available");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
|
|
226
244
|
expect(sessionEntry.transactions.length).toEqual(5);
|
|
227
245
|
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
228
246
|
expect(sessionEntry.signatureAfter[1]).toBeDefined();
|
|
@@ -230,7 +248,7 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
230
248
|
expect(sessionEntry.signatureAfter[3]).toBeDefined();
|
|
231
249
|
expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
|
|
232
250
|
|
|
233
|
-
const newContent = coValue.newContentSince({
|
|
251
|
+
const newContent = coValue.verified.newContentSince({
|
|
234
252
|
id: coValue.id,
|
|
235
253
|
header: false,
|
|
236
254
|
sessions: {},
|
|
@@ -252,9 +270,54 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
252
270
|
);
|
|
253
271
|
});
|
|
254
272
|
|
|
273
|
+
test("totalValidTransactions should return the number of valid transactions processed", async () => {
|
|
274
|
+
const client = setupTestNode({
|
|
275
|
+
connected: true,
|
|
276
|
+
});
|
|
277
|
+
const otherClient = setupTestNode({});
|
|
278
|
+
|
|
279
|
+
const otherClientConnection = otherClient.connectToSyncServer();
|
|
280
|
+
|
|
281
|
+
const group = client.node.createGroup();
|
|
282
|
+
group.addMember("everyone", "reader");
|
|
283
|
+
|
|
284
|
+
const stream = group.createStream();
|
|
285
|
+
stream.push(1, "trusting");
|
|
286
|
+
|
|
287
|
+
const streamOnOtherClient = await loadCoValueOrFail(
|
|
288
|
+
otherClient.node,
|
|
289
|
+
stream.id,
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
otherClientConnection.peerState.gracefulShutdown();
|
|
293
|
+
|
|
294
|
+
group.addMember("everyone", "writer");
|
|
295
|
+
|
|
296
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
297
|
+
|
|
298
|
+
streamOnOtherClient.push(2, "trusting");
|
|
299
|
+
|
|
300
|
+
expect(streamOnOtherClient.totalValidTransactions).toEqual(1);
|
|
301
|
+
expect(Object.keys(streamOnOtherClient.toJSON()).length).toEqual(1);
|
|
302
|
+
|
|
303
|
+
otherClient.connectToSyncServer();
|
|
304
|
+
|
|
305
|
+
await waitFor(() => {
|
|
306
|
+
expect(
|
|
307
|
+
Object.keys(
|
|
308
|
+
streamOnOtherClient.core.getCurrentContent().toJSON() as object,
|
|
309
|
+
).length,
|
|
310
|
+
).toEqual(2);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
expect(
|
|
314
|
+
streamOnOtherClient.core.getCurrentContent().totalValidTransactions,
|
|
315
|
+
).toEqual(2);
|
|
316
|
+
});
|
|
317
|
+
|
|
255
318
|
describe("isBinaryStreamEnded", () => {
|
|
256
319
|
function setup() {
|
|
257
|
-
const node =
|
|
320
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
258
321
|
|
|
259
322
|
const coValue = node.createCoValue({
|
|
260
323
|
type: "costream",
|
|
@@ -317,7 +380,7 @@ describe("Binary stream order", () => {
|
|
|
317
380
|
}
|
|
318
381
|
|
|
319
382
|
test("sorts by madeAt timestamp first", () => {
|
|
320
|
-
const node =
|
|
383
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
321
384
|
const coValue = node.createCoValue({
|
|
322
385
|
type: "costream",
|
|
323
386
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -349,7 +412,7 @@ describe("Binary stream order", () => {
|
|
|
349
412
|
});
|
|
350
413
|
|
|
351
414
|
test("sorts by sessionID when timestamps are equal", () => {
|
|
352
|
-
const node =
|
|
415
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
353
416
|
const coValue = node.createCoValue({
|
|
354
417
|
type: "costream",
|
|
355
418
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -382,7 +445,7 @@ describe("Binary stream order", () => {
|
|
|
382
445
|
});
|
|
383
446
|
|
|
384
447
|
test("sorts by txIndex when timestamps and sessionIDs are equal", () => {
|
|
385
|
-
const node =
|
|
448
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
386
449
|
const coValue = node.createCoValue({
|
|
387
450
|
type: "costream",
|
|
388
451
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assert, afterEach, beforeEach, expect, test, vi } from "vitest";
|
|
2
|
-
import { CoValueCore
|
|
2
|
+
import { CoValueCore } from "../coValueCore/coValueCore.js";
|
|
3
|
+
import { Transaction } from "../coValueCore/verifiedState.js";
|
|
3
4
|
import { MapOpPayload } from "../coValues/coMap.js";
|
|
4
5
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
5
6
|
import { stableStringify } from "../jsonStringify.js";
|
|
@@ -10,7 +11,8 @@ import {
|
|
|
10
11
|
createTestNode,
|
|
11
12
|
createTwoConnectedNodes,
|
|
12
13
|
loadCoValueOrFail,
|
|
13
|
-
|
|
14
|
+
nodeWithRandomAgentAndSessionID,
|
|
15
|
+
randomAgentAndSessionID,
|
|
14
16
|
tearDownTestMetricReader,
|
|
15
17
|
} from "./testUtils.js";
|
|
16
18
|
|
|
@@ -27,8 +29,8 @@ afterEach(() => {
|
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
test("Can create coValue with new agent credentials and add transaction to it", () => {
|
|
30
|
-
const [
|
|
31
|
-
const node = new LocalNode(
|
|
32
|
+
const [agent, sessionID] = randomAgentAndSessionID();
|
|
33
|
+
const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
|
|
32
34
|
|
|
33
35
|
const coValue = node.createCoValue({
|
|
34
36
|
type: "costream",
|
|
@@ -47,7 +49,7 @@ test("Can create coValue with new agent credentials and add transaction to it",
|
|
|
47
49
|
]),
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
const { expectedNewHash } = coValue.expectedNewHashAfter(
|
|
52
|
+
const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
|
|
51
53
|
node.currentSessionID,
|
|
52
54
|
[transaction],
|
|
53
55
|
);
|
|
@@ -58,7 +60,8 @@ test("Can create coValue with new agent credentials and add transaction to it",
|
|
|
58
60
|
node.currentSessionID,
|
|
59
61
|
[transaction],
|
|
60
62
|
expectedNewHash,
|
|
61
|
-
Crypto.sign(
|
|
63
|
+
Crypto.sign(agent.currentSignerSecret(), expectedNewHash),
|
|
64
|
+
"immediate",
|
|
62
65
|
)
|
|
63
66
|
._unsafeUnwrap(),
|
|
64
67
|
).toBe(true);
|
|
@@ -66,8 +69,7 @@ test("Can create coValue with new agent credentials and add transaction to it",
|
|
|
66
69
|
|
|
67
70
|
test("transactions with wrong signature are rejected", () => {
|
|
68
71
|
const wrongAgent = Crypto.newRandomAgentSecret();
|
|
69
|
-
const
|
|
70
|
-
const node = new LocalNode(agentSecret, sessionID, Crypto);
|
|
72
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
71
73
|
|
|
72
74
|
const coValue = node.createCoValue({
|
|
73
75
|
type: "costream",
|
|
@@ -86,7 +88,7 @@ test("transactions with wrong signature are rejected", () => {
|
|
|
86
88
|
]),
|
|
87
89
|
};
|
|
88
90
|
|
|
89
|
-
const { expectedNewHash } = coValue.expectedNewHashAfter(
|
|
91
|
+
const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
|
|
90
92
|
node.currentSessionID,
|
|
91
93
|
[transaction],
|
|
92
94
|
);
|
|
@@ -98,13 +100,14 @@ test("transactions with wrong signature are rejected", () => {
|
|
|
98
100
|
[transaction],
|
|
99
101
|
expectedNewHash,
|
|
100
102
|
Crypto.sign(Crypto.getAgentSignerSecret(wrongAgent), expectedNewHash),
|
|
103
|
+
"immediate",
|
|
101
104
|
)
|
|
102
105
|
._unsafeUnwrapErr({ withStackTrace: true });
|
|
103
106
|
});
|
|
104
107
|
|
|
105
108
|
test("transactions with correctly signed, but wrong hash are rejected", () => {
|
|
106
|
-
const [
|
|
107
|
-
const node = new LocalNode(
|
|
109
|
+
const [agent, sessionID] = randomAgentAndSessionID();
|
|
110
|
+
const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
|
|
108
111
|
|
|
109
112
|
const coValue = node.createCoValue({
|
|
110
113
|
type: "costream",
|
|
@@ -123,7 +126,7 @@ test("transactions with correctly signed, but wrong hash are rejected", () => {
|
|
|
123
126
|
]),
|
|
124
127
|
};
|
|
125
128
|
|
|
126
|
-
const { expectedNewHash } = coValue.expectedNewHashAfter(
|
|
129
|
+
const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
|
|
127
130
|
node.currentSessionID,
|
|
128
131
|
[
|
|
129
132
|
{
|
|
@@ -144,14 +147,15 @@ test("transactions with correctly signed, but wrong hash are rejected", () => {
|
|
|
144
147
|
node.currentSessionID,
|
|
145
148
|
[transaction],
|
|
146
149
|
expectedNewHash,
|
|
147
|
-
Crypto.sign(
|
|
150
|
+
Crypto.sign(agent.currentSignerSecret(), expectedNewHash),
|
|
151
|
+
"immediate",
|
|
148
152
|
)
|
|
149
153
|
._unsafeUnwrapErr({ withStackTrace: true });
|
|
150
154
|
});
|
|
151
155
|
|
|
152
156
|
test("New transactions in a group correctly update owned values, including subscriptions", async () => {
|
|
153
|
-
const [
|
|
154
|
-
const node = new LocalNode(
|
|
157
|
+
const [agent, sessionID] = randomAgentAndSessionID();
|
|
158
|
+
const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
|
|
155
159
|
|
|
156
160
|
const group = node.createGroup();
|
|
157
161
|
|
|
@@ -175,18 +179,19 @@ test("New transactions in a group correctly update owned values, including subsc
|
|
|
175
179
|
changes: stableStringify([
|
|
176
180
|
{
|
|
177
181
|
op: "set",
|
|
178
|
-
key:
|
|
182
|
+
key: agent.id,
|
|
179
183
|
value: "revoked",
|
|
180
|
-
} satisfies MapOpPayload<typeof
|
|
184
|
+
} satisfies MapOpPayload<typeof agent.id, Role>,
|
|
181
185
|
]),
|
|
182
186
|
} satisfies Transaction;
|
|
183
187
|
|
|
184
|
-
const { expectedNewHash } = group.core.expectedNewHashAfter(
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
const { expectedNewHash } = group.core.verified.expectedNewHashAfter(
|
|
189
|
+
sessionID,
|
|
190
|
+
[resignationThatWeJustLearnedAbout],
|
|
191
|
+
);
|
|
187
192
|
|
|
188
193
|
const signature = Crypto.sign(
|
|
189
|
-
node.
|
|
194
|
+
node.getCurrentAgent().currentSignerSecret(),
|
|
190
195
|
expectedNewHash,
|
|
191
196
|
);
|
|
192
197
|
|
|
@@ -198,6 +203,7 @@ test("New transactions in a group correctly update owned values, including subsc
|
|
|
198
203
|
[resignationThatWeJustLearnedAbout],
|
|
199
204
|
expectedNewHash,
|
|
200
205
|
signature,
|
|
206
|
+
"immediate",
|
|
201
207
|
)
|
|
202
208
|
._unsafeUnwrap({ withStackTrace: true });
|
|
203
209
|
|
|
@@ -210,8 +216,7 @@ test("New transactions in a group correctly update owned values, including subsc
|
|
|
210
216
|
});
|
|
211
217
|
|
|
212
218
|
test("correctly records transactions", async () => {
|
|
213
|
-
const
|
|
214
|
-
const node = new LocalNode(account, sessionID, Crypto);
|
|
219
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
215
220
|
|
|
216
221
|
const changes1 = stableStringify([{ hello: "world" }]);
|
|
217
222
|
node.syncManager.recordTransactionsSize(
|
|
@@ -253,8 +258,7 @@ test("correctly records transactions", async () => {
|
|
|
253
258
|
});
|
|
254
259
|
|
|
255
260
|
test("(smoke test) records transactions from local node", async () => {
|
|
256
|
-
const
|
|
257
|
-
const node = new LocalNode(account, sessionID, Crypto);
|
|
261
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
258
262
|
|
|
259
263
|
node.createGroup();
|
|
260
264
|
|
|
@@ -294,8 +298,7 @@ test("creating a coValue with a group should't trigger automatically a content c
|
|
|
294
298
|
});
|
|
295
299
|
|
|
296
300
|
test("loading a coValue core without having the owner group available doesn't crash", () => {
|
|
297
|
-
const
|
|
298
|
-
const node = new LocalNode(account, sessionID, Crypto);
|
|
301
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
299
302
|
|
|
300
303
|
const otherNode = createTestNode();
|
|
301
304
|
|