Skip to content

Commit 9fcb86e

Browse files
style: format tests files (#199)
1 parent cfd9547 commit 9fcb86e

File tree

8 files changed

+110
-63
lines changed

8 files changed

+110
-63
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --forceExit -b",
2929
"test:e2e:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --coverage",
3030
"lint": "eslint .",
31-
"format": "prettier --write \"src/**/*.ts\"",
32-
"check-format": "prettier --check \"src/**/*.ts\"",
31+
"format": "prettier --write \"(src|tests)/**/*.ts\"",
32+
"check-format": "prettier --check \"(src|tests)/**/*.ts\"",
3333
"stop-test-stack": "cd tests && docker compose down --volumes --remove-orphans",
3434
"start-test-stack": "cd tests && npm run stop-test-stack && node scripts/prepare-test-env.js && docker compose build && docker compose up -d && node scripts/prepare-bellecour-fork-for-tests.js"
3535
},

tests/e2e/constructor.test.ts

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
getTestWeb3SignerProvider,
88
MAX_EXPECTED_WEB2_SERVICES_TIME,
99
} from '../test-utils.js';
10-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
10+
import {
11+
DEFAULT_CHAIN_ID,
12+
getChainDefaultConfig,
13+
} from '../../src/config/config.js';
1114

1215
describe('IExecWeb3mail()', () => {
1316
it('instantiates with a valid ethProvider', async () => {
@@ -54,8 +57,7 @@ describe('IExecWeb3mail()', () => {
5457
const graphQLClient = web3mail['graphQLClient'];
5558
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
5659
expect(defaultConfig).not.toBeNull();
57-
expect(graphQLClient['url']).toBe(
58-
defaultConfig!.dataProtectorSubgraph);
60+
expect(graphQLClient['url']).toBe(defaultConfig!.dataProtectorSubgraph);
5961
});
6062

6163
it('should use provided data Protector Subgraph URL when subgraphUrl is provided', async () => {
@@ -108,7 +110,9 @@ describe('IExecWeb3mail()', () => {
108110
expect(ipfsNode).toStrictEqual(customIpfsNode);
109111
expect(ipfsGateway).toStrictEqual(customIpfsGateway);
110112
expect(dappAddressOrENS).toStrictEqual(customDapp);
111-
expect(whitelistAddress).toStrictEqual(customDappWhitelistAddress.toLowerCase());
113+
expect(whitelistAddress).toStrictEqual(
114+
customDappWhitelistAddress.toLowerCase()
115+
);
112116
expect(await iexec.config.resolveSmsURL()).toBe(smsURL);
113117
expect(await iexec.config.resolveIexecGatewayURL()).toBe(iexecGatewayURL);
114118
});
@@ -149,55 +153,70 @@ describe('IExecWeb3mail()', () => {
149153

150154
describe('With allowExperimentalNetworks: true', () => {
151155
it('should resolve the configuration', async () => {
152-
const web3mail = new IExecWeb3mail(
153-
experimentalNetworkSigner,
154-
{ allowExperimentalNetworks: true }
155-
);
156+
const web3mail = new IExecWeb3mail(experimentalNetworkSigner, {
157+
allowExperimentalNetworks: true,
158+
});
156159
await expect(web3mail.init()).resolves.toBeUndefined();
157160
expect(web3mail).toBeInstanceOf(IExecWeb3mail);
158161
});
159162

160163
it('should use Arbitrum Sepolia default configuration', async () => {
161-
const web3mail = new IExecWeb3mail(
162-
experimentalNetworkSigner,
163-
{ allowExperimentalNetworks: true }
164-
);
164+
const web3mail = new IExecWeb3mail(experimentalNetworkSigner, {
165+
allowExperimentalNetworks: true,
166+
});
165167
await web3mail.init();
166168

167-
const arbitrumSepoliaConfig = getChainDefaultConfig(421614, { allowExperimentalNetworks: true });
169+
const arbitrumSepoliaConfig = getChainDefaultConfig(421614, {
170+
allowExperimentalNetworks: true,
171+
});
168172
expect(arbitrumSepoliaConfig).not.toBeNull();
169173

170-
expect(web3mail['ipfsGateway']).toBe(arbitrumSepoliaConfig!.ipfsGateway);
174+
expect(web3mail['ipfsGateway']).toBe(
175+
arbitrumSepoliaConfig!.ipfsGateway
176+
);
171177
expect(web3mail['ipfsNode']).toBe(arbitrumSepoliaConfig!.ipfsUploadUrl);
172-
expect(web3mail['dappAddressOrENS']).toBe(arbitrumSepoliaConfig!.dappAddress);
173-
expect(web3mail['dappWhitelistAddress']).toBe(arbitrumSepoliaConfig!.whitelistSmartContract.toLowerCase());
174-
expect(web3mail['defaultWorkerpool']).toBe(arbitrumSepoliaConfig!.prodWorkerpoolAddress);
175-
expect(web3mail['graphQLClient']['url']).toBe(arbitrumSepoliaConfig!.dataProtectorSubgraph);
178+
expect(web3mail['dappAddressOrENS']).toBe(
179+
arbitrumSepoliaConfig!.dappAddress
180+
);
181+
expect(web3mail['dappWhitelistAddress']).toBe(
182+
arbitrumSepoliaConfig!.whitelistSmartContract.toLowerCase()
183+
);
184+
expect(web3mail['defaultWorkerpool']).toBe(
185+
arbitrumSepoliaConfig!.prodWorkerpoolAddress
186+
);
187+
expect(web3mail['graphQLClient']['url']).toBe(
188+
arbitrumSepoliaConfig!.dataProtectorSubgraph
189+
);
176190
});
177191

178192
it('should allow custom configuration override for Arbitrum Sepolia', async () => {
179193
const customIpfsGateway = 'https://custom-arbitrum-ipfs.com';
180194
const customDappAddress = 'custom.arbitrum.app.eth';
181195

182-
const web3mail = new IExecWeb3mail(
183-
experimentalNetworkSigner,
184-
{
185-
allowExperimentalNetworks: true,
186-
ipfsGateway: customIpfsGateway,
187-
dappAddressOrENS: customDappAddress
188-
}
189-
);
196+
const web3mail = new IExecWeb3mail(experimentalNetworkSigner, {
197+
allowExperimentalNetworks: true,
198+
ipfsGateway: customIpfsGateway,
199+
dappAddressOrENS: customDappAddress,
200+
});
190201
await web3mail.init();
191202

192203
expect(web3mail['ipfsGateway']).toBe(customIpfsGateway);
193204
expect(web3mail['dappAddressOrENS']).toBe(customDappAddress);
194205

195-
const arbitrumSepoliaConfig = getChainDefaultConfig(421614, { allowExperimentalNetworks: true });
206+
const arbitrumSepoliaConfig = getChainDefaultConfig(421614, {
207+
allowExperimentalNetworks: true,
208+
});
196209
expect(arbitrumSepoliaConfig).not.toBeNull();
197210
expect(web3mail['ipfsNode']).toBe(arbitrumSepoliaConfig!.ipfsUploadUrl);
198-
expect(web3mail['dappWhitelistAddress']).toBe(arbitrumSepoliaConfig!.whitelistSmartContract.toLowerCase());
199-
expect(web3mail['defaultWorkerpool']).toBe(arbitrumSepoliaConfig!.prodWorkerpoolAddress);
200-
expect(web3mail['graphQLClient']['url']).toBe(arbitrumSepoliaConfig!.dataProtectorSubgraph);
211+
expect(web3mail['dappWhitelistAddress']).toBe(
212+
arbitrumSepoliaConfig!.whitelistSmartContract.toLowerCase()
213+
);
214+
expect(web3mail['defaultWorkerpool']).toBe(
215+
arbitrumSepoliaConfig!.prodWorkerpoolAddress
216+
);
217+
expect(web3mail['graphQLClient']['url']).toBe(
218+
arbitrumSepoliaConfig!.dataProtectorSubgraph
219+
);
201220
});
202221
});
203222
});

tests/e2e/fetchMyContacts.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
waitSubgraphIndexing,
1717
} from '../test-utils.js';
1818
import IExec from 'iexec/IExec';
19-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
19+
import {
20+
DEFAULT_CHAIN_ID,
21+
getChainDefaultConfig,
22+
} from '../../src/config/config.js';
2023

2124
describe('web3mail.fetchMyContacts()', () => {
2225
let wallet: HDNodeWallet;
@@ -51,11 +54,11 @@ describe('web3mail.fetchMyContacts()', () => {
5154
});
5255
expect(
5356
foundContactForASpecificRequester &&
54-
foundContactForASpecificRequester.address
57+
foundContactForASpecificRequester.address
5558
).toBeDefined();
5659
expect(
5760
foundContactForASpecificRequester &&
58-
foundContactForASpecificRequester.address
61+
foundContactForASpecificRequester.address
5962
).toBe(protectedData.address.toLocaleLowerCase());
6063
},
6164
MAX_EXPECTED_WEB2_SERVICES_TIME

tests/e2e/fetchUserContacts.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
} from '@iexec/dataprotector';
55
import { beforeAll, describe, expect, it } from '@jest/globals';
66
import { HDNodeWallet, Wallet } from 'ethers';
7-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
7+
import {
8+
DEFAULT_CHAIN_ID,
9+
getChainDefaultConfig,
10+
} from '../../src/config/config.js';
811
import { IExecWeb3mail, WorkflowError } from '../../src/index.js';
912
import {
1013
MAX_EXPECTED_BLOCKTIME,

tests/e2e/sendEmail.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import {
2424
} from '../test-utils.js';
2525
import { IExec } from 'iexec';
2626
import { NULL_ADDRESS } from 'iexec/utils';
27-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
27+
import {
28+
DEFAULT_CHAIN_ID,
29+
getChainDefaultConfig,
30+
} from '../../src/config/config.js';
2831

2932
describe('web3mail.sendEmail()', () => {
3033
let consumerWallet: HDNodeWallet;
@@ -63,7 +66,10 @@ describe('web3mail.sendEmail()', () => {
6366
);
6467
const resourceProvider = new IExec({ ethProvider }, iexecOptions);
6568
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
66-
await createAndPublishAppOrders(resourceProvider, defaultConfig!.dappAddress);
69+
await createAndPublishAppOrders(
70+
resourceProvider,
71+
defaultConfig!.dappAddress
72+
);
6773

6874
learnProdWorkerpoolAddress = await resourceProvider.ens.resolveName(
6975
TEST_CHAIN.learnProdWorkerpool
@@ -284,7 +290,8 @@ describe('web3mail.sendEmail()', () => {
284290

285291
//grant access to whitelist
286292
await dataProtector.grantAccess({
287-
authorizedApp: getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract, //whitelist address
293+
authorizedApp:
294+
getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract, //whitelist address
288295
protectedData: protectedDataForWhitelist.address,
289296
authorizedUser: consumerWallet.address, // consumer wallet
290297
numberOfAccess: 1000,
@@ -453,8 +460,8 @@ describe('web3mail.sendEmail()', () => {
453460
expect(sendEmailResponse.taskId).toBeDefined();
454461
},
455462
2 * MAX_EXPECTED_BLOCKTIME +
456-
MAX_EXPECTED_WEB2_SERVICES_TIME +
457-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
463+
MAX_EXPECTED_WEB2_SERVICES_TIME +
464+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
458465
);
459466
});
460467

@@ -511,8 +518,8 @@ describe('web3mail.sendEmail()', () => {
511518
);
512519
},
513520
2 * MAX_EXPECTED_BLOCKTIME +
514-
MAX_EXPECTED_WEB2_SERVICES_TIME +
515-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
521+
MAX_EXPECTED_WEB2_SERVICES_TIME +
522+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
516523
);
517524
it(
518525
'should create task if user approves the non sponsored amount',
@@ -563,8 +570,8 @@ describe('web3mail.sendEmail()', () => {
563570
expect(sendEmailResponse.taskId).toBeDefined();
564571
},
565572
2 * MAX_EXPECTED_BLOCKTIME +
566-
MAX_EXPECTED_WEB2_SERVICES_TIME +
567-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
573+
MAX_EXPECTED_WEB2_SERVICES_TIME +
574+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
568575
);
569576
});
570577
describe('and workerpoolMaxPrice does NOT covers the non sponsored amount', () => {
@@ -617,8 +624,8 @@ describe('web3mail.sendEmail()', () => {
617624
);
618625
},
619626
2 * MAX_EXPECTED_BLOCKTIME +
620-
MAX_EXPECTED_WEB2_SERVICES_TIME +
621-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
627+
MAX_EXPECTED_WEB2_SERVICES_TIME +
628+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
622629
);
623630
});
624631
});

tests/test-utils.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const TEST_CHAIN = {
1919
voucherManagerWallet: new Wallet(
2020
'0x2c906d4022cace2b3ee6c8b596564c26c4dcadddf1e949b769bcb0ad75c40c33'
2121
),
22-
voucherSubgraphURL: 'http://127.0.0.1:8000/subgraphs/name/bellecour/iexec-voucher',
22+
voucherSubgraphURL:
23+
'http://127.0.0.1:8000/subgraphs/name/bellecour/iexec-voucher',
2324
learnProdWorkerpool: 'prod-v8-learn.main.pools.iexec.eth',
2425
learnProdWorkerpoolOwnerWallet: new Wallet(
2526
'0x800e01919eadf36f110f733decb1cc0f82e7941a748e89d7a3f76157f6654bb3'
@@ -31,13 +32,9 @@ export const TEST_CHAIN = {
3132
appOwnerWallet: new Wallet(
3233
'0xa911b93e50f57c156da0b8bff2277d241bcdb9345221a3e246a99c6e7cedcde5'
3334
),
34-
provider: new JsonRpcProvider(
35-
'http://127.0.0.1:8545',
36-
undefined,
37-
{
38-
pollingInterval: 1000, // speed up tests
39-
}
40-
),
35+
provider: new JsonRpcProvider('http://127.0.0.1:8545', undefined, {
36+
pollingInterval: 1000, // speed up tests
37+
}),
4138
hubAddress: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f',
4239
};
4340

tests/unit/fetchMyContacts.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { describe, expect, it, jest } from '@jest/globals';
22
import { Address } from 'iexec';
33
import { type FetchMyContacts } from '../../src/web3mail/fetchMyContacts.js';
44
import { getRandomAddress } from '../test-utils.js';
5-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
5+
import {
6+
DEFAULT_CHAIN_ID,
7+
getChainDefaultConfig,
8+
} from '../../src/config/config.js';
69

710
jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
811
getValidContact: jest.fn(),
@@ -76,7 +79,8 @@ describe('fetchMyContacts', () => {
7679
// @ts-expect-error No need for graphQLClient here
7780
graphQLClient: {},
7881
dappAddressOrENS: getChainDefaultConfig(DEFAULT_CHAIN_ID).dappAddress,
79-
dappWhitelistAddress: getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract,
82+
dappWhitelistAddress:
83+
getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract,
8084
isUserStrict: false,
8185
});
8286
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
@@ -95,7 +99,9 @@ describe('fetchMyContacts', () => {
9599
2,
96100
'any',
97101
{
98-
app: getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
102+
app: getChainDefaultConfig(
103+
DEFAULT_CHAIN_ID
104+
).whitelistSmartContract.toLowerCase(),
99105
requester: userAddress,
100106
isAppStrict: true,
101107
isRequesterStrict: false,
@@ -142,7 +148,10 @@ describe('fetchMyContacts', () => {
142148
// @ts-expect-error No need for graphQLClient here
143149
graphQLClient: {},
144150
dappAddressOrENS: getChainDefaultConfig(DEFAULT_CHAIN_ID).dappAddress,
145-
dappWhitelistAddress: getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
151+
dappWhitelistAddress:
152+
getChainDefaultConfig(
153+
DEFAULT_CHAIN_ID
154+
).whitelistSmartContract.toLowerCase(),
146155
isUserStrict: true,
147156
});
148157
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
@@ -161,7 +170,9 @@ describe('fetchMyContacts', () => {
161170
2,
162171
'any',
163172
{
164-
app: getChainDefaultConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
173+
app: getChainDefaultConfig(
174+
DEFAULT_CHAIN_ID
175+
).whitelistSmartContract.toLowerCase(),
165176
requester: userAddress,
166177
isAppStrict: true,
167178
isRequesterStrict: true,

tests/unit/sendEmail.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { ValidationError } from 'yup';
33
import { type SendEmail } from '../../src/web3mail/sendEmail.js';
44
import { getRandomAddress, TEST_CHAIN } from '../test-utils.js';
55
import { mockAllForSendEmail } from '../utils/mockAllForSendEmail.js';
6-
import { DEFAULT_CHAIN_ID, getChainDefaultConfig } from '../../src/config/config.js';
6+
import {
7+
DEFAULT_CHAIN_ID,
8+
getChainDefaultConfig,
9+
} from '../../src/config/config.js';
710

811
jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
912
checkProtectedDataValidity: jest.fn(),
@@ -177,9 +180,13 @@ describe('sendEmail', () => {
177180
iexec,
178181
ipfsGateway: getChainDefaultConfig(DEFAULT_CHAIN_ID)?.ipfsGateway,
179182
ipfsNode: getChainDefaultConfig(DEFAULT_CHAIN_ID)?.ipfsUploadUrl,
180-
workerpoolAddressOrEns: getChainDefaultConfig(DEFAULT_CHAIN_ID)?.prodWorkerpoolAddress,
183+
workerpoolAddressOrEns:
184+
getChainDefaultConfig(DEFAULT_CHAIN_ID)?.prodWorkerpoolAddress,
181185
dappAddressOrENS: getChainDefaultConfig(DEFAULT_CHAIN_ID)?.dappAddress,
182-
dappWhitelistAddress: getChainDefaultConfig(DEFAULT_CHAIN_ID)?.whitelistSmartContract.toLowerCase(),
186+
dappWhitelistAddress:
187+
getChainDefaultConfig(
188+
DEFAULT_CHAIN_ID
189+
)?.whitelistSmartContract.toLowerCase(),
183190
emailSubject: 'e2e mail object for test',
184191
emailContent: OVERSIZED_CONTENT,
185192
protectedData,

0 commit comments

Comments
 (0)