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.
Files changed (168) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +16 -0
  3. package/dist/PeerState.d.ts +3 -0
  4. package/dist/PeerState.d.ts.map +1 -1
  5. package/dist/PeerState.js +9 -0
  6. package/dist/PeerState.js.map +1 -1
  7. package/dist/SyncStateManager.d.ts.map +1 -1
  8. package/dist/SyncStateManager.js +2 -3
  9. package/dist/SyncStateManager.js.map +1 -1
  10. package/dist/coValue.d.ts +6 -4
  11. package/dist/coValue.d.ts.map +1 -1
  12. package/dist/coValue.js +5 -4
  13. package/dist/coValue.js.map +1 -1
  14. package/dist/coValueCore/coValueCore.d.ts +143 -0
  15. package/dist/coValueCore/coValueCore.d.ts.map +1 -0
  16. package/dist/{coValueCore.js → coValueCore/coValueCore.js} +314 -246
  17. package/dist/coValueCore/coValueCore.js.map +1 -0
  18. package/dist/coValueCore/verifiedState.d.ts +65 -0
  19. package/dist/coValueCore/verifiedState.d.ts.map +1 -0
  20. package/dist/coValueCore/verifiedState.js +210 -0
  21. package/dist/coValueCore/verifiedState.js.map +1 -0
  22. package/dist/coValues/account.d.ts +8 -10
  23. package/dist/coValues/account.d.ts.map +1 -1
  24. package/dist/coValues/account.js +12 -13
  25. package/dist/coValues/account.js.map +1 -1
  26. package/dist/coValues/coList.d.ts +10 -6
  27. package/dist/coValues/coList.d.ts.map +1 -1
  28. package/dist/coValues/coList.js +41 -15
  29. package/dist/coValues/coList.js.map +1 -1
  30. package/dist/coValues/coMap.d.ts +4 -3
  31. package/dist/coValues/coMap.d.ts.map +1 -1
  32. package/dist/coValues/coMap.js +5 -3
  33. package/dist/coValues/coMap.js.map +1 -1
  34. package/dist/coValues/coPlainText.d.ts +2 -2
  35. package/dist/coValues/coPlainText.d.ts.map +1 -1
  36. package/dist/coValues/coPlainText.js +5 -5
  37. package/dist/coValues/coPlainText.js.map +1 -1
  38. package/dist/coValues/coStream.d.ts +5 -4
  39. package/dist/coValues/coStream.d.ts.map +1 -1
  40. package/dist/coValues/coStream.js +5 -3
  41. package/dist/coValues/coStream.js.map +1 -1
  42. package/dist/coValues/group.d.ts +7 -2
  43. package/dist/coValues/group.d.ts.map +1 -1
  44. package/dist/coValues/group.js +29 -26
  45. package/dist/coValues/group.js.map +1 -1
  46. package/dist/coreToCoValue.d.ts +4 -3
  47. package/dist/coreToCoValue.d.ts.map +1 -1
  48. package/dist/coreToCoValue.js +10 -14
  49. package/dist/coreToCoValue.js.map +1 -1
  50. package/dist/exports.d.ts +6 -5
  51. package/dist/exports.d.ts.map +1 -1
  52. package/dist/exports.js +3 -4
  53. package/dist/exports.js.map +1 -1
  54. package/dist/localNode.d.ts +30 -24
  55. package/dist/localNode.d.ts.map +1 -1
  56. package/dist/localNode.js +153 -177
  57. package/dist/localNode.js.map +1 -1
  58. package/dist/permissions.d.ts +2 -1
  59. package/dist/permissions.d.ts.map +1 -1
  60. package/dist/permissions.js +15 -11
  61. package/dist/permissions.js.map +1 -1
  62. package/dist/priority.d.ts +1 -1
  63. package/dist/priority.d.ts.map +1 -1
  64. package/dist/sync.d.ts +2 -2
  65. package/dist/sync.d.ts.map +1 -1
  66. package/dist/sync.js +86 -55
  67. package/dist/sync.js.map +1 -1
  68. package/dist/tests/coList.test.js +133 -13
  69. package/dist/tests/coList.test.js.map +1 -1
  70. package/dist/tests/coMap.test.js +43 -14
  71. package/dist/tests/coMap.test.js.map +1 -1
  72. package/dist/tests/coPlainText.test.js +9 -10
  73. package/dist/tests/coPlainText.test.js.map +1 -1
  74. package/dist/tests/coStream.test.js +49 -18
  75. package/dist/tests/coStream.test.js.map +1 -1
  76. package/dist/tests/coValueCore.test.js +22 -28
  77. package/dist/tests/coValueCore.test.js.map +1 -1
  78. package/dist/tests/coValueCoreLoadingState.test.d.ts +2 -0
  79. package/dist/tests/coValueCoreLoadingState.test.d.ts.map +1 -0
  80. package/dist/tests/coValueCoreLoadingState.test.js +227 -0
  81. package/dist/tests/coValueCoreLoadingState.test.js.map +1 -0
  82. package/dist/tests/group.test.js +42 -43
  83. package/dist/tests/group.test.js.map +1 -1
  84. package/dist/tests/messagesTestUtils.d.ts +2 -2
  85. package/dist/tests/messagesTestUtils.d.ts.map +1 -1
  86. package/dist/tests/messagesTestUtils.js +1 -1
  87. package/dist/tests/messagesTestUtils.js.map +1 -1
  88. package/dist/tests/permissions.test.js +224 -292
  89. package/dist/tests/permissions.test.js.map +1 -1
  90. package/dist/tests/priority.test.js +13 -14
  91. package/dist/tests/priority.test.js.map +1 -1
  92. package/dist/tests/sync.auth.test.d.ts +2 -0
  93. package/dist/tests/sync.auth.test.d.ts.map +1 -0
  94. package/dist/tests/sync.auth.test.js +141 -0
  95. package/dist/tests/sync.auth.test.js.map +1 -0
  96. package/dist/tests/sync.load.test.js +60 -2
  97. package/dist/tests/sync.load.test.js.map +1 -1
  98. package/dist/tests/sync.mesh.test.js +70 -10
  99. package/dist/tests/sync.mesh.test.js.map +1 -1
  100. package/dist/tests/sync.peerReconciliation.test.js +19 -19
  101. package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
  102. package/dist/tests/sync.storage.test.js +20 -13
  103. package/dist/tests/sync.storage.test.js.map +1 -1
  104. package/dist/tests/sync.test.js +32 -39
  105. package/dist/tests/sync.test.js.map +1 -1
  106. package/dist/tests/sync.upload.test.js +126 -37
  107. package/dist/tests/sync.upload.test.js.map +1 -1
  108. package/dist/tests/testUtils.d.ts +24 -15
  109. package/dist/tests/testUtils.d.ts.map +1 -1
  110. package/dist/tests/testUtils.js +88 -61
  111. package/dist/tests/testUtils.js.map +1 -1
  112. package/dist/typeUtils/expectGroup.js +1 -1
  113. package/dist/typeUtils/expectGroup.js.map +1 -1
  114. package/package.json +1 -1
  115. package/src/PeerState.ts +11 -0
  116. package/src/SyncStateManager.ts +2 -3
  117. package/src/coValue.ts +14 -8
  118. package/src/{coValueCore.ts → coValueCore/coValueCore.ts} +470 -413
  119. package/src/coValueCore/verifiedState.ts +376 -0
  120. package/src/coValues/account.ts +20 -25
  121. package/src/coValues/coList.ts +63 -29
  122. package/src/coValues/coMap.ts +13 -6
  123. package/src/coValues/coPlainText.ts +10 -8
  124. package/src/coValues/coStream.ts +12 -7
  125. package/src/coValues/group.ts +50 -28
  126. package/src/coreToCoValue.ts +14 -15
  127. package/src/exports.ts +9 -7
  128. package/src/localNode.ts +248 -283
  129. package/src/permissions.ts +18 -12
  130. package/src/priority.ts +1 -1
  131. package/src/sync.ts +96 -63
  132. package/src/tests/coList.test.ts +200 -12
  133. package/src/tests/coMap.test.ts +65 -14
  134. package/src/tests/coPlainText.test.ts +12 -9
  135. package/src/tests/coStream.test.ts +80 -17
  136. package/src/tests/coValueCore.test.ts +30 -27
  137. package/src/tests/coValueCoreLoadingState.test.ts +337 -0
  138. package/src/tests/group.test.ts +44 -68
  139. package/src/tests/messagesTestUtils.ts +3 -8
  140. package/src/tests/permissions.test.ts +283 -449
  141. package/src/tests/priority.test.ts +17 -13
  142. package/src/tests/sync.auth.test.ts +188 -0
  143. package/src/tests/sync.load.test.ts +79 -2
  144. package/src/tests/sync.mesh.test.ts +89 -9
  145. package/src/tests/sync.peerReconciliation.test.ts +25 -25
  146. package/src/tests/sync.storage.test.ts +20 -13
  147. package/src/tests/sync.test.ts +43 -43
  148. package/src/tests/sync.upload.test.ts +157 -37
  149. package/src/tests/testUtils.ts +120 -74
  150. package/src/typeUtils/expectGroup.ts +1 -1
  151. package/dist/CoValuesStore.d.ts +0 -14
  152. package/dist/CoValuesStore.d.ts.map +0 -1
  153. package/dist/CoValuesStore.js +0 -32
  154. package/dist/CoValuesStore.js.map +0 -1
  155. package/dist/coValueCore.d.ts +0 -141
  156. package/dist/coValueCore.d.ts.map +0 -1
  157. package/dist/coValueCore.js.map +0 -1
  158. package/dist/coValueState.d.ts +0 -34
  159. package/dist/coValueState.d.ts.map +0 -1
  160. package/dist/coValueState.js +0 -228
  161. package/dist/coValueState.js.map +0 -1
  162. package/dist/tests/coValueState.test.d.ts +0 -2
  163. package/dist/tests/coValueState.test.d.ts.map +0 -1
  164. package/dist/tests/coValueState.test.js +0 -344
  165. package/dist/tests/coValueState.test.js.map +0 -1
  166. package/src/CoValuesStore.ts +0 -41
  167. package/src/coValueState.ts +0 -300
  168. package/src/tests/coValueState.test.ts +0 -525
