Skip to content

Commit 629d7c3

Browse files
add allowDebug e2e tests
1 parent c293208 commit 629d7c3

File tree

4 files changed

+242
-10
lines changed

4 files changed

+242
-10
lines changed

packages/sdk/.drone.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,36 @@ steps:
226226
depends_on:
227227
- sms
228228

229+
- name: sms-debug
230+
image: iexechub/iexec-sms:7.1.0
231+
detach: true
232+
environment:
233+
TZ: Europe/Paris
234+
IEXEC_SMS_BLOCKCHAIN_NODE_ADDRESS: http://bellecour-fork:8545
235+
IEXEC_HUB_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f'
236+
IEXEC_TEE_WORKER_PRE_COMPUTE_IMAGE: docker.io/iexechub/tee-worker-pre-compute:7.1.0-sconify-5.3.15-debug
237+
IEXEC_TEE_WORKER_PRE_COMPUTE_FINGERPRINT: 9f0f782d6edc611baa23ca0978f555ee58ea70e092640c961e75c25e9e4b0f22
238+
IEXEC_TEE_WORKER_PRE_COMPUTE_HEAP_SIZE_GB: 4
239+
IEXEC_TEE_WORKER_POST_COMPUTE_IMAGE: docker.io/iexechub/tee-worker-post-compute:7.1.1-sconify-5.3.15-debug
240+
IEXEC_TEE_WORKER_POST_COMPUTE_FINGERPRINT: face1376b97131e2dc75a556381d47a2e03bed9e1bc11e462471f99d1eefae50
241+
IEXEC_TEE_WORKER_POST_COMPUTE_HEAP_SIZE_GB: 4
242+
IEXEC_IGNORED_SGX_ADVISORIES: INTEL-SA-00161,INTEL-SA-00289,INTEL-SA-00334,INTEL-SA-00381,INTEL-SA-00389,INTEL-SA-00220,INTEL-SA-00270,INTEL-SA-00293,INTEL-SA-00320,INTEL-SA-00329,INTEL-SA-00477
243+
IEXEC_SCONE_TOLERATED_INSECURE_OPTIONS: debug-mode,hyperthreading,outdated-tcb
244+
IEXEC_SMS_DISPLAY_DEBUG_SESSION: 'true'
245+
IEXEC_SCONE_CAS_HOST: foo
246+
IEXEC_SMS_IMAGE_LAS_IMAGE: foo
247+
expose:
248+
- 13300
249+
depends_on:
250+
- bellecour-fork-healthy
251+
252+
- name: sms-debug-healthy
253+
image: bash
254+
commands:
255+
- while ! nc -z sms-debug 13300 ; do sleep 1 ; done && echo "sms-debug ready"
256+
depends_on:
257+
- sms-debug
258+
229259
- name: result-proxy
230260
image: iexechub/iexec-result-proxy:7.1.0
231261
detach: true
@@ -329,6 +359,7 @@ steps:
329359
depends_on:
330360
- bellecour-fork-healthy
331361
- sms-healthy
362+
- sms-debug-healthy
332363
- result-proxy-healthy
333364
- market-api-healthy
334365
- ipfs-healthy

packages/sdk/tests/docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ services:
4040
bellecour-fork:
4141
condition: service_healthy
4242

