@@ -2,15 +2,18 @@ import fsPromises from 'fs/promises';
22import path from 'path' ;
33import { beforeEach , describe , expect , it , jest } from '@jest/globals' ;
44import { HDNodeWallet , Wallet } from 'ethers' ;
5+ import { IExec } from 'iexec' ;
6+ import { SmsCallError } from 'iexec/errors' ;
57import { IExecDataProtectorCore } from '../../../src/index.js' ;
68import { ValidationError , WorkflowError } from '../../../src/utils/errors.js' ;
79import {
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
1518describe ( '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 ( ) => {
0 commit comments