@@ -14,9 +14,7 @@ use crate::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address};
14
14
use crate :: concurrency:: test_utils:: {
15
15
class_hash, contract_address, safe_versioned_state_for_testing,
16
16
} ;
17
- use crate :: concurrency:: versioned_state:: {
18
- ThreadSafeVersionedState , VersionedState , VersionedStateProxy ,
19
- } ;
17
+ use crate :: concurrency:: versioned_state:: { ThreadSafeVersionedState , VersionedState } ;
20
18
use crate :: concurrency:: TxIndex ;
21
19
use crate :: context:: BlockContext ;
22
20
use crate :: state:: cached_state:: {
@@ -73,9 +71,8 @@ fn test_versioned_state_proxy() {
73
71
let versioned_state = Arc :: new ( Mutex :: new ( VersionedState :: new ( cached_state) ) ) ;
74
72
75
73
let safe_versioned_state = ThreadSafeVersionedState ( Arc :: clone ( & versioned_state) ) ;
76
- let versioned_state_proxys: Vec <
77
- VersionedStateProxy < CachedState < DictStateReader , VisitedPcsSet > , VisitedPcsSet > ,
78
- > = ( 0 ..20 ) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
74
+ let versioned_state_proxys: Vec < _ > =
75
+ ( 0 ..20 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
79
76
80
77
// Read initial data
81
78
assert_eq ! ( versioned_state_proxys[ 5 ] . get_nonce_at( contract_address) . unwrap( ) , nonce) ;
@@ -210,14 +207,12 @@ fn test_run_parallel_txs(max_resource_bounds: ResourceBoundsMapping) {
210
207
) ) ) ) ;
211
208
212
209
let safe_versioned_state = ThreadSafeVersionedState ( Arc :: clone ( & versioned_state) ) ;
213
- let mut versioned_state_proxy_1: VersionedStateProxy < _ , VisitedPcsSet > =
214
- safe_versioned_state. pin_version ( 1 ) ;
215
- let mut state_1: TransactionalState < ' _ , _ , VisitedPcsSet > =
216
- TransactionalState :: create_transactional ( & mut versioned_state_proxy_1) ;
217
- let mut versioned_state_proxy_2: VersionedStateProxy < _ , VisitedPcsSet > =
218
- safe_versioned_state. pin_version ( 2 ) ;
219
- let mut state_2: TransactionalState < ' _ , _ , VisitedPcsSet > =
220
- TransactionalState :: create_transactional ( & mut versioned_state_proxy_2) ;
210
+ let mut versioned_state_proxy_1 = safe_versioned_state. pin_version_for_testing ( 1 ) ;
211
+ let mut state_1 =
212
+ TransactionalState :: create_transactional_for_testing ( & mut versioned_state_proxy_1) ;
213
+ let mut versioned_state_proxy_2 = safe_versioned_state. pin_version_for_testing ( 2 ) ;
214
+ let mut state_2 =
215
+ TransactionalState :: create_transactional_for_testing ( & mut versioned_state_proxy_2) ;
221
216
222
217
// Prepare transactions
223
218
let deploy_account_tx_1 = deploy_account_tx (
@@ -288,15 +283,12 @@ fn test_validate_reads(
288
283
) {
289
284
let storage_key = storage_key ! ( 0x10_u8 ) ;
290
285
291
- let mut version_state_proxy: VersionedStateProxy < _ , VisitedPcsSet > =
292
- safe_versioned_state. pin_version ( 1 ) ;
293
- let transactional_state: TransactionalState < ' _ , _ , VisitedPcsSet > =
294
- TransactionalState :: create_transactional ( & mut version_state_proxy) ;
286
+ let mut version_state_proxy = safe_versioned_state. pin_version_for_testing ( 1 ) ;
287
+ let transactional_state =
288
+ TransactionalState :: create_transactional_for_testing ( & mut version_state_proxy) ;
295
289
296
290
// Validating tx index 0 always succeeds.
297
- assert ! (
298
- safe_versioned_state. pin_version:: <VisitedPcsSet >( 0 ) . validate_reads( & StateMaps :: default ( ) )
299
- ) ;
291
+ assert ! ( safe_versioned_state. pin_version_for_testing( 0 ) . validate_reads( & StateMaps :: default ( ) ) ) ;
300
292
301
293
assert ! ( transactional_state. cache. borrow( ) . initial_reads. storage. is_empty( ) ) ;
302
294
transactional_state. get_storage_at ( contract_address, storage_key) . unwrap ( ) ;
@@ -325,7 +317,7 @@ fn test_validate_reads(
325
317
326
318
assert ! (
327
319
safe_versioned_state
328
- . pin_version :: < VisitedPcsSet > ( 1 )
320
+ . pin_version_for_testing ( 1 )
329
321
. validate_reads( & transactional_state. cache. borrow( ) . initial_reads)
330
322
) ;
331
323
}
@@ -380,10 +372,9 @@ fn test_false_validate_reads(
380
372
#[ case] tx_0_writes : StateMaps ,
381
373
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
382
374
) {
383
- let version_state_proxy: VersionedStateProxy < _ , VisitedPcsSet > =
384
- safe_versioned_state. pin_version ( 0 ) ;
375
+ let version_state_proxy = safe_versioned_state. pin_version_for_testing ( 0 ) ;
385
376
version_state_proxy. state ( ) . apply_writes ( 0 , & tx_0_writes, & HashMap :: default ( ) ) ;
386
- assert ! ( !safe_versioned_state. pin_version :: < VisitedPcsSet > ( 1 ) . validate_reads( & tx_1_reads) ) ;
377
+ assert ! ( !safe_versioned_state. pin_version_for_testing ( 1 ) . validate_reads( & tx_1_reads) ) ;
387
378
}
388
379
389
380
#[ rstest]
@@ -398,12 +389,11 @@ fn test_false_validate_reads_declared_contracts(
398
389
declared_contracts : HashMap :: from ( [ ( class_hash ! ( 1_u8 ) , true ) ] ) ,
399
390
..Default :: default ( )
400
391
} ;
401
- let version_state_proxy: VersionedStateProxy < _ , VisitedPcsSet > =
402
- safe_versioned_state. pin_version ( 0 ) ;
392
+ let version_state_proxy = safe_versioned_state. pin_version_for_testing ( 0 ) ;
403
393
let compiled_contract_calss = FeatureContract :: TestContract ( CairoVersion :: Cairo1 ) . get_class ( ) ;
404
394
let class_hash_to_class = HashMap :: from ( [ ( class_hash ! ( 1_u8 ) , compiled_contract_calss) ] ) ;
405
395
version_state_proxy. state ( ) . apply_writes ( 0 , & tx_0_writes, & class_hash_to_class) ;
406
- assert ! ( !safe_versioned_state. pin_version :: < VisitedPcsSet > ( 1 ) . validate_reads( & tx_1_reads) ) ;
396
+ assert ! ( !safe_versioned_state. pin_version_for_testing ( 1 ) . validate_reads( & tx_1_reads) ) ;
407
397
}
408
398
409
399
#[ rstest]
@@ -412,10 +402,12 @@ fn test_apply_writes(
412
402
class_hash : ClassHash ,
413
403
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
414
404
) {
415
- let mut versioned_proxy_states: Vec < VersionedStateProxy < _ , VisitedPcsSet > > =
416
- ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
417
- let mut transactional_states: Vec < TransactionalState < ' _ , _ , VisitedPcsSet > > =
418
- versioned_proxy_states. iter_mut ( ) . map ( TransactionalState :: create_transactional) . collect ( ) ;
405
+ let mut versioned_proxy_states: Vec < _ > =
406
+ ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
407
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
408
+ . iter_mut ( )
409
+ . map ( TransactionalState :: create_transactional_for_testing)
410
+ . collect ( ) ;
419
411
420
412
// Transaction 0 class hash.
421
413
let class_hash_0 = class_hash ! ( 76_u8 ) ;
@@ -429,7 +421,7 @@ fn test_apply_writes(
429
421
transactional_states[ 0 ] . set_contract_class ( class_hash, contract_class_0. clone ( ) ) . unwrap ( ) ;
430
422
assert_eq ! ( transactional_states[ 0 ] . class_hash_to_class. borrow( ) . len( ) , 1 ) ;
431
423
432
- safe_versioned_state. pin_version ( 0 ) . apply_writes (
424
+ safe_versioned_state. pin_version_for_testing ( 0 ) . apply_writes (
433
425
& transactional_states[ 0 ] . cache . borrow ( ) . writes ,
434
426
& transactional_states[ 0 ] . class_hash_to_class . borrow ( ) . clone ( ) ,
435
427
& VisitedPcsSet :: default ( ) ,
@@ -447,10 +439,12 @@ fn test_apply_writes_reexecute_scenario(
447
439
class_hash : ClassHash ,
448
440
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
449
441
) {
450
- let mut versioned_proxy_states: Vec < VersionedStateProxy < _ , VisitedPcsSet > > =
451
- ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
452
- let mut transactional_states: Vec < TransactionalState < ' _ , _ , VisitedPcsSet > > =
453
- versioned_proxy_states. iter_mut ( ) . map ( TransactionalState :: create_transactional) . collect ( ) ;
442
+ let mut versioned_proxy_states: Vec < _ > =
443
+ ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
444
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
445
+ . iter_mut ( )
446
+ . map ( TransactionalState :: create_transactional_for_testing)
447
+ . collect ( ) ;
454
448
455
449
// Transaction 0 class hash.
456
450
let class_hash_0 = class_hash ! ( 76_u8 ) ;
@@ -460,7 +454,7 @@ fn test_apply_writes_reexecute_scenario(
460
454
// updated.
461
455
assert ! ( transactional_states[ 1 ] . get_class_hash_at( contract_address) . unwrap( ) == class_hash) ;
462
456
463
- safe_versioned_state. pin_version ( 0 ) . apply_writes (
457
+ safe_versioned_state. pin_version_for_testing ( 0 ) . apply_writes (
464
458
& transactional_states[ 0 ] . cache . borrow ( ) . writes ,
465
459
& transactional_states[ 0 ] . class_hash_to_class . borrow ( ) . clone ( ) ,
466
460
& VisitedPcsSet :: default ( ) ,
@@ -471,7 +465,7 @@ fn test_apply_writes_reexecute_scenario(
471
465
472
466
// TODO: Use re-execution native util once it's ready.
473
467
// "Re-execute" the transaction.
474
- let mut versioned_state_proxy = safe_versioned_state. pin_version ( 1 ) ;
468
+ let mut versioned_state_proxy = safe_versioned_state. pin_version_for_testing ( 1 ) ;
475
469
transactional_states[ 1 ] = TransactionalState :: create_transactional ( & mut versioned_state_proxy) ;
476
470
// The class hash should be updated.
477
471
assert ! ( transactional_states[ 1 ] . get_class_hash_at( contract_address) . unwrap( ) == class_hash_0) ;
@@ -483,10 +477,12 @@ fn test_delete_writes(
483
477
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
484
478
) {
485
479
let num_of_txs = 3 ;
486
- let mut versioned_proxy_states: Vec < VersionedStateProxy < _ , VisitedPcsSet > > =
487
- ( 0 ..num_of_txs) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
488
- let mut transactional_states: Vec < TransactionalState < ' _ , _ , VisitedPcsSet > > =
489
- versioned_proxy_states. iter_mut ( ) . map ( TransactionalState :: create_transactional) . collect ( ) ;
480
+ let mut versioned_proxy_states: Vec < _ > =
481
+ ( 0 ..num_of_txs) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
482
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
483
+ . iter_mut ( )
484
+ . map ( TransactionalState :: create_transactional_for_testing)
485
+ . collect ( ) ;
490
486
491
487
// Setting 2 instances of the contract to ensure `delete_writes` removes information from
492
488
// multiple keys. Class hash values are not checked in this test.
@@ -504,14 +500,14 @@ fn test_delete_writes(
504
500
tx_state
505
501
. set_contract_class ( feature_contract. get_class_hash ( ) , feature_contract. get_class ( ) )
506
502
. unwrap ( ) ;
507
- safe_versioned_state. pin_version ( i) . apply_writes (
503
+ safe_versioned_state. pin_version_for_testing ( i) . apply_writes (
508
504
& tx_state. cache . borrow ( ) . writes ,
509
505
& tx_state. class_hash_to_class . borrow ( ) ,
510
506
& VisitedPcsSet :: default ( ) ,
511
507
) ;
512
508
}
513
509
514
- safe_versioned_state. pin_version :: < VisitedPcsSet > ( tx_index_to_delete_writes) . delete_writes (
510
+ safe_versioned_state. pin_version_for_testing ( tx_index_to_delete_writes) . delete_writes (
515
511
& transactional_states[ tx_index_to_delete_writes] . cache . borrow ( ) . writes ,
516
512
& transactional_states[ tx_index_to_delete_writes] . class_hash_to_class . borrow ( ) ,
517
513
) ;
@@ -564,7 +560,7 @@ fn test_delete_writes_completeness(
564
560
HashMap :: from ( [ ( feature_contract. get_class_hash ( ) , feature_contract. get_class ( ) ) ] ) ;
565
561
566
562
let tx_index = 0 ;
567
- let mut versioned_state_proxy = safe_versioned_state. pin_version ( tx_index) ;
563
+ let mut versioned_state_proxy = safe_versioned_state. pin_version_for_testing ( tx_index) ;
568
564
569
565
versioned_state_proxy. apply_writes (
570
566
& state_maps_writes,
@@ -608,13 +604,13 @@ fn test_versioned_proxy_state_flow(
608
604
let contract_address = contract_address ! ( "0x1" ) ;
609
605
let class_hash = ClassHash ( felt ! ( 27_u8 ) ) ;
610
606
611
- let mut versioned_proxy_states: Vec < VersionedStateProxy < _ , VisitedPcsSet > > =
612
- ( 0 ..4 ) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
607
+ let mut versioned_proxy_states: Vec < _ > =
608
+ ( 0 ..4 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
613
609
614
- let mut transactional_states: Vec < TransactionalState < ' _ , _ , VisitedPcsSet > > =
615
- Vec :: with_capacity ( 4 ) ;
610
+ let mut transactional_states = Vec :: with_capacity ( 4 ) ;
616
611
for proxy_state in & mut versioned_proxy_states {
617
- transactional_states. push ( TransactionalState :: create_transactional ( proxy_state) ) ;
612
+ transactional_states
613
+ . push ( TransactionalState :: create_transactional_for_testing ( proxy_state) ) ;
618
614
}
619
615
620
616
// Clients class hash values.
0 commit comments