@@ -156,7 +156,7 @@ impl PreComputeAppTrait for PreComputeApp {
156
156
fn download_encrypted_dataset ( & self ) -> Result < Vec < u8 > , ReplicateStatusCause > {
157
157
let args = & self . pre_compute_args ;
158
158
let chain_task_id = & self . chain_task_id ;
159
- let encrypted_dataset_url = args. encrypted_dataset_url . as_ref ( ) . unwrap ( ) ;
159
+ let encrypted_dataset_url: & str = & args. encrypted_dataset_url ;
160
160
161
161
info ! (
162
162
"Downloading encrypted dataset file [chainTaskId:{chain_task_id}, url:{encrypted_dataset_url}]" ,
@@ -181,13 +181,10 @@ impl PreComputeAppTrait for PreComputeApp {
181
181
. ok_or ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ?;
182
182
183
183
info ! ( "Checking encrypted dataset checksum [chainTaskId:{chain_task_id}]" ) ;
184
- let expected_checksum = args
185
- . encrypted_dataset_checksum
186
- . as_ref ( )
187
- . ok_or ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ?;
184
+ let expected_checksum: & str = & args. encrypted_dataset_checksum ;
188
185
let actual_checksum = sha256_from_bytes ( & encrypted_content) ;
189
186
190
- if actual_checksum != * expected_checksum {
187
+ if actual_checksum != expected_checksum {
191
188
error ! (
192
189
"Invalid dataset checksum [chainTaskId:{chain_task_id}, expected:{expected_checksum}, actual:{actual_checksum}]"
193
190
) ;
@@ -223,11 +220,9 @@ impl PreComputeAppTrait for PreComputeApp {
223
220
/// let decrypted = app.decrypt_dataset(&encrypted)?;
224
221
/// ```
225
222
fn decrypt_dataset ( & self , encrypted_content : & [ u8 ] ) -> Result < Vec < u8 > , ReplicateStatusCause > {
226
- let base64_key = self
223
+ let base64_key: & str = & self
227
224
. pre_compute_args
228
- . encrypted_dataset_base64_key
229
- . as_ref ( )
230
- . unwrap ( ) ;
225
+ . encrypted_dataset_base64_key ;
231
226
232
227
let key = general_purpose:: STANDARD
233
228
. decode ( base64_key)
@@ -273,7 +268,7 @@ impl PreComputeAppTrait for PreComputeApp {
273
268
let chain_task_id: & str = & self . chain_task_id ;
274
269
let args = & self . pre_compute_args ;
275
270
let output_dir: & str = & args. output_dir ;
276
- let plain_dataset_filename: & str = args. plain_dataset_filename . as_ref ( ) . unwrap ( ) ;
271
+ let plain_dataset_filename: & str = & args. plain_dataset_filename ;
277
272
278
273
let mut path = PathBuf :: from ( output_dir) ;
279
274
path. push ( plain_dataset_filename) ;
@@ -325,10 +320,10 @@ mod tests {
325
320
input_files : urls. into_iter ( ) . map ( String :: from) . collect ( ) ,
326
321
output_dir : output_dir. to_string ( ) ,
327
322
is_dataset_required : true ,
328
- encrypted_dataset_url : Some ( HTTP_DATASET_URL . to_string ( ) ) ,
329
- encrypted_dataset_base64_key : Some ( ENCRYPTED_DATASET_KEY . to_string ( ) ) ,
330
- encrypted_dataset_checksum : Some ( DATASET_CHECKSUM . to_string ( ) ) ,
331
- plain_dataset_filename : Some ( PLAIN_DATA_FILE . to_string ( ) ) ,
323
+ encrypted_dataset_url : HTTP_DATASET_URL . to_string ( ) ,
324
+ encrypted_dataset_base64_key : ENCRYPTED_DATASET_KEY . to_string ( ) ,
325
+ encrypted_dataset_checksum : DATASET_CHECKSUM . to_string ( ) ,
326
+ plain_dataset_filename : PLAIN_DATA_FILE . to_string ( ) ,
332
327
} ,
333
328
}
334
329
}
@@ -477,7 +472,7 @@ mod tests {
477
472
#[ test]
478
473
fn download_encrypted_dataset_failure_with_invalid_dataset_url ( ) {
479
474
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
480
- app. pre_compute_args . encrypted_dataset_url = Some ( "http://bad-url" . to_string ( ) ) ;
475
+ app. pre_compute_args . encrypted_dataset_url = "http://bad-url" . to_string ( ) ;
481
476
let actual_content = app. download_encrypted_dataset ( ) ;
482
477
assert_eq ! (
483
478
actual_content,
@@ -488,9 +483,9 @@ mod tests {
488
483
#[ test]
489
484
fn download_encrypted_dataset_success_with_valid_iexec_gateway ( ) {
490
485
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
491
- app. pre_compute_args . encrypted_dataset_url = Some ( IPFS_DATASET_URL . to_string ( ) ) ;
486
+ app. pre_compute_args . encrypted_dataset_url = IPFS_DATASET_URL . to_string ( ) ;
492
487
app. pre_compute_args . encrypted_dataset_checksum =
493
- Some ( "0x323b1637c7999942fbebfe5d42fe15dbfe93737577663afa0181938d7ad4a2ac" . to_string ( ) ) ;
488
+ "0x323b1637c7999942fbebfe5d42fe15dbfe93737577663afa0181938d7ad4a2ac" . to_string ( ) ;
494
489
let actual_content = app. download_encrypted_dataset ( ) ;
495
490
let expected_content = Ok ( "hello world !\n " . as_bytes ( ) . to_vec ( ) ) ;
496
491
assert_eq ! ( actual_content, expected_content) ;
@@ -500,7 +495,7 @@ mod tests {
500
495
fn download_encrypted_dataset_failure_with_invalid_gateway ( ) {
501
496
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
502
497
app. pre_compute_args . encrypted_dataset_url =
503
- Some ( "/ipfs/INVALID_IPFS_DATASET_URL" . to_string ( ) ) ;
498
+ "/ipfs/INVALID_IPFS_DATASET_URL" . to_string ( ) ;
504
499
let actual_content = app. download_encrypted_dataset ( ) ;
505
500
let expected_content = Err ( ReplicateStatusCause :: PreComputeDatasetDownloadFailed ) ;
506
501
assert_eq ! ( actual_content, expected_content) ;
@@ -510,7 +505,7 @@ mod tests {
510
505
fn download_encrypted_dataset_failure_with_invalid_dataset_checksum ( ) {
511
506
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
512
507
app. pre_compute_args . encrypted_dataset_checksum =
513
- Some ( "invalid_dataset_checksum" . to_string ( ) ) ;
508
+ "invalid_dataset_checksum" . to_string ( ) ;
514
509
let actual_content = app. download_encrypted_dataset ( ) ;
515
510
let expected_content = Err ( ReplicateStatusCause :: PreComputeInvalidDatasetChecksum ) ;
516
511
assert_eq ! ( actual_content, expected_content) ;
@@ -532,7 +527,7 @@ mod tests {
532
527
#[ test]
533
528
fn decrypt_dataset_failure_with_bad_key ( ) {
534
529
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , "" ) ;
535
- app. pre_compute_args . encrypted_dataset_base64_key = Some ( "bad_key" . to_string ( ) ) ;
530
+ app. pre_compute_args . encrypted_dataset_base64_key = "bad_key" . to_string ( ) ;
536
531
let encrypted_data = app. download_encrypted_dataset ( ) . unwrap ( ) ;
537
532
let actual_plain_data = app. decrypt_dataset ( & encrypted_data) ;
538
533
@@ -577,7 +572,7 @@ mod tests {
577
572
578
573
let mut app = get_pre_compute_app ( CHAIN_TASK_ID , vec ! [ ] , output_path) ;
579
574
app. pre_compute_args . plain_dataset_filename =
580
- Some ( "/some-folder-123/not-found" . to_string ( ) ) ;
575
+ "/some-folder-123/not-found" . to_string ( ) ;
581
576
let plain_dataset = "Some very useful data." . as_bytes ( ) . to_vec ( ) ;
582
577
let saved_dataset = app. save_plain_dataset_file ( & plain_dataset) ;
583
578
0 commit comments