43+
sms-debug:
44+
image: iexechub/iexec-sms:7.1.0
45+
restart: unless-stopped
46+
environment:
47+
TZ: Europe/Paris
48+
IEXEC_SMS_BLOCKCHAIN_NODE_ADDRESS: http://bellecour-fork:8545
49+
IEXEC_HUB_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f'
50+
IEXEC_TEE_WORKER_PRE_COMPUTE_IMAGE: docker.io/iexechub/tee-worker-pre-compute:7.1.0-sconify-5.3.15-debug
51+
IEXEC_TEE_WORKER_PRE_COMPUTE_FINGERPRINT: 9f0f782d6edc611baa23ca0978f555ee58ea70e092640c961e75c25e9e4b0f22
52+
IEXEC_TEE_WORKER_PRE_COMPUTE_HEAP_SIZE_GB: 4
53+
IEXEC_TEE_WORKER_POST_COMPUTE_IMAGE: docker.io/iexechub/tee-worker-post-compute:7.1.1-sconify-5.3.15-debug
54+
IEXEC_TEE_WORKER_POST_COMPUTE_FINGERPRINT: face1376b97131e2dc75a556381d47a2e03bed9e1bc11e462471f99d1eefae50
55+
IEXEC_TEE_WORKER_POST_COMPUTE_HEAP_SIZE_GB: 4
56+
IEXEC_IGNORED_SGX_ADVISORIES: INTEL-SA-00161,INTEL-SA-00289,INTEL-SA-00334,INTEL-SA-00381,INTEL-SA-00389,INTEL-SA-00220,INTEL-SA-00270,INTEL-SA-00293,INTEL-SA-00320,INTEL-SA-00329,INTEL-SA-00477
57+
IEXEC_SCONE_TOLERATED_INSECURE_OPTIONS: debug-mode,hyperthreading,outdated-tcb
58+
IEXEC_SMS_DISPLAY_DEBUG_SESSION: 'true'
59+
IEXEC_SCONE_CAS_HOST: foo
60+
IEXEC_SMS_IMAGE_LAS_IMAGE: foo
61+
ports:
62+
- 13301:13300
63+
depends_on:
64+
bellecour-fork:
65+
condition: service_healthy
66+
4367
result-proxy:
4468
image: iexechub/iexec-result-proxy:7.1.0
4569
restart: unless-stopped
@@ -226,6 +250,8 @@ services:
226250
condition: service_healthy
227251
sms:
228252
condition: service_started
253+
sms-debug:
254+
condition: service_started
229255
market-watcher:
230256
condition: service_started
231257
market-api:

packages/sdk/tests/e2e/dataProtectorCore/protectData.test.ts

Lines changed: 181 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import fsPromises from 'fs/promises';
22
import path from 'path';
33
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
44
import { HDNodeWallet, Wallet } from 'ethers';
5+
import { IExec } from 'iexec';
6+
import { SmsCallError } from 'iexec/errors';
57
import { IExecDataProtectorCore } from '../../../src/index.js';
68
import { ValidationError, WorkflowError } from '../../../src/utils/errors.js';
79
import {
810
MAX_EXPECTED_BLOCKTIME,
911
MAX_EXPECTED_WEB2_SERVICES_TIME,
1012
getTestConfig,
13+
getTestIExecOption,
14+
getTestRpcProvider,
1115
getTestWeb3SignerProvider,
1216
} from '../../test-utils.js';
13-
import { SmsCallError } from 'iexec/errors';
1417

