@@ -29,6 +29,20 @@ const SCHEMA_GQL: &str = "
2929 id: ID!,
3030 count: Int!,
3131 }
32+ type PoolCreated @entity(immutable: true) {
33+ id: Bytes!,
34+ token0: Bytes!,
35+ token1: Bytes!,
36+ fee: Int!,
37+ tickSpacing: Int!,
38+ pool: Bytes!,
39+ blockNumber: BigInt!,
40+ blockTimestamp: BigInt!,
41+ transactionHash: Bytes!,
42+ transactionFrom: Bytes!,
43+ transactionGasPrice: BigInt!,
44+ logIndex: BigInt!
45+ }
3246" ;
3347
3448const COUNTER : & str = "Counter" ;
@@ -406,3 +420,71 @@ fn read_immutable_only_range_test() {
406420 assert_eq ! ( e. len( ) , 4 ) ;
407421 } )
408422}
423+
424+ #[ test]
425+ fn read_range_pool_created_test ( ) {
426+ run_test ( |store, writable, sourceable, deployment| async move {
427+ let result_entities = vec ! [
428+ 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 }}])" ) ,
429+ 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 }}])" ) ,
430+ ] ;
431+
432+ // Rest of the test remains the same
433+ let subgraph_store = store. subgraph_store ( ) ;
434+ writable. deployment_synced ( ) . unwrap ( ) ;
435+
436+ let pool_created_type = TEST_SUBGRAPH_SCHEMA . entity_type ( "PoolCreated" ) . unwrap ( ) ;
437+ let entity_types = vec ! [ pool_created_type. clone( ) ] ;
438+
439+ for count in ( 1 ..=2 ) . map ( |x| x as i64 ) {
440+ let id = if count == 1 {
441+ "0xff80818283848586"
442+ } else {
443+ "0xff90919293949596"
444+ } ;
445+
446+ let data = entity ! { TEST_SUBGRAPH_SCHEMA =>
447+ id: id,
448+ token0: if count == 1 { "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" } else { "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599" } ,
449+ token1: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" ,
450+ fee: if count == 1 { 500 } else { 3000 } ,
451+ tickSpacing: if count == 1 { 10 } else { 60 } ,
452+ pool: if count == 1 { "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8" } else { "0x4585fe77225b41b697c938b018e2ac67ac5a20c0" } ,
453+ blockNumber: 12369621 + count - 1 ,
454+ blockTimestamp: 1620243254 + count - 1 ,
455+ transactionHash: format!( "0x1234{:0>76}" , if count == 1 { "0" } else { "1" } ) ,
456+ transactionFrom: if count == 1 { "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" } else { "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599" } ,
457+ transactionGasPrice: 100000000000i64 ,
458+ logIndex: count - 1
459+ } ;
460+
461+ let key = pool_created_type. parse_key ( id) . unwrap ( ) ;
462+ let op = EntityOperation :: Set {
463+ key : key. clone ( ) ,
464+ data : EntityV :: new ( data, count) ,
465+ } ;
466+
467+ transact_entity_operations (
468+ & subgraph_store,
469+ & deployment,
470+ block_pointer ( count as u8 ) ,
471+ vec ! [ op] ,
472+ )
473+ . await
474+ . unwrap ( ) ;
475+ }
476+ writable. flush ( ) . await . unwrap ( ) ;
477+ writable. deployment_synced ( ) . unwrap ( ) ;
478+
479+ let br: Range < BlockNumber > = 0 ..18 ;
480+ let e: BTreeMap < i32 , Vec < EntitySourceOperation > > = sourceable
481+ . get_range ( entity_types. clone ( ) , CausalityRegion :: ONCHAIN , br. clone ( ) )
482+ . unwrap ( ) ;
483+ assert_eq ! ( e. len( ) , 2 ) ;
484+ for en in & e {
485+ let index = * en. 0 - 1 ;
486+ let a = result_entities[ index as usize ] . clone ( ) ;
487+ assert_eq ! ( a, format!( "{:?}" , en) ) ;
488+ }
489+ } )
490+ }
0 commit comments