@@ -90,24 +90,46 @@ fn main_chain_scripts() -> MainChainScripts {
90
90
}
91
91
}
92
92
93
- macro_rules! with_migration_versions {
94
- ( $( async fn $name: ident( $pool : ident: PgPool ) $body: block ) * ) => {
93
+ macro_rules! with_migration_versions_and_caching {
94
+ ( $( async fn $name: ident( $data_source : ident: & dyn TokenBridgeDataSource < ByteString > ) $body: block ) * ) => {
95
95
$(
96
96
mod $name {
97
+ use super :: * ;
98
+
99
+ async fn $name( $data_source: & dyn TokenBridgeDataSource <ByteString >) $body
100
+
101
+ mod uncached {
97
102
use super :: * ;
103
+ #[ allow( unused_imports) ]
98
104
use pretty_assertions:: assert_eq;
99
105
100
- async fn $name( $pool: PgPool ) $body
106
+ #[ sqlx:: test( migrations = "./testdata/bridge/migrations-tx-in-enabled" ) ]
107
+ async fn tx_in_enabled( pool: PgPool ) {
108
+ $name( & create_data_source( pool) ) . await
109
+ }
110
+
111
+ #[ sqlx:: test( migrations = "./testdata/bridge/migrations-tx-in-consumed" ) ]
112
+ async fn tx_in_consumed( pool: PgPool ) {
113
+ $name( & create_data_source( pool) ) . await
114
+ }
115
+ }
116
+
117
+ mod cached {
118
+ use super :: * ;
119
+ #[ allow( unused_imports) ]
120
+ use pretty_assertions:: assert_eq;
101
121
102
122
#[ sqlx:: test( migrations = "./testdata/bridge/migrations-tx-in-enabled" ) ]
103
- async fn tx_in_enabled( $ pool: PgPool ) {
104
- $name( $ pool) . await
123
+ async fn tx_in_enabled( pool: PgPool ) {
124
+ $name( & create_cached_source ( pool) ) . await
105
125
}
106
126
107
127
#[ sqlx:: test( migrations = "./testdata/bridge/migrations-tx-in-consumed" ) ]
108
- async fn tx_in_consumed( $ pool: PgPool ) {
109
- $name( $ pool) . await
128
+ async fn tx_in_consumed( pool: PgPool ) {
129
+ $name( & create_cached_source ( pool) ) . await
110
130
}
131
+ }
132
+
111
133
}
112
134
) *
113
135
}
@@ -145,9 +167,8 @@ fn create_cached_source(pool: PgPool) -> CachedTokenBridgeDataSourceImpl {
145
167
CachedTokenBridgeDataSourceImpl :: new ( pool, None , blocks, cache_lookahead)
146
168
}
147
169
148
- with_migration_versions ! {
149
- async fn gets_transfers_from_init_to_block_2( pool: PgPool ) {
150
- let data_source: & dyn TokenBridgeDataSource <ByteString > = & create_data_source( pool) ;
170
+ with_migration_versions_and_caching ! {
171
+ async fn gets_transfers_from_init_to_block_2( data_source: & dyn TokenBridgeDataSource <ByteString >) {
151
172
let data_checkpoint = BridgeDataCheckpoint :: Utxo ( last_ics_init_utxo( ) ) ;
152
173
let current_mc_block = block_2_hash( ) ;
153
174
let max_transfers = 2 ;
@@ -163,8 +184,7 @@ with_migration_versions! {
163
184
assert_eq!( new_checkpoint, BridgeDataCheckpoint :: Utxo ( user_transfer_1_utxo( ) ) )
164
185
}
165
186
166
- async fn gets_transfers_from_init_to_block_4( pool: PgPool ) {
167
- let data_source: & dyn TokenBridgeDataSource <ByteString > = & create_data_source( pool) ;
187
+ async fn gets_transfers_from_init_to_block_4( data_source: & dyn TokenBridgeDataSource <ByteString >) {
168
188
let data_checkpoint = BridgeDataCheckpoint :: Utxo ( last_ics_init_utxo( ) ) ;
169
189
let current_mc_block = block_4_hash( ) ;
170
190
let max_transfers = 4 ;
@@ -183,8 +203,7 @@ with_migration_versions! {
183
203
assert_eq!( new_checkpoint, BridgeDataCheckpoint :: Utxo ( invalid_transfer_1_utxo( ) ) )
184
204
}
185
205
186
- async fn accepts_block_checkpoint( pool: PgPool ) {
187
- let data_source: & dyn TokenBridgeDataSource <ByteString > = & create_data_source( pool) ;
206
+ async fn accepts_block_checkpoint( data_source: & dyn TokenBridgeDataSource <ByteString >) {
188
207
let data_checkpoint = BridgeDataCheckpoint :: Block ( McBlockNumber ( 1 ) ) ;
189
208
let current_mc_block = block_4_hash( ) ;
190
209
let max_transfers = 4 ;
@@ -203,8 +222,7 @@ with_migration_versions! {
203
222
assert_eq!( new_checkpoint, BridgeDataCheckpoint :: Utxo ( invalid_transfer_1_utxo( ) ) )
204
223
}
205
224
206
- async fn returns_block_checkpoint_when_no_transfers_are_found( pool: PgPool ) {
207
- let data_source: & dyn TokenBridgeDataSource <ByteString > = & create_data_source( pool) ;
225
+ async fn returns_block_checkpoint_when_no_transfers_are_found( data_source: & dyn TokenBridgeDataSource <ByteString >) {
208
226
let data_checkpoint = BridgeDataCheckpoint :: Block ( McBlockNumber ( 6 ) ) ;
209
227
let current_mc_block = block_8_hash( ) ;
210
228
let max_transfers = 32 ;
@@ -219,8 +237,7 @@ with_migration_versions! {
219
237
assert_eq!( new_checkpoint, BridgeDataCheckpoint :: Block ( McBlockNumber ( 8 ) ) )
220
238
}
221
239
222
- async fn returns_block_checkpoint_when_less_than_maximum_transfers_found( pool: PgPool ) {
223
- let data_source: & dyn TokenBridgeDataSource <ByteString > = & create_data_source( pool) ;
240
+ async fn returns_block_checkpoint_when_less_than_maximum_transfers_found( data_source: & dyn TokenBridgeDataSource <ByteString >) {
224
241
let data_checkpoint = BridgeDataCheckpoint :: Block ( McBlockNumber ( 0 ) ) ;
225
242
let current_mc_block = block_8_hash( ) ;
226
243
let max_transfers = 32 ;
0 commit comments