1518
describe('dataProtectorCore.protectData()', () => {
1619
let dataProtectorCore: IExecDataProtectorCore;
@@ -26,7 +29,7 @@ describe('dataProtectorCore.protectData()', () => {
2629
'creates the protected data',
2730
async () => {
2831
// load some binary data
29-
await fsPromises.readFile(
32+
const pngImage = await fsPromises.readFile(
3033
path.join(process.cwd(), 'tests', '_test_inputs_', 'image.png')
3134
);
3235
const data = {
@@ -43,8 +46,7 @@ describe('dataProtectorCore.protectData()', () => {
4346
with: {
4447
binary: {
4548
data: {
46-
pngImage: 'placeholder',
47-
// pngImage, // commented as currently too large for IPFS upload
49+
pngImage,
4850
},
4951
},
5052
},
@@ -68,8 +70,7 @@ describe('dataProtectorCore.protectData()', () => {
6870
with: {
6971
binary: {
7072
data: {
71-
pngImage: 'string',
72-
// pngImage: '', // commented as currently too large for IPFS upload
73+
pngImage: 'image/png',
7374
},
7475
},
7576
},
@@ -89,17 +90,28 @@ describe('dataProtectorCore.protectData()', () => {
8990
expect(typeof result.transactionHash).toBe('string');
9091
expect(result.zipFile).toBeInstanceOf(Uint8Array);
9192
expect(typeof result.encryptionKey).toBe('string');
93+
94+
const ethProvider = getTestRpcProvider();
95+
const iexecOptions = getTestIExecOption();
96+
const iexecProd = new IExec({ ethProvider }, iexecOptions);
97+
const iexecDebug = new IExec(
98+
{ ethProvider },
99+
{ ...iexecOptions, smsURL: iexecOptions.smsDebugURL }
100+
);
101+
const prodSecretPushed = await iexecProd.dataset.checkDatasetSecretExists(
102+
result.address
103+
);
104+
const debugSecretPushed =
105+
await iexecDebug.dataset.checkDatasetSecretExists(result.address);
106+
expect(prodSecretPushed).toBe(true);
107+
expect(debugSecretPushed).toBe(false);
92108
},
93109
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
94110
);
95111

96112
it(
97113
'calls the onStatusUpdate() callback function at each step',
98114
async () => {
99-
// load some binary data
100-
await fsPromises.readFile(
101-
path.join(process.cwd(), 'tests', '_test_inputs_', 'image.png')
102-
);
103115
const data = {
104116
string: 'hello world!',
105117
};
@@ -201,6 +213,165 @@ describe('dataProtectorCore.protectData()', () => {
201213
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
202214
);
203215

216+
describe('when allowDebug = true', () => {
217+
it(
218+
'creates the protected data with secret pushed on both prod and debug SMS',
219+
async () => {
220+
const data = {
221+
string: 'hello world!',
222+
};
223+
const DATA_NAME = 'test do not use';
224+
225+
const result = await dataProtectorCore.protectData({
226+
data,
227+
name: DATA_NAME,
228+
allowDebug: true,
229+
});
230+
expect(result.name).toBe(DATA_NAME);
231+
expect(typeof result.address).toBe('string');
232+
expect(result.owner).toBe(wallet.address);
233+
expect(typeof result.creationTimestamp).toBe('number');
234+
expect(typeof result.transactionHash).toBe('string');
235+
expect(result.zipFile).toBeInstanceOf(Uint8Array);
236+
expect(typeof result.encryptionKey).toBe('string');
237+
238+
const ethProvider = getTestRpcProvider();
239+
const iexecOptions = getTestIExecOption();
240+
const iexecProd = new IExec({ ethProvider }, iexecOptions);
241+
const iexecDebug = new IExec(
242+
{ ethProvider },
243+
{ ...iexecOptions, smsURL: iexecOptions.smsDebugURL }
244+
);
245+
const prodSecretPushed =
246+
await iexecProd.dataset.checkDatasetSecretExists(result.address);
247+
const debugSecretPushed =
248+
await iexecDebug.dataset.checkDatasetSecretExists(result.address);
249+
expect(prodSecretPushed).toBe(true);
250+
expect(debugSecretPushed).toBe(true);
251+
},
252+
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
253+
);
254+
255+
it(
256+
'calls the onStatusUpdate() callback function at each step including PUSH_SECRET_TO_DEBUG_SMS',
257+
async () => {
258+
const data = {
259+
string: 'hello world!',
260+
};
261+
262+
const DATA_NAME = 'test do not use';
263+
264+
const onStatusUpdateMock = jest.fn();
265+
266+
await dataProtectorCore.protectData({
267+
data,
268+
name: DATA_NAME,
269+
allowDebug: true,
270+
onStatusUpdate: onStatusUpdateMock,
271+
});
272+
273+
expect(onStatusUpdateMock).toHaveBeenCalledTimes(16);
274+
275+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(1, {
276+
title: 'EXTRACT_DATA_SCHEMA',
277+
isDone: false,
278+
});
279+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(2, {
280+
title: 'EXTRACT_DATA_SCHEMA',
281+
isDone: true,
282+
});
283+
284+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(3, {
285+
title: 'CREATE_ZIP_FILE',
286+
isDone: false,
287+
});
288+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(4, {
289+
title: 'CREATE_ZIP_FILE',
290+
isDone: true,
291+
});
292+
293+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(5, {
294+
title: 'CREATE_ENCRYPTION_KEY',
295+
isDone: false,
296+
});
297+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(6, {
298+
title: 'CREATE_ENCRYPTION_KEY',
299+
isDone: true,
300+
payload: {
301+
encryptionKey: expect.any(String),
302+
},
303+
});
304+
305+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(7, {
306+
title: 'ENCRYPT_FILE',
307+
isDone: false,
308+
});
309+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(8, {
310+
title: 'ENCRYPT_FILE',
311+
isDone: true,
312+
});
313+
314+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(9, {
315+
title: 'UPLOAD_ENCRYPTED_FILE',
316+
isDone: false,
317+
});
318+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(10, {
319+
title: 'UPLOAD_ENCRYPTED_FILE',
320+
isDone: true,
321+
payload: {
322+
cid: expect.any(String),
323+
},
324+
});
325+
326+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(11, {
327+
title: 'DEPLOY_PROTECTED_DATA',
328+
isDone: false,
329+
});
330+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(12, {
331+
title: 'DEPLOY_PROTECTED_DATA',
332+
isDone: true,
333+
payload: {
334+
address: expect.any(String),
335+
explorerUrl: expect.any(String),
336+
owner: expect.any(String),
337+
creationTimestamp: expect.any(String),
338+
txHash: expect.any(String),
339+
},
340+
});
341+
342+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(13, {
343+
title: 'PUSH_SECRET_TO_SMS',
344+
isDone: false,
345+
payload: {
346+
teeFramework: expect.any(String),
347+
},
348+
});
349+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(14, {
350+
title: 'PUSH_SECRET_TO_SMS',
351+
isDone: true,
352+
payload: {
353+
teeFramework: expect.any(String),
354+
},
355+
});
356+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(15, {
357+
title: 'PUSH_SECRET_TO_DEBUG_SMS',
358+
isDone: false,
359+
payload: {
360+
teeFramework: expect.any(String),
361+
},
362+
});
363+
expect(onStatusUpdateMock).toHaveBeenNthCalledWith(16, {
364+
title: 'PUSH_SECRET_TO_DEBUG_SMS',
365+
isDone: true,
366+
payload: {
367+
teeFramework: expect.any(String),
368+
},
369+
});
370+
},
371+
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
372+
);
373+
});
374+
204375
it(
205376
'checks name is a string',
206377
async () => {

packages/sdk/tests/test-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const TEST_CHAIN = {
1313
rpcURL: DRONE ? 'http://bellecour-fork:8545' : 'http://localhost:8545',
1414
chainId: '134',
1515
smsURL: DRONE ? 'http://sms:13300' : 'http://127.0.0.1:13300',
16+
smsDebugURL: DRONE ? 'http://sms-debug:13300' : 'http://127.0.0.1:13301',
1617
resultProxyURL: DRONE
1718
? 'http://result-proxy:13200'
1819
: 'http://127.0.0.1:13200',
@@ -27,8 +28,11 @@ export const getTestWeb3SignerProvider = (
2728
): Web3SignerProvider =>
2829
utils.getSignerFromPrivateKey(TEST_CHAIN.rpcURL, privateKey);
2930

31+
export const getTestRpcProvider = () => new JsonRpcProvider(TEST_CHAIN.rpcURL);
32+
3033
export const getTestIExecOption = () => ({
3134
smsURL: TEST_CHAIN.smsURL,
35+
smsDebugURL: TEST_CHAIN.smsDebugURL,
3236
resultProxyURL: TEST_CHAIN.resultProxyURL,
3337
iexecGatewayURL: TEST_CHAIN.iexecGatewayURL,
3438
});

0 commit comments

Comments
 (0)