Skip to content

Commit 8aeff30

Browse files
test: refactor tests to support multichain configuration
1 parent 4b2de3a commit 8aeff30

File tree

6 files changed

+55
-58
lines changed

6 files changed

+55
-58
lines changed

tests/e2e/constructor.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
// needed to access and assert IExecDataProtector's private properties
33
import { describe, expect, it } from '@jest/globals';
44
import { Wallet } from 'ethers';
5-
import {
6-
DATAPROTECTOR_SUBGRAPH_ENDPOINT,
7-
DEFAULT_IPFS_GATEWAY,
8-
} from '../../src/config/config.js';
95
import { IExecWeb3mail } from '../../src/index.js';
106
import {
117
getTestWeb3SignerProvider,
128
MAX_EXPECTED_WEB2_SERVICES_TIME,
139
} from '../test-utils.js';
10+
import { DEFAULT_CHAIN_ID, getChainConfig } from '../../src/config/config.js';
1411

1512
describe('IExecWeb3mail()', () => {
1613
it('instantiates with a valid ethProvider', async () => {
1714
const wallet = Wallet.createRandom();
1815
const web3mail = new IExecWeb3mail(
1916
getTestWeb3SignerProvider(wallet.privateKey)
2017
);
18+
await web3mail.init();
2119
expect(web3mail).toBeInstanceOf(IExecWeb3mail);
2220
});
2321

@@ -26,8 +24,9 @@ describe('IExecWeb3mail()', () => {
2624
const web3mail = new IExecWeb3mail(
2725
getTestWeb3SignerProvider(wallet.privateKey)
2826
);
27+
await web3mail.init();
2928
const ipfsGateway = web3mail['ipfsGateway'];
30-
expect(ipfsGateway).toStrictEqual(DEFAULT_IPFS_GATEWAY);
29+
expect(ipfsGateway).toStrictEqual(getChainConfig(DEFAULT_CHAIN_ID).ipfsGateway);
3130
});
3231

3332
it('should use provided ipfs gateway url when ipfsGateway is provided', async () => {
@@ -39,6 +38,7 @@ describe('IExecWeb3mail()', () => {
3938
ipfsGateway: customIpfsGateway,
4039
}
4140
);
41+
await web3mail.init();
4242
const ipfsGateway = web3mail['ipfsGateway'];
4343
expect(ipfsGateway).toStrictEqual(customIpfsGateway);
4444
});
@@ -48,8 +48,10 @@ describe('IExecWeb3mail()', () => {
4848
const web3mail = new IExecWeb3mail(
4949
getTestWeb3SignerProvider(wallet.privateKey)
5050
);
51+
await web3mail.init();
5152
const graphQLClientUrl = web3mail['graphQLClient'];
52-
expect(graphQLClientUrl['url']).toBe(DATAPROTECTOR_SUBGRAPH_ENDPOINT);
53+
expect(graphQLClientUrl['url']).toBe(
54+
getChainConfig(DEFAULT_CHAIN_ID).dataProtectorSubgraph);
5355
});
5456

5557
it('should use provided data Protector Subgraph URL when subgraphUrl is provided', async () => {
@@ -61,6 +63,7 @@ describe('IExecWeb3mail()', () => {
6163
dataProtectorSubgraph: customSubgraphUrl,
6264
}
6365
);
66+
await web3mail.init();
6467
const graphQLClient = web3mail['graphQLClient'];
6568
expect(graphQLClient['url']).toBe(customSubgraphUrl);
6669
});
@@ -89,6 +92,7 @@ describe('IExecWeb3mail()', () => {
8992
dappWhitelistAddress: customDappWhitelistAddress,
9093
}
9194
);
95+
await web3mail.init();
9296
const graphQLClient = web3mail['graphQLClient'];
9397
const ipfsNode = web3mail['ipfsNode'];
9498
const ipfsGateway = web3mail['ipfsGateway'];
@@ -100,7 +104,7 @@ describe('IExecWeb3mail()', () => {
100104
expect(ipfsNode).toStrictEqual(customIpfsNode);
101105
expect(ipfsGateway).toStrictEqual(customIpfsGateway);
102106
expect(dappAddressOrENS).toStrictEqual(customDapp);
103-
expect(whitelistAddress).toStrictEqual(customDappWhitelistAddress);
107+
expect(whitelistAddress).toStrictEqual(customDappWhitelistAddress.toLowerCase());
104108
expect(await iexec.config.resolveSmsURL()).toBe(smsURL);
105109
expect(await iexec.config.resolveIexecGatewayURL()).toBe(iexecGatewayURL);
106110
});
@@ -110,6 +114,7 @@ describe('IExecWeb3mail()', () => {
110114
async () => {
111115
// --- GIVEN
112116
const web3mail = new IExecWeb3mail();
117+
await web3mail.init();
113118
const wallet = Wallet.createRandom();
114119

115120
// --- WHEN/THEN

tests/e2e/fetchMyContacts.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
import { beforeAll, describe, expect, it } from '@jest/globals';
66
import { HDNodeWallet, Wallet } from 'ethers';
77
import { NULL_ADDRESS } from 'iexec/utils';
8-
import { WEB3_MAIL_DAPP_ADDRESS } from '../../src/config/config.js';
98
import { IExecWeb3mail } from '../../src/index.js';
109
import {
1110
MAX_EXPECTED_BLOCKTIME,
@@ -17,6 +16,7 @@ import {
1716
waitSubgraphIndexing,
1817
} from '../test-utils.js';
1918
import IExec from 'iexec/IExec';
19+
import { DEFAULT_CHAIN_ID, getChainConfig } from '../../src/config/config.js';
2020

2121
describe('web3mail.fetchMyContacts()', () => {
2222
let wallet: HDNodeWallet;
@@ -41,7 +41,7 @@ describe('web3mail.fetchMyContacts()', () => {
4141
'pass with a granted access for a specific requester',
4242
async () => {
4343
await dataProtector.grantAccess({
44-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
44+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
4545
protectedData: protectedData.address,
4646
authorizedUser: wallet.address,
4747
});
@@ -51,11 +51,11 @@ describe('web3mail.fetchMyContacts()', () => {
5151
});
5252
expect(
5353
foundContactForASpecificRequester &&
54-
foundContactForASpecificRequester.address
54+
foundContactForASpecificRequester.address
5555
).toBeDefined();
5656
expect(
5757
foundContactForASpecificRequester &&
58-
foundContactForASpecificRequester.address
58+
foundContactForASpecificRequester.address
5959
).toBe(protectedData.address.toLocaleLowerCase());
6060
},
6161
MAX_EXPECTED_WEB2_SERVICES_TIME
@@ -65,7 +65,7 @@ describe('web3mail.fetchMyContacts()', () => {
6565
'pass with a granted access for any requester',
6666
async () => {
6767
const grantedAccessForAnyRequester = await dataProtector.grantAccess({
68-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
68+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
6969
protectedData: protectedData.address,
7070
authorizedUser: NULL_ADDRESS,
7171
});
@@ -104,7 +104,7 @@ describe('web3mail.fetchMyContacts()', () => {
104104
const encryptionKey = await iexec.dataset.generateEncryptionKey();
105105
await iexec.dataset.pushDatasetSecret(dataset.address, encryptionKey);
106106
await dataProtector.grantAccess({
107-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
107+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
108108
protectedData: dataset.address,
109109
authorizedUser: wallet.address,
110110
});
@@ -126,7 +126,7 @@ describe('web3mail.fetchMyContacts()', () => {
126126
await waitSubgraphIndexing();
127127

128128
await dataProtector.grantAccess({
129-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
129+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
130130
protectedData: notValidProtectedData.address,
131131
authorizedUser: wallet.address,
132132
});

tests/e2e/fetchUserContacts.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '@iexec/dataprotector';
55
import { beforeAll, describe, expect, it } from '@jest/globals';
66
import { HDNodeWallet, Wallet } from 'ethers';
7-
import { WEB3_MAIL_DAPP_ADDRESS } from '../../src/config/config.js';
7+
import { DEFAULT_CHAIN_ID, getChainConfig } from '../../src/config/config.js';
88
import { IExecWeb3mail, WorkflowError } from '../../src/index.js';
99
import {
1010
MAX_EXPECTED_BLOCKTIME,
@@ -45,13 +45,13 @@ describe('web3mail.fetchMyContacts()', () => {
4545
const user1 = Wallet.createRandom().address;
4646
const user2 = Wallet.createRandom().address;
4747
await dataProtector.grantAccess({
48-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
48+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
4949
protectedData: protectedData1.address,
5050
authorizedUser: user1,
5151
});
5252

5353
await dataProtector.grantAccess({
54-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
54+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
5555
protectedData: protectedData2.address,
5656
authorizedUser: user2,
5757
});
@@ -71,12 +71,12 @@ describe('web3mail.fetchMyContacts()', () => {
7171
'Test that the protected data can be accessed by authorized user',
7272
async () => {
7373
const userWithAccess = Wallet.createRandom().address;
74-
await dataProtector.grantAccess({
75-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
74+
const res = await dataProtector.grantAccess({
75+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
7676
protectedData: protectedData1.address,
7777
authorizedUser: userWithAccess,
7878
});
79-
79+
console.log("res", res);
8080
const contacts = await web3mail.fetchUserContacts({
8181
userAddress: userWithAccess,
8282
});

tests/e2e/sendEmail.test.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import {
44
} from '@iexec/dataprotector';
55
import { beforeAll, describe, expect, it } from '@jest/globals';
66
import { HDNodeWallet } from 'ethers';
7-
import {
8-
WEB3_MAIL_DAPP_ADDRESS,
9-
WHITELIST_SMART_CONTRACT_ADDRESS,
10-
} from '../../src/config/config.js';
117
import { IExecWeb3mail, WorkflowError } from '../../src/index.js';
128
import {
139
MAX_EXPECTED_BLOCKTIME,
@@ -28,6 +24,7 @@ import {
2824
} from '../test-utils.js';
2925
import { IExec } from 'iexec';
3026
import { NULL_ADDRESS } from 'iexec/utils';
27+
import { DEFAULT_CHAIN_ID, getChainConfig } from '../../src/config/config.js';
3128

3229
describe('web3mail.sendEmail()', () => {
3330
let consumerWallet: HDNodeWallet;
@@ -65,7 +62,7 @@ describe('web3mail.sendEmail()', () => {
6562
TEST_CHAIN.appOwnerWallet.privateKey
6663
);
6764
const resourceProvider = new IExec({ ethProvider }, iexecOptions);
68-
await createAndPublishAppOrders(resourceProvider, WEB3_MAIL_DAPP_ADDRESS);
65+
await createAndPublishAppOrders(resourceProvider, getChainConfig(DEFAULT_CHAIN_ID).dappAddress);
6966

7067
learnProdWorkerpoolAddress = await resourceProvider.ens.resolveName(
7168
TEST_CHAIN.learnProdWorkerpool
@@ -101,7 +98,7 @@ describe('web3mail.sendEmail()', () => {
10198
iexecOptions
10299
);
103100
await dataProtector.grantAccess({
104-
authorizedApp: WEB3_MAIL_DAPP_ADDRESS,
101+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
105102
protectedData: validProtectedData.address,
106103
authorizedUser: consumerWallet.address, // consumer wallet
107104
numberOfAccess: 1000,
@@ -286,7 +283,7 @@ describe('web3mail.sendEmail()', () => {
286283

287284
//grant access to whitelist
288285
await dataProtector.grantAccess({
289-
authorizedApp: WHITELIST_SMART_CONTRACT_ADDRESS, //whitelist address
286+
authorizedApp: getChainConfig(DEFAULT_CHAIN_ID).whitelistSmartContract, //whitelist address
290287
protectedData: protectedDataForWhitelist.address,
291288
authorizedUser: consumerWallet.address, // consumer wallet
292289
numberOfAccess: 1000,
@@ -455,8 +452,8 @@ describe('web3mail.sendEmail()', () => {
455452
expect(sendEmailResponse.taskId).toBeDefined();
456453
},
457454
2 * MAX_EXPECTED_BLOCKTIME +
458-
MAX_EXPECTED_WEB2_SERVICES_TIME +
459-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
455+
MAX_EXPECTED_WEB2_SERVICES_TIME +
456+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
460457
);
461458
});
462459

@@ -513,8 +510,8 @@ describe('web3mail.sendEmail()', () => {
513510
);
514511
},
515512
2 * MAX_EXPECTED_BLOCKTIME +
516-
MAX_EXPECTED_WEB2_SERVICES_TIME +
517-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
513+
MAX_EXPECTED_WEB2_SERVICES_TIME +
514+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
518515
);
519516
it(
520517
'should create task if user approves the non sponsored amount',
@@ -565,8 +562,8 @@ describe('web3mail.sendEmail()', () => {
565562
expect(sendEmailResponse.taskId).toBeDefined();
566563
},
567564
2 * MAX_EXPECTED_BLOCKTIME +
568-
MAX_EXPECTED_WEB2_SERVICES_TIME +
569-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
565+
MAX_EXPECTED_WEB2_SERVICES_TIME +
566+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
570567
);
571568
});
572569
describe('and workerpoolMaxPrice does NOT covers the non sponsored amount', () => {
@@ -619,8 +616,8 @@ describe('web3mail.sendEmail()', () => {
619616
);
620617
},
621618
2 * MAX_EXPECTED_BLOCKTIME +
622-
MAX_EXPECTED_WEB2_SERVICES_TIME +
623-
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
619+
MAX_EXPECTED_WEB2_SERVICES_TIME +
620+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME
624621
);
625622
});
626623
});

tests/unit/fetchMyContacts.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { describe, expect, it, jest } from '@jest/globals';
22
import { Address } from 'iexec';
3-
import {
4-
WEB3_MAIL_DAPP_ADDRESS,
5-
WHITELIST_SMART_CONTRACT_ADDRESS,
6-
} from '../../src/config/config.js';
73
import { type FetchMyContacts } from '../../src/web3mail/fetchMyContacts.js';
84
import { getRandomAddress } from '../test-utils.js';
5+
import { DEFAULT_CHAIN_ID, getChainConfig } from '../../src/config/config.js';
96

107
jest.unstable_mockModule('../../src/utils/subgraphQuery.js', () => ({
118
getValidContact: jest.fn(),
@@ -78,15 +75,16 @@ describe('fetchMyContacts', () => {
7875
iexec: iexec,
7976
// @ts-expect-error No need for graphQLClient here
8077
graphQLClient: {},
81-
dappAddressOrENS: WEB3_MAIL_DAPP_ADDRESS,
82-
dappWhitelistAddress: WHITELIST_SMART_CONTRACT_ADDRESS,
78+
dappAddressOrENS: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
79+
dappWhitelistAddress: getChainConfig(DEFAULT_CHAIN_ID).whitelistSmartContract,
80+
isUserStrict: false,
8381
});
8482
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
8583
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
8684
1,
8785
'any',
8886
{
89-
app: WEB3_MAIL_DAPP_ADDRESS,
87+
app: getChainConfig(DEFAULT_CHAIN_ID).dappAddress.toLowerCase(),
9088
requester: userAddress,
9189
isAppStrict: true,
9290
isRequesterStrict: false,
@@ -97,7 +95,7 @@ describe('fetchMyContacts', () => {
9795
2,
9896
'any',
9997
{
100-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
98+
app: getChainConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
10199
requester: userAddress,
102100
isAppStrict: true,
103101
isRequesterStrict: false,
@@ -143,16 +141,16 @@ describe('fetchMyContacts', () => {
143141
iexec: iexec,
144142
// @ts-expect-error No need for graphQLClient here
145143
graphQLClient: {},
146-
dappAddressOrENS: WEB3_MAIL_DAPP_ADDRESS,
147-
dappWhitelistAddress: WHITELIST_SMART_CONTRACT_ADDRESS,
144+
dappAddressOrENS: getChainConfig(DEFAULT_CHAIN_ID).dappAddress,
145+
dappWhitelistAddress: getChainConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
148146
isUserStrict: true,
149147
});
150148
const userAddress = (await iexec.wallet.getAddress()).toLowerCase();
151149
expect(iexec.orderbook.fetchDatasetOrderbook).toHaveBeenNthCalledWith(
152150
1,
153151
'any',
154152
{
155-
app: WEB3_MAIL_DAPP_ADDRESS,
153+
app: getChainConfig(DEFAULT_CHAIN_ID).dappAddress.toLowerCase(),
156154
requester: userAddress,
157155
isAppStrict: true,
158156
isRequesterStrict: true,
@@ -163,7 +161,7 @@ describe('fetchMyContacts', () => {
163161
2,
164162
'any',
165163
{
166-
app: WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase(),
164+
app: getChainConfig(DEFAULT_CHAIN_ID).whitelistSmartContract.toLowerCase(),
167165
requester: userAddress,
168166
isAppStrict: true,
169167
isRequesterStrict: true,

0 commit comments

Comments
 (0)