@@ -24,7 +24,6 @@ use std::sync::Arc;
2424use web3:: types:: H256 ;
2525
2626use graph_store_postgres:: SubgraphStore as DieselSubgraphStore ;
27- use test_store:: store:: filter_vid;
2827use test_store:: * ;
2928
3029lazy_static ! {
@@ -208,13 +207,13 @@ fn insert_modifications() {
208207 let store = Arc :: new ( store) ;
209208 let mut cache = EntityCache :: new ( store) ;
210209
211- let mogwai_data = entity ! { SCHEMA => id: "mogwai" , name: "Mogwai" } ;
210+ let mogwai_data = entity ! { SCHEMA => id: "mogwai" , name: "Mogwai" } ;
212211 let mogwai_key = make_band_key ( "mogwai" ) ;
213212 cache
214213 . set ( mogwai_key. clone ( ) , EntityV :: new ( mogwai_data. clone ( ) , 0 ) )
215214 . unwrap ( ) ;
216215
217- let sigurros_data = entity ! { SCHEMA => id: "sigurros" , name: "Sigur Ros" } ;
216+ let sigurros_data = entity ! { SCHEMA => id: "sigurros" , name: "Sigur Ros" } ;
218217 let sigurros_key = make_band_key ( "sigurros" ) ;
219218 cache
220219 . set ( sigurros_key. clone ( ) , EntityV :: new ( sigurros_data. clone ( ) , 0 ) )
@@ -254,7 +253,7 @@ fn overwrite_modifications() {
254253 let store = Arc :: new ( store) ;
255254 let mut cache = EntityCache :: new ( store) ;
256255
257- let mogwai_data = entity ! { SCHEMA => id: "mogwai" , name: "Mogwai" , founded: 1995 } ;
256+ let mogwai_data = entity ! { SCHEMA => id: "mogwai" , name: "Mogwai" , founded: 1995 } ;
258257 let mogwai_key = make_band_key ( "mogwai" ) ;
259258 cache
260259 . set ( mogwai_key. clone ( ) , EntityV :: new ( mogwai_data. clone ( ) , 0 ) )
@@ -281,9 +280,8 @@ fn consecutive_modifications() {
281280 // Pre-populate the store with data so that we can test setting a field to
282281 // `Value::Null`.
283282 let store = {
284- let entities = vec ! [
285- entity! { SCHEMA => id: "mogwai" , name: "Mogwai" , label: "Chemikal Underground" , vid: 0i64 } ,
286- ] ;
283+ let entities =
284+ vec ! [ entity! { SCHEMA => id: "mogwai" , name: "Mogwai" , label: "Chemikal Underground" } ] ;
287285
288286 MockStore :: new ( entity_version_map ( "Band" , entities) )
289287 } ;
@@ -311,7 +309,7 @@ fn consecutive_modifications() {
311309 sort_by_entity_key( result. unwrap( ) . modifications) ,
312310 sort_by_entity_key( vec![ EntityModification :: overwrite(
313311 update_key,
314- entity! { SCHEMA => id: "mogwai" , name: "Mogwai" , founded: 1995 , vid : 0i64 } ,
312+ entity! { SCHEMA => id: "mogwai" , name: "Mogwai" , founded: 1995 } ,
315313 0 ,
316314 0
317315 ) ] )
@@ -477,13 +475,12 @@ fn create_account_entity(id: &str, name: &str, email: &str, age: i32, vid: i64)
477475 }
478476}
479477
480- fn create_wallet_entity ( id : & str , account_id : & Id , balance : i32 , vid : i64 ) -> EntityV {
478+ fn create_wallet_entity ( id : & str , account_id : & Id , balance : i32 ) -> Entity {
481479 let account_id = Value :: from ( account_id. clone ( ) ) ;
482- let e = entity ! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance} ;
483- EntityV :: new ( e, vid)
480+ entity ! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance }
484481}
485482fn create_wallet_operation ( id : & str , account_id : & Id , balance : i32 , vid : i64 ) -> EntityOperation {
486- let test_wallet = create_wallet_entity ( id, account_id, balance, vid) ;
483+ let test_wallet = EntityV :: new ( create_wallet_entity ( id, account_id, balance) , vid) ;
487484 EntityOperation :: Set {
488485 key : WALLET_TYPE . parse_key ( id) . unwrap ( ) ,
489486 data : test_wallet,
@@ -501,12 +498,12 @@ fn check_for_account_with_multiple_wallets() {
501498 causality_region : CausalityRegion :: ONCHAIN ,
502499 } ;
503500 let result = cache. load_related ( & request) . unwrap ( ) ;
504- let wallet_1 = create_wallet_entity ( "1" , & account_id, 67_i32 , 0 ) . e ;
505- let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 , 1 ) . e ;
506- let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 , 2 ) . e ;
501+ let wallet_1 = create_wallet_entity ( "1" , & account_id, 67_i32 ) ;
502+ let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 ) ;
503+ let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 ) ;
507504 let expeted_vec = vec ! [ wallet_1, wallet_2, wallet_3] ;
508505
509- assert_eq ! ( result, filter_vid ( expeted_vec) ) ;
506+ assert_eq ! ( result, expeted_vec) ;
510507 } ) ;
511508}
512509
@@ -521,10 +518,10 @@ fn check_for_account_with_single_wallet() {
521518 causality_region : CausalityRegion :: ONCHAIN ,
522519 } ;
523520 let result = cache. load_related ( & request) . unwrap ( ) ;
524- let wallet_1 = create_wallet_entity ( "4" , & account_id, 32_i32 , 1 ) . e ;
521+ let wallet_1 = create_wallet_entity ( "4" , & account_id, 32_i32 ) ;
525522 let expeted_vec = vec ! [ wallet_1] ;
526523
527- assert_eq ! ( result, filter_vid ( expeted_vec) ) ;
524+ assert_eq ! ( result, expeted_vec) ;
528525 } ) ;
529526}
530527
@@ -605,15 +602,14 @@ fn check_for_insert_async_store() {
605602 causality_region : CausalityRegion :: ONCHAIN ,
606603 } ;
607604 let result = cache. load_related ( & request) . unwrap ( ) ;
608- let wallet_1 = create_wallet_entity ( "4" , & account_id, 32_i32 , 21 ) . e ;
609- let wallet_2 = create_wallet_entity ( "5" , & account_id, 79_i32 , 22 ) . e ;
610- let wallet_3 = create_wallet_entity ( "6" , & account_id, 200_i32 , 23 ) . e ;
605+ let wallet_1 = create_wallet_entity ( "4" , & account_id, 32_i32 ) ;
606+ let wallet_2 = create_wallet_entity ( "5" , & account_id, 79_i32 ) ;
607+ let wallet_3 = create_wallet_entity ( "6" , & account_id, 200_i32 ) ;
611608 let expeted_vec = vec ! [ wallet_1, wallet_2, wallet_3] ;
612609
613- assert_eq ! ( filter_vid ( result) , filter_vid ( expeted_vec) ) ;
610+ assert_eq ! ( result, expeted_vec) ;
614611 } ) ;
615612}
616-
617613#[ test]
618614fn check_for_insert_async_not_related ( ) {
619615 run_store_test ( |mut cache, store, deployment, _writable| async move {
@@ -638,12 +634,12 @@ fn check_for_insert_async_not_related() {
638634 causality_region : CausalityRegion :: ONCHAIN ,
639635 } ;
640636 let result = cache. load_related ( & request) . unwrap ( ) ;
641- let wallet_1 = create_wallet_entity ( "1" , & account_id, 67_i32 , 1 ) . e ;
642- let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 , 2 ) . e ;
643- let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 , 3 ) . e ;
637+ let wallet_1 = create_wallet_entity ( "1" , & account_id, 67_i32 ) ;
638+ let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 ) ;
639+ let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 ) ;
644640 let expeted_vec = vec ! [ wallet_1, wallet_2, wallet_3] ;
645641
646- assert_eq ! ( result, filter_vid ( expeted_vec) ) ;
642+ assert_eq ! ( result, expeted_vec) ;
647643 } ) ;
648644}
649645
@@ -657,9 +653,8 @@ fn check_for_update_async_related() {
657653 let new_data = match wallet_entity_update {
658654 EntityOperation :: Set { ref data, .. } => data. clone ( ) ,
659655 _ => unreachable ! ( ) ,
660- }
661- . e ;
662- assert_ne ! ( writable. get( & entity_key) . unwrap( ) . unwrap( ) , new_data) ;
656+ } ;
657+ assert_ne ! ( writable. get( & entity_key) . unwrap( ) . unwrap( ) , new_data. e) ;
663658 // insert a new wallet
664659 transact_entity_operations (
665660 & store,
@@ -677,11 +672,11 @@ fn check_for_update_async_related() {
677672 causality_region : CausalityRegion :: ONCHAIN ,
678673 } ;
679674 let result = cache. load_related ( & request) . unwrap ( ) ;
680- let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 , 12 ) . e ;
681- let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 , 13 ) . e ;
682- let expeted_vec = vec ! [ new_data, wallet_2, wallet_3] ;
675+ let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 ) ;
676+ let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 ) ;
677+ let expeted_vec = vec ! [ new_data. e , wallet_2, wallet_3] ;
683678
684- assert_eq ! ( filter_vid ( result) , filter_vid ( expeted_vec) ) ;
679+ assert_eq ! ( result, expeted_vec) ;
685680 } ) ;
686681}
687682
@@ -707,55 +702,55 @@ fn check_for_delete_async_related() {
707702 causality_region : CausalityRegion :: ONCHAIN ,
708703 } ;
709704 let result = cache. load_related ( & request) . unwrap ( ) ;
710- let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 , 2 ) . e ;
711- let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 , 3 ) . e ;
705+ let wallet_2 = create_wallet_entity ( "2" , & account_id, 92_i32 ) ;
706+ let wallet_3 = create_wallet_entity ( "3" , & account_id, 192_i32 ) ;
712707 let expeted_vec = vec ! [ wallet_2, wallet_3] ;
713708
714- assert_eq ! ( result, filter_vid ( expeted_vec) ) ;
709+ assert_eq ! ( result, expeted_vec) ;
715710 } ) ;
716711}
717-
718712#[ test]
719713fn scoped_get ( ) {
720714 run_store_test ( |mut cache, _store, _deployment, _writable| async move {
721715 // Key for an existing entity that is in the store
722716 let account1 = ACCOUNT_TYPE . parse_id ( "1" ) . unwrap ( ) ;
723717 let key1 = WALLET_TYPE . parse_key ( "1" ) . unwrap ( ) ;
724- let wallet1 = create_wallet_entity ( "1" , & account1, 67 , 1 ) ;
718+ let wallet1 = create_wallet_entity ( "1" , & account1, 67 ) ;
725719
726720 // Create a new entity that is not in the store
727721 let account5 = ACCOUNT_TYPE . parse_id ( "5" ) . unwrap ( ) ;
728- let wallet5 = create_wallet_entity ( "5" , & account5, 100 , 5 ) ;
722+ let wallet5 = create_wallet_entity ( "5" , & account5, 100 ) ;
729723 let key5 = WALLET_TYPE . parse_key ( "5" ) . unwrap ( ) ;
730- cache. set ( key5. clone ( ) , wallet5. clone ( ) ) . unwrap ( ) ;
724+ cache
725+ . set ( key5. clone ( ) , EntityV :: new ( wallet5. clone ( ) , 5 ) )
726+ . unwrap ( ) ;
731727
732728 // For the new entity, we can retrieve it with either scope
733729 let act5 = cache. get ( & key5, GetScope :: InBlock ) . unwrap ( ) ;
734- assert_eq ! ( Some ( & wallet5. e ) , act5. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
730+ assert_eq ! ( Some ( & wallet5) , act5. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
735731 let act5 = cache. get ( & key5, GetScope :: Store ) . unwrap ( ) ;
736- assert_eq ! ( Some ( & wallet5. e ) , act5. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
732+ assert_eq ! ( Some ( & wallet5) , act5. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
737733
738734 // For an entity in the store, we can not get it `InBlock` but with
739735 // `Store`
740736 let act1 = cache. get ( & key1, GetScope :: InBlock ) . unwrap ( ) ;
741737 assert_eq ! ( None , act1) ;
742738 let act1 = cache. get ( & key1, GetScope :: Store ) . unwrap ( ) ;
743- assert_eq ! (
744- filter_vid( vec![ wallet1. e. clone( ) ] ) ,
745- vec![ act1. as_ref( ) . map( |e| e. as_ref( ) ) . unwrap( ) . clone( ) ]
746- ) ;
739+ assert_eq ! ( Some ( & wallet1) , act1. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
747740 // Even after reading from the store, the entity is not visible with
748741 // `InBlock`
749742 let act1 = cache. get ( & key1, GetScope :: InBlock ) . unwrap ( ) ;
750743 assert_eq ! ( None , act1) ;
751744 // But if it gets updated, it becomes visible with either scope
752745 let mut wallet1 = wallet1;
753- wallet1. e . set ( "balance" , 70 ) . unwrap ( ) ;
754- cache. set ( key1. clone ( ) , wallet1. clone ( ) ) . unwrap ( ) ;
746+ wallet1. set ( "balance" , 70 ) . unwrap ( ) ;
747+ cache
748+ . set ( key1. clone ( ) , EntityV :: new ( wallet1. clone ( ) , 1 ) )
749+ . unwrap ( ) ;
755750 let act1 = cache. get ( & key1, GetScope :: InBlock ) . unwrap ( ) ;
756- assert_eq ! ( Some ( & wallet1. e ) , act1. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
751+ assert_eq ! ( Some ( & wallet1) , act1. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
757752 let act1 = cache. get ( & key1, GetScope :: Store ) . unwrap ( ) ;
758- assert_eq ! ( Some ( & wallet1. e ) , act1. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
753+ assert_eq ! ( Some ( & wallet1) , act1. as_ref( ) . map( |e| e. as_ref( ) ) ) ;
759754 } )
760755}
761756
0 commit comments