cojson 0.8.12 → 0.8.16
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/CHANGELOG.md +89 -83
- package/dist/native/PeerKnownStates.js +1 -1
- package/dist/native/PeerKnownStates.js.map +1 -1
- package/dist/native/PeerState.js +1 -1
- package/dist/native/PeerState.js.map +1 -1
- package/dist/native/PriorityBasedMessageQueue.js +1 -10
- package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/native/base64url.js.map +1 -1
- package/dist/native/base64url.test.js +1 -1
- package/dist/native/base64url.test.js.map +1 -1
- package/dist/native/coValue.js.map +1 -1
- package/dist/native/coValueCore.js +141 -149
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValueState.js.map +1 -1
- package/dist/native/coValues/account.js +6 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +2 -3
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +1 -1
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +3 -5
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/group.js +11 -11
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coreToCoValue.js +2 -2
- package/dist/native/coreToCoValue.js.map +1 -1
- package/dist/native/crypto/PureJSCrypto.js +4 -4
- package/dist/native/crypto/PureJSCrypto.js.map +1 -1
- package/dist/native/crypto/crypto.js.map +1 -1
- package/dist/native/exports.js +12 -12
- package/dist/native/exports.js.map +1 -1
- package/dist/native/ids.js.map +1 -1
- package/dist/native/jsonStringify.js.map +1 -1
- package/dist/native/localNode.js +5 -7
- package/dist/native/localNode.js.map +1 -1
- package/dist/native/permissions.js +4 -7
- package/dist/native/permissions.js.map +1 -1
- package/dist/native/priority.js.map +1 -1
- package/dist/native/storage/FileSystem.js.map +1 -1
- package/dist/native/storage/chunksAndKnownStates.js +2 -4
- package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/native/storage/index.js +6 -15
- package/dist/native/storage/index.js.map +1 -1
- package/dist/native/streamUtils.js.map +1 -1
- package/dist/native/sync.js +2 -4
- package/dist/native/sync.js.map +1 -1
- package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/native/typeUtils/expectGroup.js.map +1 -1
- package/dist/native/typeUtils/isAccountID.js.map +1 -1
- package/dist/native/typeUtils/isCoValue.js +1 -1
- package/dist/native/typeUtils/isCoValue.js.map +1 -1
- package/dist/web/PeerKnownStates.js +1 -1
- package/dist/web/PeerKnownStates.js.map +1 -1
- package/dist/web/PeerState.js +1 -1
- package/dist/web/PeerState.js.map +1 -1
- package/dist/web/PriorityBasedMessageQueue.js +1 -10
- package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/web/base64url.js.map +1 -1
- package/dist/web/base64url.test.js +1 -1
- package/dist/web/base64url.test.js.map +1 -1
- package/dist/web/coValue.js.map +1 -1
- package/dist/web/coValueCore.js +141 -149
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValueState.js.map +1 -1
- package/dist/web/coValues/account.js +6 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +2 -3
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +1 -1
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +3 -5
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/group.js +11 -11
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coreToCoValue.js +2 -2
- package/dist/web/coreToCoValue.js.map +1 -1
- package/dist/web/crypto/PureJSCrypto.js +4 -4
- package/dist/web/crypto/PureJSCrypto.js.map +1 -1
- package/dist/web/crypto/WasmCrypto.js +5 -5
- package/dist/web/crypto/WasmCrypto.js.map +1 -1
- package/dist/web/crypto/crypto.js.map +1 -1
- package/dist/web/exports.js +12 -12
- package/dist/web/exports.js.map +1 -1
- package/dist/web/ids.js.map +1 -1
- package/dist/web/jsonStringify.js.map +1 -1
- package/dist/web/localNode.js +5 -7
- package/dist/web/localNode.js.map +1 -1
- package/dist/web/permissions.js +4 -7
- package/dist/web/permissions.js.map +1 -1
- package/dist/web/priority.js.map +1 -1
- package/dist/web/storage/FileSystem.js.map +1 -1
- package/dist/web/storage/chunksAndKnownStates.js +2 -4
- package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/web/storage/index.js +6 -15
- package/dist/web/storage/index.js.map +1 -1
- package/dist/web/streamUtils.js.map +1 -1
- package/dist/web/sync.js +2 -4
- package/dist/web/sync.js.map +1 -1
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/web/typeUtils/expectGroup.js.map +1 -1
- package/dist/web/typeUtils/isAccountID.js.map +1 -1
- package/dist/web/typeUtils/isCoValue.js +1 -1
- package/dist/web/typeUtils/isCoValue.js.map +1 -1
- package/package.json +4 -14
- package/src/PeerKnownStates.ts +91 -89
- package/src/PeerState.ts +72 -73
- package/src/PriorityBasedMessageQueue.ts +42 -49
- package/src/base64url.test.ts +24 -24
- package/src/base64url.ts +44 -45
- package/src/coValue.ts +45 -45
- package/src/coValueCore.ts +746 -785
- package/src/coValueState.ts +82 -72
- package/src/coValues/account.ts +143 -150
- package/src/coValues/coList.ts +520 -522
- package/src/coValues/coMap.ts +283 -285
- package/src/coValues/coStream.ts +320 -324
- package/src/coValues/group.ts +306 -305
- package/src/coreToCoValue.ts +28 -31
- package/src/crypto/PureJSCrypto.ts +188 -194
- package/src/crypto/WasmCrypto.ts +236 -254
- package/src/crypto/crypto.ts +302 -309
- package/src/exports.ts +116 -116
- package/src/ids.ts +9 -9
- package/src/jsonStringify.ts +46 -46
- package/src/jsonValue.ts +24 -10
- package/src/localNode.ts +635 -660
- package/src/media.ts +3 -3
- package/src/permissions.ts +272 -278
- package/src/priority.ts +21 -19
- package/src/storage/FileSystem.ts +91 -99
- package/src/storage/chunksAndKnownStates.ts +110 -115
- package/src/storage/index.ts +466 -497
- package/src/streamUtils.ts +60 -60
- package/src/sync.ts +593 -615
- package/src/tests/PeerKnownStates.test.ts +38 -34
- package/src/tests/PeerState.test.ts +101 -64
- package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
- package/src/tests/account.test.ts +59 -59
- package/src/tests/coList.test.ts +65 -65
- package/src/tests/coMap.test.ts +137 -137
- package/src/tests/coStream.test.ts +254 -257
- package/src/tests/coValueCore.test.ts +153 -156
- package/src/tests/crypto.test.ts +136 -144
- package/src/tests/cryptoImpl.test.ts +205 -197
- package/src/tests/group.test.ts +24 -24
- package/src/tests/permissions.test.ts +1306 -1371
- package/src/tests/priority.test.ts +65 -82
- package/src/tests/sync.test.ts +1300 -1291
- package/src/tests/testUtils.ts +52 -53
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
- package/src/typeUtils/expectGroup.ts +9 -9
- package/src/typeUtils/isAccountID.ts +1 -1
- package/src/typeUtils/isCoValue.ts +9 -9
- package/tsconfig.json +4 -6
- package/tsconfig.native.json +9 -11
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -25
- package/.prettierrc.js +0 -9
|
@@ -1,304 +1,301 @@
|
|
|
1
|
-
import { expect, test
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
import { expectStream } from "../coValue.js";
|
|
3
|
-
import { RawBinaryCoStream } from "../coValues/coStream.js";
|
|
4
3
|
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
|
|
4
|
+
import { RawBinaryCoStream } from "../coValues/coStream.js";
|
|
5
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
5
6
|
import { LocalNode } from "../localNode.js";
|
|
6
7
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
7
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
8
8
|
|
|
9
9
|
const Crypto = await WasmCrypto.create();
|
|
10
10
|
|
|
11
11
|
test("Empty CoStream works", () => {
|
|
12
|
-
|
|
12
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const coValue = node.createCoValue({
|
|
15
|
+
type: "costream",
|
|
16
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
17
|
+
meta: null,
|
|
18
|
+
...Crypto.createdNowUnique(),
|
|
19
|
+
});
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const content = expectStream(coValue.getCurrentContent());
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
expect(content.type).toEqual("costream");
|
|
24
|
+
expect(content.toJSON()).toEqual({});
|
|
25
|
+
expect(content.getSingleStream()).toEqual(undefined);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test("Can push into CoStream", () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
30
|
+
|
|
31
|
+
const coValue = node.createCoValue({
|
|
32
|
+
type: "costream",
|
|
33
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
34
|
+
meta: null,
|
|
35
|
+
...Crypto.createdNowUnique(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const content = expectStream(coValue.getCurrentContent());
|
|
39
|
+
|
|
40
|
+
content.push({ hello: "world" }, "trusting");
|
|
41
|
+
expect(content.toJSON()).toEqual({
|
|
42
|
+
[node.currentSessionID]: [{ hello: "world" }],
|
|
43
|
+
});
|
|
44
|
+
content.push({ foo: "bar" }, "trusting");
|
|
45
|
+
expect(content.toJSON()).toEqual({
|
|
46
|
+
[node.currentSessionID]: [{ hello: "world" }, { foo: "bar" }],
|
|
47
|
+
});
|
|
48
|
+
expect(content.getSingleStream()).toEqual([
|
|
49
|
+
{ hello: "world" },
|
|
50
|
+
{ foo: "bar" },
|
|
51
|
+
]);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
test("Empty RawBinaryCoStream works", () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
56
|
+
|
|
57
|
+
const coValue = node.createCoValue({
|
|
58
|
+
type: "costream",
|
|
59
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
60
|
+
meta: { type: "binary" },
|
|
61
|
+
...Crypto.createdNowUnique(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const content = coValue.getCurrentContent();
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
content.type !== "costream" ||
|
|
68
|
+
content.headerMeta?.type !== "binary" ||
|
|
69
|
+
!(content instanceof RawBinaryCoStream)
|
|
70
|
+
) {
|
|
71
|
+
throw new Error("Expected binary stream");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
expect(content.type).toEqual("costream");
|
|
75
|
+
expect(content.headerMeta.type).toEqual("binary");
|
|
76
|
+
expect(content.toJSON()).toEqual({});
|
|
77
|
+
expect(content.getBinaryChunks()).toEqual(undefined);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
test("Can push into RawBinaryCoStream", () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
81
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
82
|
+
|
|
83
|
+
const coValue = node.createCoValue({
|
|
84
|
+
type: "costream",
|
|
85
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
86
|
+
meta: { type: "binary" },
|
|
87
|
+
...Crypto.createdNowUnique(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const content = coValue.getCurrentContent();
|
|
91
|
+
|
|
92
|
+
if (
|
|
93
|
+
content.type !== "costream" ||
|
|
94
|
+
content.headerMeta?.type !== "binary" ||
|
|
95
|
+
!(content instanceof RawBinaryCoStream)
|
|
96
|
+
) {
|
|
97
|
+
throw new Error("Expected binary stream");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
content.startBinaryStream(
|
|
101
|
+
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
102
|
+
"trusting",
|
|
103
|
+
);
|
|
104
|
+
content.pushBinaryStreamChunk(new Uint8Array([1, 2, 3]), "trusting");
|
|
105
|
+
content.pushBinaryStreamChunk(new Uint8Array([4, 5, 6]), "trusting");
|
|
106
|
+
|
|
107
|
+
content.endBinaryStream("trusting");
|
|
108
|
+
expect(content.getBinaryChunks()).toEqual({
|
|
109
|
+
mimeType: "text/plain",
|
|
110
|
+
fileName: "test.txt",
|
|
111
|
+
chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
|
|
112
|
+
finished: true,
|
|
113
|
+
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
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", () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
117
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
118
|
+
|
|
119
|
+
const coValue = node.createCoValue({
|
|
120
|
+
type: "costream",
|
|
121
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
122
|
+
meta: { type: "binary" },
|
|
123
|
+
...Crypto.createdNowUnique(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const content = coValue.getCurrentContent();
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
content.type !== "costream" ||
|
|
130
|
+
content.headerMeta?.type !== "binary" ||
|
|
131
|
+
!(content instanceof RawBinaryCoStream)
|
|
132
|
+
) {
|
|
133
|
+
throw new Error("Expected binary stream");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
content.startBinaryStream(
|
|
137
|
+
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
138
|
+
"trusting",
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < 10; i++) {
|
|
142
|
+
const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE / 3 + 100);
|
|
143
|
+
|
|
144
|
+
content.pushBinaryStreamChunk(chunk, "trusting");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
content.endBinaryStream("trusting");
|
|
148
|
+
|
|
149
|
+
const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
|
|
150
|
+
expect(sessionEntry.transactions.length).toEqual(12);
|
|
151
|
+
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
152
|
+
expect(sessionEntry.signatureAfter[1]).not.toBeDefined();
|
|
153
|
+
expect(sessionEntry.signatureAfter[2]).not.toBeDefined();
|
|
154
|
+
expect(sessionEntry.signatureAfter[3]).toBeDefined();
|
|
155
|
+
expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
|
|
156
|
+
expect(sessionEntry.signatureAfter[5]).not.toBeDefined();
|
|
157
|
+
expect(sessionEntry.signatureAfter[6]).toBeDefined();
|
|
158
|
+
expect(sessionEntry.signatureAfter[7]).not.toBeDefined();
|
|
159
|
+
expect(sessionEntry.signatureAfter[8]).not.toBeDefined();
|
|
160
|
+
expect(sessionEntry.signatureAfter[9]).toBeDefined();
|
|
161
|
+
expect(sessionEntry.signatureAfter[10]).not.toBeDefined();
|
|
162
|
+
expect(sessionEntry.signatureAfter[11]).not.toBeDefined();
|
|
163
|
+
|
|
164
|
+
const newContent = coValue.newContentSince({
|
|
165
|
+
id: coValue.id,
|
|
166
|
+
header: false,
|
|
167
|
+
sessions: {},
|
|
168
|
+
})!;
|
|
169
|
+
|
|
170
|
+
expect(newContent.length).toEqual(5);
|
|
171
|
+
expect(newContent[0]!.header).toBeDefined();
|
|
172
|
+
expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
173
|
+
sessionEntry.signatureAfter[3],
|
|
174
|
+
);
|
|
175
|
+
expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
176
|
+
sessionEntry.signatureAfter[6],
|
|
177
|
+
);
|
|
178
|
+
expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
179
|
+
sessionEntry.signatureAfter[9],
|
|
180
|
+
);
|
|
181
|
+
expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
182
|
+
sessionEntry.lastSignature,
|
|
183
|
+
);
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
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", () => {
|
|
187
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
188
|
+
|
|
189
|
+
const coValue = node.createCoValue({
|
|
190
|
+
type: "costream",
|
|
191
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
192
|
+
meta: { type: "binary" },
|
|
193
|
+
...Crypto.createdNowUnique(),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const content = coValue.getCurrentContent();
|
|
197
|
+
|
|
198
|
+
if (
|
|
199
|
+
content.type !== "costream" ||
|
|
200
|
+
content.headerMeta?.type !== "binary" ||
|
|
201
|
+
!(content instanceof RawBinaryCoStream)
|
|
202
|
+
) {
|
|
203
|
+
throw new Error("Expected binary stream");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
content.startBinaryStream(
|
|
207
|
+
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
208
|
+
"trusting",
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE + 100);
|
|
212
|
+
|
|
213
|
+
for (let i = 0; i < 3; i++) {
|
|
214
|
+
content.pushBinaryStreamChunk(chunk, "trusting");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
content.endBinaryStream("trusting");
|
|
218
|
+
|
|
219
|
+
const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
|
|
220
|
+
expect(sessionEntry.transactions.length).toEqual(5);
|
|
221
|
+
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
222
|
+
expect(sessionEntry.signatureAfter[1]).toBeDefined();
|
|
223
|
+
expect(sessionEntry.signatureAfter[2]).toBeDefined();
|
|
224
|
+
expect(sessionEntry.signatureAfter[3]).toBeDefined();
|
|
225
|
+
expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
|
|
226
|
+
|
|
227
|
+
const newContent = coValue.newContentSince({
|
|
228
|
+
id: coValue.id,
|
|
229
|
+
header: false,
|
|
230
|
+
sessions: {},
|
|
231
|
+
})!;
|
|
232
|
+
|
|
233
|
+
expect(newContent.length).toEqual(5);
|
|
234
|
+
expect(newContent[0]!.header).toBeDefined();
|
|
235
|
+
expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
236
|
+
sessionEntry.signatureAfter[1],
|
|
237
|
+
);
|
|
238
|
+
expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
239
|
+
sessionEntry.signatureAfter[2],
|
|
240
|
+
);
|
|
241
|
+
expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
242
|
+
sessionEntry.signatureAfter[3],
|
|
243
|
+
);
|
|
244
|
+
expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
245
|
+
sessionEntry.lastSignature,
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("isBinaryStreamEnded", () => {
|
|
250
|
+
function setup() {
|
|
187
251
|
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
188
252
|
|
|
189
253
|
const coValue = node.createCoValue({
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
254
|
+
type: "costream",
|
|
255
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
256
|
+
meta: { type: "binary" },
|
|
257
|
+
...Crypto.createdNowUnique(),
|
|
194
258
|
});
|
|
195
259
|
|
|
196
260
|
const content = coValue.getCurrentContent();
|
|
197
261
|
|
|
198
262
|
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
263
|
+
content.type !== "costream" ||
|
|
264
|
+
content.headerMeta?.type !== "binary" ||
|
|
265
|
+
!(content instanceof RawBinaryCoStream)
|
|
202
266
|
) {
|
|
203
|
-
|
|
267
|
+
throw new Error("Expected binary stream");
|
|
204
268
|
}
|
|
205
269
|
|
|
206
|
-
content
|
|
207
|
-
|
|
208
|
-
"trusting",
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE + 100);
|
|
270
|
+
return content;
|
|
271
|
+
}
|
|
212
272
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
273
|
+
test("returns true when the last item is end", () => {
|
|
274
|
+
const stream = setup();
|
|
216
275
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
expect(sessionEntry.transactions.length).toEqual(5);
|
|
221
|
-
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
222
|
-
expect(sessionEntry.signatureAfter[1]).toBeDefined();
|
|
223
|
-
expect(sessionEntry.signatureAfter[2]).toBeDefined();
|
|
224
|
-
expect(sessionEntry.signatureAfter[3]).toBeDefined();
|
|
225
|
-
expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
|
|
226
|
-
|
|
227
|
-
const newContent = coValue.newContentSince({
|
|
228
|
-
id: coValue.id,
|
|
229
|
-
header: false,
|
|
230
|
-
sessions: {},
|
|
231
|
-
})!;
|
|
232
|
-
|
|
233
|
-
expect(newContent.length).toEqual(5);
|
|
234
|
-
expect(newContent[0]!.header).toBeDefined();
|
|
235
|
-
expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
236
|
-
sessionEntry.signatureAfter[1],
|
|
237
|
-
);
|
|
238
|
-
expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
239
|
-
sessionEntry.signatureAfter[2],
|
|
240
|
-
);
|
|
241
|
-
expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(
|
|
242
|
-
sessionEntry.signatureAfter[3],
|
|
276
|
+
stream.startBinaryStream(
|
|
277
|
+
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
278
|
+
"trusting",
|
|
243
279
|
);
|
|
244
|
-
|
|
245
|
-
sessionEntry.lastSignature,
|
|
246
|
-
);
|
|
247
|
-
});
|
|
280
|
+
stream.endBinaryStream("trusting");
|
|
248
281
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const node = new LocalNode(
|
|
252
|
-
...randomAnonymousAccountAndSessionID(),
|
|
253
|
-
Crypto,
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
const coValue = node.createCoValue({
|
|
257
|
-
type: "costream",
|
|
258
|
-
ruleset: { type: "unsafeAllowAll" },
|
|
259
|
-
meta: { type: "binary" },
|
|
260
|
-
...Crypto.createdNowUnique(),
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
const content = coValue.getCurrentContent();
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
content.type !== "costream" ||
|
|
267
|
-
content.headerMeta?.type !== "binary" ||
|
|
268
|
-
!(content instanceof RawBinaryCoStream)
|
|
269
|
-
) {
|
|
270
|
-
throw new Error("Expected binary stream");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return content;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
test("returns true when the last item is end", () => {
|
|
277
|
-
const stream = setup();
|
|
282
|
+
expect(stream.isBinaryStreamEnded()).toBe(true);
|
|
283
|
+
});
|
|
278
284
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
"trusting",
|
|
282
|
-
);
|
|
283
|
-
stream.endBinaryStream("trusting");
|
|
284
|
-
|
|
285
|
-
expect(stream.isBinaryStreamEnded()).toBe(true);
|
|
286
|
-
});
|
|
285
|
+
test("returns false if the stream isn't ended", () => {
|
|
286
|
+
const stream = setup();
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
293
|
-
"trusting",
|
|
294
|
-
);
|
|
288
|
+
stream.startBinaryStream(
|
|
289
|
+
{ mimeType: "text/plain", fileName: "test.txt" },
|
|
290
|
+
"trusting",
|
|
291
|
+
);
|
|
295
292
|
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
expect(stream.isBinaryStreamEnded()).toBe(false);
|
|
294
|
+
});
|
|
298
295
|
|
|
299
|
-
|
|
300
|
-
|
|
296
|
+
test("returns false if the stream isn't started", () => {
|
|
297
|
+
const stream = setup();
|
|
301
298
|
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
expect(stream.isBinaryStreamEnded()).toBe(false);
|
|
300
|
+
});
|
|
304
301
|
});
|