Skip to content

Commit 0c069ad

Browse files
committed
format tests
1 parent 547cf6e commit 0c069ad

File tree

5 files changed

+141
-27
lines changed

5 files changed

+141
-27
lines changed

app/tests/utils/proving/actorMock.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
13
import { jest } from '@jest/globals';
24

35
// Minimal actor stub used to observe send calls and emit state transitions

app/tests/utils/proving/provingMachine.generatePayload.test.ts

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
13
import { jest } from '@jest/globals';
2-
import { useProvingStore } from '../../../src/utils/proving/provingMachine';
4+
35
import { useProtocolStore } from '../../../src/stores/protocolStore';
46
import { useSelfAppStore } from '../../../src/stores/selfAppStore';
7+
import { useProvingStore } from '../../../src/utils/proving/provingMachine';
58

69
jest.mock('xstate', () => {
710
const actual = jest.requireActual('xstate');
811
const { actorMock } = require('./actorMock');
912
return { ...actual, createActor: jest.fn(() => actorMock) };
1013
});
1114

12-
jest.mock('../../../src/utils/analytics', () => () => ({ trackEvent: jest.fn() }));
15+
jest.mock('../../../src/utils/analytics', () => () => ({
16+
trackEvent: jest.fn(),
17+
}));
1318

1419
jest.mock('@selfxyz/common', () => {
1520
const actual = jest.requireActual('@selfxyz/common');
16-
return { ...actual, getSolidityPackedUserContextData: jest.fn(() => '0x1234') };
21+
return {
22+
...actual,
23+
getSolidityPackedUserContextData: jest.fn(() => '0x1234'),
24+
};
1725
});
1826

