@@ -158,29 +158,39 @@ mod tests {
158
158
}
159
159
160
160
#[ tokio:: test]
161
- async fn test_compute_merkle_root ( ) {
162
- let transaction_1 = CardanoTransaction :: new ( "tx-hash-123" , 10 , 1 , "block_hash" , 1 ) ;
163
- let transaction_2 = CardanoTransaction :: new ( "tx-hash-456" , 20 , 2 , "block_hash" , 1 ) ;
164
- let transaction_3 = CardanoTransaction :: new ( "tx-hash-789" , 30 , 3 , "block_hash" , 1 ) ;
165
- let transaction_4 = CardanoTransaction :: new ( "tx-hash-abc" , 40 , 4 , "block_hash" , 1 ) ;
166
-
167
- let transactions_set_reference = vec ! [
168
- transaction_1. clone( ) ,
169
- transaction_2. clone( ) ,
170
- transaction_3. clone( ) ,
171
- ] ;
161
+ async fn test_compute_merkle_root_in_same_block_range ( ) {
162
+ let transaction_1 = CardanoTransaction :: new ( "tx-hash-123" , 1 , 10 , "block_hash" , 1 ) ;
163
+ let transaction_2 = CardanoTransaction :: new ( "tx-hash-456" , 2 , 20 , "block_hash" , 1 ) ;
164
+ let transaction_3 = CardanoTransaction :: new ( "tx-hash-789" , 3 , 30 , "block_hash" , 1 ) ;
165
+ let transaction_4 = CardanoTransaction :: new ( "tx-hash-abc" , 4 , 40 , "block_hash" , 1 ) ;
166
+
167
+ for tx in [
168
+ & transaction_1,
169
+ & transaction_2,
170
+ & transaction_3,
171
+ & transaction_4,
172
+ ] {
173
+ assert ! (
174
+ tx. block_number < BlockRange :: LENGTH ,
175
+ "all manipulated transactions should be in the same block range"
176
+ ) ;
177
+ }
178
+
172
179
let cardano_transaction_signable_builder = CardanoTransactionsSignableBuilder :: new (
173
- Arc :: new ( DumbTransactionParser :: new (
174
- transactions_set_reference. clone ( ) ,
175
- ) ) ,
180
+ Arc :: new ( DumbTransactionParser :: new ( vec ! [ ] ) ) ,
176
181
Arc :: new ( MockTransactionStore :: new ( ) ) ,
177
182
Path :: new ( "/tmp" ) ,
178
183
create_logger ( ) ,
179
184
) ;
180
185
181
186
let merkle_root_reference = cardano_transaction_signable_builder
182
- . compute_merkle_root ( & transactions_set_reference)
187
+ . compute_merkle_root ( & [
188
+ transaction_1. clone ( ) ,
189
+ transaction_2. clone ( ) ,
190
+ transaction_3. clone ( ) ,
191
+ ] )
183
192
. unwrap ( ) ;
193
+
184
194
{
185
195
let transactions_set = vec ! [ transaction_1. clone( ) ] ;
186
196
let mk_root = cardano_transaction_signable_builder
@@ -209,7 +219,7 @@ mod tests {
209
219
}
210
220
211
221
{
212
- // Transactions in a different order returns a different merkle root.
222
+ // In a same block range Transactions in a different order returns a different merkle root.
213
223
let transactions_set = vec ! [
214
224
transaction_1. clone( ) ,
215
225
transaction_3. clone( ) ,
@@ -222,6 +232,34 @@ mod tests {
222
232
}
223
233
}
224
234
235
+ #[ tokio:: test]
236
+ async fn test_compute_merkle_root_order_of_block_range_does_not_matter ( ) {
237
+ let transaction_1 =
238
+ CardanoTransaction :: new ( "tx-hash-123" , BlockRange :: LENGTH - 1 , 10 , "block_hash" , 1 ) ;
239
+ let transaction_2 =
240
+ CardanoTransaction :: new ( "tx-hash-456" , BlockRange :: LENGTH + 1 , 20 , "block_hash" , 1 ) ;
241
+
242
+ let cardano_transaction_signable_builder = CardanoTransactionsSignableBuilder :: new (
243
+ Arc :: new ( DumbTransactionParser :: new ( vec ! [ ] ) ) ,
244
+ Arc :: new ( MockTransactionStore :: new ( ) ) ,
245
+ Path :: new ( "/tmp" ) ,
246
+ create_logger ( ) ,
247
+ ) ;
248
+
249
+ let merkle_root_reference = cardano_transaction_signable_builder
250
+ . compute_merkle_root ( & [ transaction_1. clone ( ) , transaction_2. clone ( ) ] )
251
+ . unwrap ( ) ;
252
+
253
+ // Transactions in two different block range compute the same merkle root as long as their
254
+ // order in their block range is the same but the order of appearance of the block range
255
+ // doesn't matter.
256
+ let mk_root = cardano_transaction_signable_builder
257
+ . compute_merkle_root ( & [ transaction_2. clone ( ) , transaction_1. clone ( ) ] )
258
+ . unwrap ( ) ;
259
+
260
+ assert_eq ! ( merkle_root_reference, mk_root) ;
261
+ }
262
+
225
263
#[ tokio:: test]
226
264
async fn test_compute_signable ( ) {
227
265
// Arrange
0 commit comments