Skip to content

Commit 9703458

Browse files
test(unit): update unit tests for multichain config and mocks
1 parent 9622976 commit 9703458

File tree

2 files changed

+64
-56
lines changed

2 files changed

+64
-56
lines changed

tests/unit/fetchMyContacts.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { describe, expect, it, jest } from '@jest/globals';
22
import { Address } from 'iexec';
3-
import {
4-
WEB3TELEGRAM_DAPP_ADDRESS,
5-
WHITELIST_SMART_CONTRACT_ADDRESS,
6-
} from '../../src/config/config.js';
3+
import { CHAIN_CONFIG, CHAIN_IDS } from '../../src/config/config.js';
74
import { type FetchMyContacts } from '../../src/web3telegram/fetchMyContacts.js';
85
import { getRandomAddress } from '../test-utils.js';
96

@@ -78,15 +75,15 @@ describe('fetchMyContacts', () => {
7875
iexec: iexec,
7976
// @ts-expect-error No need for graphQLClient here
8077
graphQLClient: {},
81-
dappAddressOrENS: WEB3TELEGRAM_DAPP_ADDRESS,
82-
dappWhitelistAddress: WHITELIST_SMART_CONTRACT_ADDRESS,
78+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
79+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
8380
});
8481
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
8582
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
8683
1,
8784
'any',
8885
{
89-
app: WEB3TELEGRAM_DAPP_ADDRESS.toLowerCase(),
86+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
9087
requester: userAddress,
9188
isAppStrict: true,
9289
isRequesterStrict: false,
@@ -97,7 +94,7 @@ describe('fetchMyContacts', () => {
9794
2,
9895
'any',
9996
{
100-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
97+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
10198
requester: userAddress,
10299
isAppStrict: true,
103100
isRequesterStrict: false,
@@ -143,16 +140,16 @@ describe('fetchMyContacts', () => {
143140
iexec: iexec,
144141
// @ts-expect-error No need for graphQLClient here
145142
graphQLClient: {},
146-
dappAddressOrENS: WEB3TELEGRAM_DAPP_ADDRESS,
147-
dappWhitelistAddress: WHITELIST_SMART_CONTRACT_ADDRESS,
143+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
144+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
148145
isUserStrict: true,
149146
});
150147
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
151148
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
152149
1,
153150
'any',
154151
{
155-
app: WEB3TELEGRAM_DAPP_ADDRESS.toLowerCase(),
152+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
156153
requester: userAddress,
157154
isAppStrict: true,
158155
isRequesterStrict: true,
@@ -163,7 +160,7 @@ describe('fetchMyContacts', () => {
163160
2,
164161
'any',
165162
{
166-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
163+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
167164
requester: userAddress,
168165
isAppStrict: true,
169166
isRequesterStrict: true,

tests/unit/sendTelegram.test.ts

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { expect, it, jest } from '@jest/globals';
22
import { type SendTelegram } from '../../src/web3telegram/sendTelegram.js';
3-
import { getRandomAddress, TEST_CHAIN } from '../test-utils.js';
4-
import {
5-
WEB3TELEGRAM_DAPP_ADDRESS,
6-
WHITELIST_SMART_CONTRACT_ADDRESS,
7-
} from '../../src/config/config.js';
3+
import { getRandomAddress } from '../test-utils.js';
4+
import { CHAIN_CONFIG, CHAIN_IDS } from '../../src/config/config.js';
85
import { mockAllForSendTelegram } from '../utils/mockAllForSendTelegram.js';
96

107
jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
118
checkProtectedDataValidity: jest.fn(),
129
}));
1310

11+
jest.unstable_mockModule('../../src/utils/ipfs-service.js', () => ({
12+
add: jest.fn(() => Promise.resolve('QmSBoN71925mWJ6acehqDLQrrxihxX55EXrqHxpYja4HCG')),
13+
get: jest.fn(() => Promise.resolve(new ArrayBuffer(8))),
14+
}));
15+
1416
describe('sendTelegram', () => {
1517
let testedModule: any;
1618
let sendTelegram: SendTelegram;
@@ -33,10 +35,13 @@ describe('sendTelegram', () => {
3335

3436
await expect(
3537
sendTelegram({
36-
// @ts-expect-error No need for graphQLClient here
37-
graphQLClient: {},
38-
// @ts-expect-error No need for iexec here
39-
iexec: {},
38+
graphQLClient: { request: jest.fn() } as any,
39+
iexec: mockAllForSendTelegram() as any,
40+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
41+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
42+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
43+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
44+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
4045
senderName: 'AB', // Trop court, déclenche l'erreur Yup
4146
...sendTelegramParams,
4247
})
@@ -63,10 +68,13 @@ describe('sendTelegram', () => {
6368

6469
await expect(
6570
sendTelegram({
66-
// @ts-expect-error No need for graphQLClient here
67-
graphQLClient: {},
68-
// @ts-expect-error No need for iexec here
69-
iexec: {},
71+
graphQLClient: { request: jest.fn() } as any,
72+
iexec: mockAllForSendTelegram() as any,
73+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
74+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
75+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
76+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
77+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
7078
senderName: 'AB', // Trop court, déclenche l'erreur Yup
7179
...sendTelegramParams,
7280
})
@@ -93,10 +101,13 @@ describe('sendTelegram', () => {
93101

94102
await expect(
95103
sendTelegram({
96-
// @ts-expect-error No need for graphQLClient here
97-
graphQLClient: {},
98-
// @ts-expect-error No need for iexec here
99-
iexec: {},
104+
graphQLClient: { request: jest.fn() } as any,
105+
iexec: mockAllForSendTelegram() as any,
106+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
107+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
108+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
109+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
110+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
100111
...sendTelegramParams,
101112
})
102113
).rejects.toMatchObject({
@@ -121,15 +132,16 @@ describe('sendTelegram', () => {
121132
};
122133

123134
await expect(
124-
// --- WHEN
125135
sendTelegram({
126-
// @ts-expect-error No need for graphQLClient here
127-
graphQLClient: {},
128-
// @ts-expect-error No need for iexec here
129-
iexec: {},
136+
graphQLClient: { request: jest.fn() } as any,
137+
iexec: mockAllForSendTelegram() as any,
138+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
139+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
140+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
141+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
142+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
130143
...sendTelegramParams,
131144
})
132-
// --- THEN
133145
).rejects.toMatchObject({
134146
message: 'Failed to sendTelegram',
135147
cause: expect.objectContaining({
@@ -154,15 +166,16 @@ describe('sendTelegram', () => {
154166
};
155167

156168
await expect(
157-
// --- WHEN
158169
sendTelegram({
159-
// @ts-expect-error No need for graphQLClient here
160-
graphQLClient: {},
161-
// @ts-expect-error No need for iexec here
162-
iexec: {},
170+
graphQLClient: { request: jest.fn() } as any,
171+
iexec: mockAllForSendTelegram() as any,
172+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
173+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
174+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
175+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
176+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
163177
...sendTelegramParams,
164178
})
165-
// --- THEN
166179
).rejects.toMatchObject({
167180
message: 'Failed to sendTelegram',
168181
cause: expect.objectContaining({
@@ -187,21 +200,19 @@ describe('sendTelegram', () => {
187200
checkProtectedDataValidity.mockResolvedValue(true);
188201

189202
const protectedData = getRandomAddress().toLowerCase();
190-
const iexec = mockAllForSendTelegram();
203+
const iexec = mockAllForSendTelegram() as any;
191204

192205
const userAddress = await iexec.wallet.getAddress();
193206

194207
// --- WHEN
195208
await sendTelegram({
196-
// @ts-expect-error No need for graphQLClient here
197-
graphQLClient: {},
198-
// @ts-expect-error No need for iexec here
209+
graphQLClient: { request: jest.fn() } as any,
199210
iexec,
200-
// // @ts-expect-error No need
201-
// ipfsNode: "",
202-
// ipfsGateway: this.ipfsGateway,
203-
dappAddressOrENS: WEB3TELEGRAM_DAPP_ADDRESS,
204-
dappWhitelistAddress: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
211+
workerpoolAddressOrEns: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
212+
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
213+
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
214+
ipfsNode: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsUploadUrl,
215+
ipfsGateway: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].ipfsGateway,
205216
telegramContent: 'e2e telegram content for test',
206217
protectedData,
207218
});
@@ -211,8 +222,8 @@ describe('sendTelegram', () => {
211222
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
212223
1,
213224
{
214-
workerpool: TEST_CHAIN.prodWorkerpool,
215-
app: WEB3TELEGRAM_DAPP_ADDRESS.toLowerCase(),
225+
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
226+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
216227
dataset: protectedData,
217228
requester: userAddress,
218229
isRequesterStrict: false,
@@ -224,8 +235,8 @@ describe('sendTelegram', () => {
224235
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
225236
2,
226237
{
227-
workerpool: TEST_CHAIN.prodWorkerpool,
228-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
238+
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
239+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
229240
dataset: protectedData,
230241
requester: userAddress,
231242
isRequesterStrict: false,
@@ -237,8 +248,8 @@ describe('sendTelegram', () => {
237248
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
238249
2,
239250
{
240-
workerpool: TEST_CHAIN.prodWorkerpool,
241-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
251+
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
252+
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
242253
dataset: protectedData,
243254
requester: userAddress,
244255
isRequesterStrict: false,

0 commit comments

Comments
 (0)