11use acuity_index_substrate:: { shared:: * , substrate:: * , websockets:: * , * } ;
22
3- use crate :: { ideal :: SubscriptionId , ChainKey , IdealIndexer } ;
3+ use crate :: { ChainKey , IdealIndexer } ;
44
55#[ tokio:: test]
66async fn test_process_msg_account_balance ( ) {
@@ -71,20 +71,20 @@ async fn test_process_msg_extrinsic_hash() {
7171 assert_eq ! ( events[ 2 ] . block_number, 4 ) ;
7272}
7373
74- // IDN-specific tests for SubstrateKey::SubscriptionId indexing
74+ // IDN-specific tests for SubstrateKey::SubscriptionId indexing using upstream types
7575
7676#[ tokio:: test]
7777async fn test_subscription_id_indexing ( ) {
7878 let db_config = sled:: Config :: new ( ) . temporary ( true ) ;
7979 let trees = open_trees :: < IdealIndexer > ( db_config) . unwrap ( ) ;
8080 let indexer = Indexer :: < IdealIndexer > :: new_test ( trees. clone ( ) ) ;
8181
82- // Create different subscription IDs
83- let sub_id_1 = SubscriptionId :: new ( [ 1u8 ; 32 ] ) ;
84- let sub_id_2 = SubscriptionId :: new ( [ 2u8 ; 32 ] ) ;
82+ // Create different subscription IDs using upstream SubscriptionId type
83+ let sub_id_1 = SubscriptionId :: from ( [ 1u8 ; 32 ] ) ;
84+ let sub_id_2 = SubscriptionId :: from ( [ 2u8 ; 32 ] ) ;
8585
86- let key1 = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id_1. to_u32 ( ) ) ) ;
87- let key2 = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id_2. to_u32 ( ) ) ) ;
86+ let key1 = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id_1) ) ;
87+ let key2 = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id_2) ) ;
8888
8989 // Index events for subscription 1
9090 indexer. index_event ( key1. clone ( ) , 100 , 0 ) . unwrap ( ) ;
@@ -117,24 +117,24 @@ async fn test_subscription_id_indexing() {
117117}
118118
119119#[ tokio:: test]
120- async fn test_h256_to_u32_conversion ( ) {
121- // Test the conversion logic
120+ async fn test_h256_to_subscription_id_conversion ( ) {
121+ // Test the upstream SubscriptionId type conversion
122122 let test_bytes = [
123123 0x78 , 0x56 , 0x34 , 0x12 , 0xAB , 0xCD , 0xEF , 0x00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
124124 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
125125 ] ;
126- let sub_id = SubscriptionId :: new ( test_bytes) ;
126+ let sub_id = SubscriptionId :: from ( test_bytes) ;
127127
128- // Should convert to 0x12345678 (little-endian)
129- assert_eq ! ( sub_id . to_u32 ( ) , 0x12345678 ) ;
128+ // Verify that the SubscriptionId stores the full [u8; 32]
129+ assert_eq ! ( < SubscriptionId as AsRef < [ u8 ; 32 ] >> :: as_ref ( & sub_id ) , & test_bytes ) ;
130130
131131 // Test another case
132132 let test_bytes2 = [
133133 0xFF , 0x00 , 0x00 , 0x00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
134134 0 , 0 , 0 , 0 , 0 , 0 ,
135135 ] ;
136- let sub_id2 = SubscriptionId :: new ( test_bytes2) ;
137- assert_eq ! ( sub_id2 . to_u32 ( ) , 0x000000FF ) ;
136+ let sub_id2 = SubscriptionId :: from ( test_bytes2) ;
137+ assert_eq ! ( < SubscriptionId as AsRef < [ u8 ; 32 ] >> :: as_ref ( & sub_id2 ) , & test_bytes2 ) ;
138138}
139139
140140#[ tokio:: test]
@@ -143,8 +143,8 @@ async fn test_multiple_subscription_events_same_block() {
143143 let trees = open_trees :: < IdealIndexer > ( db_config) . unwrap ( ) ;
144144 let indexer = Indexer :: < IdealIndexer > :: new_test ( trees. clone ( ) ) ;
145145
146- let sub_id = SubscriptionId :: new ( [ 1u8 ; 32 ] ) ;
147- let key = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id. to_u32 ( ) ) ) ;
146+ let sub_id = SubscriptionId :: from ( [ 1u8 ; 32 ] ) ;
147+ let key = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id) ) ;
148148 let block_number = 100 ;
149149
150150 // Index multiple events in the same block
@@ -171,8 +171,8 @@ async fn test_subscription_events_across_blocks() {
171171 let trees = open_trees :: < IdealIndexer > ( db_config) . unwrap ( ) ;
172172 let indexer = Indexer :: < IdealIndexer > :: new_test ( trees. clone ( ) ) ;
173173
174- let sub_id = SubscriptionId :: new ( [ 1u8 ; 32 ] ) ;
175- let key = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id. to_u32 ( ) ) ) ;
174+ let sub_id = SubscriptionId :: from ( [ 1u8 ; 32 ] ) ;
175+ let key = Key :: Substrate ( SubstrateKey :: SubscriptionId ( sub_id) ) ;
176176
177177 // Index events across multiple blocks in non-sequential order
178178 indexer. index_event ( key. clone ( ) , 105 , 1 ) . unwrap ( ) ;
0 commit comments