@@ -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,10 +283,9 @@ 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
291
assert ! (
@@ -380,8 +374,7 @@ fn test_false_validate_reads(
380
374
#[ case] tx_0_writes : StateMaps ,
381
375
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
382
376
) {
383
- let version_state_proxy: VersionedStateProxy < _ , VisitedPcsSet > =
384
- safe_versioned_state. pin_version ( 0 ) ;
377
+ let version_state_proxy = safe_versioned_state. pin_version_for_testing ( 0 ) ;
385
378
version_state_proxy. state ( ) . apply_writes ( 0 , & tx_0_writes, & HashMap :: default ( ) ) ;
386
379
assert ! ( !safe_versioned_state. pin_version:: <VisitedPcsSet >( 1 ) . validate_reads( & tx_1_reads) ) ;
387
380
}
@@ -398,8 +391,7 @@ fn test_false_validate_reads_declared_contracts(
398
391
declared_contracts : HashMap :: from ( [ ( class_hash ! ( 1_u8 ) , true ) ] ) ,
399
392
..Default :: default ( )
400
393
} ;
401
- let version_state_proxy: VersionedStateProxy < _ , VisitedPcsSet > =
402
- safe_versioned_state. pin_version ( 0 ) ;
394
+ let version_state_proxy = safe_versioned_state. pin_version_for_testing ( 0 ) ;
403
395
let compiled_contract_calss = FeatureContract :: TestContract ( CairoVersion :: Cairo1 ) . get_class ( ) ;
404
396
let class_hash_to_class = HashMap :: from ( [ ( class_hash ! ( 1_u8 ) , compiled_contract_calss) ] ) ;
405
397
version_state_proxy. state ( ) . apply_writes ( 0 , & tx_0_writes, & class_hash_to_class) ;
@@ -412,10 +404,12 @@ fn test_apply_writes(
412
404
class_hash : ClassHash ,
413
405
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
414
406
) {
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 ( ) ;
407
+ let mut versioned_proxy_states: Vec < _ > =
408
+ ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
409
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
410
+ . iter_mut ( )
411
+ . map ( TransactionalState :: create_transactional_for_testing)
412
+ . collect ( ) ;
419
413
420
414
// Transaction 0 class hash.
421
415
let class_hash_0 = class_hash ! ( 76_u8 ) ;
@@ -429,7 +423,7 @@ fn test_apply_writes(
429
423
transactional_states[ 0 ] . set_contract_class ( class_hash, contract_class_0. clone ( ) ) . unwrap ( ) ;
430
424
assert_eq ! ( transactional_states[ 0 ] . class_hash_to_class. borrow( ) . len( ) , 1 ) ;
431
425
432
- safe_versioned_state. pin_version ( 0 ) . apply_writes (
426
+ safe_versioned_state. pin_version_for_testing ( 0 ) . apply_writes (
433
427
& transactional_states[ 0 ] . cache . borrow ( ) . writes ,
434
428
& transactional_states[ 0 ] . class_hash_to_class . borrow ( ) . clone ( ) ,
435
429
& VisitedPcsSet :: default ( ) ,
@@ -447,10 +441,12 @@ fn test_apply_writes_reexecute_scenario(
447
441
class_hash : ClassHash ,
448
442
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
449
443
) {
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 ( ) ;
444
+ let mut versioned_proxy_states: Vec < _ > =
445
+ ( 0 ..2 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
446
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
447
+ . iter_mut ( )
448
+ . map ( TransactionalState :: create_transactional_for_testing)
449
+ . collect ( ) ;
454
450
455
451
// Transaction 0 class hash.
456
452
let class_hash_0 = class_hash ! ( 76_u8 ) ;
@@ -460,7 +456,7 @@ fn test_apply_writes_reexecute_scenario(
460
456
// updated.
461
457
assert ! ( transactional_states[ 1 ] . get_class_hash_at( contract_address) . unwrap( ) == class_hash) ;
462
458
463
- safe_versioned_state. pin_version ( 0 ) . apply_writes (
459
+ safe_versioned_state. pin_version_for_testing ( 0 ) . apply_writes (
464
460
& transactional_states[ 0 ] . cache . borrow ( ) . writes ,
465
461
& transactional_states[ 0 ] . class_hash_to_class . borrow ( ) . clone ( ) ,
466
462
& VisitedPcsSet :: default ( ) ,
@@ -471,7 +467,7 @@ fn test_apply_writes_reexecute_scenario(
471
467
472
468
// TODO: Use re-execution native util once it's ready.
473
469
// "Re-execute" the transaction.
474
- let mut versioned_state_proxy = safe_versioned_state. pin_version ( 1 ) ;
470
+ let mut versioned_state_proxy = safe_versioned_state. pin_version_for_testing ( 1 ) ;
475
471
transactional_states[ 1 ] = TransactionalState :: create_transactional ( & mut versioned_state_proxy) ;
476
472
// The class hash should be updated.
477
473
assert ! ( transactional_states[ 1 ] . get_class_hash_at( contract_address) . unwrap( ) == class_hash_0) ;
@@ -483,10 +479,12 @@ fn test_delete_writes(
483
479
safe_versioned_state : ThreadSafeVersionedState < CachedState < DictStateReader , VisitedPcsSet > > ,
484
480
) {
485
481
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 ( ) ;
482
+ let mut versioned_proxy_states: Vec < _ > =
483
+ ( 0 ..num_of_txs) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
484
+ let mut transactional_states: Vec < _ > = versioned_proxy_states
485
+ . iter_mut ( )
486
+ . map ( TransactionalState :: create_transactional_for_testing)
487
+ . collect ( ) ;
490
488
491
489
// Setting 2 instances of the contract to ensure `delete_writes` removes information from
492
490
// multiple keys. Class hash values are not checked in this test.
@@ -504,7 +502,7 @@ fn test_delete_writes(
504
502
tx_state
505
503
. set_contract_class ( feature_contract. get_class_hash ( ) , feature_contract. get_class ( ) )
506
504
. unwrap ( ) ;
507
- safe_versioned_state. pin_version ( i) . apply_writes (
505
+ safe_versioned_state. pin_version_for_testing ( i) . apply_writes (
508
506
& tx_state. cache . borrow ( ) . writes ,
509
507
& tx_state. class_hash_to_class . borrow ( ) ,
510
508
& VisitedPcsSet :: default ( ) ,
@@ -564,7 +562,7 @@ fn test_delete_writes_completeness(
564
562
HashMap :: from ( [ ( feature_contract. get_class_hash ( ) , feature_contract. get_class ( ) ) ] ) ;
565
563
566
564
let tx_index = 0 ;
567
- let mut versioned_state_proxy = safe_versioned_state. pin_version ( tx_index) ;
565
+ let mut versioned_state_proxy = safe_versioned_state. pin_version_for_testing ( tx_index) ;
568
566
569
567
versioned_state_proxy. apply_writes (
570
568
& state_maps_writes,
@@ -608,13 +606,13 @@ fn test_versioned_proxy_state_flow(
608
606
let contract_address = contract_address ! ( "0x1" ) ;
609
607
let class_hash = ClassHash ( felt ! ( 27_u8 ) ) ;
610
608
611
- let mut versioned_proxy_states: Vec < VersionedStateProxy < _ , VisitedPcsSet > > =
612
- ( 0 ..4 ) . map ( |i| safe_versioned_state. pin_version ( i) ) . collect ( ) ;
609
+ let mut versioned_proxy_states: Vec < _ > =
610
+ ( 0 ..4 ) . map ( |i| safe_versioned_state. pin_version_for_testing ( i) ) . collect ( ) ;
613
611
614
- let mut transactional_states: Vec < TransactionalState < ' _ , _ , VisitedPcsSet > > =
615
- Vec :: with_capacity ( 4 ) ;
612
+ let mut transactional_states = Vec :: with_capacity ( 4 ) ;
616
613
for proxy_state in & mut versioned_proxy_states {
617
- transactional_states. push ( TransactionalState :: create_transactional ( proxy_state) ) ;
614
+ transactional_states
615
+ . push ( TransactionalState :: create_transactional_for_testing ( proxy_state) ) ;
618
616
}
619
617
620
618
// Clients class hash values.
0 commit comments