@session-foundation/qa-seeder 0.1.23 → 0.1.25
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/dist/index.js +63 -23
- package/dist/index.mjs +65 -25
- package/package.json +10 -3
- package/tests/buildState.test.ts +133 -0
- package/tsconfig.test.json +11 -0
package/dist/index.js
CHANGED
|
@@ -375,17 +375,20 @@ var SessionUser = class {
|
|
|
375
375
|
constructor({ sessionTools, sodium }) {
|
|
376
376
|
const mnemonic = generateMnemonic({ sodium });
|
|
377
377
|
const seed = mnemonicToRawSeed(mnemonic, sodium);
|
|
378
|
-
const userKeys = sessionGenerateKeyPair({
|
|
378
|
+
const userKeys = sessionGenerateKeyPair({
|
|
379
|
+
seed: seed.buffer,
|
|
380
|
+
sodium
|
|
381
|
+
});
|
|
379
382
|
const userProfile = new sessionTools.UserProfileW(
|
|
380
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
383
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
381
384
|
void 0
|
|
382
385
|
);
|
|
383
386
|
const contacts = new sessionTools.ContactsW(
|
|
384
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
387
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
385
388
|
void 0
|
|
386
389
|
);
|
|
387
390
|
const userGroups = new sessionTools.UserGroupsW(
|
|
388
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
391
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
389
392
|
void 0
|
|
390
393
|
);
|
|
391
394
|
const wrappers = [userProfile, contacts, userGroups];
|
|
@@ -550,9 +553,9 @@ var SessionGroup = class {
|
|
|
550
553
|
newGroup.joinedAtSeconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
551
554
|
this.groupSecretKey = sodium.from_hex(newGroup.adminSecretKey.toString());
|
|
552
555
|
this.metagroupW = new sessionTools.MetaGroupW(
|
|
553
|
-
creator.ed25519Sk,
|
|
554
|
-
|
|
555
|
-
this.groupSecretKey,
|
|
556
|
+
sodium.to_hex(creator.ed25519Sk),
|
|
557
|
+
newGroup.groupPk.toString().slice(2),
|
|
558
|
+
sodium.to_hex(this.groupSecretKey),
|
|
556
559
|
void 0
|
|
557
560
|
);
|
|
558
561
|
[creator, ...otherMembers].forEach((member) => {
|
|
@@ -567,9 +570,9 @@ var SessionGroup = class {
|
|
|
567
570
|
);
|
|
568
571
|
groupForUser.name = newGroup.name;
|
|
569
572
|
groupForUser.joinedAtSeconds = newGroup.joinedAtSeconds;
|
|
570
|
-
groupForUser.
|
|
573
|
+
groupForUser.invitePending = false;
|
|
571
574
|
groupForUser.priority = 0;
|
|
572
|
-
groupForUser.authData =
|
|
575
|
+
groupForUser.authData = authDataHex;
|
|
573
576
|
member.userGroups.setGroup(groupForUser);
|
|
574
577
|
} else {
|
|
575
578
|
member.userGroups.setGroup(newGroup);
|
|
@@ -593,21 +596,57 @@ var SessionGroup = class {
|
|
|
593
596
|
}
|
|
594
597
|
async pushChangesToSwarm(snode) {
|
|
595
598
|
const pushHex = this.metagroupW.pushHex();
|
|
596
|
-
const
|
|
597
|
-
pushHex.keysPush,
|
|
598
|
-
pushHex.
|
|
599
|
-
|
|
599
|
+
const keysRequests = pushHex.keysPush ? new StoreGroupConfigSubRequest({
|
|
600
|
+
namespace: pushHex.keysPush.storageNamespace.value,
|
|
601
|
+
encryptedData: this.sodium.from_hex(pushHex.keysPush.dataHex),
|
|
602
|
+
groupPk: this.groupPk,
|
|
603
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
604
|
+
// 1 day should be enough for testing and debugging a test?
|
|
605
|
+
adminGroupSigner: this.adminGroupSigner
|
|
606
|
+
}) : null;
|
|
607
|
+
const membersRequests = [];
|
|
608
|
+
if (pushHex.membersPush?.dataHex) {
|
|
609
|
+
for (let i = 0; i < pushHex.membersPush.dataHex.size(); i++) {
|
|
610
|
+
const dataHex = pushHex.membersPush.dataHex.get(i);
|
|
611
|
+
if (!dataHex) {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
const memberRequest = new StoreGroupConfigSubRequest({
|
|
615
|
+
namespace: pushHex.membersPush.storageNamespace.value,
|
|
616
|
+
encryptedData: this.sodium.from_hex(dataHex),
|
|
617
|
+
groupPk: this.groupPk,
|
|
618
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
619
|
+
// 1 day should be enough for testing and debugging a test?
|
|
620
|
+
adminGroupSigner: this.adminGroupSigner
|
|
621
|
+
});
|
|
622
|
+
membersRequests.push(memberRequest);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
console.warn("pushHex.membersPush.dataHex", pushHex.membersPush?.dataHex.size());
|
|
626
|
+
console.warn("membersRequests", membersRequests);
|
|
627
|
+
const infosRequests = [];
|
|
628
|
+
if (pushHex.infosPush?.dataHex) {
|
|
629
|
+
for (let i = 0; i < pushHex.infosPush.dataHex.size(); i++) {
|
|
630
|
+
const dataHex = pushHex.infosPush.dataHex.get(i);
|
|
631
|
+
if (!dataHex) {
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
const infoRequest = new StoreGroupConfigSubRequest({
|
|
635
|
+
namespace: pushHex.infosPush.storageNamespace.value,
|
|
636
|
+
encryptedData: this.sodium.from_hex(dataHex),
|
|
637
|
+
groupPk: this.groupPk,
|
|
638
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
639
|
+
// 1 day should be enough for testing and debugging a test?
|
|
640
|
+
adminGroupSigner: this.adminGroupSigner
|
|
641
|
+
});
|
|
642
|
+
infosRequests.push(infoRequest);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const storeRequests = (0, import_lodash3.compact)([
|
|
646
|
+
keysRequests,
|
|
647
|
+
...membersRequests,
|
|
648
|
+
...infosRequests
|
|
600
649
|
]);
|
|
601
|
-
const storeRequests = toPush.map((m) => {
|
|
602
|
-
return new StoreGroupConfigSubRequest({
|
|
603
|
-
namespace: m.storageNamespace.value,
|
|
604
|
-
encryptedData: this.sodium.from_hex(m.dataHex.toString()),
|
|
605
|
-
groupPk: this.groupPk,
|
|
606
|
-
ttlMs: 1e3 * 3600 * 24,
|
|
607
|
-
// 1 day should be enough for testing and debugging a test?
|
|
608
|
-
adminGroupSigner: this.adminGroupSigner
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
650
|
const storeResult = await Promise.all(
|
|
612
651
|
storeRequests.map(async (request) => {
|
|
613
652
|
const builtRequest = await request.build();
|
|
@@ -874,6 +913,7 @@ function prepareUsers({
|
|
|
874
913
|
sessionTools
|
|
875
914
|
});
|
|
876
915
|
assignNamesToUsers(users);
|
|
916
|
+
console.warn("assignNamesToUsers", assignNamesToUsers, assignNamesToUsers);
|
|
877
917
|
return users;
|
|
878
918
|
}
|
|
879
919
|
function prepareFriends({
|
package/dist/index.mjs
CHANGED
|
@@ -60,9 +60,9 @@ var GetSnodesFromSeed = class {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
// src/sessionTools/index.ts
|
|
63
|
-
import
|
|
63
|
+
import MainModuleFactory from "@session-foundation/libsession-wasm";
|
|
64
64
|
async function loadSessionTools() {
|
|
65
|
-
const loaded = await
|
|
65
|
+
const loaded = await MainModuleFactory();
|
|
66
66
|
return loaded;
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -341,17 +341,20 @@ var SessionUser = class {
|
|
|
341
341
|
constructor({ sessionTools, sodium }) {
|
|
342
342
|
const mnemonic = generateMnemonic({ sodium });
|
|
343
343
|
const seed = mnemonicToRawSeed(mnemonic, sodium);
|
|
344
|
-
const userKeys = sessionGenerateKeyPair({
|
|
344
|
+
const userKeys = sessionGenerateKeyPair({
|
|
345
|
+
seed: seed.buffer,
|
|
346
|
+
sodium
|
|
347
|
+
});
|
|
345
348
|
const userProfile = new sessionTools.UserProfileW(
|
|
346
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
349
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
347
350
|
void 0
|
|
348
351
|
);
|
|
349
352
|
const contacts = new sessionTools.ContactsW(
|
|
350
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
353
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
351
354
|
void 0
|
|
352
355
|
);
|
|
353
356
|
const userGroups = new sessionTools.UserGroupsW(
|
|
354
|
-
userKeys.ed25519KeyPair.privateKey,
|
|
357
|
+
sodium.to_hex(userKeys.ed25519KeyPair.privateKey),
|
|
355
358
|
void 0
|
|
356
359
|
);
|
|
357
360
|
const wrappers = [userProfile, contacts, userGroups];
|
|
@@ -518,9 +521,9 @@ var SessionGroup = class {
|
|
|
518
521
|
newGroup.joinedAtSeconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
519
522
|
this.groupSecretKey = sodium.from_hex(newGroup.adminSecretKey.toString());
|
|
520
523
|
this.metagroupW = new sessionTools.MetaGroupW(
|
|
521
|
-
creator.ed25519Sk,
|
|
522
|
-
|
|
523
|
-
this.groupSecretKey,
|
|
524
|
+
sodium.to_hex(creator.ed25519Sk),
|
|
525
|
+
newGroup.groupPk.toString().slice(2),
|
|
526
|
+
sodium.to_hex(this.groupSecretKey),
|
|
524
527
|
void 0
|
|
525
528
|
);
|
|
526
529
|
[creator, ...otherMembers].forEach((member) => {
|
|
@@ -535,9 +538,9 @@ var SessionGroup = class {
|
|
|
535
538
|
);
|
|
536
539
|
groupForUser.name = newGroup.name;
|
|
537
540
|
groupForUser.joinedAtSeconds = newGroup.joinedAtSeconds;
|
|
538
|
-
groupForUser.
|
|
541
|
+
groupForUser.invitePending = false;
|
|
539
542
|
groupForUser.priority = 0;
|
|
540
|
-
groupForUser.authData =
|
|
543
|
+
groupForUser.authData = authDataHex;
|
|
541
544
|
member.userGroups.setGroup(groupForUser);
|
|
542
545
|
} else {
|
|
543
546
|
member.userGroups.setGroup(newGroup);
|
|
@@ -561,21 +564,57 @@ var SessionGroup = class {
|
|
|
561
564
|
}
|
|
562
565
|
async pushChangesToSwarm(snode) {
|
|
563
566
|
const pushHex = this.metagroupW.pushHex();
|
|
564
|
-
const
|
|
565
|
-
pushHex.keysPush,
|
|
566
|
-
pushHex.
|
|
567
|
-
|
|
567
|
+
const keysRequests = pushHex.keysPush ? new StoreGroupConfigSubRequest({
|
|
568
|
+
namespace: pushHex.keysPush.storageNamespace.value,
|
|
569
|
+
encryptedData: this.sodium.from_hex(pushHex.keysPush.dataHex),
|
|
570
|
+
groupPk: this.groupPk,
|
|
571
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
572
|
+
// 1 day should be enough for testing and debugging a test?
|
|
573
|
+
adminGroupSigner: this.adminGroupSigner
|
|
574
|
+
}) : null;
|
|
575
|
+
const membersRequests = [];
|
|
576
|
+
if (pushHex.membersPush?.dataHex) {
|
|
577
|
+
for (let i = 0; i < pushHex.membersPush.dataHex.size(); i++) {
|
|
578
|
+
const dataHex = pushHex.membersPush.dataHex.get(i);
|
|
579
|
+
if (!dataHex) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const memberRequest = new StoreGroupConfigSubRequest({
|
|
583
|
+
namespace: pushHex.membersPush.storageNamespace.value,
|
|
584
|
+
encryptedData: this.sodium.from_hex(dataHex),
|
|
585
|
+
groupPk: this.groupPk,
|
|
586
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
587
|
+
// 1 day should be enough for testing and debugging a test?
|
|
588
|
+
adminGroupSigner: this.adminGroupSigner
|
|
589
|
+
});
|
|
590
|
+
membersRequests.push(memberRequest);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
console.warn("pushHex.membersPush.dataHex", pushHex.membersPush?.dataHex.size());
|
|
594
|
+
console.warn("membersRequests", membersRequests);
|
|
595
|
+
const infosRequests = [];
|
|
596
|
+
if (pushHex.infosPush?.dataHex) {
|
|
597
|
+
for (let i = 0; i < pushHex.infosPush.dataHex.size(); i++) {
|
|
598
|
+
const dataHex = pushHex.infosPush.dataHex.get(i);
|
|
599
|
+
if (!dataHex) {
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
const infoRequest = new StoreGroupConfigSubRequest({
|
|
603
|
+
namespace: pushHex.infosPush.storageNamespace.value,
|
|
604
|
+
encryptedData: this.sodium.from_hex(dataHex),
|
|
605
|
+
groupPk: this.groupPk,
|
|
606
|
+
ttlMs: 1e3 * 3600 * 24,
|
|
607
|
+
// 1 day should be enough for testing and debugging a test?
|
|
608
|
+
adminGroupSigner: this.adminGroupSigner
|
|
609
|
+
});
|
|
610
|
+
infosRequests.push(infoRequest);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const storeRequests = compact([
|
|
614
|
+
keysRequests,
|
|
615
|
+
...membersRequests,
|
|
616
|
+
...infosRequests
|
|
568
617
|
]);
|
|
569
|
-
const storeRequests = toPush.map((m) => {
|
|
570
|
-
return new StoreGroupConfigSubRequest({
|
|
571
|
-
namespace: m.storageNamespace.value,
|
|
572
|
-
encryptedData: this.sodium.from_hex(m.dataHex.toString()),
|
|
573
|
-
groupPk: this.groupPk,
|
|
574
|
-
ttlMs: 1e3 * 3600 * 24,
|
|
575
|
-
// 1 day should be enough for testing and debugging a test?
|
|
576
|
-
adminGroupSigner: this.adminGroupSigner
|
|
577
|
-
});
|
|
578
|
-
});
|
|
579
618
|
const storeResult = await Promise.all(
|
|
580
619
|
storeRequests.map(async (request) => {
|
|
581
620
|
const builtRequest = await request.build();
|
|
@@ -844,6 +883,7 @@ function prepareUsers({
|
|
|
844
883
|
sessionTools
|
|
845
884
|
});
|
|
846
885
|
assignNamesToUsers(users);
|
|
886
|
+
console.warn("assignNamesToUsers", assignNamesToUsers, assignNamesToUsers);
|
|
847
887
|
return users;
|
|
848
888
|
}
|
|
849
889
|
function prepareFriends({
|
package/package.json
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@session-foundation/qa-seeder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"lodash": "^4.17.21",
|
|
9
|
-
"@session-foundation/libsession-wasm": "^0.0.7",
|
|
10
9
|
"@session-foundation/basic-types": "^0.0.6",
|
|
11
10
|
"@session-foundation/mnemonic": "^0.0.8",
|
|
11
|
+
"@session-foundation/libsession-wasm": "^0.0.10",
|
|
12
12
|
"@session-foundation/sodium": "^0.0.6"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@turbo/gen": "^2.4.4",
|
|
16
|
+
"@types/chai": "^5.2.2",
|
|
16
17
|
"@types/lodash": "^4.17.16",
|
|
18
|
+
"@types/mocha": "^10.0.10",
|
|
17
19
|
"@types/node": "^22.13.10",
|
|
20
|
+
"chai": "^5.2.0",
|
|
18
21
|
"eslint": "^9.23.0",
|
|
22
|
+
"mocha": "^11.7.1",
|
|
23
|
+
"ts-node": "^10.9.2",
|
|
19
24
|
"tsup": "^8.5.1",
|
|
20
25
|
"typescript": "5.8.2",
|
|
21
26
|
"@repo/eslint-config": "0.0.0",
|
|
@@ -29,6 +34,8 @@
|
|
|
29
34
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
30
35
|
"dev": "pnpm build --watch",
|
|
31
36
|
"lint": "eslint . --max-warnings 0",
|
|
32
|
-
"check-types": "tsc --noEmit"
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
"pretest": "tsc --project tsconfig.test.json",
|
|
39
|
+
"test": "mocha --require ts-node/register --extensions ts 'tests/**/*.test.ts'"
|
|
33
40
|
}
|
|
34
41
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, it } from 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { buildStateForTest, USERNAME } from '../src/index';
|
|
4
|
+
|
|
5
|
+
describe('buildStateForTest', () => {
|
|
6
|
+
// Use testnet for faster tests (no need to hit mainnet)
|
|
7
|
+
const network = 'http://sesh-net.local:1280';
|
|
8
|
+
|
|
9
|
+
describe('1user', () => {
|
|
10
|
+
it('should create a single user with valid properties', async () => {
|
|
11
|
+
// This test may take a while as it pushes to the network
|
|
12
|
+
|
|
13
|
+
const state = await buildStateForTest('1user', undefined, network);
|
|
14
|
+
|
|
15
|
+
expect(state).to.have.property('users');
|
|
16
|
+
expect(state.users).to.be.an('array');
|
|
17
|
+
expect(state.users).to.have.lengthOf(1);
|
|
18
|
+
|
|
19
|
+
const user = state.users[0];
|
|
20
|
+
if (!user) {
|
|
21
|
+
throw new Error('User should be defined');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Validate user properties
|
|
25
|
+
expect(user).to.have.property('seed');
|
|
26
|
+
expect(user.seed).to.be.instanceOf(Uint8Array);
|
|
27
|
+
expect(user.seed).to.have.lengthOf(32);
|
|
28
|
+
|
|
29
|
+
expect(user).to.have.property('seedPhrase');
|
|
30
|
+
expect(user.seedPhrase).to.be.a('string');
|
|
31
|
+
expect(user.seedPhrase.split(' ')).to.have.lengthOf(13);
|
|
32
|
+
|
|
33
|
+
expect(user).to.have.property('sessionId');
|
|
34
|
+
expect(user.sessionId).to.be.a('string');
|
|
35
|
+
expect(user.sessionId).to.match(/^05[0-9a-f]{64}$/);
|
|
36
|
+
|
|
37
|
+
expect(user).to.have.property('userName');
|
|
38
|
+
expect(user.userName).to.equal(USERNAME.ALICE);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should create a user that gets pushed to the swarm', async function () {
|
|
42
|
+
const state = await buildStateForTest('1user', undefined, network);
|
|
43
|
+
|
|
44
|
+
// The fact that buildStateForTest completes without throwing
|
|
45
|
+
// means the user was successfully pushed to the swarm
|
|
46
|
+
expect(state.users).to.have.lengthOf(1);
|
|
47
|
+
expect(state.users[0]?.sessionId).to.be.a('string');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('2friendsInGroup', () => {
|
|
52
|
+
const groupName = 'Test Group';
|
|
53
|
+
|
|
54
|
+
it('should create two friends in a group with valid properties', async () => {
|
|
55
|
+
const state = await buildStateForTest('2friendsInGroup', groupName, network);
|
|
56
|
+
|
|
57
|
+
// Validate users
|
|
58
|
+
expect(state).to.have.property('users');
|
|
59
|
+
expect(state.users).to.be.an('array');
|
|
60
|
+
expect(state.users).to.have.lengthOf(2);
|
|
61
|
+
|
|
62
|
+
const user1 = state.users[0];
|
|
63
|
+
const user2 = state.users[1];
|
|
64
|
+
|
|
65
|
+
if (!user1 || !user2) {
|
|
66
|
+
throw new Error('Both users should be defined');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Validate first user
|
|
70
|
+
expect(user1).to.have.property('seed');
|
|
71
|
+
expect(user1.seed).to.be.instanceOf(Uint8Array);
|
|
72
|
+
expect(user1).to.have.property('seedPhrase');
|
|
73
|
+
expect(user1.seedPhrase).to.be.a('string');
|
|
74
|
+
expect(user1).to.have.property('sessionId');
|
|
75
|
+
expect(user1.sessionId).to.match(/^05[0-9a-f]{64}$/);
|
|
76
|
+
expect(user1).to.have.property('userName');
|
|
77
|
+
expect(user1.userName).to.equal(USERNAME.ALICE);
|
|
78
|
+
|
|
79
|
+
// Validate second user
|
|
80
|
+
expect(user2).to.have.property('seed');
|
|
81
|
+
expect(user2.seed).to.be.instanceOf(Uint8Array);
|
|
82
|
+
expect(user2).to.have.property('seedPhrase');
|
|
83
|
+
expect(user2.seedPhrase).to.be.a('string');
|
|
84
|
+
expect(user2).to.have.property('sessionId');
|
|
85
|
+
expect(user2.sessionId).to.match(/^05[0-9a-f]{64}$/);
|
|
86
|
+
expect(user2).to.have.property('userName');
|
|
87
|
+
expect(user2.userName).to.equal(USERNAME.BOB);
|
|
88
|
+
|
|
89
|
+
// Validate users are different
|
|
90
|
+
expect(user1.sessionId).to.not.equal(user2.sessionId);
|
|
91
|
+
|
|
92
|
+
// Validate group
|
|
93
|
+
expect(state).to.have.property('group');
|
|
94
|
+
expect(state.group).to.be.an('object');
|
|
95
|
+
expect(state.group.groupPk).to.be.a('string');
|
|
96
|
+
expect(state.group.groupPk).to.match(/^03[0-9a-f]{64}$/);
|
|
97
|
+
expect(state.group.groupName).to.equal(groupName);
|
|
98
|
+
expect(state.group.adminSecretKey).to.be.instanceOf(Uint8Array);
|
|
99
|
+
expect(state.group.adminSecretKey).to.have.lengthOf(64);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should create friends that get pushed to the swarm', async () => {
|
|
103
|
+
const state = await buildStateForTest('2friendsInGroup', groupName, network);
|
|
104
|
+
|
|
105
|
+
// The fact that buildStateForTest completes without throwing
|
|
106
|
+
// means the users and group were successfully pushed to the swarm
|
|
107
|
+
expect(state.users).to.have.lengthOf(2);
|
|
108
|
+
expect(state.users[0]?.sessionId).to.be.a('string');
|
|
109
|
+
expect(state.users[1]?.sessionId).to.be.a('string');
|
|
110
|
+
expect(state.group.groupPk).to.be.a('string');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should throw error when groupName is not provided', async () => {
|
|
114
|
+
try {
|
|
115
|
+
// @ts-expect-error - Testing runtime error when groupName is undefined
|
|
116
|
+
await buildStateForTest('2friendsInGroup', undefined, network);
|
|
117
|
+
throw new Error('Should have thrown an error');
|
|
118
|
+
} catch (error) {
|
|
119
|
+
expect(error).to.be.instanceOf(Error);
|
|
120
|
+
expect((error as Error).message).to.include('groupName');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('none', () => {
|
|
126
|
+
it('should return empty users object', async () => {
|
|
127
|
+
const state = await buildStateForTest('none', undefined, network);
|
|
128
|
+
|
|
129
|
+
expect(state).to.have.property('users');
|
|
130
|
+
expect(state.users).to.deep.equal({});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|