Skip to content

Commit 776e485

Browse files
fix unit tests
1 parent 6c0b33a commit 776e485

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

packages/sdk/tests/unit/constructor.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('IExecDataProtector()', () => {
1010
const dataProtector = new IExecDataProtector(
1111
getWeb3Provider(Wallet.createRandom().privateKey)
1212
);
13+
await dataProtector['init']();
1314
const ipfsNode = dataProtector['ipfsNode'];
1415
expect(ipfsNode).toStrictEqual(CHAIN_CONFIG['134'].ipfsNode);
1516
});
@@ -22,6 +23,7 @@ describe('IExecDataProtector()', () => {
2223
ipfsNode: customIpfsNode,
2324
}
2425
);
26+
await dataProtector['init']();
2527
const ipfsNode = dataProtector['ipfsNode'];
2628
expect(ipfsNode).toStrictEqual(customIpfsNode);
2729
});
@@ -30,6 +32,7 @@ describe('IExecDataProtector()', () => {
3032
const dataProtector = new IExecDataProtector(
3133
getWeb3Provider(Wallet.createRandom().privateKey)
3234
);
35+
await dataProtector['init']();
3336
const ipfsGateway = dataProtector['ipfsGateway'];
3437
expect(ipfsGateway).toStrictEqual(CHAIN_CONFIG['134'].ipfsGateway);
3538
});
@@ -42,6 +45,7 @@ describe('IExecDataProtector()', () => {
4245
ipfsGateway: customIpfsGateway,
4346
}
4447
);
48+
await dataProtector['init']();
4549
const ipfsGateway = dataProtector['ipfsGateway'];
4650
expect(ipfsGateway).toStrictEqual(customIpfsGateway);
4751
});
@@ -50,6 +54,7 @@ describe('IExecDataProtector()', () => {
5054
const dataProtector = new IExecDataProtector(
5155
getWeb3Provider(Wallet.createRandom().privateKey)
5256
);
57+
await dataProtector['init']();
5358
const dataprotectorContractAddress =
5459
dataProtector['dataprotectorContractAddress'];
5560
expect(dataprotectorContractAddress).toStrictEqual(
@@ -65,6 +70,7 @@ describe('IExecDataProtector()', () => {
6570
dataprotectorContractAddress: customSContractAddress,
6671
}
6772
);
73+
await dataProtector['init']();
6874
const dataprotectorContractAddress =
6975
dataProtector['dataprotectorContractAddress'];
7076
expect(dataprotectorContractAddress).toStrictEqual(
@@ -76,6 +82,7 @@ describe('IExecDataProtector()', () => {
7682
const dataProtector = new IExecDataProtector(
7783
getWeb3Provider(Wallet.createRandom().privateKey)
7884
);
85+
await dataProtector['init']();
7986
const graphQLClientUrl = dataProtector['graphQLClient'];
8087
expect(graphQLClientUrl['url']).toBe(CHAIN_CONFIG['134'].subgraphUrl);
8188
});
@@ -88,6 +95,7 @@ describe('IExecDataProtector()', () => {
8895
subgraphUrl: customSubgraphUrl,
8996
}
9097
);
98+
await dataProtector['init']();
9199
const graphQLClient = dataProtector['graphQLClient'];
92100
expect(graphQLClient['url']).toBe(customSubgraphUrl);
93101
});
@@ -99,6 +107,7 @@ describe('IExecDataProtector()', () => {
99107
const customIpfsNode = 'https://example.com/node';
100108
const smsURL = 'https://custom-sms-url.com';
101109
const iexecGatewayURL = 'https://custom-market-api-url.com';
110+
102111
const dataProtector = new IExecDataProtector(
103112
getWeb3Provider(Wallet.createRandom().privateKey),
104113
{
@@ -112,6 +121,8 @@ describe('IExecDataProtector()', () => {
112121
},
113122
}
114123
);
124+
await dataProtector['init']();
125+
115126
const graphQLClient = dataProtector['graphQLClient'];
116127
const ipfsNode = dataProtector['ipfsNode'];
117128
const ipfsGateway = dataProtector['ipfsGateway'];
@@ -129,12 +140,11 @@ describe('IExecDataProtector()', () => {
129140
expect(await iexec.config.resolveIexecGatewayURL()).toBe(iexecGatewayURL);
130141
}, 20_000);
131142

132-
it('throw when instantiated with an invalid ethProvider', async () => {
143+
it('throws when calling init() with an invalid ethProvider', async () => {
133144
const invalidProvider: any = {};
134-
expect(() => new IExecDataProtector(invalidProvider)).toThrow(
135-
Error(
136-
'Unsupported ethProvider, Invalid ethProvider: Unsupported provider'
137-
)
145+
const dataProtector = new IExecDataProtector(invalidProvider);
146+
await expect(dataProtector['init']()).rejects.toThrow(
147+
'Unsupported ethProvider: Invalid ethProvider: Unsupported provider'
138148
);
139149
});
140150

@@ -143,6 +153,7 @@ describe('IExecDataProtector()', () => {
143153
const dataProtector = new IExecDataProtector(
144154
getWeb3Provider(wallet.privateKey)
145155
);
156+
await dataProtector['init']();
146157
expect(dataProtector).toBeInstanceOf(IExecDataProtector);
147158
});
148159

@@ -157,22 +168,19 @@ describe('IExecDataProtector()', () => {
157168
},
158169
}
159170
);
171+
await dataProtector['init']();
160172
const iexec = dataProtector['iexec'];
161173
expect(await iexec.config.resolveSmsURL()).toBe(smsURL);
162174
});
163175

164176
describe('When instantiating SDK without a signer', () => {
165177
describe('When calling a write method', () => {
166178
it('should throw the corresponding exception', async () => {
167-
// --- GIVEN
168179
const dataProtector = new IExecDataProtector();
169-
170-
// ---- WHEN / THEN
180+
await dataProtector['init']();
171181
await expect(
172182
dataProtector.core.protectData({
173-
data: {
174-
175-
},
183+
data: { email: '[email protected]' },
176184
})
177185
).rejects.toThrow(
178186
'Unauthorized method. Please log in with your wallet, you must set a valid provider with a signer.'

0 commit comments

Comments
 (0)