@@ -26,105 +26,120 @@ const BLOCK_6: McBlockHash =
26
26
const BLOCK_7 : McBlockHash =
27
27
McBlockHash ( hex ! ( "b702000000000000000000000000000000000000000000000000000000000008" ) ) ;
28
28
29
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
30
- async fn test_governed_map_fails_on_wrong_block_hash ( pool : PgPool ) {
31
- let source = make_source ( pool, TxInConfiguration :: Consumed ) ;
32
- let mc_block =
33
- McBlockHash ( hex ! ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ) ;
34
- let result = source. get_mapping_changes ( None , mc_block, scripts ( ) ) . await ;
35
- assert_err ! ( result) ;
36
- }
29
+ macro_rules! with_migration_versions {
30
+ ( $( async fn $name: ident( $pool: ident: PgPool , $tx_in_cfg: ident: TxInConfiguration ) $body: block ) * ) => {
37
31
38
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
39
- async fn test_cached_governed_map_fails_on_wrong_block_hash ( pool : PgPool ) {
40
- let source = make_cached_source ( pool, TxInConfiguration :: Consumed ) . await ;
41
- let mc_block =
42
- McBlockHash ( hex ! ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ) ;
43
- let result = source. get_mapping_changes ( None , mc_block, scripts ( ) ) . await ;
44
- assert_err ! ( result) ;
45
- }
32
+ $(
33
+ paste:: paste!(
34
+ async fn $name( $pool: PgPool , $tx_in_cfg: TxInConfiguration ) $body
46
35
47
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
48
- async fn test_governed_map_insert ( pool : PgPool ) {
49
- let source = make_source ( pool, TxInConfiguration :: Consumed ) ;
50
- let mut result = source. get_mapping_changes ( None , BLOCK_1 , scripts ( ) ) . await . unwrap ( ) ;
51
- result. sort ( ) ;
52
- let expected = vec ! [
53
- (
54
- "key1" . to_owned( ) ,
55
- Some ( ByteString :: from( hex!( "11111111111111111111111111111111" ) . to_vec( ) ) ) ,
56
- ) ,
57
- (
58
- "key2" . to_owned( ) ,
59
- Some ( ByteString :: from( hex!( "22222222222222222222222222222222" ) . to_vec( ) ) ) ,
60
- ) ,
61
- ] ;
62
- assert_eq ! ( result, expected) ;
63
- }
36
+ #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v1" ) ]
37
+ async fn [ <$name _v1>] ( $pool: PgPool ) {
38
+ $name( $pool, TxInConfiguration :: Legacy ) . await
39
+ }
64
40
65
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
66
- async fn test_cached_governed_map_insert ( pool : PgPool ) {
67
- let source = make_cached_source ( pool, TxInConfiguration :: Consumed ) . await ;
68
- let result = source. get_mapping_changes ( None , BLOCK_1 , scripts ( ) ) . await . unwrap ( ) ;
69
-
70
- let expected = vec ! [
71
- (
72
- "key2" . to_owned( ) ,
73
- Some ( ByteString :: from( hex!( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) . to_vec( ) ) ) ,
74
- ) ,
75
- (
76
- "key1" . to_owned( ) ,
77
- Some ( ByteString :: from( hex!( "11111111111111111111111111111111" ) . to_vec( ) ) ) ,
78
- ) ,
79
- (
80
- "key2" . to_owned( ) ,
81
- Some ( ByteString :: from( hex!( "22222222222222222222222222222222" ) . to_vec( ) ) ) ,
82
- ) ,
83
- ] ;
84
- assert_eq ! ( result, expected) ;
41
+ #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
42
+ async fn [ <$name _v2>] ( $pool: PgPool ) {
43
+ $name( $pool, TxInConfiguration :: Consumed ) . await
44
+ }
45
+ ) ;
46
+ ) *
47
+ } ;
85
48
}
86
49
87
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
88
- async fn test_governed_map_delete ( pool : PgPool ) {
89
- let source = make_source ( pool, TxInConfiguration :: Consumed ) ;
90
- let result = source. get_mapping_changes ( Some ( BLOCK_1 ) , BLOCK_4 , scripts ( ) ) . await ;
91
- let expected = vec ! [ ( "key1" . to_owned( ) , None ) ] ;
92
- assert_eq ! ( result. unwrap( ) , expected) ;
93
- }
50
+ with_migration_versions ! {
51
+ async fn test_governed_map_fails_on_wrong_block_hash( pool: PgPool , tx_in_config: TxInConfiguration ) {
52
+ let source = make_source( pool, tx_in_config) ;
53
+ let mc_block =
54
+ McBlockHash ( hex!( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ) ;
55
+ let result = source. get_mapping_changes( None , mc_block, scripts( ) ) . await ;
56
+ assert_err!( result) ;
57
+ }
94
58
95
- # [ sqlx :: test ( migrations = "./testdata/governed-map/migrations-v2" ) ]
96
- async fn test_cached_governed_map_delete ( pool : PgPool ) {
97
- let source = make_cached_source ( pool , TxInConfiguration :: Consumed ) . await ;
98
- let result = source . get_mapping_changes ( Some ( BLOCK_1 ) , BLOCK_4 , scripts ( ) ) . await ;
99
- let expected = vec ! [ ( "key1" . to_owned ( ) , None ) ] ;
100
- assert_eq ! ( result. unwrap ( ) , expected ) ;
101
- }
59
+ async fn test_cached_governed_map_fails_on_wrong_block_hash ( pool : PgPool , tx_in_config : TxInConfiguration ) {
60
+ let source = make_cached_source ( pool, tx_in_config ) . await ;
61
+ let mc_block =
62
+ McBlockHash ( hex! ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ) ;
63
+ let result = source . get_mapping_changes ( None , mc_block , scripts ( ) ) . await ;
64
+ assert_err !( result) ;
65
+ }
102
66
103
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
104
- async fn test_governed_map_upsert ( pool : PgPool ) {
105
- let source = make_source ( pool, TxInConfiguration :: Consumed ) ;
106
- let mut result = source. get_mapping_changes ( Some ( BLOCK_6 ) , BLOCK_7 , scripts ( ) ) . await . unwrap ( ) ;
107
- result. sort ( ) ;
108
- let expected = vec ! [ (
109
- "key3" . to_owned( ) ,
110
- Some ( ByteString :: from( hex!( "44444444444444444444444444444444" ) . to_vec( ) ) ) ,
111
- ) ] ;
112
- assert_eq ! ( result, expected) ;
113
- }
67
+ async fn test_governed_map_insert( pool: PgPool , tx_in_config: TxInConfiguration ) {
68
+ let source = make_source( pool, tx_in_config) ;
69
+ let mut result = source. get_mapping_changes( None , BLOCK_1 , scripts( ) ) . await . unwrap( ) ;
70
+ result. sort( ) ;
71
+ let expected = vec![
72
+ (
73
+ "key1" . to_owned( ) ,
74
+ Some ( ByteString :: from( hex!( "11111111111111111111111111111111" ) . to_vec( ) ) ) ,
75
+ ) ,
76
+ (
77
+ "key2" . to_owned( ) ,
78
+ Some ( ByteString :: from( hex!( "22222222222222222222222222222222" ) . to_vec( ) ) ) ,
79
+ ) ,
80
+ ] ;
81
+ assert_eq!( result, expected) ;
82
+ }
83
+
84
+ async fn test_cached_governed_map_insert( pool: PgPool , tx_in_config: TxInConfiguration ) {
85
+ let source = make_cached_source( pool, tx_in_config) . await ;
86
+ let result = source. get_mapping_changes( None , BLOCK_1 , scripts( ) ) . await . unwrap( ) ;
114
87
115
- #[ sqlx:: test( migrations = "./testdata/governed-map/migrations-v2" ) ]
116
- async fn test_cached_governed_map_upsert ( pool : PgPool ) {
117
- let source = make_cached_source ( pool, TxInConfiguration :: Consumed ) . await ;
118
- let mut result = source. get_mapping_changes ( Some ( BLOCK_6 ) , BLOCK_7 , scripts ( ) ) . await . unwrap ( ) ;
119
- result. sort ( ) ;
120
- let expected = vec ! [
121
- ( "key3" . to_owned( ) , None ) ,
122
- (
88
+ let expected = vec![
89
+ (
90
+ "key2" . to_owned( ) ,
91
+ Some ( ByteString :: from( hex!( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) . to_vec( ) ) ) ,
92
+ ) ,
93
+ (
94
+ "key1" . to_owned( ) ,
95
+ Some ( ByteString :: from( hex!( "11111111111111111111111111111111" ) . to_vec( ) ) ) ,
96
+ ) ,
97
+ (
98
+ "key2" . to_owned( ) ,
99
+ Some ( ByteString :: from( hex!( "22222222222222222222222222222222" ) . to_vec( ) ) ) ,
100
+ ) ,
101
+ ] ;
102
+ assert_eq!( result, expected) ;
103
+ }
104
+
105
+ async fn test_governed_map_delete( pool: PgPool , tx_in_config: TxInConfiguration ) {
106
+ let source = make_source( pool, tx_in_config) ;
107
+ let result = source. get_mapping_changes( Some ( BLOCK_1 ) , BLOCK_4 , scripts( ) ) . await ;
108
+ let expected = vec![ ( "key1" . to_owned( ) , None ) ] ;
109
+ assert_eq!( result. unwrap( ) , expected) ;
110
+ }
111
+
112
+ async fn test_cached_governed_map_delete( pool: PgPool , tx_in_config: TxInConfiguration ) {
113
+ let source = make_cached_source( pool, tx_in_config) . await ;
114
+ let result = source. get_mapping_changes( Some ( BLOCK_1 ) , BLOCK_4 , scripts( ) ) . await ;
115
+ let expected = vec![ ( "key1" . to_owned( ) , None ) ] ;
116
+ assert_eq!( result. unwrap( ) , expected) ;
117
+ }
118
+
119
+ async fn test_governed_map_upsert( pool: PgPool , tx_in_config: TxInConfiguration ) {
120
+ let source = make_source( pool, tx_in_config) ;
121
+ let mut result = source. get_mapping_changes( Some ( BLOCK_6 ) , BLOCK_7 , scripts( ) ) . await . unwrap( ) ;
122
+ result. sort( ) ;
123
+ let expected = vec![ (
123
124
"key3" . to_owned( ) ,
124
125
Some ( ByteString :: from( hex!( "44444444444444444444444444444444" ) . to_vec( ) ) ) ,
125
- ) ,
126
- ] ;
127
- assert_eq ! ( result, expected) ;
126
+ ) ] ;
127
+ assert_eq!( result, expected) ;
128
+ }
129
+
130
+ async fn test_cached_governed_map_upsert( pool: PgPool , tx_in_config: TxInConfiguration ) {
131
+ let source = make_cached_source( pool, tx_in_config) . await ;
132
+ let mut result = source. get_mapping_changes( Some ( BLOCK_6 ) , BLOCK_7 , scripts( ) ) . await . unwrap( ) ;
133
+ result. sort( ) ;
134
+ let expected = vec![
135
+ ( "key3" . to_owned( ) , None ) ,
136
+ (
137
+ "key3" . to_owned( ) ,
138
+ Some ( ByteString :: from( hex!( "44444444444444444444444444444444" ) . to_vec( ) ) ) ,
139
+ ) ,
140
+ ] ;
141
+ assert_eq!( result, expected) ;
142
+ }
128
143
}
129
144
130
145
fn scripts ( ) -> MainChainScriptsV1 {
0 commit comments