Skip to content

Commit a252580

Browse files
test: update unit tests to use new chain configuration
1 parent 1da68d3 commit a252580

File tree

2 files changed

+57
-47
lines changed

2 files changed

+57
-47
lines changed

tests/unit/fetchMyContacts.test.ts

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

@@ -11,6 +14,7 @@ jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
1114
describe('fetchMyContacts', () => {
1215
let testedModule: any;
1316
let fetchMyContacts: FetchMyContacts;
17+
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
1418

1519
beforeAll(async () => {
1620
// import tested module after all mocked modules
@@ -75,15 +79,15 @@ describe('fetchMyContacts', () => {
7579
iexec: iexec,
7680
// @ts-expect-error No need for graphQLClient here
7781
graphQLClient: {},
78-
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
79-
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
82+
dappAddressOrENS: defaultConfig.dappAddress,
83+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
8084
});
8185
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
8286
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
8387
1,
8488
'any',
8589
{
86-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
90+
app: defaultConfig.dappAddress.toLowerCase(),
8791
requester: userAddress,
8892
isAppStrict: true,
8993
isRequesterStrict: false,
@@ -94,7 +98,7 @@ describe('fetchMyContacts', () => {
9498
2,
9599
'any',
96100
{
97-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
101+
app: defaultConfig.whitelistSmartContract.toLowerCase(),
98102
requester: userAddress,
99103
isAppStrict: true,
100104
isRequesterStrict: false,
@@ -140,16 +144,16 @@ describe('fetchMyContacts', () => {
140144
iexec: iexec,
141145
// @ts-expect-error No need for graphQLClient here
142146
graphQLClient: {},
143-
dappAddressOrENS: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress,
144-
dappWhitelistAddress: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract,
147+
dappAddressOrENS: defaultConfig.dappAddress,
148+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
145149
isUserStrict: true,
146150
});
147151
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
148152
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
149153
1,
150154
'any',
151155
{
152-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
156+
app: defaultConfig.dappAddress.toLowerCase(),
153157
requester: userAddress,
154158
isAppStrict: true,
155159
isRequesterStrict: true,
@@ -160,7 +164,7 @@ describe('fetchMyContacts', () => {
160164
2,
161165
'any',
162166
{
163-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
167+
app: defaultConfig.whitelistSmartContract.toLowerCase(),
164168
requester: userAddress,
165169
isAppStrict: true,
166170
isRequesterStrict: true,

tests/unit/sendTelegram.test.ts

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { expect, it, jest } from '@jest/globals';
22
import { type SendTelegram } from '../../src/web3telegram/sendTelegram.js';
33
import { getRandomAddress } from '../test-utils.js';
4-
import { CHAIN_CONFIG, CHAIN_IDS } from '../../src/config/config.js';
4+
import {
5+
DEFAULT_CHAIN_ID,
6+
getChainDefaultConfig,
7+
} from '../../src/config/config.js';
58
import { mockAllForSendTelegram } from '../utils/mockAllForSendTelegram.js';
69

710
jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
811
checkProtectedDataValidity: jest.fn(),
912
}));
1013

1114
jest.unstable_mockModule('../../src/utils/ipfs-service.js', () => ({
12-
add: jest.fn(() => Promise.resolve('QmSBoN71925mWJ6acehqDLQrrxihxX55EXrqHxpYja4HCG')),
15+
add: jest.fn(() =>
16+
Promise.resolve('QmSBoN71925mWJ6acehqDLQrrxihxX55EXrqHxpYja4HCG')
17+
),
1318
get: jest.fn(() => Promise.resolve(new ArrayBuffer(8))),
1419
}));
1520

1621
describe('sendTelegram', () => {
1722
let testedModule: any;
1823
let sendTelegram: SendTelegram;
24+
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
1925

2026
beforeAll(async () => {
2127
// import tested module after all mocked modules
@@ -37,11 +43,11 @@ describe('sendTelegram', () => {
3743
sendTelegram({
3844
graphQLClient: { request: jest.fn() } as any,
3945
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,
46+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
47+
dappAddressOrENS: defaultConfig.dappAddress,
48+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
49+
ipfsNode: defaultConfig.ipfsUploadUrl,
50+
ipfsGateway: defaultConfig.ipfsGateway,
4551
senderName: 'AB', // Trop court, déclenche l'erreur Yup
4652
...sendTelegramParams,
4753
})
@@ -70,11 +76,11 @@ describe('sendTelegram', () => {
7076
sendTelegram({
7177
graphQLClient: { request: jest.fn() } as any,
7278
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,
79+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
80+
dappAddressOrENS: defaultConfig.dappAddress,
81+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
82+
ipfsNode: defaultConfig.ipfsUploadUrl,
83+
ipfsGateway: defaultConfig.ipfsGateway,
7884
senderName: 'AB', // Trop court, déclenche l'erreur Yup
7985
...sendTelegramParams,
8086
})
@@ -103,11 +109,11 @@ describe('sendTelegram', () => {
103109
sendTelegram({
104110
graphQLClient: { request: jest.fn() } as any,
105111
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,
112+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
113+
dappAddressOrENS: defaultConfig.dappAddress,
114+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
115+
ipfsNode: defaultConfig.ipfsUploadUrl,
116+
ipfsGateway: defaultConfig.ipfsGateway,
111117
...sendTelegramParams,
112118
})
113119
).rejects.toMatchObject({
@@ -135,11 +141,11 @@ describe('sendTelegram', () => {
135141
sendTelegram({
136142
graphQLClient: { request: jest.fn() } as any,
137143
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,
144+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
145+
dappAddressOrENS: defaultConfig.dappAddress,
146+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
147+
ipfsNode: defaultConfig.ipfsUploadUrl,
148+
ipfsGateway: defaultConfig.ipfsGateway,
143149
...sendTelegramParams,
144150
})
145151
).rejects.toMatchObject({
@@ -169,11 +175,11 @@ describe('sendTelegram', () => {
169175
sendTelegram({
170176
graphQLClient: { request: jest.fn() } as any,
171177
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,
178+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
179+
dappAddressOrENS: defaultConfig.dappAddress,
180+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
181+
ipfsNode: defaultConfig.ipfsUploadUrl,
182+
ipfsGateway: defaultConfig.ipfsGateway,
177183
...sendTelegramParams,
178184
})
179185
).rejects.toMatchObject({
@@ -208,11 +214,11 @@ describe('sendTelegram', () => {
208214
await sendTelegram({
209215
graphQLClient: { request: jest.fn() } as any,
210216
iexec,
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,
217+
workerpoolAddressOrEns: defaultConfig.prodWorkerpoolAddress,
218+
dappAddressOrENS: defaultConfig.dappAddress,
219+
dappWhitelistAddress: defaultConfig.whitelistSmartContract,
220+
ipfsNode: defaultConfig.ipfsUploadUrl,
221+
ipfsGateway: defaultConfig.ipfsGateway,
216222
telegramContent: 'e2e telegram content for test',
217223
protectedData,
218224
});
@@ -222,8 +228,8 @@ describe('sendTelegram', () => {
222228
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
223229
1,
224230
{
225-
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
226-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].dappAddress.toLowerCase(),
231+
workerpool: defaultConfig.prodWorkerpoolAddress,
232+
app: defaultConfig.dappAddress.toLowerCase(),
227233
dataset: protectedData,
228234
requester: userAddress,
229235
isRequesterStrict: false,
@@ -235,8 +241,8 @@ describe('sendTelegram', () => {
235241
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
236242
2,
237243
{
238-
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
239-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
244+
workerpool: defaultConfig.prodWorkerpoolAddress,
245+
app: defaultConfig.whitelistSmartContract.toLowerCase(),
240246
dataset: protectedData,
241247
requester: userAddress,
242248
isRequesterStrict: false,
@@ -248,8 +254,8 @@ describe('sendTelegram', () => {
248254
expect(iexec.orderbook.fetchWorkerpoolOrderbook).toHaveBeenNthCalledWith(
249255
2,
250256
{
251-
workerpool: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].prodWorkerpoolAddress,
252-
app: CHAIN_CONFIG[CHAIN_IDS.BELLECOUR].whitelistSmartContract.toLowerCase(),
257+
workerpool: defaultConfig.prodWorkerpoolAddress,
258+
app: defaultConfig.whitelistSmartContract.toLowerCase(),
253259
dataset: protectedData,
254260
requester: userAddress,
255261
isRequesterStrict: false,

0 commit comments

Comments
 (0)