Skip to content

Commit 6307e9a

Browse files
committed
Remove immutable file number from CardanoTransactionsBuilder
1 parent 5ba9982 commit 6307e9a

File tree

1 file changed

+26
-97
lines changed

1 file changed

+26
-97
lines changed

mithril-common/src/test_utils/cardano_transactions_builder.rs

Lines changed: 26 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use crate::entities::{BlockRange, CardanoTransaction};
1818
/// assert_eq!(8, txs.len());
1919
/// assert_eq!(
2020
/// vec![
21-
/// CardanoTransaction::new("tx-hash-0-100", 0, 100, "block-hash-0", 1),
22-
/// CardanoTransaction::new("tx-hash-0-101", 0, 101, "block-hash-0", 2),
23-
/// CardanoTransaction::new("tx-hash-0-102", 0, 102, "block-hash-0", 3),
24-
/// CardanoTransaction::new("tx-hash-1-103", 1, 103, "block-hash-1", 4),
25-
/// CardanoTransaction::new("tx-hash-1-104", 1, 104, "block-hash-1", 5),
26-
/// CardanoTransaction::new("tx-hash-1-105", 1, 105, "block-hash-1", 6),
27-
/// CardanoTransaction::new("tx-hash-15-106", 15, 106, "block-hash-15", 7),
28-
/// CardanoTransaction::new("tx-hash-15-107", 15, 107, "block-hash-15", 8)
21+
/// CardanoTransaction::new("tx-hash-0-100", 0, 100, "block-hash-0", 0),
22+
/// CardanoTransaction::new("tx-hash-0-101", 0, 101, "block-hash-0", 0),
23+
/// CardanoTransaction::new("tx-hash-0-102", 0, 102, "block-hash-0", 0),
24+
/// CardanoTransaction::new("tx-hash-1-103", 1, 103, "block-hash-1", 0),
25+
/// CardanoTransaction::new("tx-hash-1-104", 1, 104, "block-hash-1", 0),
26+
/// CardanoTransaction::new("tx-hash-1-105", 1, 105, "block-hash-1", 0),
27+
/// CardanoTransaction::new("tx-hash-15-106", 15, 106, "block-hash-15", 0),
28+
/// CardanoTransaction::new("tx-hash-15-107", 15, 107, "block-hash-15", 0)
2929
/// ],
3030
/// txs
3131
/// );
@@ -45,27 +45,25 @@ use crate::entities::{BlockRange, CardanoTransaction};
4545
/// assert_eq!(3 * 2 * 2, txs.len());
4646
/// assert_eq!(
4747
/// vec![
48-
/// CardanoTransaction::new("tx-hash-0-100", 0, 100, "block-hash-0", 1),
49-
/// CardanoTransaction::new("tx-hash-0-101", 0, 101, "block-hash-0", 2),
50-
/// CardanoTransaction::new("tx-hash-0-102", 0, 102, "block-hash-0", 3),
51-
/// CardanoTransaction::new("tx-hash-1-103", 1, 103, "block-hash-1", 4),
52-
/// CardanoTransaction::new("tx-hash-1-104", 1, 104, "block-hash-1", 5),
53-
/// CardanoTransaction::new("tx-hash-1-105", 1, 105, "block-hash-1", 6),
54-
/// CardanoTransaction::new("tx-hash-15-106", 15, 106, "block-hash-15", 7),
55-
/// CardanoTransaction::new("tx-hash-15-107", 15, 107, "block-hash-15", 8),
56-
/// CardanoTransaction::new("tx-hash-15-108", 15, 108, "block-hash-15", 9),
57-
/// CardanoTransaction::new("tx-hash-16-109", 16, 109, "block-hash-16", 10),
58-
/// CardanoTransaction::new("tx-hash-16-110", 16, 110, "block-hash-16", 11),
59-
/// CardanoTransaction::new("tx-hash-16-111", 16, 111, "block-hash-16", 12),
48+
/// CardanoTransaction::new("tx-hash-0-100", 0, 100, "block-hash-0", 0),
49+
/// CardanoTransaction::new("tx-hash-0-101", 0, 101, "block-hash-0", 0),
50+
/// CardanoTransaction::new("tx-hash-0-102", 0, 102, "block-hash-0", 0),
51+
/// CardanoTransaction::new("tx-hash-1-103", 1, 103, "block-hash-1", 0),
52+
/// CardanoTransaction::new("tx-hash-1-104", 1, 104, "block-hash-1", 0),
53+
/// CardanoTransaction::new("tx-hash-1-105", 1, 105, "block-hash-1", 0),
54+
/// CardanoTransaction::new("tx-hash-15-106", 15, 106, "block-hash-15", 0),
55+
/// CardanoTransaction::new("tx-hash-15-107", 15, 107, "block-hash-15", 0),
56+
/// CardanoTransaction::new("tx-hash-15-108", 15, 108, "block-hash-15", 0),
57+
/// CardanoTransaction::new("tx-hash-16-109", 16, 109, "block-hash-16", 0),
58+
/// CardanoTransaction::new("tx-hash-16-110", 16, 110, "block-hash-16", 0),
59+
/// CardanoTransaction::new("tx-hash-16-111", 16, 111, "block-hash-16", 0),
6060
/// ],
6161
/// txs
6262
/// );
6363
/// ```
6464
pub struct CardanoTransactionsBuilder {
6565
max_transactions_per_block: usize,
6666
max_blocks_per_block_range: usize,
67-
max_transactions_per_immutable_file: usize,
68-
first_immutable_file: u64,
6967
}
7068

