Skip to content

Commit 7b252a7

Browse files
committed
Make repository_get_transaction_by_hashes test more robust
It check that it won't retrieve data that were not asked and won't retrieve data that doesn't exist. + Simplify test & add not exist case to `repository_create_and_get_transaction` as well.
1 parent 476b869 commit 7b252a7

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

mithril-aggregator/src/database/repository/cardano_transaction_repository.rs

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -186,51 +186,67 @@ mod tests {
186186
let connection = Arc::new(cardano_tx_db_connection().unwrap());
187187
let repository = CardanoTransactionRepository::new(connection);
188188
repository
189-
.create_transaction("tx-hash-123", 10, 50, "block_hash-123", 99)
189+
.create_transactions(vec![
190+
CardanoTransaction::new("tx_hash-123", 10, 50, "block_hash-123", 99),
191+
CardanoTransaction::new("tx_hash-456", 11, 51, "block_hash-456", 100),
192+
])
190193
.await
191194
.unwrap();
192-
repository
193-
.create_transaction("tx-hash-456", 11, 51, "block_hash-456", 100)
194-
.await
195-
.unwrap();
196-
let transaction_result = repository.get_transaction("tx-hash-123").await.unwrap();
197195

198-
assert_eq!(
199-
Some(CardanoTransactionRecord {
200-
transaction_hash: "tx-hash-123".to_string(),
201-
block_number: 10,
202-
slot_number: 50,
203-
block_hash: "block_hash-123".to_string(),
204-
immutable_file_number: 99
205-
}),
206-
transaction_result
207-
);
196+
{
197+
let transaction_result = repository.get_transaction("tx_hash-123").await.unwrap();
198+
assert_eq!(
199+
Some(CardanoTransactionRecord {
200+
transaction_hash: "tx_hash-123".to_string(),
201+
block_number: 10,
202+
slot_number: 50,
203+
block_hash: "block_hash-123".to_string(),
204+
immutable_file_number: 99
205+
}),
206+
transaction_result
207+
);
208+
}
209+
{
210+
let transaction_result = repository.get_transaction("not-exist").await.unwrap();
211+
assert_eq!(None, transaction_result);
212+
}
208213
}
209214

210215
#[tokio::test]
211216
async fn repository_get_transaction_by_hashes() {
212217
let connection = Arc::new(cardano_tx_db_connection().unwrap());
213218
let repository = CardanoTransactionRepository::new(connection);
214219
repository
215-
.create_transaction("tx-hash-123", 10, 50, "block_hash-123", 99)
216-
.await
217-
.unwrap();
218-
repository
219-
.create_transaction("tx-hash-456", 11, 51, "block_hash-456", 100)
220-
.await
221-
.unwrap();
222-
let transactions_result = repository
223-
.get_by_hashes(vec!["tx-hash-123".to_string(), "tx-hash-456".to_string()])
220+
.create_transactions(vec![
221+
CardanoTransaction::new("tx_hash-123", 10, 50, "block_hash-123", 99),
222+
CardanoTransaction::new("tx_hash-456", 11, 51, "block_hash-456", 100),
223+
CardanoTransaction::new("tx_hash-789", 12, 52, "block_hash-789", 101),
224+
])
224225
.await
225226
.unwrap();
226227

227-
assert_eq!(
228-
vec![
229-
CardanoTransaction::new("tx-hash-123", 10, 50, "block_hash-123", 99),
230-
CardanoTransaction::new("tx-hash-456", 11, 51, "block_hash-456", 100),
231-
],
232-
transactions_result
233-
);
228+
{
229+
let transactions = repository
230+
.get_by_hashes(vec!["tx_hash-123".to_string(), "tx_hash-789".to_string()])
231+
.await
232+
.unwrap();
233+
234+
assert_eq!(
235+
vec![
236+
CardanoTransaction::new("tx_hash-123", 10, 50, "block_hash-123", 99),
237+
CardanoTransaction::new("tx_hash-789", 12, 52, "block_hash-789", 101),
238+
],
239+
transactions
240+
);
241+
}
242+
{
243+
let transactions = repository
244+
.get_by_hashes(vec!["not-exist".to_string()])
245+
.await
246+
.unwrap();
247+
248+
assert_eq!(Vec::<CardanoTransaction>::new(), transactions);
249+
}
234250
}
235251

236252
#[tokio::test]

0 commit comments

Comments
 (0)