@@ -29,6 +29,32 @@ const SCHEMA_GQL: &str = "
2929 id: ID!,
3030 count: Int!,
3131 }
32+ type BytesId @entity {
33+ id: Bytes!,
34+ value: String!
35+ }
36+ type Int8Id @entity {
37+ id: Int8!,
38+ value: String!
39+ }
40+ type StringId @entity {
41+ id: String!,
42+ value: String!
43+ }
44+ type PoolCreated @entity(immutable: true) {
45+ id: Bytes!,
46+ token0: Bytes!,
47+ token1: Bytes!,
48+ fee: Int!,
49+ tickSpacing: Int!,
50+ pool: Bytes!,
51+ blockNumber: BigInt!,
52+ blockTimestamp: BigInt!,
53+ transactionHash: Bytes!,
54+ transactionFrom: Bytes!,
55+ transactionGasPrice: BigInt!,
56+ logIndex: BigInt!
57+ }
3258" ;
3359
3460const COUNTER : & str = "Counter" ;
@@ -406,3 +432,71 @@ fn read_immutable_only_range_test() {
406432 assert_eq ! ( e. len( ) , 4 ) ;
407433 } )
408434}
435+
436+ #[ test]
437+ fn read_range_pool_created_test ( ) {
438+ run_test ( |store, writable, sourceable, deployment| async move {
439+ let result_entities = vec ! [
440+ format!( "(1, [EntitySourceOperation {{ entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity {{ blockNumber: BigInt(12369621), blockTimestamp: BigInt(1620243254), fee: Int(500), id: Bytes(0xff80818283848586), logIndex: BigInt(0), pool: Bytes(0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8), tickSpacing: Int(10), token0: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000000) }}, vid: 1 }}])" ) ,
441+ format!( "(2, [EntitySourceOperation {{ entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity {{ blockNumber: BigInt(12369622), blockTimestamp: BigInt(1620243255), fee: Int(3000), id: Bytes(0xff90919293949596), logIndex: BigInt(1), pool: Bytes(0x4585fe77225b41b697c938b018e2ac67ac5a20c0), tickSpacing: Int(60), token0: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000001) }}, vid: 2 }}])" ) ,
442+ ] ;
443+
444+ // Rest of the test remains the same
445+ let subgraph_store = store. subgraph_store ( ) ;
446+ writable. deployment_synced ( ) . unwrap ( ) ;
447+
448+ let pool_created_type = TEST_SUBGRAPH_SCHEMA . entity_type ( "PoolCreated" ) . unwrap ( ) ;
449+ let entity_types = vec ! [ pool_created_type. clone( ) ] ;
450+
451+ for count in ( 1 ..=2 ) . map ( |x| x as i64 ) {
452+ let id = if count == 1 {
453+ "0xff80818283848586"
454+ } else {
455+ "0xff90919293949596"
456+ } ;
457+
458+ let data = entity ! { TEST_SUBGRAPH_SCHEMA =>
459+ id: id,
460+ token0: if count == 1 { "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" } else { "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599" } ,
461+ token1: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" ,
462+ fee: if count == 1 { 500 } else { 3000 } ,
463+ tickSpacing: if count == 1 { 10 } else { 60 } ,
464+ pool: if count == 1 { "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8" } else { "0x4585fe77225b41b697c938b018e2ac67ac5a20c0" } ,
465+ blockNumber: 12369621 + count - 1 ,
466+ blockTimestamp: 1620243254 + count - 1 ,
467+ transactionHash: format!( "0x1234{:0>76}" , if count == 1 { "0" } else { "1" } ) ,
468+ transactionFrom: if count == 1 { "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" } else { "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599" } ,
469+ transactionGasPrice: 100000000000i64 ,
470+ logIndex: count - 1
471+ } ;
472+
473+ let key = pool_created_type. parse_key ( id) . unwrap ( ) ;
474+ let op = EntityOperation :: Set {
475+ key : key. clone ( ) ,
476+ data : EntityV :: new ( data, count) ,
477+ } ;
478+
479+ transact_entity_operations (
480+ & subgraph_store,
481+ & deployment,
482+ block_pointer ( count as u8 ) ,
483+ vec ! [ op] ,
484+ )
485+ . await
486+ . unwrap ( ) ;
487+ }
488+ writable. flush ( ) . await . unwrap ( ) ;
489+ writable. deployment_synced ( ) . unwrap ( ) ;
490+
491+ let br: Range < BlockNumber > = 0 ..18 ;
492+ let e: BTreeMap < i32 , Vec < EntitySourceOperation > > = sourceable
493+ . get_range ( entity_types. clone ( ) , CausalityRegion :: ONCHAIN , br. clone ( ) )
494+ . unwrap ( ) ;
495+ assert_eq ! ( e. len( ) , 2 ) ;
496+ for en in & e {
497+ let index = * en. 0 - 1 ;
498+ let a = result_entities[ index as usize ] . clone ( ) ;
499+ assert_eq ! ( a, format!( "{:?}" , en) ) ;
500+ }
501+ } )
502+ }
0 commit comments