7169
impl Default for CardanoTransactionsBuilder {
@@ -80,8 +78,6 @@ impl CardanoTransactionsBuilder {
8078
Self {
8179
max_transactions_per_block: 1,
8280
max_blocks_per_block_range: 1,
83-
max_transactions_per_immutable_file: 1,
84-
first_immutable_file: 1,
8581
}
8682
}
8783

@@ -91,21 +87,6 @@ impl CardanoTransactionsBuilder {
9187
self
9288
}
9389

94-
/// Define how many transactions we generate for one immutable_file.
95-
pub fn max_transactions_per_immutable_file(
96-
mut self,
97-
transactions_per_immutable_file: usize,
98-
) -> Self {
99-
self.max_transactions_per_immutable_file = transactions_per_immutable_file;
100-
self
101-
}
102-
103-
/// Define the first immutable file number.
104-
pub fn first_immutable_file(mut self, first_immutable_file: u64) -> Self {
105-
self.first_immutable_file = first_immutable_file;
106-
self
107-
}
108-
10990
/// Define how many blocks we generate in each block_range.
11091
/// If we set too many blocks for a block_range, this function panic.
11192
pub fn blocks_per_block_range(mut self, blocks_per_block_range: usize) -> Self {
@@ -125,14 +106,10 @@ impl CardanoTransactionsBuilder {
125106
let first_transaction_number = 100;
126107
for tx_index in 0..transactions_count {
127108
let block_number = self.block_number_from_transaction_index(tx_index);
128-
let immutable_file_number = tx_index as u64
129-
/ self.max_transactions_per_immutable_file as u64
130-
+ self.first_immutable_file;
131-
transactions.push(self.create_transaction(
132-
tx_index as u64 + first_transaction_number,
133-
block_number,
134-
immutable_file_number,
135-
))
109+
110+
transactions.push(
111+
self.create_transaction(tx_index as u64 + first_transaction_number, block_number),
112+
)
136113
}
137114

138115
transactions
@@ -158,18 +135,13 @@ impl CardanoTransactionsBuilder {
158135
}
159136

160137
/// Create a transaction with a given index and block number.
161-
fn create_transaction(
162-
&self,
163-
transaction_id: u64,
164-
block_number: u64,
165-
immutable_file_number: u64,
166-
) -> CardanoTransaction {
138+
fn create_transaction(&self, transaction_id: u64, block_number: u64) -> CardanoTransaction {
167139
CardanoTransaction::new(
168140
format!("tx-hash-{}-{}", block_number, transaction_id),
169141
block_number,
170142
transaction_id,
171143
format!("block-hash-{block_number}"),
172-
immutable_file_number,
144+
0,
173145
)
174146
}
175147
}
@@ -218,7 +190,6 @@ mod test {
218190
assert_eq!(3, count_distinct_values(&txs, &|t| t.block_number));
219191
assert_eq!(3, count_distinct_values(&txs, &|t| t.slot_number));
220192
assert_eq!(3, count_distinct_values(&txs, &|t| t.block_hash.clone()));
221-
assert_eq!(3, count_distinct_values(&txs, &|t| t.immutable_file_number));
222193
}
223194

224195
#[test]
@@ -371,46 +342,4 @@ mod test {
371342
fn should_panic_when_too_many_blocks_per_block_range() {
372343
CardanoTransactionsBuilder::new().blocks_per_block_range(BlockRange::LENGTH as usize + 1);
373344
}
374-
375-
#[test]
376-
fn build_transactions_with_many_transactions_per_immutable_file() {
377-
let transactions = CardanoTransactionsBuilder::new()
378-
.max_transactions_per_immutable_file(5)
379-
.build_transactions(18);
380-
381-
assert_eq!(transactions.len(), 18);
382-
383-
assert_eq!(
384-
4,
385-
count_distinct_values(&transactions, &|t| t.immutable_file_number)
386-
);
387-
}
388-
389-
#[test]
390-
fn build_transactions_with_same_number_of_transactions_per_immutable_file() {
391-
let transactions = CardanoTransactionsBuilder::new()
392-
.max_transactions_per_immutable_file(5)
393-
.build_transactions(20);
394-
395-
assert_eq!(transactions.len(), 20);
396-
397-
let grouped_by_immutable_file = group_by(&transactions, &|t| t.immutable_file_number);
398-
assert_eq!(4, grouped_by_immutable_file.len());
399-
400-
for transaction_for_immutable_file in grouped_by_immutable_file.values() {
401-
assert_eq!(5, transaction_for_immutable_file.len());
402-
}
403-
}
404-
405-
#[test]
406-
fn build_transactions_with_immutable_file_starting_at_a_specific_number() {
407-
let transactions = CardanoTransactionsBuilder::new()
408-
.first_immutable_file(5)
409-
.build_transactions(3);
410-
411-
assert_eq!(
412-
vec![5, 6, 7],
413-
extract_by(&transactions, &|t| t.immutable_file_number)
414-
);
415-
}
416345
}

0 commit comments

Comments
 (0)