Skip to content

Commit ac93466

Browse files
committed
wip
1 parent 3c10e8d commit ac93466

File tree

6 files changed

+457
-89
lines changed

6 files changed

+457
-89
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ sqlx = { version = "0.8.6", default-features = false, features = [
185185
] }
186186
derive-where = { version = "1.2.7", default-features = false }
187187
once_cell = { version = "1.21.3", default-features = false }
188+
paste = { version = "1.0.15" }
188189

189190
# substrate dependencies
190191
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2506" }

toolkit/data-sources/db-sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tokio-test = "0.4.3"
5656
ctor = "0.4.1"
5757
testcontainers-modules = { version = "0.1.3", features = ["postgres"] }
5858
pretty_assertions = { workspace = true }
59+
paste = { workspace = true }
5960

6061
[features]
6162
default = []

toolkit/data-sources/db-sync/src/governed_map/tests.rs

Lines changed: 104 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -26,105 +26,120 @@ const BLOCK_6: McBlockHash =
2626
const BLOCK_7: McBlockHash =
2727
McBlockHash(hex!("b702000000000000000000000000000000000000000000000000000000000008"));
2828

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 )*) => {
3731

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
4635

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+
}
6440

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+
};
8548
}
8649

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+
}
9458

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+
}
10266

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();
11487

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![(
123124
"key3".to_owned(),
124125
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+
}
128143
}
129144

130145
fn scripts() -> MainChainScriptsV1 {

0 commit comments

Comments
 (0)