@session-foundation/qa-seeder 0.1.24 → 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 +50 -14
- package/dist/index.mjs +50 -14
- package/package.json +12 -5
- package/tests/buildState.test.ts +133 -0
- package/tsconfig.test.json +11 -0
package/dist/index.js
CHANGED
|
@@ -596,21 +596,57 @@ var SessionGroup = class {
|
|
|
596
596
|
}
|
|
597
597
|
async pushChangesToSwarm(snode) {
|
|
598
598
|
const pushHex = this.metagroupW.pushHex();
|
|
599
|
-
const
|
|
600
|
-
pushHex.keysPush,
|
|
601
|
-
pushHex.
|
|
602
|
-
|
|
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
|
|
603
649
|
]);
|
|
604
|
-
const storeRequests = toPush.map((m) => {
|
|
605
|
-
return new StoreGroupConfigSubRequest({
|
|
606
|
-
namespace: m.storageNamespace.value,
|
|
607
|
-
encryptedData: this.sodium.from_hex(m.dataHex.toString()),
|
|
608
|
-
groupPk: this.groupPk,
|
|
609
|
-
ttlMs: 1e3 * 3600 * 24,
|
|
610
|
-
// 1 day should be enough for testing and debugging a test?
|
|
611
|
-
adminGroupSigner: this.adminGroupSigner
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
650
|
const storeResult = await Promise.all(
|
|
615
651
|
storeRequests.map(async (request) => {
|
|
616
652
|
const builtRequest = await request.build();
|
package/dist/index.mjs
CHANGED
|
@@ -564,21 +564,57 @@ var SessionGroup = class {
|
|
|
564
564
|
}
|
|
565
565
|
async pushChangesToSwarm(snode) {
|
|
566
566
|
const pushHex = this.metagroupW.pushHex();
|
|
567
|
-
const
|
|
568
|
-
pushHex.keysPush,
|
|
569
|
-
pushHex.
|
|
570
|
-
|
|
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
|
|
571
617
|
]);
|
|
572
|
-
const storeRequests = toPush.map((m) => {
|
|
573
|
-
return new StoreGroupConfigSubRequest({
|
|
574
|
-
namespace: m.storageNamespace.value,
|
|
575
|
-
encryptedData: this.sodium.from_hex(m.dataHex.toString()),
|
|
576
|
-
groupPk: this.groupPk,
|
|
577
|
-
ttlMs: 1e3 * 3600 * 24,
|
|
578
|
-
// 1 day should be enough for testing and debugging a test?
|
|
579
|
-
adminGroupSigner: this.adminGroupSigner
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
618
|
const storeResult = await Promise.all(
|
|
583
619
|
storeRequests.map(async (request) => {
|
|
584
620
|
const builtRequest = await request.build();
|
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/basic-types": "^0.0.6",
|
|
9
10
|
"@session-foundation/mnemonic": "^0.0.8",
|
|
10
|
-
"@session-foundation/libsession-wasm": "^0.0.
|
|
11
|
-
"@session-foundation/sodium": "^0.0.6"
|
|
12
|
-
"@session-foundation/basic-types": "^0.0.6"
|
|
11
|
+
"@session-foundation/libsession-wasm": "^0.0.10",
|
|
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
|
+
});
|