@@ -63,6 +63,7 @@ impl Job for DaJob {
63
63
64
64
async fn process_job ( & self , config : & Config , job : & mut JobItem ) -> Result < String > {
65
65
let block_no = job. internal_id . parse :: < u64 > ( ) ?;
66
+
66
67
let state_update = config. starknet_client ( ) . get_state_update ( BlockId :: Number ( block_no) ) . await ?;
67
68
68
69
let state_update = match state_update {
@@ -127,7 +128,7 @@ impl Job for DaJob {
127
128
}
128
129
}
129
130
130
- fn fft_transformation ( elements : Vec < BigUint > ) -> Vec < BigUint > {
131
+ pub fn fft_transformation ( elements : Vec < BigUint > ) -> Vec < BigUint > {
131
132
let xs: Vec < BigUint > = ( 0 ..* BLOB_LEN )
132
133
. map ( |i| {
133
134
let bin = format ! ( "{:012b}" , i) ;
@@ -149,7 +150,7 @@ fn fft_transformation(elements: Vec<BigUint>) -> Vec<BigUint> {
149
150
transform
150
151
}
151
152
152
- fn convert_to_biguint ( elements : Vec < FieldElement > ) -> Vec < BigUint > {
153
+ pub fn convert_to_biguint ( elements : Vec < FieldElement > ) -> Vec < BigUint > {
153
154
// Initialize the vector with 4096 BigUint zeros
154
155
let mut biguint_vec = vec ! [ BigUint :: zero( ) ; 4096 ] ;
155
156
@@ -200,7 +201,7 @@ fn data_to_blobs(blob_size: u64, block_data: Vec<BigUint>) -> Result<Vec<Vec<u8>
200
201
Ok ( blobs)
201
202
}
202
203
203
- async fn state_update_to_blob_data (
204
+ pub async fn state_update_to_blob_data (
204
205
block_no : u64 ,
205
206
state_update : StateUpdate ,
206
207
config : & Config ,
@@ -342,32 +343,37 @@ fn da_word(class_flag: bool, nonce_change: Option<FieldElement>, num_changes: u6
342
343
}
343
344
344
345
#[ cfg( test) ]
345
- mod tests {
346
+
347
+ pub mod test {
348
+ use crate :: jobs:: da_job:: da_word;
346
349
use std:: fs;
347
350
use std:: fs:: File ;
348
351
use std:: io:: Read ;
349
352
353
+ use crate :: data_storage:: MockDataStorage ;
350
354
use :: serde:: { Deserialize , Serialize } ;
355
+ use color_eyre:: Result ;
356
+ use da_client_interface:: MockDaClient ;
351
357
use httpmock:: prelude:: * ;
352
358
use majin_blob_core:: blob;
353
359
use majin_blob_types:: serde;
354
360
use majin_blob_types:: state_diffs:: UnorderedEq ;
355
- // use majin_blob_types::serde;
356
- use crate :: data_storage:: MockDataStorage ;
357
- use da_client_interface:: MockDaClient ;
358
361
use rstest:: rstest;
359
362
use serde_json:: json;
363
+ use starknet_core:: types:: { FieldElement , StateUpdate } ;
360
364
361
- use super :: * ;
362
- // use majin_blob_types::serde;
363
365
use crate :: tests:: common:: init_config;
364
366
367
+ /// Tests `da_word` function with various inputs for class flag, new nonce, and number of changes.
368
+ /// Verifies that `da_word` produces the correct FieldElement based on the provided parameters.
369
+ /// Uses test cases with different combinations of inputs and expected output strings.
370
+ /// Asserts the function's correctness by comparing the computed and expected FieldElements.
365
371
#[ rstest]
366
372
#[ case( false , 1 , 1 , "18446744073709551617" ) ]
367
373
#[ case( false , 1 , 0 , "18446744073709551616" ) ]
368
374
#[ case( false , 0 , 6 , "6" ) ]
369
375
#[ case( true , 1 , 0 , "340282366920938463481821351505477763072" ) ]
370
- fn da_word_works (
376
+ fn test_da_word (
371
377
#[ case] class_flag : bool ,
372
378
#[ case] new_nonce : u64 ,
373
379
#[ case] num_changes : u64 ,
@@ -379,24 +385,28 @@ mod tests {
379
385
assert_eq ! ( da_word, expected) ;
380
386
}
381
387
388
+ /// Tests `state_update_to_blob_data` conversion with different state update files and block numbers.
389
+ /// Mocks DA client and storage client interactions for the test environment.
390
+ /// Compares the generated blob data against expected values to ensure correctness.
391
+ /// Verifies the data integrity by checking that the parsed state diffs match the expected diffs.
382
392
#[ rstest]
383
393
#[ case(
384
394
631861 ,
385
- "src/jobs/da_job/test_data/state_update_from_block_631861 .txt" ,
386
- "src/jobs/da_job/test_data/test_blob_631861 .txt" ,
387
- "src/jobs/da_job/test_data/nonces_from_block_631861 .txt"
395
+ "src/tests/ jobs/da_job/test_data/state_update/631861 .txt" ,
396
+ "src/tests/ jobs/da_job/test_data/test_blob/631861 .txt" ,
397
+ "src/tests/ jobs/da_job/test_data/nonces/631861 .txt"
388
398
) ]
389
399
#[ case(
390
400
638353 ,
391
- "src/jobs/da_job/test_data/state_update_from_block_638353 .txt" ,
392
- "src/jobs/da_job/test_data/test_blob_638353 .txt" ,
393
- "src/jobs/da_job/test_data/nonces_from_block_638353 .txt"
401
+ "src/tests/ jobs/da_job/test_data/state_update/638353 .txt" ,
402
+ "src/tests/ jobs/da_job/test_data/test_blob/638353 .txt" ,
403
+ "src/tests/ jobs/da_job/test_data/nonces/638353 .txt"
394
404
) ]
395
405
#[ case(
396
406
640641 ,
397
- "src/jobs/da_job/test_data/state_update_from_block_640641 .txt" ,
398
- "src/jobs/da_job/test_data/test_blob_640641 .txt" ,
399
- "src/jobs/da_job/test_data/nonces_from_block_640641 .txt"
407
+ "src/tests/ jobs/da_job/test_data/state_update/640641 .txt" ,
408
+ "src/tests/ jobs/da_job/test_data/test_blob/640641 .txt" ,
409
+ "src/tests/ jobs/da_job/test_data/nonces/640641 .txt"
400
410
) ]
401
411
#[ tokio:: test]
402
412
async fn test_state_update_to_blob_data (
@@ -405,6 +415,8 @@ mod tests {
405
415
#[ case] file_path : & str ,
406
416
#[ case] nonce_file_path : & str ,
407
417
) {
418
+ use crate :: jobs:: da_job:: { convert_to_biguint, state_update_to_blob_data} ;
419
+
408
420
let server = MockServer :: start ( ) ;
409
421
let mut da_client = MockDaClient :: new ( ) ;
410
422
let mut storage_client = MockDataStorage :: new ( ) ;
@@ -446,16 +458,22 @@ mod tests {
446
458
assert ! ( block_data_state_diffs. unordered_eq( & blob_data_state_diffs) , "value of data json should be identical" ) ;
447
459
}
448
460
461
+ /// Tests the `fft_transformation` function with various test blob files.
462
+ /// Verifies the correctness of FFT and IFFT transformations by ensuring round-trip consistency.
463
+ /// Parses the original blob data, recovers it using IFFT, and re-applies FFT.
464
+ /// Asserts that the transformed data matches the original pre-IFFT data, ensuring integrity.
449
465
#[ rstest]
450
- #[ case( "src/jobs/da_job/test_data/test_blob_631861 .txt" ) ]
451
- #[ case( "src/jobs/da_job/test_data/test_blob_638353 .txt" ) ]
452
- #[ case( "src/jobs/da_job/test_data/test_blob_639404 .txt" ) ]
453
- #[ case( "src/jobs/da_job/test_data/test_blob_640641 .txt" ) ]
454
- #[ case( "src/jobs/da_job/test_data/test_blob_640644 .txt" ) ]
455
- #[ case( "src/jobs/da_job/test_data/test_blob_640646 .txt" ) ]
456
- #[ case( "src/jobs/da_job/test_data/test_blob_640647 .txt" ) ]
466
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/638353 .txt" ) ]
467
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/631861 .txt" ) ]
468
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/639404 .txt" ) ]
469
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/640641 .txt" ) ]
470
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/640644 .txt" ) ]
471
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/640646 .txt" ) ]
472
+ #[ case( "src/tests/ jobs/da_job/test_data/test_blob/640647 .txt" ) ]
457
473
fn test_fft_transformation ( #[ case] file_to_check : & str ) {
458
474
// parsing the blob hex to the bigUints
475
+
476
+ use crate :: jobs:: da_job:: fft_transformation;
459
477
let original_blob_data = serde:: parse_file_to_blob_data ( file_to_check) ;
460
478
// converting the data to its original format
461
479
let ifft_blob_data = blob:: recover ( original_blob_data. clone ( ) ) ;
@@ -466,6 +484,10 @@ mod tests {
466
484
assert_eq ! ( fft_blob_data, original_blob_data) ;
467
485
}
468
486
487
+ /// Tests the serialization and deserialization process using bincode.
488
+ /// Serializes a nested vector of integers and then deserializes it back.
489
+ /// Verifies that the original data matches the deserialized data.
490
+ /// Ensures the integrity and correctness of bincode's (de)serialization.
469
491
#[ rstest]
470
492
fn test_bincode ( ) {
471
493
let data = vec ! [ vec![ 1 , 2 ] , vec![ 3 , 4 ] ] ;
@@ -476,7 +498,7 @@ mod tests {
476
498
assert_eq ! ( data, deserialize_data) ;
477
499
}
478
500
479
- pub fn read_state_update_from_file ( file_path : & str ) -> Result < StateUpdate > {
501
+ pub ( crate ) fn read_state_update_from_file ( file_path : & str ) -> Result < StateUpdate > {
480
502
// let file_path = format!("state_update_block_no_{}.txt", block_no);
481
503
let mut file = File :: open ( file_path) ?;
482
504
let mut json = String :: new ( ) ;
@@ -520,8 +542,6 @@ mod tests {
520
542
521
543
let mut new_hex_chars = hex_chars. join ( "" ) ;
522
544
new_hex_chars = new_hex_chars. trim_start_matches ( '0' ) . to_string ( ) ;
523
-
524
- // Handle the case where the trimmed string is empty (e.g., data was all zeros)
525
545
if new_hex_chars. is_empty ( ) {
526
546
"0x0" . to_string ( )
527
547
} else {
0 commit comments