Skip to content

Commit e742a6f

Browse files
author
Zoran Cvetkov
committed
cleanup
1 parent f05c8c1 commit e742a6f

File tree

1 file changed

+43
-47
lines changed

1 file changed

+43
-47
lines changed

store/test-store/tests/graph/entity_cache.rs

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -716,53 +716,49 @@ fn check_for_delete_async_related() {
716716
});
717717
}
718718

719-
// #[test]
720-
// fn scoped_get() {
721-
// run_store_test(|mut cache, _store, _deployment, _writable| async move {
722-
// // Key for an existing entity that is in the store
723-
// let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
724-
// let key1 = WALLET_TYPE.parse_key("1").unwrap();
725-
// let wallet1 = create_wallet_entity("1", &account1, 67, 1);
726-
727-
// // Create a new entity that is not in the store
728-
// let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
729-
// let wallet5 = create_wallet_entity("5", &account5, 100, 5);
730-
// let key5 = WALLET_TYPE.parse_key("5").unwrap();
731-
// cache
732-
// .set(key5.clone(), EntityV::new(wallet5.clone(), 5))
733-
// .unwrap();
734-
735-
// // For the new entity, we can retrieve it with either scope
736-
// let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
737-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
738-
// let act5 = cache.get(&key5, GetScope::Store).unwrap();
739-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
740-
741-
// // For an entity in the store, we can not get it `InBlock` but with
742-
// // `Store`
743-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
744-
// assert_eq!(None, act1);
745-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
746-
// assert_eq!(
747-
// filter_vid(vec![wallet1.clone()]),
748-
// vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
749-
// );
750-
// // Even after reading from the store, the entity is not visible with
751-
// // `InBlock`
752-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
753-
// assert_eq!(None, act1);
754-
// // But if it gets updated, it becomes visible with either scope
755-
// let mut wallet1 = wallet1;
756-
// wallet1.set("balance", 70).unwrap();
757-
// cache
758-
// .set(key1.clone(), EntityV::new(wallet1.clone(), 1))
759-
// .unwrap();
760-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
761-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
762-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
763-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
764-
// })
765-
// }
719+
#[test]
720+
fn scoped_get() {
721+
run_store_test(|mut cache, _store, _deployment, _writable| async move {
722+
// Key for an existing entity that is in the store
723+
let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
724+
let key1 = WALLET_TYPE.parse_key("1").unwrap();
725+
let wallet1 = create_wallet_entity("1", &account1, 67, 1);
726+
727+
// Create a new entity that is not in the store
728+
let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
729+
let wallet5 = create_wallet_entity("5", &account5, 100, 5);
730+
let key5 = WALLET_TYPE.parse_key("5").unwrap();
731+
cache.set(key5.clone(), wallet5.clone()).unwrap();
732+
733+
// For the new entity, we can retrieve it with either scope
734+
let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
735+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
736+
let act5 = cache.get(&key5, GetScope::Store).unwrap();
737+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
738+
739+
// For an entity in the store, we can not get it `InBlock` but with
740+
// `Store`
741+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
742+
assert_eq!(None, act1);
743+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
744+
assert_eq!(
745+
filter_vid(vec![wallet1.e.clone()]),
746+
vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
747+
);
748+
// Even after reading from the store, the entity is not visible with
749+
// `InBlock`
750+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
751+
assert_eq!(None, act1);
752+
// But if it gets updated, it becomes visible with either scope
753+
let mut wallet1 = wallet1;
754+
wallet1.e.set("balance", 70).unwrap();
755+
cache.set(key1.clone(), wallet1.clone()).unwrap();
756+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
757+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
758+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
759+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
760+
})
761+
}
766762

767763
/// Entities should never contain a `__typename` or `g$parent_id` field, if
768764
/// they do, that can cause PoI divergences, because entities will differ

0 commit comments

Comments
 (0)