@@ -163,8 +163,8 @@ impl PreComputeAppTrait for PreComputeApp {
163
163
/// ```
164
164
fn download_encrypted_dataset ( & self ) -> Result < Vec < u8 > , ReplicateStatusCause > {
165
165
let args = self . pre_compute_args . as_ref ( ) . unwrap ( ) ;
166
- let chain_task_id = self . chain_task_id . as_ref ( ) . unwrap ( ) ;
167
- let encrypted_dataset_url = args. encrypted_dataset_url . as_ref ( ) . unwrap ( ) ;
166
+ let chain_task_id: & str = self . chain_task_id . as_ref ( ) . unwrap ( ) ;
167
+ let encrypted_dataset_url: & str = & args. encrypted_dataset_url ;
168
168
169
169
info ! (
170
170
"Downloading encrypted dataset file [chainTaskId:{chain_task_id}, url:{encrypted_dataset_url}]" ,
@@ -189,13 +189,10 @@ impl PreComputeAppTrait for PreComputeApp {
189
189
. ok_or ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ?;
190
190
191
191
info ! ( "Checking encrypted dataset checksum [chainTaskId:{chain_task_id}]" ) ;
192
- let expected_checksum = args
193
- . encrypted_dataset_checksum
194
- . as_ref ( )
195
- . ok_or ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ?;
192
+ let expected_checksum: & str = & args. encrypted_dataset_checksum ;
196
193
let actual_checksum = sha256_from_bytes ( & encrypted_content) ;
197
194
198
- if actual_checksum != * expected_checksum {
195
+ if actual_checksum != expected_checksum {
199
196
error ! (
200
197
"Invalid dataset checksum [chainTaskId:{chain_task_id}, expected:{expected_checksum}, actual:{actual_checksum}]"
201
198
) ;
@@ -231,13 +228,11 @@ impl PreComputeAppTrait for PreComputeApp {
231
228
/// let decrypted = app.decrypt_dataset(&encrypted)?;
232
229
/// ```
233
230
fn decrypt_dataset ( & self , encrypted_content : & [ u8 ] ) -> Result < Vec < u8 > , ReplicateStatusCause > {
234
- let base64_key = self
231
+ let base64_key: & str = & self
235
232
. pre_compute_args
236
233
. as_ref ( )
237
234
. unwrap ( )
238
- . encrypted_dataset_base64_key
239
- . as_ref ( )
240
- . unwrap ( ) ;
235
+ . encrypted_dataset_base64_key ;
241
236
242
237
let key = general_purpose:: STANDARD
243
238
. decode ( base64_key)
@@ -280,10 +275,10 @@ impl PreComputeAppTrait for PreComputeApp {
280
275
/// app.save_plain_dataset_file(&plain_data)?;
281
276
/// ```
282
277
fn save_plain_dataset_file ( & self , plain_dataset : & [ u8 ] ) -> Result < ( ) , ReplicateStatusCause > {
283
- let chain_task_id = self . chain_task_id . as_ref ( ) . unwrap ( ) ;
278
+ let chain_task_id: & str = self . chain_task_id . as_ref ( ) . unwrap ( ) ;
284
279
let args = self . pre_compute_args . as_ref ( ) . unwrap ( ) ;
285
- let output_dir = & args. output_dir ;
286
- let plain_dataset_filename = args. plain_dataset_filename . as_ref ( ) . unwrap ( ) ;
280
+ let output_dir: & str = & args. output_dir ;
281
+ let plain_dataset_filename: & str = & args. plain_dataset_filename ;
287
282
288
283
let mut path = PathBuf :: from ( output_dir) ;
289
284
path. push ( plain_dataset_filename) ;
@@ -335,10 +330,10 @@ mod tests {
335
330
input_files : urls. into_iter ( ) . map ( String :: from) . collect ( ) ,
336
331
output_dir : output_dir. to_string ( ) ,
337
332
is_dataset_required : true ,
338
- encrypted_dataset_url : Some ( HTTP_DATASET_URL . to_string ( ) ) ,
339
- encrypted_dataset_base64_key : Some ( ENCRYPTED_DATASET_KEY . to_string ( ) ) ,
340
- encrypted_dataset_checksum : Some ( DATASET_CHECKSUM . to_string ( ) ) ,
341
- plain_dataset_filename : Some ( PLAIN_DATA_FILE . to_string ( ) ) ,
333
+ encrypted_dataset_url : HTTP_DATASET_URL . to_string ( ) ,
334
+ encrypted_dataset_base64_key : ENCRYPTED_DATASET_KEY . to_string ( ) ,
335
+ encrypted_dataset_checksum : DATASET_CHECKSUM . to_string ( ) ,
336
+ plain_dataset_filename : PLAIN_DATA_FILE . to_string ( ) ,
342
337
} ) ,
343
338
}
344
339
}
@@ -501,7 +496,7 @@ mod tests {
501
496
fn download_encrypted_dataset_failure_with_invalid_dataset_url ( ) {
502
497
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
503
498
if let Some ( args) = & mut app. pre_compute_args {
504
- args. encrypted_dataset_url = Some ( "http://bad-url" . to_string ( ) ) ;
499
+ args. encrypted_dataset_url = "http://bad-url" . to_string ( ) ;
505
500
}
506
501
let actual_content = app. download_encrypted_dataset ( ) ;
507
502
assert_eq ! (
@@ -514,10 +509,9 @@ mod tests {
514
509
fn download_encrypted_dataset_success_with_valid_iexec_gateway ( ) {
515
510
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
516
511
if let Some ( args) = & mut app. pre_compute_args {
517
- args. encrypted_dataset_url = Some ( IPFS_DATASET_URL . to_string ( ) ) ;
518
- args. encrypted_dataset_checksum = Some (
519
- "0x323b1637c7999942fbebfe5d42fe15dbfe93737577663afa0181938d7ad4a2ac" . to_string ( ) ,
520
- )
512
+ args. encrypted_dataset_url = IPFS_DATASET_URL . to_string ( ) ;
513
+ args. encrypted_dataset_checksum =
514
+ "0x323b1637c7999942fbebfe5d42fe15dbfe93737577663afa0181938d7ad4a2ac" . to_string ( ) ;
521
515
}
522
516
let actual_content = app. download_encrypted_dataset ( ) ;
523
517
let expected_content = Ok ( "hello world !\n " . as_bytes ( ) . to_vec ( ) ) ;
@@ -528,7 +522,7 @@ mod tests {
528
522
fn download_encrypted_dataset_failure_with_invalid_gateway ( ) {
529
523
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
530
524
if let Some ( args) = & mut app. pre_compute_args {
531
- args. encrypted_dataset_url = Some ( "/ipfs/INVALID_IPFS_DATASET_URL" . to_string ( ) ) ;
525
+ args. encrypted_dataset_url = "/ipfs/INVALID_IPFS_DATASET_URL" . to_string ( ) ;
532
526
}
533
527
let actual_content = app. download_encrypted_dataset ( ) ;
534
528
let expected_content = Err ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ;
@@ -539,7 +533,7 @@ mod tests {
539
533
fn download_encrypted_dataset_failure_with_invalid_dataset_checksum ( ) {
540
534
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
541
535
if let Some ( args) = & mut app. pre_compute_args {
542
- args. encrypted_dataset_checksum = Some ( "invalid_dataset_checksum" . to_string ( ) )
536
+ args. encrypted_dataset_checksum = "invalid_dataset_checksum" . to_string ( )
543
537
}
544
538
let actual_content = app. download_encrypted_dataset ( ) ;
545
539
let expected_content = Err ( ReplicateStatusCause :: PreComputeInvalidDatasetChecksum ) ;
@@ -563,7 +557,7 @@ mod tests {
563
557
fn decrypt_dataset_failure_with_bad_key ( ) {
564
558
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
565
559
if let Some ( args) = & mut app. pre_compute_args {
566
- args. encrypted_dataset_base64_key = Some ( "bad_key" . to_string ( ) ) ;
560
+ args. encrypted_dataset_base64_key = "bad_key" . to_string ( ) ;
567
561
}
568
562
let encrypted_data = app. download_encrypted_dataset ( ) . unwrap ( ) ;
569
563
let actual_plain_data = app. decrypt_dataset ( & encrypted_data) ;
@@ -609,7 +603,7 @@ mod tests {
609
603
610
604
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , output_path) ;
611
605
if let Some ( args) = & mut app. pre_compute_args {
612
- args. plain_dataset_filename = Some ( "/some-folder-123/not-found" . to_string ( ) ) ;
606
+ args. plain_dataset_filename = "/some-folder-123/not-found" . to_string ( ) ;
613
607
}
614
608
let plain_dataset = "Some very useful data." . as_bytes ( ) . to_vec ( ) ;
615
609
let saved_dataset = app. save_plain_dataset_file ( & plain_dataset) ;
0 commit comments