@@ -5,14 +5,15 @@ import { WasmCrypto } from "../crypto/WasmCrypto.js";
5
5
  import { expectGroup } from "../typeUtils/expectGroup.js";
6
6
  import {
7
7
  connectTwoPeers,
8
+ createAccountInNode,
8
9
  createThreeConnectedNodes,
9
10
  createTwoConnectedNodes,
10
11
  groupWithTwoAdmins,
11
12
  groupWithTwoAdminsHighLevel,
12
- hotSleep,
13
13
  loadCoValueOrFail,
14
14
  newGroup,
15
15
  newGroupHighLevel,
16
+ waitFor,
16
17
  } from "./testUtils.js";
17
18
 
18
19
  const Crypto = await WasmCrypto.create();
@@ -29,17 +30,12 @@ test("Added admin can add a third admin to a group", () => {
29
30
  const { groupCore, otherAdmin, node } = groupWithTwoAdmins();
30
31
 
31
32
  const groupAsOtherAdmin = expectGroup(
32
- groupCore
33
- .testWithDifferentAccount(
34
- otherAdmin,
35
- Crypto.newRandomSessionID(otherAdmin.id),
36
- )
37
- .getCurrentContent(),
33
+ groupCore.contentInClonedNodeWithDifferentAccount(otherAdmin),
38
34
  );
39
35
 
40
36
  expect(groupAsOtherAdmin.get(otherAdmin.id)).toEqual("admin");
41
37
 
42
- const thirdAdmin = node.createAccount();
38
+ const thirdAdmin = createAccountInNode(groupAsOtherAdmin.core.node);
43
39
 
44
40
  groupAsOtherAdmin.set(thirdAdmin.id, "admin", "trusting");
45
41
  expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
@@ -49,15 +45,10 @@ test("Added adming can add a third admin to a group (high level)", () => {
49
45
  const { group, otherAdmin } = groupWithTwoAdminsHighLevel();
50
46
 
51
47
  const groupAsOtherAdmin = expectGroup(
52
- group.core
53
- .testWithDifferentAccount(
54
- otherAdmin,
55
- Crypto.newRandomSessionID(otherAdmin.id),
56
- )
57
- .getCurrentContent(),
48
+ group.core.contentInClonedNodeWithDifferentAccount(otherAdmin),
58
49
  );
59
50
 
60
- const thirdAdmin = groupAsOtherAdmin.core.node.createAccount();
51
+ const thirdAdmin = createAccountInNode(groupAsOtherAdmin.core.node);
61
52
 
62
53
  groupAsOtherAdmin.addMember(thirdAdmin, "admin");
63
54
 
@@ -75,12 +66,7 @@ test("Admins can't demote other admins in a group", () => {
75
66
  expect(groupContent.get(otherAdmin.id)).toEqual("admin");
76
67
 
77
68
  const groupAsOtherAdmin = expectGroup(
78
- groupCore
79
- .testWithDifferentAccount(
80
- otherAdmin,
81
- Crypto.newRandomSessionID(otherAdmin.id),
82
- )
83
- .getCurrentContent(),
69
+ groupCore.contentInClonedNodeWithDifferentAccount(otherAdmin),
84
70
  );
85
71
 
86
72
  groupAsOtherAdmin.set(admin.id, "writer", "trusting");
@@ -91,12 +77,7 @@ test("Admins can't demote other admins in a group (high level)", () => {
91
77
  const { group, admin, otherAdmin } = groupWithTwoAdminsHighLevel();
92
78
 
93
79
  const groupAsOtherAdmin = expectGroup(
94
- group.core
95
- .testWithDifferentAccount(
96
- otherAdmin,
97
- Crypto.newRandomSessionID(otherAdmin.id),
98
- )
99
- .getCurrentContent(),
80
+ group.core.contentInClonedNodeWithDifferentAccount(otherAdmin),
100
81
  );
101
82
 
102
83
  expect(() => groupAsOtherAdmin.addMemberInternal(admin.id, "writer")).toThrow(
@@ -108,7 +89,7 @@ test("Admins can't demote other admins in a group (high level)", () => {
108
89
 
109
90
  test("Admins an add writers to a group, who can't add admins, writers, or readers", () => {
110
91
  const { groupCore, node } = newGroup();
111
- const writer = node.createAccount();
92
+ const writer = createAccountInNode(node);
112
93
 
113
94
  const groupContent = expectGroup(groupCore.getCurrentContent());
114
95
 
@@ -118,14 +99,12 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
118
99
  expect(groupContent.get(writer.id)).toEqual("writer");
119
100
 
120
101
  const groupAsWriter = expectGroup(
121
- groupCore
122
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
123
- .getCurrentContent(),
102
+ groupCore.contentInClonedNodeWithDifferentAccount(writer),
124
103
  );
125
104
 
126
105
  expect(groupAsWriter.get(writer.id)).toEqual("writer");
127
106
 
128
- const otherAgent = node.createAccount();
107
+ const otherAgent = createAccountInNode(node);
129
108
 
130
109
  groupAsWriter.set(otherAgent.id, "admin", "trusting");
131
110
  expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
@@ -140,20 +119,18 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
140
119
  test("Admins an add writers to a group, who can't add admins, writers, or readers (high level)", () => {
141
120
  const { group, node } = newGroupHighLevel();
142
121
 
143
- const writer = node.createAccount();
122
+ const writer = createAccountInNode(node);
144
123
 
145
124
  group.addMember(writer, "writer");
146
125
  expect(group.get(writer.id)).toEqual("writer");
147
126
 
148
127
  const groupAsWriter = expectGroup(
149
- group.core
150
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
151
- .getCurrentContent(),
128
+ group.core.contentInClonedNodeWithDifferentAccount(writer),
152
129
  );
153
130
 
154
131
  expect(groupAsWriter.get(writer.id)).toEqual("writer");
155
132
 
156
- const otherAgent = groupAsWriter.core.node.createAccount();
133
+ const otherAgent = createAccountInNode(groupAsWriter.core.node);
157
134
 
158
135
  expect(() => groupAsWriter.addMember(otherAgent, "admin")).toThrow(
159
136
  "Failed to set role",
@@ -170,7 +147,7 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
170
147
 
171
148
  test("Admins can add readers to a group, who can't add admins, writers, or readers", () => {
172
149
  const { groupCore, node } = newGroup();
173
- const reader = node.createAccount();
150
+ const reader = createAccountInNode(node);
174
151
 
175
152
  const groupContent = expectGroup(groupCore.getCurrentContent());
176
153
 
@@ -178,14 +155,12 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
178
155
  expect(groupContent.get(reader.id)).toEqual("reader");
179
156
 
180
157
  const groupAsReader = expectGroup(
181
- groupCore
182
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
183
- .getCurrentContent(),
158
+ groupCore.contentInClonedNodeWithDifferentAccount(reader),
184
159
  );
185
160
 
186
161
  expect(groupAsReader.get(reader.id)).toEqual("reader");
187
162
 
188
- const otherAgent = node.createAccount();
163
+ const otherAgent = createAccountInNode(node);
189
164
 
190
165
  groupAsReader.set(otherAgent.id, "admin", "trusting");
191
166
  expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
@@ -201,20 +176,18 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
201
176
  test("Admins can add readers to a group, who can't add admins, writers, or readers (high level)", () => {
202
177
  const { group, node } = newGroupHighLevel();
203
178
 
204
- const reader = node.createAccount();
179
+ const reader = createAccountInNode(node);
205
180
 
206
181
  group.addMember(reader, "reader");
207
182
  expect(group.get(reader.id)).toEqual("reader");
208
183
 
209
184
  const groupAsReader = expectGroup(
210
- group.core
211
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
212
- .getCurrentContent(),
185
+ group.core.contentInClonedNodeWithDifferentAccount(reader),
213
186
  );
214
187
 
215
188
  expect(groupAsReader.get(reader.id)).toEqual("reader");
216
189
 
217
- const otherAgent = groupAsReader.core.node.createAccount();
190
+ const otherAgent = createAccountInNode(groupAsReader.core.node);
218
191
 
219
192
  expect(() => groupAsReader.addMember(otherAgent, "admin")).toThrow(
220
193
  "Failed to set role",
@@ -257,7 +230,7 @@ test("Admins can write to an object that is owned by their group (high level)",
257
230
  test("Writers can write to an object that is owned by their group", () => {
258
231
  const { node, groupCore } = newGroup();
259
232
 
260
- const writer = node.createAccount();
233
+ const writer = createAccountInNode(node);
261
234
 
262
235
  const group = expectGroup(groupCore.getCurrentContent());
263
236
  group.set(writer.id, "writer", "trusting");
@@ -270,32 +243,25 @@ test("Writers can write to an object that is owned by their group", () => {
270
243
  ...Crypto.createdNowUnique(),
271
244
  });
272
245
 
273
- const childObjectAsWriter = childObject.testWithDifferentAccount(
274
- writer,
275
- Crypto.newRandomSessionID(writer.id),
276
- );
277
-
278
- const childContentAsWriter = expectMap(
279
- childObjectAsWriter.getCurrentContent(),
246
+ const childObjectAsWriter = expectMap(
247
+ childObject.contentInClonedNodeWithDifferentAccount(writer),
280
248
  );
281
249
 
282
- childContentAsWriter.set("foo", "bar", "trusting");
283
- expect(childContentAsWriter.get("foo")).toEqual("bar");
250
+ childObjectAsWriter.set("foo", "bar", "trusting");
251
+ expect(childObjectAsWriter.get("foo")).toEqual("bar");
284
252
  });
285
253
 
286
254
  test("Writers can write to an object that is owned by their group (high level)", () => {
287
255
  const { node, group } = newGroupHighLevel();
288
256
 
289
- const writer = node.createAccount();
257
+ const writer = createAccountInNode(node);
290
258
 
291
259
  group.addMember(writer, "writer");
292
260
 
293
261
  const childObject = group.createMap();
294
262
 
295
263
  const childObjectAsWriter = expectMap(
296
- childObject.core
297
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
298
- .getCurrentContent(),
264
+ childObject.core.contentInClonedNodeWithDifferentAccount(writer),
299
265
  );
300
266
 
301
267
  childObjectAsWriter.set("foo", "bar", "trusting");
@@ -305,7 +271,7 @@ test("Writers can write to an object that is owned by their group (high level)",
305
271
  test("Readers can not write to an object that is owned by their group", () => {
306
272
  const { node, groupCore } = newGroup();
307
273
 
308
- const reader = node.createAccount();
274
+ const reader = createAccountInNode(node);
309
275
 
310
276
  const group = expectGroup(groupCore.getCurrentContent());
311
277
  group.set(reader.id, "reader", "trusting");
@@ -318,32 +284,26 @@ test("Readers can not write to an object that is owned by their group", () => {
318
284
  ...Crypto.createdNowUnique(),
319
285
  });
320
286
 
321
- const childObjectAsReader = childObject.testWithDifferentAccount(
322
- reader,
323
- Crypto.newRandomSessionID(reader.id),
324
- );
325
-
326
- const childContentAsReader = expectMap(
327
- childObjectAsReader.getCurrentContent(),
287
+ const childObjectAsReader = expectMap(
288
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
328
289
  );
329
290
 
330
- childContentAsReader.set("foo", "bar", "trusting");
331
- expect(childContentAsReader.get("foo")).toBeUndefined();
291
+ childObjectAsReader.set("foo", "bar", "trusting");
292
+ childObjectAsReader.set("foo", "bar", "trusting");
293
+ expect(childObjectAsReader.get("foo")).toBeUndefined();
332
294
  });
333
295
 
334
296
  test("Readers can not write to an object that is owned by their group (high level)", () => {
335
297
  const { node, group } = newGroupHighLevel();
336
298
 
337
- const reader = node.createAccount();
299
+ const reader = createAccountInNode(node);
338
300
 
339
301
  group.addMember(reader, "reader");
340
302
 
341
303
  const childObject = group.createMap();
342
304
 
343
305
  const childObjectAsReader = expectMap(
344
- childObject.core
345
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
346
- .getCurrentContent(),
306
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader),
347
307
  );
348
308
 
349
309
  childObjectAsReader.set("foo", "bar", "trusting");
@@ -401,7 +361,7 @@ test("Admins can set group read key and then use it to create and read private t
401
361
  test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects", () => {
402
362
  const { node, groupCore, admin } = newGroup();
403
363
 
404
- const writer = node.createAccount();
364
+ const writer = createAccountInNode(node);
405
365
 
406
366
  const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
407
367
 
@@ -443,34 +403,28 @@ test("Admins can set group read key and then writers can use it to create and re
443
403
  ...Crypto.createdNowUnique(),
444
404
  });
445
405
 
446
- const childObjectAsWriter = childObject.testWithDifferentAccount(
447
- writer,
448
- Crypto.newRandomSessionID(writer.id),
406
+ const childObjectAsWriter = expectMap(
407
+ childObject.contentInClonedNodeWithDifferentAccount(writer),
449
408
  );
450
409
 
451
410
  expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
411
+ expect(childObjectAsWriter.core.getCurrentReadKey().secret).toEqual(readKey);
452
412
 
453
- const childContentAsWriter = expectMap(
454
- childObjectAsWriter.getCurrentContent(),
455
- );
456
-
457
- childContentAsWriter.set("foo", "bar", "private");
458
- expect(childContentAsWriter.get("foo")).toEqual("bar");
413
+ childObjectAsWriter.set("foo", "bar", "private");
414
+ expect(childObjectAsWriter.get("foo")).toEqual("bar");
459
415
  });
460
416
 
461
417
  test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects (high level)", () => {
462
418
  const { node, group } = newGroupHighLevel();
463
419
 
464
- const writer = node.createAccount();
420
+ const writer = createAccountInNode(node);
465
421
 
466
422
  group.addMember(writer, "writer");
467
423
 
468
424
  const childObject = group.createMap();
469
425
 
470
426
  const childObjectAsWriter = expectMap(
471
- childObject.core
472
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
473
- .getCurrentContent(),
427
+ childObject.core.contentInClonedNodeWithDifferentAccount(writer),
474
428
  );
475
429
 
476
430
  childObjectAsWriter.set("foo", "bar", "private");
@@ -480,7 +434,7 @@ test("Admins can set group read key and then writers can use it to create and re
480
434
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read", () => {
481
435
  const { node, groupCore, admin } = newGroup();
482
436
 
483
- const reader = node.createAccount();
437
+ const reader = createAccountInNode(node);
484
438
 
485
439
  const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
486
440
 
@@ -527,24 +481,18 @@ test("Admins can set group read key and then use it to create private transactio
527
481
  childContent.set("foo", "bar", "private");
528
482
  expect(childContent.get("foo")).toEqual("bar");
529
483
 
530
- const childObjectAsReader = childObject.testWithDifferentAccount(
531
- reader,
532
- Crypto.newRandomSessionID(reader.id),
533
- );
534
-
535
- expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
536
-
537
- const childContentAsReader = expectMap(
538
- childObjectAsReader.getCurrentContent(),
484
+ const childObjectAsReader = expectMap(
485
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
539
486
  );
540
487
 
541
- expect(childContentAsReader.get("foo")).toEqual("bar");
488
+ expect(childObjectAsReader.core.getCurrentReadKey().secret).toEqual(readKey);
489
+ expect(childObjectAsReader.get("foo")).toEqual("bar");
542
490
  });
543
491
 
544
492
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read (high level)", () => {
545
493
  const { node, group } = newGroupHighLevel();
546
494
 
547
- const reader = node.createAccount();
495
+ const reader = createAccountInNode(node);
548
496
 
549
497
  group.addMember(reader, "reader");
550
498
 
@@ -554,9 +502,7 @@ test("Admins can set group read key and then use it to create private transactio
554
502
  expect(childObject.get("foo")).toEqual("bar");
555
503
 
556
504
  const childContentAsReader = expectMap(
557
- childObject.core
558
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
559
- .getCurrentContent(),
505
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader),
560
506
  );
561
507
 
562
508
  expect(childContentAsReader.get("foo")).toEqual("bar");
@@ -565,9 +511,9 @@ test("Admins can set group read key and then use it to create private transactio
565
511
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read, even with a separate later revelation for the same read key", () => {
566
512
  const { node, groupCore, admin } = newGroup();
567
513
 
568
- const reader1 = node.createAccount();
514
+ const reader1 = createAccountInNode(node);
569
515
 
570
- const reader2 = node.createAccount();
516
+ const reader2 = createAccountInNode(node);
571
517
 
572
518
  const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
573
519
 
@@ -614,18 +560,12 @@ test("Admins can set group read key and then use it to create private transactio
614
560
  childContent.set("foo", "bar", "private");
615
561
  expect(childContent.get("foo")).toEqual("bar");
616
562
 
617
- const childObjectAsReader1 = childObject.testWithDifferentAccount(
618
- reader1,
619
- Crypto.newRandomSessionID(reader1.id),
620
- );
621
-
622
- expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
623
-
624
- const childContentAsReader1 = expectMap(
625
- childObjectAsReader1.getCurrentContent(),
563
+ const childObjectAsReader1 = expectMap(
564
+ childObject.contentInClonedNodeWithDifferentAccount(reader1),
626
565
  );
627
566
 
628
- expect(childContentAsReader1.get("foo")).toEqual("bar");
567
+ expect(childObjectAsReader1.core.getCurrentReadKey().secret).toEqual(readKey);
568
+ expect(childObjectAsReader1.get("foo")).toEqual("bar");
629
569
 
630
570
  const revelation3 = Crypto.seal({
631
571
  message: readKey,
@@ -639,26 +579,20 @@ test("Admins can set group read key and then use it to create private transactio
639
579
 
640
580
  groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
641
581
 
642
- const childObjectAsReader2 = childObject.testWithDifferentAccount(
643
- reader2,
644
- Crypto.newRandomSessionID(reader2.id),
582
+ const childObjectAsReader2 = expectMap(
583
+ childObject.contentInClonedNodeWithDifferentAccount(reader2),
645
584
  );
646
585
 
647
- expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
648
-
649
- const childContentAsReader2 = expectMap(
650
- childObjectAsReader2.getCurrentContent(),
651
- );
652
-
653
- expect(childContentAsReader2.get("foo")).toEqual("bar");
586
+ expect(childObjectAsReader2.core.getCurrentReadKey().secret).toEqual(readKey);
587
+ expect(childObjectAsReader2.get("foo")).toEqual("bar");
654
588
  });
655
589
 
656
590
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read, even with a separate later revelation for the same read key (high level)", () => {
657
591
  const { node, group } = newGroupHighLevel();
658
592
 
659
- const reader1 = node.createAccount();
593
+ const reader1 = createAccountInNode(node);
660
594
 
661
- const reader2 = node.createAccount();
595
+ const reader2 = createAccountInNode(node);
662
596
 
663
597
  group.addMember(reader1, "reader");
664
598
 
@@ -668,21 +602,15 @@ test("Admins can set group read key and then use it to create private transactio
668
602
  expect(childObject.get("foo")).toEqual("bar");
669
603
 
670
604
  const childContentAsReader1 = expectMap(
671
- childObject.core
672
- .testWithDifferentAccount(reader1, Crypto.newRandomSessionID(reader1.id))
673
- .getCurrentContent(),
605
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader1),
674
606
  );
675
-
676
607
  expect(childContentAsReader1.get("foo")).toEqual("bar");
677
608
 
678
609
  group.addMember(reader2, "reader");
679
610
 
680
611
  const childContentAsReader2 = expectMap(
681
- childObject.core
682
- .testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
683
- .getCurrentContent(),
612
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader2),
684
613
  );
685
-
686
614
  expect(childContentAsReader2.get("foo")).toEqual("bar");
687
615
  });
688
616
 
@@ -798,7 +726,7 @@ test("Admins can set group read key, make a private transaction in an owned obje
798
726
 
799
727
  expect(childContent.get("foo")).toEqual("bar");
800
728
 
801
- const reader = node.createAccount();
729
+ const reader = createAccountInNode(node);
802
730
 
803
731
  const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
804
732
 
@@ -846,19 +774,13 @@ test("Admins can set group read key, make a private transaction in an owned obje
846
774
  childContent.set("foo2", "bar2", "private");
847
775
  expect(childContent.get("foo2")).toEqual("bar2");
848
776
 
849
- const childObjectAsReader = childObject.testWithDifferentAccount(
850
- reader,
851
- Crypto.newRandomSessionID(reader.id),
852
- );
853
-
854
- expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
855
-
856
- const childContentAsReader = expectMap(
857
- childObjectAsReader.getCurrentContent(),
777
+ const childObjectAsReader = expectMap(
778
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
858
779
  );
859
780
 
860
- expect(childContentAsReader.get("foo")).toEqual("bar");
861
- expect(childContentAsReader.get("foo2")).toEqual("bar2");
781
+ expect(childObjectAsReader.core.getCurrentReadKey().secret).toEqual(readKey2);
782
+ expect(childObjectAsReader.get("foo")).toEqual("bar");
783
+ expect(childObjectAsReader.get("foo2")).toEqual("bar2");
862
784
  });
863
785
 
864
786
  test("Admins can set group read key, make a private transaction in an owned object, rotate the read key, add a reader, make another private transaction in the owned object, and both can be read by the reader (high level)", () => {
@@ -877,7 +799,7 @@ test("Admins can set group read key, make a private transaction in an owned obje
877
799
 
878
800
  expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
879
801
 
880
- const reader = node.createAccount();
802
+ const reader = createAccountInNode(node);
881
803
 
882
804
  group.addMember(reader, "reader");
883
805
 
@@ -885,9 +807,7 @@ test("Admins can set group read key, make a private transaction in an owned obje
885
807
  expect(childObject.get("foo2")).toEqual("bar2");
886
808
 
887
809
  const childContentAsReader = expectMap(
888
- childObject.core
889
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
890
- .getCurrentContent(),
810
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader),
891
811
  );
892
812
 
893
813
  expect(childContentAsReader.get("foo")).toEqual("bar");
@@ -901,12 +821,9 @@ test("only admins can add agent ids", () => {
901
821
  const inviteID = Crypto.getAgentID(inviteSecret);
902
822
 
903
823
  const groupAsInvite = expectGroup(
904
- groupCore
905
- .testWithDifferentAccount(
906
- new ControlledAgent(inviteSecret, Crypto),
907
- Crypto.newRandomSessionID(inviteID),
908
- )
909
- .getCurrentContent(),
824
+ groupCore.contentInClonedNodeWithDifferentAccount(
825
+ new ControlledAgent(inviteSecret, Crypto),
826
+ ),
910
827
  );
911
828
 
912
829
  groupAsInvite.set(inviteID, "adminInvite", "trusting");
@@ -926,9 +843,9 @@ test("Admins can set group read rey, make a private transaction in an owned obje
926
843
 
927
844
  const groupContent = expectGroup(groupCore.getCurrentContent());
928
845
  const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
929
- const reader = node.createAccount();
846
+ const reader = createAccountInNode(node);
930
847
 
931
- const reader2 = node.createAccount();
848
+ const reader2 = createAccountInNode(node);
932
849
 
933
850
  const revelation1 = Crypto.seal({
934
851
  message: readKey,
@@ -980,23 +897,17 @@ test("Admins can set group read rey, make a private transaction in an owned obje
980
897
  childContent.set("foo", "bar", "private");
981
898
  expect(childContent.get("foo")).toEqual("bar");
982
899
 
983
- let childObjectAsReader = childObject.testWithDifferentAccount(
984
- reader,
985
- Crypto.newRandomSessionID(reader.id),
900
+ let childObjectAsReader = expectMap(
901
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
986
902
  );
987
903
 
988
- expect(expectMap(childObjectAsReader.getCurrentContent()).get("foo")).toEqual(
989
- "bar",
990
- );
904
+ expect(childObjectAsReader.get("foo")).toEqual("bar");
991
905
 
992
- let childObjectAsReader2 = childObject.testWithDifferentAccount(
993
- reader,
994
- Crypto.newRandomSessionID(reader.id),
906
+ let childObjectAsReader2 = expectMap(
907
+ childObject.contentInClonedNodeWithDifferentAccount(reader2),
995
908
  );
996
909
 
997
- expect(
998
- expectMap(childObjectAsReader2.getCurrentContent()).get("foo"),
999
- ).toEqual("bar");
910
+ expect(childObjectAsReader2.get("foo")).toEqual("bar");
1000
911
 
1001
912
  const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
1002
913
 
@@ -1041,21 +952,15 @@ test("Admins can set group read rey, make a private transaction in an owned obje
1041
952
  expect(childContent.get("foo2")).toEqual("bar2");
1042
953
 
1043
954
  // TODO: make sure these instances of coValues sync between each other so this isn't necessary?
1044
- childObjectAsReader = childObject.testWithDifferentAccount(
1045
- reader,
1046
- Crypto.newRandomSessionID(reader.id),
955
+ childObjectAsReader = expectMap(
956
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
1047
957
  );
1048
- childObjectAsReader2 = childObject.testWithDifferentAccount(
1049
- reader2,
1050
- Crypto.newRandomSessionID(reader2.id),
958
+ childObjectAsReader2 = expectMap(
959
+ childObject.contentInClonedNodeWithDifferentAccount(reader2),
1051
960
  );
1052
961
 
1053
- expect(
1054
- expectMap(childObjectAsReader.getCurrentContent()).get("foo2"),
1055
- ).toBeUndefined();
1056
- expect(
1057
- expectMap(childObjectAsReader2.getCurrentContent()).get("foo2"),
1058
- ).toEqual("bar2");
962
+ expect(childObjectAsReader.get("foo2")).toBeUndefined();
963
+ expect(childObjectAsReader2.get("foo2")).toEqual("bar2");
1059
964
  });
1060
965
 
1061
966
  test("Admins can set group read rey, make a private transaction in an owned object, rotate the read key, add two readers, rotate the read key again to kick out one reader, make another private transaction in the owned object, and only the remaining reader can read both transactions (high level)", async () => {
@@ -1072,9 +977,9 @@ test("Admins can set group read rey, make a private transaction in an owned obje
1072
977
 
1073
978
  const secondReadKey = childObject.core.getCurrentReadKey();
1074
979
 
1075
- const reader = node.createAccount();
980
+ const reader = createAccountInNode(node);
1076
981
 
1077
- const reader2 = node.createAccount();
982
+ const reader2 = createAccountInNode(node);
1078
983
 
1079
984
  group.addMember(reader, "reader");
1080
985
  group.addMember(reader2, "reader");
@@ -1090,9 +995,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
1090
995
  expect(childObject.get("foo3")).toEqual("bar3");
1091
996
 
1092
997
  const childContentAsReader2 = expectMap(
1093
- childObject.core
1094
- .testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
1095
- .getCurrentContent(),
998
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader2),
1096
999
  );
1097
1000
 
1098
1001
  expect(childContentAsReader2.get("foo")).toEqual("bar");
@@ -1101,9 +1004,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
1101
1004
 
1102
1005
  expect(
1103
1006
  expectMap(
1104
- childObject.core
1105
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
1106
- .getCurrentContent(),
1007
+ childObject.core.contentInClonedNodeWithDifferentAccount(reader),
1107
1008
  ).get("foo3"),
1108
1009
  ).toBeUndefined();
1109
1010
  });
@@ -1167,12 +1068,9 @@ test("Admins can create an adminInvite, which can add an admin", () => {
1167
1068
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1168
1069
 
1169
1070
  const groupAsInvite = expectGroup(
1170
- groupCore
1171
- .testWithDifferentAccount(
1172
- new ControlledAgent(inviteSecret, Crypto),
1173
- Crypto.newRandomSessionID(inviteID),
1174
- )
1175
- .getCurrentContent(),
1071
+ groupCore.contentInClonedNodeWithDifferentAccount(
1072
+ new ControlledAgent(inviteSecret, Crypto),
1073
+ ),
1176
1074
  );
1177
1075
 
1178
1076
  const invitedAdminSecret = Crypto.newRandomAgentSecret();
@@ -1215,9 +1113,8 @@ test("Admins can create an adminInvite, which can add an admin (high-level)", as
1215
1113
  const invitedAdminSecret = Crypto.newRandomAgentSecret();
1216
1114
  const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1217
1115
 
1218
- const nodeAsInvitedAdmin = node.testWithDifferentAccount(
1116
+ const nodeAsInvitedAdmin = node.cloneWithDifferentAccount(
1219
1117
  new ControlledAgent(invitedAdminSecret, Crypto),
1220
- Crypto.newRandomSessionID(invitedAdminID),
1221
1118
  );
1222
1119
 
1223
1120
  await nodeAsInvitedAdmin.acceptInvite(group.id, inviteSecret);
@@ -1277,12 +1174,9 @@ test("Admins can create a writerInvite, which can add a writer", () => {
1277
1174
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1278
1175
 
1279
1176
  const groupAsInvite = expectGroup(
1280
- groupCore
1281
- .testWithDifferentAccount(
1282
- new ControlledAgent(inviteSecret, Crypto),
1283
- Crypto.newRandomSessionID(inviteID),
1284
- )
1285
- .getCurrentContent(),
1177
+ groupCore.contentInClonedNodeWithDifferentAccount(
1178
+ new ControlledAgent(inviteSecret, Crypto),
1179
+ ),
1286
1180
  );
1287
1181
 
1288
1182
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
@@ -1325,9 +1219,8 @@ test("Admins can create a writerInvite, which can add a writer (high-level)", as
1325
1219
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
1326
1220
  const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1327
1221
 
1328
- const nodeAsInvitedWriter = node.testWithDifferentAccount(
1222
+ const nodeAsInvitedWriter = node.cloneWithDifferentAccount(
1329
1223
  new ControlledAgent(invitedWriterSecret, Crypto),
1330
- Crypto.newRandomSessionID(invitedWriterID),
1331
1224
  );
1332
1225
 
1333
1226
  await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
@@ -1380,12 +1273,9 @@ test("Admins can create a readerInvite, which can add a reader", () => {
1380
1273
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1381
1274
 
1382
1275
  const groupAsInvite = expectGroup(
1383
- groupCore
1384
- .testWithDifferentAccount(
1385
- new ControlledAgent(inviteSecret, Crypto),
1386
- Crypto.newRandomSessionID(inviteID),
1387
- )
1388
- .getCurrentContent(),
1276
+ groupCore.contentInClonedNodeWithDifferentAccount(
1277
+ new ControlledAgent(inviteSecret, Crypto),
1278
+ ),
1389
1279
  );
1390
1280
 
1391
1281
  const invitedReaderSecret = Crypto.newRandomAgentSecret();
@@ -1418,9 +1308,8 @@ test("Admins can create a readerInvite, which can add a reader (high-level)", as
1418
1308
  const invitedReaderSecret = Crypto.newRandomAgentSecret();
1419
1309
  const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
1420
1310
 
1421
- const nodeAsInvitedReader = node.testWithDifferentAccount(
1311
+ const nodeAsInvitedReader = node.cloneWithDifferentAccount(
1422
1312
  new ControlledAgent(invitedReaderSecret, Crypto),
1423
- Crypto.newRandomSessionID(invitedReaderID),
1424
1313
  );
1425
1314
 
1426
1315
  await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
@@ -1473,12 +1362,9 @@ test("WriterInvites can not invite admins", () => {
1473
1362
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1474
1363
 
1475
1364
  const groupAsInvite = expectGroup(
1476
- groupCore
1477
- .testWithDifferentAccount(
1478
- new ControlledAgent(inviteSecret, Crypto),
1479
- Crypto.newRandomSessionID(inviteID),
1480
- )
1481
- .getCurrentContent(),
1365
+ groupCore.contentInClonedNodeWithDifferentAccount(
1366
+ new ControlledAgent(inviteSecret, Crypto),
1367
+ ),
1482
1368
  );
1483
1369
 
1484
1370
  const invitedAdminSecret = Crypto.newRandomAgentSecret();
@@ -1527,12 +1413,9 @@ test("ReaderInvites can not invite admins", () => {
1527
1413
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1528
1414
 
1529
1415
  const groupAsInvite = expectGroup(
1530
- groupCore
1531
- .testWithDifferentAccount(
1532
- new ControlledAgent(inviteSecret, Crypto),
1533
- Crypto.newRandomSessionID(inviteID),
1534
- )
1535
- .getCurrentContent(),
1416
+ groupCore.contentInClonedNodeWithDifferentAccount(
1417
+ new ControlledAgent(inviteSecret, Crypto),
1418
+ ),
1536
1419
  );
1537
1420
 
1538
1421
  const invitedAdminSecret = Crypto.newRandomAgentSecret();
@@ -1581,12 +1464,9 @@ test("ReaderInvites can not invite writers", () => {
1581
1464
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1582
1465
 
1583
1466
  const groupAsInvite = expectGroup(
1584
- groupCore
1585
- .testWithDifferentAccount(
1586
- new ControlledAgent(inviteSecret, Crypto),
1587
- Crypto.newRandomSessionID(inviteID),
1588
- )
1589
- .getCurrentContent(),
1467
+ groupCore.contentInClonedNodeWithDifferentAccount(
1468
+ new ControlledAgent(inviteSecret, Crypto),
1469
+ ),
1590
1470
  );
1591
1471
 
1592
1472
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
@@ -1635,12 +1515,9 @@ test("WriteOnlyInvites can not invite writers", () => {
1635
1515
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1636
1516
 
1637
1517
  const groupAsInvite = expectGroup(
1638
- groupCore
1639
- .testWithDifferentAccount(
1640
- new ControlledAgent(inviteSecret, Crypto),
1641
- Crypto.newRandomSessionID(inviteID),
1642
- )
1643
- .getCurrentContent(),
1518
+ groupCore.contentInClonedNodeWithDifferentAccount(
1519
+ new ControlledAgent(inviteSecret, Crypto),
1520
+ ),
1644
1521
  );
1645
1522
 
1646
1523
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
@@ -1689,12 +1566,9 @@ test("WriteOnlyInvites can not invite admins", () => {
1689
1566
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1690
1567
 
1691
1568
  const groupAsInvite = expectGroup(
1692
- groupCore
1693
- .testWithDifferentAccount(
1694
- new ControlledAgent(inviteSecret, Crypto),
1695
- Crypto.newRandomSessionID(inviteID),
1696
- )
1697
- .getCurrentContent(),
1569
+ groupCore.contentInClonedNodeWithDifferentAccount(
1570
+ new ControlledAgent(inviteSecret, Crypto),
1571
+ ),
1698
1572
  );
1699
1573
 
1700
1574
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
@@ -1743,12 +1617,9 @@ test("WriteOnlyInvites can invite writeOnly", () => {
1743
1617
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1744
1618
 
1745
1619
  const groupAsInvite = expectGroup(
1746
- groupCore
1747
- .testWithDifferentAccount(
1748
- new ControlledAgent(inviteSecret, Crypto),
1749
- Crypto.newRandomSessionID(inviteID),
1750
- )
1751
- .getCurrentContent(),
1620
+ groupCore.contentInClonedNodeWithDifferentAccount(
1621
+ new ControlledAgent(inviteSecret, Crypto),
1622
+ ),
1752
1623
  );
1753
1624
 
1754
1625
  const invitedWriterSecret = Crypto.newRandomAgentSecret();
@@ -1797,12 +1668,9 @@ test("WriteOnlyInvites can set writeKeys", () => {
1797
1668
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1798
1669
 
1799
1670
  const groupAsInvite = expectGroup(
1800
- groupCore
1801
- .testWithDifferentAccount(
1802
- new ControlledAgent(inviteSecret, Crypto),
1803
- Crypto.newRandomSessionID(inviteID),
1804
- )
1805
- .getCurrentContent(),
1671
+ groupCore.contentInClonedNodeWithDifferentAccount(
1672
+ new ControlledAgent(inviteSecret, Crypto),
1673
+ ),
1806
1674
  );
1807
1675
 
1808
1676
  groupAsInvite.set(`writeKeyFor_${admin.id}`, readKeyID, "trusting");
@@ -1848,12 +1716,9 @@ test("Invites can't override key revelations", () => {
1848
1716
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1849
1717
 
1850
1718
  const groupAsInvite = expectGroup(
1851
- groupCore
1852
- .testWithDifferentAccount(
1853
- new ControlledAgent(inviteSecret, Crypto),
1854
- Crypto.newRandomSessionID(inviteID),
1855
- )
1856
- .getCurrentContent(),
1719
+ groupCore.contentInClonedNodeWithDifferentAccount(
1720
+ new ControlledAgent(inviteSecret, Crypto),
1721
+ ),
1857
1722
  );
1858
1723
 
1859
1724
  groupAsInvite.set(
@@ -1903,12 +1768,9 @@ test("WriteOnlyInvites can't override writeKeys", () => {
1903
1768
  group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1904
1769
 
1905
1770
  const groupAsInvite = expectGroup(
1906
- groupCore
1907
- .testWithDifferentAccount(
1908
- new ControlledAgent(inviteSecret, Crypto),
1909
- Crypto.newRandomSessionID(inviteID),
1910
- )
1911
- .getCurrentContent(),
1771
+ groupCore.contentInClonedNodeWithDifferentAccount(
1772
+ new ControlledAgent(inviteSecret, Crypto),
1773
+ ),
1912
1774
  );
1913
1775
 
1914
1776
  groupAsInvite.set(`writeKeyFor_${admin.id}`, readKeyID, "trusting");
@@ -1947,12 +1809,7 @@ test("Can give read permission to 'everyone'", () => {
1947
1809
  const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1948
1810
 
1949
1811
  const childContent2 = expectMap(
1950
- childObject
1951
- .testWithDifferentAccount(
1952
- newAccount,
1953
- Crypto.newRandomSessionID(newAccount.currentAgentID()),
1954
- )
1955
- .getCurrentContent(),
1812
+ childObject.contentInClonedNodeWithDifferentAccount(newAccount),
1956
1813
  );
1957
1814
 
1958
1815
  expect(childContent2.get("foo")).toEqual("bar");
@@ -1973,12 +1830,7 @@ test("Can give read permissions to 'everyone' (high-level)", async () => {
1973
1830
  const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1974
1831
 
1975
1832
  const childContent2 = expectMap(
1976
- childObject.core
1977
- .testWithDifferentAccount(
1978
- new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto),
1979
- Crypto.newRandomSessionID(newAccount.currentAgentID()),
1980
- )
1981
- .getCurrentContent(),
1833
+ childObject.core.contentInClonedNodeWithDifferentAccount(newAccount),
1982
1834
  );
1983
1835
 
1984
1836
  expect(childContent2.get("foo")).toEqual("bar");
@@ -2011,12 +1863,7 @@ test("Can give write permission to 'everyone'", async () => {
2011
1863
  const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
2012
1864
 
2013
1865
  const childContent2 = expectMap(
2014
- childObject
2015
- .testWithDifferentAccount(
2016
- newAccount,
2017
- Crypto.newRandomSessionID(newAccount.currentAgentID()),
2018
- )
2019
- .getCurrentContent(),
1866
+ childObject.contentInClonedNodeWithDifferentAccount(newAccount),
2020
1867
  );
2021
1868
 
2022
1869
  // TODO: resolve race condition
@@ -2043,12 +1890,7 @@ test("Can give write permissions to 'everyone' (high-level)", async () => {
2043
1890
  const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
2044
1891
 
2045
1892
  const childContent2 = expectMap(
2046
- childObject.core
2047
- .testWithDifferentAccount(
2048
- newAccount,
2049
- Crypto.newRandomSessionID(newAccount.currentAgentID()),
2050
- )
2051
- .getCurrentContent(),
1893
+ childObject.core.contentInClonedNodeWithDifferentAccount(newAccount),
2052
1894
  );
2053
1895
 
2054
1896
  connectTwoPeers(group.core.node, childContent2.core.node, "server", "server");
@@ -2074,11 +1916,11 @@ test("Writers, readers and invitees can not set parent extensions", () => {
2074
1916
  const { group, node } = newGroupHighLevel();
2075
1917
  const parentGroup = node.createGroup();
2076
1918
 
2077
- const writer = node.createAccount();
2078
- const reader = node.createAccount();
2079
- const adminInvite = node.createAccount();
2080
- const writerInvite = node.createAccount();
2081
- const readerInvite = node.createAccount();
1919
+ const writer = createAccountInNode(node);
1920
+ const reader = createAccountInNode(node);
1921
+ const adminInvite = createAccountInNode(node);
1922
+ const writerInvite = createAccountInNode(node);
1923
+ const readerInvite = createAccountInNode(node);
2082
1924
 
2083
1925
  group.addMember(writer, "writer");
2084
1926
  group.addMember(reader, "reader");
@@ -2087,54 +1929,35 @@ test("Writers, readers and invitees can not set parent extensions", () => {
2087
1929
  group.addMember(readerInvite, "readerInvite");
2088
1930
 
2089
1931
  const groupAsWriter = expectGroup(
2090
- group.core
2091
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
2092
- .getCurrentContent(),
1932
+ group.core.contentInClonedNodeWithDifferentAccount(writer),
2093
1933
  );
2094
1934
 
2095
1935
  groupAsWriter.set(`parent_${parentGroup.id}`, "extend", "trusting");
2096
1936
  expect(groupAsWriter.get(`parent_${parentGroup.id}`)).toBeUndefined();
2097
1937
 
2098
1938
  const groupAsReader = expectGroup(
2099
- group.core
2100
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2101
- .getCurrentContent(),
1939
+ group.core.contentInClonedNodeWithDifferentAccount(reader),
2102
1940
  );
2103
1941
 
2104
1942
  groupAsReader.set(`parent_${parentGroup.id}`, "extend", "trusting");
2105
1943
  expect(groupAsReader.get(`parent_${parentGroup.id}`)).toBeUndefined();
2106
1944
 
2107
1945
  const groupAsAdminInvite = expectGroup(
2108
- group.core
2109
- .testWithDifferentAccount(
2110
- adminInvite,
2111
- Crypto.newRandomSessionID(adminInvite.currentAgentID()),
2112
- )
2113
- .getCurrentContent(),
1946
+ group.core.contentInClonedNodeWithDifferentAccount(adminInvite),
2114
1947
  );
2115
1948
 
2116
1949
  groupAsAdminInvite.set(`parent_${parentGroup.id}`, "extend", "trusting");
2117
1950
  expect(groupAsAdminInvite.get(`parent_${parentGroup.id}`)).toBeUndefined();
2118
1951
 
2119
1952
  const groupAsWriterInvite = expectGroup(
2120
- group.core
2121
- .testWithDifferentAccount(
2122
- writerInvite,
2123
- Crypto.newRandomSessionID(writerInvite.currentAgentID()),
2124
- )
2125
- .getCurrentContent(),
1953
+ group.core.contentInClonedNodeWithDifferentAccount(writerInvite),
2126
1954
  );
2127
1955
 
2128
1956
  groupAsWriterInvite.set(`parent_${parentGroup.id}`, "extend", "trusting");
2129
1957
  expect(groupAsWriterInvite.get(`parent_${parentGroup.id}`)).toBeUndefined();
2130
1958
 
2131
1959
  const groupAsReaderInvite = expectGroup(
2132
- group.core
2133
- .testWithDifferentAccount(
2134
- readerInvite,
2135
- Crypto.newRandomSessionID(readerInvite.currentAgentID()),
2136
- )
2137
- .getCurrentContent(),
1960
+ group.core.contentInClonedNodeWithDifferentAccount(readerInvite),
2138
1961
  );
2139
1962
 
2140
1963
  groupAsReaderInvite.set(`parent_${parentGroup.id}`, "extend", "trusting");
@@ -2183,27 +2006,23 @@ test("Writers, readers and writeOnly can set child extensions", () => {
2183
2006
  const { group, node } = newGroupHighLevel();
2184
2007
  const childGroup = node.createGroup();
2185
2008
 
2186
- const writer = node.createAccount();
2187
- const reader = node.createAccount();
2188
- const writeOnly = node.createAccount();
2009
+ const writer = createAccountInNode(node);
2010
+ const reader = createAccountInNode(node);
2011
+ const writeOnly = createAccountInNode(node);
2189
2012
 
2190
2013
  group.addMember(writer, "writer");
2191
2014
  group.addMember(reader, "reader");
2192
2015
  group.addMember(writeOnly, "writeOnly");
2193
2016
 
2194
2017
  const groupAsWriter = expectGroup(
2195
- group.core
2196
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
2197
- .getCurrentContent(),
2018
+ group.core.contentInClonedNodeWithDifferentAccount(writer),
2198
2019
  );
2199
2020
 
2200
2021
  groupAsWriter.set(`child_${childGroup.id}`, "extend", "trusting");
2201
2022
  expect(groupAsWriter.get(`child_${childGroup.id}`)).toEqual("extend");
2202
2023
 
2203
2024
  const groupAsReader = expectGroup(
2204
- group.core
2205
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2206
- .getCurrentContent(),
2025
+ group.core.contentInClonedNodeWithDifferentAccount(reader),
2207
2026
  );
2208
2027
 
2209
2028
  groupAsReader.set(`child_${childGroup.id}`, "extend", "trusting");
@@ -2214,45 +2033,30 @@ test("Invitees can not set child extensions", () => {
2214
2033
  const { group, node } = newGroupHighLevel();
2215
2034
  const childGroup = node.createGroup();
2216
2035
 
2217
- const adminInvite = node.createAccount();
2218
- const writerInvite = node.createAccount();
2219
- const readerInvite = node.createAccount();
2036
+ const adminInvite = createAccountInNode(node);
2037
+ const writerInvite = createAccountInNode(node);
2038
+ const readerInvite = createAccountInNode(node);
2220
2039
 
2221
2040
  group.addMember(adminInvite, "adminInvite");
2222
2041
  group.addMember(writerInvite, "writerInvite");
2223
2042
  group.addMember(readerInvite, "readerInvite");
2224
2043
 
2225
2044
  const groupAsAdminInvite = expectGroup(
2226
- group.core
2227
- .testWithDifferentAccount(
2228
- adminInvite,
2229
- Crypto.newRandomSessionID(adminInvite.currentAgentID()),
2230
- )
2231
- .getCurrentContent(),
2045
+ group.core.contentInClonedNodeWithDifferentAccount(adminInvite),
2232
2046
  );
2233
2047
 
2234
2048
  groupAsAdminInvite.set(`child_${childGroup.id}`, "extend", "trusting");
2235
2049
  expect(groupAsAdminInvite.get(`child_${childGroup.id}`)).toBeUndefined();
2236
2050
 
2237
2051
  const groupAsWriterInvite = expectGroup(
2238
- group.core
2239
- .testWithDifferentAccount(
2240
- writerInvite,
2241
- Crypto.newRandomSessionID(writerInvite.currentAgentID()),
2242
- )
2243
- .getCurrentContent(),
2052
+ group.core.contentInClonedNodeWithDifferentAccount(writerInvite),
2244
2053
  );
2245
2054
 
2246
2055
  groupAsWriterInvite.set(`child_${childGroup.id}`, "extend", "trusting");
2247
2056
  expect(groupAsWriterInvite.get(`child_${childGroup.id}`)).toBeUndefined();
2248
2057
 
2249
2058
  const groupAsReaderInvite = expectGroup(
2250
- group.core
2251
- .testWithDifferentAccount(
2252
- readerInvite,
2253
- Crypto.newRandomSessionID(readerInvite.currentAgentID()),
2254
- )
2255
- .getCurrentContent(),
2059
+ group.core.contentInClonedNodeWithDifferentAccount(readerInvite),
2256
2060
  );
2257
2061
 
2258
2062
  groupAsReaderInvite.set(`child_${childGroup.id}`, "extend", "trusting");
@@ -2265,11 +2069,11 @@ test("Member roles are inherited by child groups (except invites)", () => {
2265
2069
 
2266
2070
  group.set(`parent_${parentGroup.id}`, "extend", "trusting");
2267
2071
 
2268
- const writer = node.createAccount();
2269
- const reader = node.createAccount();
2270
- const adminInvite = node.createAccount();
2271
- const writerInvite = node.createAccount();
2272
- const readerInvite = node.createAccount();
2072
+ const writer = createAccountInNode(node);
2073
+ const reader = createAccountInNode(node);
2074
+ const adminInvite = createAccountInNode(node);
2075
+ const writerInvite = createAccountInNode(node);
2076
+ const readerInvite = createAccountInNode(node);
2273
2077
 
2274
2078
  parentGroup.addMember(writer, "writer");
2275
2079
  parentGroup.addMember(reader, "reader");
@@ -2298,11 +2102,11 @@ test("Member roles are inherited by grand-children groups (except invites)", ()
2298
2102
  group.set(`parent_${parentGroup.id}`, "extend", "trusting");
2299
2103
  parentGroup.set(`parent_${grandParentGroup.id}`, "extend", "trusting");
2300
2104
 
2301
- const writer = node.createAccount();
2302
- const reader = node.createAccount();
2303
- const adminInvite = node.createAccount();
2304
- const writerInvite = node.createAccount();
2305
- const readerInvite = node.createAccount();
2105
+ const writer = createAccountInNode(node);
2106
+ const reader = createAccountInNode(node);
2107
+ const adminInvite = createAccountInNode(node);
2108
+ const writerInvite = createAccountInNode(node);
2109
+ const readerInvite = createAccountInNode(node);
2306
2110
 
2307
2111
  grandParentGroup.addMember(writer, "writer");
2308
2112
  grandParentGroup.addMember(reader, "reader");
@@ -2344,7 +2148,7 @@ test("Admins can reveal parent read keys to child groups", () => {
2344
2148
  expect(group.get(`${readKeyID}_for_${parentReadKeyID}`)).toEqual(encrypted);
2345
2149
  });
2346
2150
 
2347
- test("Writers, readers and invites can't reveal parent read keys to child groups", () => {
2151
+ test("Writers can't reveal parent read keys to child groups", () => {
2348
2152
  const { group, node } = newGroupHighLevel();
2349
2153
  const parentGroup = node.createGroup();
2350
2154
 
@@ -2361,22 +2165,11 @@ test("Writers, readers and invites can't reveal parent read keys to child groups
2361
2165
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2362
2166
  const encrypted = "fake_encrypted_key_secret" as any;
2363
2167
 
2364
- const writer = node.createAccount();
2365
- const reader = node.createAccount();
2366
- const adminInvite = node.createAccount();
2367
- const writerInvite = node.createAccount();
2368
- const readerInvite = node.createAccount();
2369
-
2168
+ const writer = createAccountInNode(node);
2370
2169
  group.addMember(writer, "writer");
2371
- group.addMember(reader, "reader");
2372
- group.addMember(adminInvite, "adminInvite");
2373
- group.addMember(writerInvite, "writerInvite");
2374
- group.addMember(readerInvite, "readerInvite");
2375
2170
 
2376
2171
  const groupAsWriter = expectGroup(
2377
- group.core
2378
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
2379
- .getCurrentContent(),
2172
+ group.core.contentInClonedNodeWithDifferentAccount(writer),
2380
2173
  );
2381
2174
 
2382
2175
  groupAsWriter.set(
@@ -2387,11 +2180,30 @@ test("Writers, readers and invites can't reveal parent read keys to child groups
2387
2180
  expect(
2388
2181
  groupAsWriter.get(`${readKeyID}_for_${parentReadKeyID}`),
2389
2182
  ).toBeUndefined();
2183
+ });
2184
+
2185
+ test("Readers can't reveal parent read keys to child groups", () => {
2186
+ const { group, node } = newGroupHighLevel();
2187
+ const parentGroup = node.createGroup();
2188
+
2189
+ const parentReadKeyID = parentGroup.get("readKey");
2190
+ if (!parentReadKeyID) {
2191
+ throw new Error("Can't get parent group read key");
2192
+ }
2193
+
2194
+ const readKeyID = group.get("readKey");
2195
+ if (!readKeyID) {
2196
+ throw new Error("Can't get group read key");
2197
+ }
2198
+
2199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2200
+ const encrypted = "fake_encrypted_key_secret" as any;
2201
+
2202
+ const reader = createAccountInNode(node);
2203
+ group.addMember(reader, "reader");
2390
2204
 
2391
2205
  const groupAsReader = expectGroup(
2392
- group.core
2393
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2394
- .getCurrentContent(),
2206
+ group.core.contentInClonedNodeWithDifferentAccount(reader),
2395
2207
  );
2396
2208
 
2397
2209
  groupAsReader.set(
@@ -2402,14 +2214,30 @@ test("Writers, readers and invites can't reveal parent read keys to child groups
2402
2214
  expect(
2403
2215
  groupAsReader.get(`${readKeyID}_for_${parentReadKeyID}`),
2404
2216
  ).toBeUndefined();
2217
+ });
2218
+
2219
+ test.skip("Admin invites can't reveal parent read keys to child groups", () => {
2220
+ const { group, node } = newGroupHighLevel();
2221
+ const parentGroup = node.createGroup();
2222
+
2223
+ const parentReadKeyID = parentGroup.get("readKey");
2224
+ if (!parentReadKeyID) {
2225
+ throw new Error("Can't get parent group read key");
2226
+ }
2227
+
2228
+ const readKeyID = group.get("readKey");
2229
+ if (!readKeyID) {
2230
+ throw new Error("Can't get group read key");
2231
+ }
2232
+
2233
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2234
+ const encrypted = "fake_encrypted_key_secret" as any;
2235
+
2236
+ const adminInvite = createAccountInNode(node);
2237
+ group.addMember(adminInvite, "adminInvite");
2405
2238
 
2406
2239
  const groupAsAdminInvite = expectGroup(
2407
- group.core
2408
- .testWithDifferentAccount(
2409
- adminInvite,
2410
- Crypto.newRandomSessionID(adminInvite.currentAgentID()),
2411
- )
2412
- .getCurrentContent(),
2240
+ group.core.contentInClonedNodeWithDifferentAccount(adminInvite),
2413
2241
  );
2414
2242
 
2415
2243
  groupAsAdminInvite.set(
@@ -2420,14 +2248,30 @@ test("Writers, readers and invites can't reveal parent read keys to child groups
2420
2248
  expect(
2421
2249
  groupAsAdminInvite.get(`${readKeyID}_for_${parentReadKeyID}`),
2422
2250
  ).toBeUndefined();
2251
+ });
2252
+
2253
+ test.skip("Writer invites can't reveal parent read keys to child groups", () => {
2254
+ const { group, node } = newGroupHighLevel();
2255
+ const parentGroup = node.createGroup();
2256
+
2257
+ const parentReadKeyID = parentGroup.get("readKey");
2258
+ if (!parentReadKeyID) {
2259
+ throw new Error("Can't get parent group read key");
2260
+ }
2261
+
2262
+ const readKeyID = group.get("readKey");
2263
+ if (!readKeyID) {
2264
+ throw new Error("Can't get group read key");
2265
+ }
2266
+
2267
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2268
+ const encrypted = "fake_encrypted_key_secret" as any;
2269
+
2270
+ const writerInvite = createAccountInNode(node);
2271
+ group.addMember(writerInvite, "writerInvite");
2423
2272
 
2424
2273
  const groupAsWriterInvite = expectGroup(
2425
- group.core
2426
- .testWithDifferentAccount(
2427
- writerInvite,
2428
- Crypto.newRandomSessionID(writerInvite.currentAgentID()),
2429
- )
2430
- .getCurrentContent(),
2274
+ group.core.contentInClonedNodeWithDifferentAccount(writerInvite),
2431
2275
  );
2432
2276
 
2433
2277
  groupAsWriterInvite.set(
@@ -2438,14 +2282,30 @@ test("Writers, readers and invites can't reveal parent read keys to child groups
2438
2282
  expect(
2439
2283
  groupAsWriterInvite.get(`${readKeyID}_for_${parentReadKeyID}`),
2440
2284
  ).toBeUndefined();
2285
+ });
2286
+
2287
+ test.skip("Reader invites can't reveal parent read keys to child groups", () => {
2288
+ const { group, node } = newGroupHighLevel();
2289
+ const parentGroup = node.createGroup();
2290
+
2291
+ const parentReadKeyID = parentGroup.get("readKey");
2292
+ if (!parentReadKeyID) {
2293
+ throw new Error("Can't get parent group read key");
2294
+ }
2295
+
2296
+ const readKeyID = group.get("readKey");
2297
+ if (!readKeyID) {
2298
+ throw new Error("Can't get group read key");
2299
+ }
2300
+
2301
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2302
+ const encrypted = "fake_encrypted_key_secret" as any;
2303
+
2304
+ const readerInvite = createAccountInNode(node);
2305
+ group.addMember(readerInvite, "readerInvite");
2441
2306
 
2442
2307
  const groupAsReaderInvite = expectGroup(
2443
- group.core
2444
- .testWithDifferentAccount(
2445
- readerInvite,
2446
- Crypto.newRandomSessionID(readerInvite.currentAgentID()),
2447
- )
2448
- .getCurrentContent(),
2308
+ group.core.contentInClonedNodeWithDifferentAccount(readerInvite),
2449
2309
  );
2450
2310
 
2451
2311
  groupAsReaderInvite.set(
@@ -2490,8 +2350,8 @@ test("Writers and readers in a parent group can read from an object owned by a c
2490
2350
 
2491
2351
  group.set(`${readKeyID}_for_${parentReadKeyID}`, encrypted, "trusting");
2492
2352
 
2493
- const writer = node.createAccount();
2494
- const reader = node.createAccount();
2353
+ const writer = createAccountInNode(node);
2354
+ const reader = createAccountInNode(node);
2495
2355
  parentGroup.addMember(writer, "writer");
2496
2356
  parentGroup.addMember(reader, "reader");
2497
2357
 
@@ -2508,17 +2368,13 @@ test("Writers and readers in a parent group can read from an object owned by a c
2508
2368
  expect(childContent.get("foo")).toEqual("bar");
2509
2369
 
2510
2370
  const childContentAsWriter = expectMap(
2511
- childObject
2512
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
2513
- .getCurrentContent(),
2371
+ childObject.contentInClonedNodeWithDifferentAccount(writer),
2514
2372
  );
2515
2373
 
2516
2374
  expect(childContentAsWriter.get("foo")).toEqual("bar");
2517
2375
 
2518
2376
  const childContentAsReader = expectMap(
2519
- childObject
2520
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2521
- .getCurrentContent(),
2377
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
2522
2378
  );
2523
2379
 
2524
2380
  expect(childContentAsReader.get("foo")).toEqual("bar");
@@ -2556,7 +2412,7 @@ test("Writers in a parent group can write to an object owned by a child group",
2556
2412
 
2557
2413
  group.set(`${readKeyID}_for_${parentReadKeyID}`, encrypted, "trusting");
2558
2414
 
2559
- const writer = node.createAccount();
2415
+ const writer = createAccountInNode(node);
2560
2416
  parentGroup.addMember(writer, "writer");
2561
2417
 
2562
2418
  const childObject = node.createCoValue({
@@ -2567,9 +2423,7 @@ test("Writers in a parent group can write to an object owned by a child group",
2567
2423
  });
2568
2424
 
2569
2425
  const childContentAsWriter = expectMap(
2570
- childObject
2571
- .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
2572
- .getCurrentContent(),
2426
+ childObject.contentInClonedNodeWithDifferentAccount(writer),
2573
2427
  );
2574
2428
 
2575
2429
  childContentAsWriter.set("foo", "bar", "private");
@@ -2738,7 +2592,7 @@ test("Calling extend on group sets up parent and child references and reveals ch
2738
2592
 
2739
2593
  expect(group.get(`${childReadKeyID}_for_${parentReadKeyID}`)).toBeDefined();
2740
2594
 
2741
- const reader = node.createAccount();
2595
+ const reader = createAccountInNode(node);
2742
2596
  parentGroup.addMember(reader, "reader");
2743
2597
 
2744
2598
  const childObject = node.createCoValue({
@@ -2752,9 +2606,7 @@ test("Calling extend on group sets up parent and child references and reveals ch
2752
2606
  childMap.set("foo", "bar", "private");
2753
2607
 
2754
2608
  const childContentAsReader = expectMap(
2755
- childObject
2756
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2757
- .getCurrentContent(),
2609
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
2758
2610
  );
2759
2611
 
2760
2612
  expect(childContentAsReader.get("foo")).toEqual("bar");
@@ -2773,7 +2625,7 @@ test("Calling extend to create grand-child groups parent and child references an
2773
2625
  expect(parentGroup.get(`child_${group.id}`)).toEqual("extend");
2774
2626
  expect(grandParentGroup.get(`child_${parentGroup.id}`)).toEqual("extend");
2775
2627
 
2776
- const reader = node.createAccount();
2628
+ const reader = createAccountInNode(node);
2777
2629
  grandParentGroup.addMember(reader, "reader");
2778
2630
 
2779
2631
  const childObject = node.createCoValue({
@@ -2787,9 +2639,7 @@ test("Calling extend to create grand-child groups parent and child references an
2787
2639
  childMap.set("foo", "bar", "private");
2788
2640
 
2789
2641
  const childContentAsReader = expectMap(
2790
- childObject
2791
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
2792
- .getCurrentContent(),
2642
+ childObject.contentInClonedNodeWithDifferentAccount(reader),
2793
2643
  );
2794
2644
 
2795
2645
  expect(childContentAsReader.get("foo")).toEqual("bar");
@@ -2884,8 +2734,8 @@ test("revoking write access to parent group", async () => {
2884
2734
 
2885
2735
  // Create an account (`alice`) that can write to the parent group
2886
2736
  // Create an account (`bob`) that can write to the child group
2887
- const alice = node.createAccount();
2888
- const bob = node.createAccount();
2737
+ const alice = createAccountInNode(node);
2738
+ const bob = createAccountInNode(node);
2889
2739
  parentGroup.addMember(alice, "writer");
2890
2740
  group.addMember(bob, "writer");
2891
2741
 
@@ -2897,9 +2747,7 @@ test("revoking write access to parent group", async () => {
2897
2747
  ...Crypto.createdNowUnique(),
2898
2748
  });
2899
2749
  const bobMap = expectMap(
2900
- mapCore
2901
- .testWithDifferentAccount(bob, Crypto.newRandomSessionID(bob.id))
2902
- .getCurrentContent(),
2750
+ mapCore.contentInClonedNodeWithDifferentAccount(bob),
2903
2751
  );
2904
2752
 
2905
2753
  // `bob` sets `foo` to `bar`
@@ -2908,9 +2756,7 @@ test("revoking write access to parent group", async () => {
2908
2756
  expect(bobMap.get("foo")).toEqual("bar");
2909
2757
 
2910
2758
  const aliceMap = expectMap(
2911
- mapCore
2912
- .testWithDifferentAccount(alice, Crypto.newRandomSessionID(alice.id))
2913
- .getCurrentContent(),
2759
+ mapCore.contentInClonedNodeWithDifferentAccount(alice),
2914
2760
  );
2915
2761
  // `alice` sets `foo` to `baz`
2916
2762
  aliceMap.set("foo", "baz", "private");
@@ -2926,9 +2772,7 @@ test("revoking write access to parent group", async () => {
2926
2772
  expect(bobMap.get("foo")).toEqual("abc");
2927
2773
 
2928
2774
  const aliceMapAfterUnextend = expectMap(
2929
- mapCore
2930
- .testWithDifferentAccount(alice, Crypto.newRandomSessionID(alice.id))
2931
- .getCurrentContent(),
2775
+ mapCore.contentInClonedNodeWithDifferentAccount(alice),
2932
2776
  );
2933
2777
  // `alice` attempts to set `foo` to `def`, but fails
2934
2778
  expect(() => aliceMapAfterUnextend.set("foo", "def", "private")).toThrow(
@@ -3052,11 +2896,15 @@ test("a user should have write access if the parent group has everyone as a writ
3052
2896
 
3053
2897
  childMap.set("foo", "bar", "private");
3054
2898
 
2899
+ await new Promise((resolve) => setTimeout(resolve, 10));
2900
+
3055
2901
  const mapOnNode2 = await loadCoValueOrFail(node2.node, childMap.id);
3056
2902
 
3057
2903
  mapOnNode2.set("foo", "baz", "private");
3058
2904
 
3059
- expect(mapOnNode2.get("foo")).toEqual("baz");
2905
+ await waitFor(async () => {
2906
+ expect(mapOnNode2.get("foo")).toEqual("baz");
2907
+ });
3060
2908
  });
3061
2909
 
3062
2910
  test("High-level permissions work correctly when a group is extended", async () => {
@@ -3065,7 +2913,7 @@ test("High-level permissions work correctly when a group is extended", async ()
3065
2913
 
3066
2914
  group.extend(parentGroup);
3067
2915
 
3068
- const reader = node.createAccount();
2916
+ const reader = createAccountInNode(node);
3069
2917
  parentGroup.addMember(reader, "reader");
3070
2918
 
3071
2919
  const mapCore = node.createCoValue({
@@ -3080,9 +2928,7 @@ test("High-level permissions work correctly when a group is extended", async ()
3080
2928
  map.set("foo", "bar", "private");
3081
2929
 
3082
2930
  const mapAsReader = expectMap(
3083
- mapCore
3084
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
3085
- .getCurrentContent(),
2931
+ mapCore.contentInClonedNodeWithDifferentAccount(reader),
3086
2932
  );
3087
2933
 
3088
2934
  expect(mapAsReader.get("foo")).toEqual("bar");
@@ -3097,9 +2943,7 @@ test("High-level permissions work correctly when a group is extended", async ()
3097
2943
  map.set("foo", "baz", "private");
3098
2944
 
3099
2945
  const mapAsReaderAfterRemove = expectMap(
3100
- mapCore
3101
- .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
3102
- .getCurrentContent(),
2946
+ mapCore.contentInClonedNodeWithDifferentAccount(reader),
3103
2947
  );
3104
2948
 
3105
2949
  expect(mapAsReaderAfterRemove.get("foo")).not.toEqual("baz");
@@ -3183,12 +3027,7 @@ test("Can revoke read permission from 'everyone'", async () => {
3183
3027
  // Create a new account to verify access
3184
3028
  const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
3185
3029
  const childContent = expectMap(
3186
- childObject.core
3187
- .testWithDifferentAccount(
3188
- newAccount,
3189
- Crypto.newRandomSessionID(newAccount.currentAgentID()),
3190
- )
3191
- .getCurrentContent(),
3030
+ childObject.core.contentInClonedNodeWithDifferentAccount(newAccount),
3192
3031
  );
3193
3032
 
3194
3033
  // Verify the new account can read
@@ -3205,12 +3044,7 @@ test("Can revoke read permission from 'everyone'", async () => {
3205
3044
  Crypto,
3206
3045
  );
3207
3046
  const childContent2 = expectMap(
3208
- childObject.core
3209
- .testWithDifferentAccount(
3210
- newAccount2,
3211
- Crypto.newRandomSessionID(newAccount2.currentAgentID()),
3212
- )
3213
- .getCurrentContent(),
3047
+ childObject.core.contentInClonedNodeWithDifferentAccount(newAccount2),
3214
3048
  );
3215
3049
 
3216
3050
  // Verify the new account cannot read after revocation