Skip to content

Commit 120c219

Browse files
dlachaumejpraynaud
authored andcommitted
Refactoring after review
1 parent 2d18ec5 commit 120c219

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,11 @@ mod tests {
477477
let repository = CardanoTransactionRepository::new(connection);
478478

479479
let cardano_transactions: Vec<CardanoTransactionRecord> = CardanoTransactionsBuilder::new()
480-
.per_immutable_file(10)
480+
.max_transactions_per_immutable_file(10)
481481
.first_immutable_file(120)
482482
.build_transactions(40)
483-
.iter()
484-
.map(|transaction| CardanoTransactionRecord::from(transaction.clone()))
483+
.into_iter()
484+
.map(CardanoTransactionRecord::from)
485485
.collect();
486486

487487
repository
@@ -898,8 +898,8 @@ mod tests {
898898
let cardano_transactions: Vec<CardanoTransactionRecord> = CardanoTransactionsBuilder::new()
899899
.blocks_per_block_range(15)
900900
.build_transactions(53)
901-
.iter()
902-
.map(|transaction| CardanoTransactionRecord::from(transaction.clone()))
901+
.into_iter()
902+
.map(CardanoTransactionRecord::from)
903903
.collect();
904904

905905
repository

mithril-aggregator/src/services/prover.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,9 @@ mod tests {
208208
) -> BTreeMap<BlockRange, Vec<CardanoTransaction>> {
209209
let mut block_ranges_map = BTreeMap::new();
210210
for transaction in transactions {
211-
let block_range_first_block =
212-
BlockRange::from_block_number(transaction.block_number);
213-
let block_range_transactions: &mut Vec<_> = block_ranges_map
214-
.entry(block_range_first_block)
215-
.or_insert(vec![]);
211+
let block_range = BlockRange::from_block_number(transaction.block_number);
212+
let block_range_transactions: &mut Vec<_> =
213+
block_ranges_map.entry(block_range).or_insert(vec![]);
216214
block_range_transactions.push(transaction.to_owned())
217215
}
218216

@@ -319,7 +317,7 @@ mod tests {
319317
let total_block_ranges = 5;
320318
let total_transactions_per_block_range = 3;
321319
let transactions = CardanoTransactionsBuilder::new()
322-
.per_block(1)
320+
.max_transactions_per_block(1)
323321
.blocks_per_block_range(total_transactions_per_block_range)
324322
.build_block_ranges(total_block_ranges);
325323
let transactions_to_prove =
@@ -372,7 +370,7 @@ mod tests {
372370
let total_block_ranges = 5;
373371
let total_transactions_per_block_range = 3;
374372
let transactions = CardanoTransactionsBuilder::new()
375-
.per_block(1)
373+
.max_transactions_per_block(1)
376374
.blocks_per_block_range(total_transactions_per_block_range)
377375
.build_block_ranges(total_block_ranges);
378376
let transactions_to_prove = test_data::filter_transactions_for_indices(&[], &transactions);
@@ -420,7 +418,7 @@ mod tests {
420418
let total_block_ranges = 5;
421419
let total_transactions_per_block_range = 3;
422420
let transactions = CardanoTransactionsBuilder::new()
423-
.per_block(1)
421+
.max_transactions_per_block(1)
424422
.blocks_per_block_range(total_transactions_per_block_range)
425423
.build_block_ranges(total_block_ranges);
426424
let transactions_to_prove =
@@ -481,7 +479,7 @@ mod tests {
481479
let total_block_ranges = 5;
482480
let total_transactions_per_block_range = 3;
483481
let transactions = CardanoTransactionsBuilder::new()
484-
.per_block(1)
482+
.max_transactions_per_block(1)
485483
.blocks_per_block_range(total_transactions_per_block_range)
486484
.build_block_ranges(total_block_ranges);
487485
let transactions_to_prove =
@@ -511,7 +509,7 @@ mod tests {
511509
let total_block_ranges = 5;
512510
let total_transactions_per_block_range = 3;
513511
let transactions = CardanoTransactionsBuilder::new()
514-
.per_block(1)
512+
.max_transactions_per_block(1)
515513
.blocks_per_block_range(total_transactions_per_block_range)
516514
.build_block_ranges(total_block_ranges);
517515
let transactions_to_prove =

mithril-common/src/test_utils/cardano_transactions_builder.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ impl CardanoTransactionsBuilder {
2626
}
2727

2828
/// Define how many transactions we generate in each block.
29-
pub fn per_block(mut self, transactions_per_block: usize) -> Self {
29+
pub fn max_transactions_per_block(mut self, transactions_per_block: usize) -> Self {
3030
self.max_transactions_per_block = transactions_per_block;
3131
self
3232
}
3333

3434
/// Define how many transactions we generate for one immutable_file.
35-
pub fn per_immutable_file(mut self, transactions_per_immutable_file: usize) -> Self {
35+
pub fn max_transactions_per_immutable_file(
36+
mut self,
37+
transactions_per_immutable_file: usize,
38+
) -> Self {
3639
self.max_transactions_per_immutable_file = transactions_per_immutable_file;
3740
self
3841
}
@@ -56,11 +59,6 @@ impl CardanoTransactionsBuilder {
5659
self
5760
}
5861

59-
/// Default build that build only one transaction.
60-
pub fn build(self) -> Vec<CardanoTransaction> {
61-
self.build_transactions(1)
62-
}
63-
6462
/// Build the number of transactions requested.
6563
pub fn build_transactions(self, transactions_count: usize) -> Vec<CardanoTransaction> {
6664
let mut transactions = Vec::new();
@@ -147,13 +145,6 @@ mod test {
147145
list.iter().map(extract_value).collect()
148146
}
149147

150-
#[test]
151-
fn return_one_transaction_by_default() {
152-
let transactions = CardanoTransactionsBuilder::new().build();
153-
154-
assert_eq!(transactions.len(), 1);
155-
}
156-
157148
#[test]
158149
fn return_given_number_of_transactions_with_distinct_values() {
159150
let txs = CardanoTransactionsBuilder::new().build_transactions(3);
@@ -174,7 +165,7 @@ mod test {
174165
fn return_all_transactions_in_same_block_when_ask_less_transactions_than_transactions_per_block(
175166
) {
176167
let txs = CardanoTransactionsBuilder::new()
177-
.per_block(10)
168+
.max_transactions_per_block(10)
178169
.build_transactions(3);
179170

180171
assert_eq!(txs.len(), 3);
@@ -190,7 +181,7 @@ mod test {
190181
#[test]
191182
fn return_no_more_transactions_in_a_same_block_than_number_per_block_requested() {
192183
let txs = CardanoTransactionsBuilder::new()
193-
.per_block(3)
184+
.max_transactions_per_block(3)
194185
.build_transactions(12);
195186

196187
assert_eq!(txs.len(), 12);
@@ -206,7 +197,7 @@ mod test {
206197
#[test]
207198
fn only_the_last_block_is_not_full_when_we_can_not_fill_all_blocks() {
208199
let txs = CardanoTransactionsBuilder::new()
209-
.per_block(5)
200+
.max_transactions_per_block(5)
210201
.build_transactions(12);
211202

212203
assert_eq!(txs.len(), 12);
@@ -245,7 +236,7 @@ mod test {
245236
#[test]
246237
fn build_block_ranges_return_many_transactions_per_block_when_requested() {
247238
let txs = CardanoTransactionsBuilder::new()
248-
.per_block(5)
239+
.max_transactions_per_block(5)
249240
.build_block_ranges(3);
250241

251242
assert_eq!(txs.len(), 3 * 5);
@@ -266,7 +257,7 @@ mod test {
266257
#[test]
267258
fn build_block_ranges_with_many_blocks_per_block_ranges() {
268259
let txs = CardanoTransactionsBuilder::new()
269-
.per_block(5)
260+
.max_transactions_per_block(5)
270261
.blocks_per_block_range(2)
271262
.build_block_ranges(3);
272263

@@ -291,7 +282,7 @@ mod test {
291282
#[test]
292283
fn build_transactions_with_many_blocks_per_block_ranges() {
293284
let txs = CardanoTransactionsBuilder::new()
294-
.per_block(5)
285+
.max_transactions_per_block(5)
295286
.blocks_per_block_range(2)
296287
.build_transactions(18);
297288

@@ -324,7 +315,7 @@ mod test {
324315
#[test]
325316
fn build_transactions_with_many_transactions_per_immutable_file() {
326317
let transactions = CardanoTransactionsBuilder::new()
327-
.per_immutable_file(5)
318+
.max_transactions_per_immutable_file(5)
328319
.build_transactions(18);
329320

330321
assert_eq!(transactions.len(), 18);
@@ -338,7 +329,7 @@ mod test {
338329
#[test]
339330
fn build_transactions_with_same_number_of_transactions_per_immutable_file() {
340331
let transactions = CardanoTransactionsBuilder::new()
341-
.per_immutable_file(5)
332+
.max_transactions_per_immutable_file(5)
342333
.build_transactions(20);
343334

344335
assert_eq!(transactions.len(), 20);

0 commit comments

Comments
 (0)