1927
jest.mock('../../../src/utils/proving/provingInputs', () => ({
@@ -42,12 +50,23 @@ jest.mock('../../../src/utils/proving/provingUtils', () => {
4250
return {
4351
...actual,
4452
getPayload: jest.fn(() => ({ mocked: true })),
45-
encryptAES256GCM: jest.fn(() => ({ nonce: [0], cipher_text: [1], auth_tag: [2] })),
53+
encryptAES256GCM: jest.fn(() => ({
54+
nonce: [0],
55+
cipher_text: [1],
56+
auth_tag: [2],
57+
})),
4658
};
4759
});
4860

49-
const { getPayload, encryptAES256GCM } = require('../../../src/utils/proving/provingUtils');
50-
const { generateTEEInputsRegister, generateTEEInputsDSC, generateTEEInputsDisclose } = require('../../../src/utils/proving/provingInputs');
61+
const {
62+
getPayload,
63+
encryptAES256GCM,
64+
} = require('../../../src/utils/proving/provingUtils');
65+
const {
66+
generateTEEInputsRegister,
67+
generateTEEInputsDSC,
68+
generateTEEInputsDisclose,
69+
} = require('../../../src/utils/proving/provingInputs');
5170

5271
describe('_generatePayload', () => {
5372
beforeEach(() => {
@@ -60,8 +79,42 @@ describe('_generatePayload', () => {
6079
sharedKey: Buffer.alloc(32, 1),
6180
env: 'prod',
6281
});
63-
useSelfAppStore.setState({ selfApp: { chainID: 1, userId: 'u', userDefinedData: '0x0', endpointType: 'https', endpoint: 'https://e', scope: 's', sessionId: '', appName: '', logoBase64: '', header: '', userIdType: 'uuid', devMode: false, disclosures: {}, version: 1 } });
64-
useProtocolStore.setState({ passport: { dsc_tree: 'tree', csca_tree: [['a']], commitment_tree: null, deployed_circuits: null, circuits_dns_mapping: null, alternative_csca: {} }, id_card: { commitment_tree: null, dsc_tree: null, csca_tree: null, deployed_circuits: null, circuits_dns_mapping: null, alternative_csca: {} } });
82+
useSelfAppStore.setState({
83+
selfApp: {
84+
chainID: 1,
85+
userId: 'u',
86+
userDefinedData: '0x0',
87+
endpointType: 'https',
88+
endpoint: 'https://e',
89+
scope: 's',
90+
sessionId: '',
91+
appName: '',
92+
logoBase64: '',
93+
header: '',
94+
userIdType: 'uuid',
95+
devMode: false,
96+
disclosures: {},
97+
version: 1,
98+
},
99+
});
100+
useProtocolStore.setState({
101+
passport: {
102+
dsc_tree: 'tree',
103+
csca_tree: [['a']],
104+
commitment_tree: null,
105+
deployed_circuits: null,
106+
circuits_dns_mapping: null,
107+
alternative_csca: {},
108+
},
109+
id_card: {
110+
commitment_tree: null,
111+
dsc_tree: null,
112+
csca_tree: null,
113+
deployed_circuits: null,
114+
circuits_dns_mapping: null,
115+
alternative_csca: {},
116+
},
117+
});
65118
});
66119

67120
it('register circuit', async () => {
@@ -71,7 +124,12 @@ describe('_generatePayload', () => {
71124
expect(getPayload).toHaveBeenCalled();
72125
expect(encryptAES256GCM).toHaveBeenCalled();
73126
expect(useProvingStore.getState().endpointType).toBe('celo');
74-
expect(payload.params).toEqual({ uuid: '123', nonce: [0], cipher_text: [1], auth_tag: [2] });
127+
expect(payload.params).toEqual({
128+
uuid: '123',
129+
nonce: [0],
130+
cipher_text: [1],
131+
auth_tag: [2],
132+
});
75133
});
76134

77135
it('dsc circuit', async () => {

app/tests/utils/proving/provingMachine.init.test.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
13
import { jest } from '@jest/globals';
4+
25
import { useProvingStore } from '../../../src/utils/proving/provingMachine';
36
import { emitState } from './actorMock';
47

@@ -16,9 +19,13 @@ jest.mock('../../../src/providers/authProvider', () => ({
1619
unsafe_getPrivateKey: jest.fn(),
1720
}));
1821

19-
jest.mock('../../../src/utils/analytics', () => () => ({ trackEvent: jest.fn() }));
22+
jest.mock('../../../src/utils/analytics', () => () => ({
23+
trackEvent: jest.fn(),
24+
}));
2025

21-
const { loadSelectedDocument } = require('../../../src/providers/passportDataProvider');
26+
const {
27+
loadSelectedDocument,
28+
} = require('../../../src/providers/passportDataProvider');
2229
const { unsafe_getPrivateKey } = require('../../../src/providers/authProvider');
2330
const { actorMock } = require('./actorMock');
2431

@@ -31,16 +38,25 @@ describe('provingMachine init', () => {
3138
it('handles missing document', async () => {
3239
loadSelectedDocument.mockResolvedValue(null);
3340
await useProvingStore.getState().init('register');
34-
expect(actorMock.send).toHaveBeenCalledWith({ type: 'PASSPORT_DATA_NOT_FOUND' });
41+
expect(actorMock.send).toHaveBeenCalledWith({
42+
type: 'PASSPORT_DATA_NOT_FOUND',
43+
});
3544
emitState('passport_data_not_found');
36-
expect(useProvingStore.getState().currentState).toBe('passport_data_not_found');
45+
expect(useProvingStore.getState().currentState).toBe(
46+
'passport_data_not_found',
47+
);
3748
});
3849

3950
it('initializes state with document and secret', async () => {
40-
loadSelectedDocument.mockResolvedValue({ data: { documentCategory: 'passport', mock: false } });
51+
loadSelectedDocument.mockResolvedValue({
52+
data: { documentCategory: 'passport', mock: false },
53+
});
4154
unsafe_getPrivateKey.mockResolvedValue('mysecret');
4255
await useProvingStore.getState().init('register');
43-
expect(useProvingStore.getState().passportData).toEqual({ documentCategory: 'passport', mock: false });
56+
expect(useProvingStore.getState().passportData).toEqual({
57+
documentCategory: 'passport',
58+
mock: false,
59+
});
4460
expect(useProvingStore.getState().secret).toBe('mysecret');
4561
expect(useProvingStore.getState().env).toBe('prod');
4662
expect(useProvingStore.getState().circuitType).toBe('register');

app/tests/utils/proving/provingMachine.websocket.test.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
13
import { jest } from '@jest/globals';
2-
import { useProvingStore } from '../../../src/utils/proving/provingMachine';
34

5+
import { useProvingStore } from '../../../src/utils/proving/provingMachine';
46

57
jest.mock('xstate', () => {
68
const actual = jest.requireActual('xstate');
79
const { actorMock } = require('./actorMock');
810
return { ...actual, createActor: jest.fn(() => actorMock) };
911
});
1012

11-
jest.mock('../../../src/utils/analytics', () => () => ({ trackEvent: jest.fn() }));
13+
jest.mock('../../../src/utils/analytics', () => () => ({
14+
trackEvent: jest.fn(),
15+
}));
1216
jest.mock('uuid', () => ({ v4: jest.fn(() => 'uuid') }));
1317

1418
jest.mock('../../../src/utils/proving/attest', () => ({
@@ -22,7 +26,9 @@ jest.mock('../../../src/utils/proving/provingUtils', () => ({
2226
}));
2327

2428
jest.mock('../../../src/providers/passportDataProvider', () => ({
25-
loadSelectedDocument: jest.fn(() => Promise.resolve({ data: { documentCategory: 'passport', mock: false } })),
29+
loadSelectedDocument: jest.fn(() =>
30+
Promise.resolve({ data: { documentCategory: 'passport', mock: false } }),
31+
),
2632
}));
2733

2834
jest.mock('../../../src/providers/authProvider', () => ({
@@ -36,9 +42,23 @@ const { verifyAttestation } = require('../../../src/utils/proving/attest');
3642
describe('websocket handlers', () => {
3743
beforeEach(async () => {
3844
jest.clearAllMocks();
39-
useProvingStore.setState({ wsConnection: { send: jest.fn(), addEventListener: jest.fn(), removeEventListener: jest.fn(), close: jest.fn() } as any });
45+
useProvingStore.setState({
46+
wsConnection: {
47+
send: jest.fn(),
48+
addEventListener: jest.fn(),
49+
removeEventListener: jest.fn(),
50+
close: jest.fn(),
51+
} as any,
52+
});
4053
await useProvingStore.getState().init('register');
41-
useProvingStore.setState({ wsConnection: { send: jest.fn(), addEventListener: jest.fn(), removeEventListener: jest.fn(), close: jest.fn() } as any });
54+
useProvingStore.setState({
55+
wsConnection: {
56+
send: jest.fn(),
57+
addEventListener: jest.fn(),
58+
removeEventListener: jest.fn(),
59+
close: jest.fn(),
60+
} as any,
61+
});
4262
});
4363

4464
it('_handleWsOpen sends hello', () => {
@@ -51,14 +71,20 @@ describe('websocket handlers', () => {
5171
});
5272

5373
it('_handleWebSocketMessage processes attestation', async () => {
54-
const message = new MessageEvent('message', { data: JSON.stringify({ result: { attestation: 'a' } }) });
74+
const message = new MessageEvent('message', {
75+
data: JSON.stringify({ result: { attestation: 'a' } }),
76+
});
5577
await useProvingStore.getState()._handleWebSocketMessage(message);
5678
expect(verifyAttestation).toHaveBeenCalled();
57-
expect(actorMock.send.mock.calls.some(c => c[0].type === 'CONNECT_SUCCESS')).toBe(true);
79+
expect(
80+
actorMock.send.mock.calls.some(c => c[0].type === 'CONNECT_SUCCESS'),
81+
).toBe(true);
5882
});
5983

6084
it('_handleWebSocketMessage handles error', async () => {
61-
const message = new MessageEvent('message', { data: JSON.stringify({ error: 'oops' }) });
85+
const message = new MessageEvent('message', {
86+
data: JSON.stringify({ error: 'oops' }),
87+
});
6288
await useProvingStore.getState()._handleWebSocketMessage(message);
6389
const lastCall = actorMock.send.mock.calls.pop();
6490
expect(lastCall[0]).toEqual({ type: 'PROVE_ERROR' });

app/tests/utils/proving/provingUtils.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
13
import forge from 'node-forge';
4+
25
import {
36
encryptAES256GCM,
47
getPayload,
@@ -11,14 +14,21 @@ describe('provingUtils', () => {
1114
const plaintext = 'hello world';
1215
const encrypted = encryptAES256GCM(plaintext, forge.util.createBuffer(key));
1316

14-
const decipher = forge.cipher.createDecipher('AES-GCM', forge.util.createBuffer(key));
17+
const decipher = forge.cipher.createDecipher(
18+
'AES-GCM',
19+
forge.util.createBuffer(key),
20+
);
1521
decipher.start({
1622
iv: Buffer.from(encrypted.nonce).toString('binary'),
1723
tagLength: 128,
18-
tag: forge.util.createBuffer(Buffer.from(encrypted.auth_tag).toString('binary')),
24+
tag: forge.util.createBuffer(
25+
Buffer.from(encrypted.auth_tag).toString('binary'),
26+
),
1927
});
2028
decipher.update(
21-
forge.util.createBuffer(Buffer.from(encrypted.cipher_text).toString('binary')),
29+
forge.util.createBuffer(
30+
Buffer.from(encrypted.cipher_text).toString('binary'),
31+
),
2232
);
2333
const success = decipher.finish();
2434
const decrypted = decipher.output.toString();
@@ -68,6 +78,8 @@ describe('provingUtils', () => {
6878
it('getWSDbRelayerUrl handles endpoint types', () => {
6979
expect(getWSDbRelayerUrl('celo')).toContain('websocket.self.xyz');
7080
expect(getWSDbRelayerUrl('https')).toContain('websocket.self.xyz');
71-
expect(getWSDbRelayerUrl('staging_celo')).toContain('websocket.staging.self.xyz');
81+
expect(getWSDbRelayerUrl('staging_celo')).toContain(
82+
'websocket.staging.self.xyz',
83+
);
7284
});
7385
});

0 commit comments

Comments
 (0)