ckb-verification 0.37.0

TODO(doc): crate description
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
use super::super::transaction_verifier::{
    CapacityVerifier, DuplicateDepsVerifier, EmptyVerifier, MaturityVerifier, OutputsDataVerifier,
    Since, SinceVerifier, SizeVerifier, VersionVerifier,
};
use crate::error::TransactionErrorSource;
use crate::TransactionError;
use ckb_chain_spec::{build_genesis_type_id_script, OUTPUT_INDEX_DAO};
use ckb_error::{assert_error_eq, Error};
use ckb_test_chain_utils::MockMedianTime;
use ckb_traits::BlockMedianTimeContext;
use ckb_types::{
    bytes::Bytes,
    constants::TX_VERSION,
    core::{
        capacity_bytes,
        cell::{CellMetaBuilder, ResolvedTransaction},
        BlockNumber, Capacity, EpochNumber, EpochNumberWithFraction, TransactionBuilder,
        TransactionInfo, TransactionView,
    },
    h256,
    packed::{CellDep, CellInput, CellOutput, OutPoint},
    prelude::*,
    H256,
};
use std::sync::Arc;

#[test]
pub fn test_empty() {
    let transaction = TransactionBuilder::default().build();
    let verifier = EmptyVerifier::new(&transaction);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::Empty {
            source: TransactionErrorSource::Inputs,
        }
    );
}

#[test]
pub fn test_version() {
    let transaction = TransactionBuilder::default()
        .version((TX_VERSION + 1).pack())
        .build();
    let verifier = VersionVerifier::new(&transaction, TX_VERSION);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::MismatchedVersion {
            expected: 0,
            actual: 1
        },
    );
}

#[test]
pub fn test_exceeded_maximum_block_bytes() {
    let data: Bytes = vec![1; 500].into();
    let transaction = TransactionBuilder::default()
        .output(
            CellOutput::new_builder()
                .capacity(capacity_bytes!(50).pack())
                .build(),
        )
        .output_data(data.pack())
        .build();
    let verifier = SizeVerifier::new(&transaction, 100);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::ExceededMaximumBlockBytes {
            actual: 661,
            limit: 100
        },
    );
}

#[test]
pub fn test_capacity_outofbound() {
    let data = Bytes::from(vec![1; 51]);
    let transaction = TransactionBuilder::default()
        .output(
            CellOutput::new_builder()
                .capacity(capacity_bytes!(50).pack())
                .build(),
        )
        .output_data(data.pack())
        .build();

    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: Vec::new(),
        resolved_inputs: vec![CellMetaBuilder::from_cell_output(
            CellOutput::new_builder()
                .capacity(capacity_bytes!(50).pack())
                .build(),
            Bytes::new(),
        )
        .build()],
        resolved_dep_groups: vec![],
    };
    let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash();
    let verifier = CapacityVerifier::new(&rtx, Some(dao_type_hash));

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::InsufficientCellCapacity {
            source: TransactionErrorSource::Outputs,
            index: 0,
            capacity: capacity_bytes!(50),
            occupied_capacity: capacity_bytes!(92),
        }
    );
}

#[test]
pub fn test_skip_dao_capacity_check() {
    let dao_type_script = build_genesis_type_id_script(OUTPUT_INDEX_DAO);
    let transaction = TransactionBuilder::default()
        .output(
            CellOutput::new_builder()
                .capacity(capacity_bytes!(500).pack())
                .type_(Some(dao_type_script.clone()).pack())
                .build(),
        )
        .output_data(Bytes::new().pack())
        .build();

    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: Vec::new(),
        resolved_inputs: vec![],
        resolved_dep_groups: vec![],
    };
    let verifier = CapacityVerifier::new(&rtx, Some(dao_type_script.calc_script_hash()));

    assert!(verifier.verify().is_ok());
}

// inputs immature verify
#[test]
pub fn test_inputs_cellbase_maturity() {
    let transaction = TransactionBuilder::default().build();
    let output = CellOutput::new_builder()
        .capacity(capacity_bytes!(50).pack())
        .build();
    let base_epoch = EpochNumberWithFraction::new(10, 0, 10);
    let cellbase_maturity = EpochNumberWithFraction::new(5, 0, 1);

    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: Vec::new(),
        resolved_dep_groups: Vec::new(),
        resolved_inputs: vec![CellMetaBuilder::from_cell_output(output, Bytes::new())
            .transaction_info(MockMedianTime::get_transaction_info(30, base_epoch, 0))
            .build()],
    };

    let mut current_epoch = EpochNumberWithFraction::new(0, 0, 10);
    let threshold = cellbase_maturity.to_rational() + base_epoch.to_rational();
    while current_epoch.number() < cellbase_maturity.number() + base_epoch.number() + 5 {
        let verifier = MaturityVerifier::new(&rtx, current_epoch, cellbase_maturity);
        let current = current_epoch.to_rational();
        if current < threshold {
            assert_error_eq!(
                verifier.verify().unwrap_err(),
                TransactionError::CellbaseImmaturity {
                    source: TransactionErrorSource::Inputs,
                    index: 0
                },
                "base_epoch = {}, current_epoch = {}, cellbase_maturity = {}",
                base_epoch,
                current_epoch,
                cellbase_maturity
            );
        } else {
            assert!(
                verifier.verify().is_ok(),
                "base_epoch = {}, current_epoch = {}, cellbase_maturity = {}",
                base_epoch,
                current_epoch,
                cellbase_maturity
            );
        }
        {
            let number = current_epoch.number();
            let length = current_epoch.length();
            let index = current_epoch.index();
            current_epoch = if index == length {
                EpochNumberWithFraction::new(number + 1, 0, length)
            } else {
                EpochNumberWithFraction::new(number, index + 1, length)
            };
        }
    }
}

#[test]
fn test_ignore_genesis_cellbase_maturity() {
    let transaction = TransactionBuilder::default().build();
    let output = CellOutput::new_builder()
        .capacity(capacity_bytes!(50).pack())
        .build();
    let base_epoch = EpochNumberWithFraction::new(0, 0, 10);
    let cellbase_maturity = EpochNumberWithFraction::new(5, 0, 1);
    // Transaction use genesis cellbase
    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: Vec::new(),
        resolved_dep_groups: Vec::new(),
        resolved_inputs: vec![CellMetaBuilder::from_cell_output(output, Bytes::new())
            .transaction_info(MockMedianTime::get_transaction_info(0, base_epoch, 0))
            .build()],
    };

    let mut current_epoch = EpochNumberWithFraction::new(0, 0, 10);
    while current_epoch.number() < cellbase_maturity.number() + base_epoch.number() + 5 {
        let verifier = MaturityVerifier::new(&rtx, current_epoch, cellbase_maturity);
        assert!(
            verifier.verify().is_ok(),
            "base_epoch = {}, current_epoch = {}, cellbase_maturity = {}",
            base_epoch,
            current_epoch,
            cellbase_maturity
        );
        {
            let number = current_epoch.number();
            let length = current_epoch.length();
            let index = current_epoch.index();
            current_epoch = if index == length {
                EpochNumberWithFraction::new(number + 1, 0, length)
            } else {
                EpochNumberWithFraction::new(number, index + 1, length)
            };
        }
    }
}

// deps immature verify
#[test]
pub fn test_deps_cellbase_maturity() {
    let transaction = TransactionBuilder::default().build();
    let output = CellOutput::new_builder()
        .capacity(capacity_bytes!(50).pack())
        .build();

    let base_epoch = EpochNumberWithFraction::new(0, 0, 10);
    let cellbase_maturity = EpochNumberWithFraction::new(5, 0, 1);

    // The 1st dep is cellbase, the 2nd one is not.
    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: vec![
            CellMetaBuilder::from_cell_output(output.clone(), Bytes::new())
                .transaction_info(MockMedianTime::get_transaction_info(30, base_epoch, 0))
                .build(),
            CellMetaBuilder::from_cell_output(output, Bytes::new())
                .transaction_info(MockMedianTime::get_transaction_info(40, base_epoch, 1))
                .build(),
        ],
        resolved_inputs: Vec::new(),
        resolved_dep_groups: vec![],
    };

    let mut current_epoch = EpochNumberWithFraction::new(0, 0, 10);
    let threshold = cellbase_maturity.to_rational() + base_epoch.to_rational();
    while current_epoch.number() < cellbase_maturity.number() + base_epoch.number() + 5 {
        let verifier = MaturityVerifier::new(&rtx, current_epoch, cellbase_maturity);
        let current = current_epoch.to_rational();
        if current < threshold {
            assert_error_eq!(
                verifier.verify().unwrap_err(),
                TransactionError::CellbaseImmaturity {
                    source: TransactionErrorSource::CellDeps,
                    index: 0
                },
                "base_epoch = {}, current_epoch = {}, cellbase_maturity = {}",
                base_epoch,
                current_epoch,
                cellbase_maturity,
            );
        } else {
            assert!(
                verifier.verify().is_ok(),
                "base_epoch = {}, current_epoch = {}, cellbase_maturity = {}",
                base_epoch,
                current_epoch,
                cellbase_maturity
            );
        }
        {
            let number = current_epoch.number();
            let length = current_epoch.length();
            let index = current_epoch.index();
            current_epoch = if index == length {
                EpochNumberWithFraction::new(number + 1, 0, length)
            } else {
                EpochNumberWithFraction::new(number, index + 1, length)
            };
        }
    }
}

#[test]
pub fn test_capacity_invalid() {
    // The outputs capacity is 50 + 100 = 150
    let transaction = TransactionBuilder::default()
        .outputs(vec![
            CellOutput::new_builder()
                .capacity(capacity_bytes!(50).pack())
                .build(),
            CellOutput::new_builder()
                .capacity(capacity_bytes!(100).pack())
                .build(),
        ])
        .outputs_data(vec![Bytes::new().pack(); 2])
        .build();

    // The inputs capacity is 49 + 100 = 149,
    // is less than outputs capacity
    let rtx = ResolvedTransaction {
        transaction,
        resolved_cell_deps: Vec::new(),
        resolved_inputs: vec![
            CellMetaBuilder::from_cell_output(
                CellOutput::new_builder()
                    .capacity(capacity_bytes!(49).pack())
                    .build(),
                Bytes::new(),
            )
            .build(),
            CellMetaBuilder::from_cell_output(
                CellOutput::new_builder()
                    .capacity(capacity_bytes!(100).pack())
                    .build(),
                Bytes::new(),
            )
            .build(),
        ],
        resolved_dep_groups: vec![],
    };
    let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash();
    let verifier = CapacityVerifier::new(&rtx, Some(dao_type_hash));

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::OutputsSumOverflow {
            inputs_sum: capacity_bytes!(149),
            outputs_sum: capacity_bytes!(150),
        },
    );
}

#[test]
pub fn test_duplicate_cell_deps() {
    let out_point = OutPoint::new(h256!("0x1").pack(), 0);
    let cell_dep = CellDep::new_builder().out_point(out_point).build();
    let transaction = TransactionBuilder::default()
        .cell_deps(vec![cell_dep.clone(), cell_dep.clone()])
        .build();

    let verifier = DuplicateDepsVerifier::new(&transaction);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::DuplicateCellDeps {
            out_point: cell_dep.out_point()
        },
    );
}

#[test]
pub fn test_duplicate_header_deps() {
    let transaction = TransactionBuilder::default()
        .header_deps(vec![h256!("0x1").pack(), h256!("0x1").pack()])
        .build();

    let verifier = DuplicateDepsVerifier::new(&transaction);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::DuplicateHeaderDeps {
            hash: h256!("0x1").pack()
        },
    );
}

fn verify_since<'a, M>(
    rtx: &'a ResolvedTransaction,
    block_median_time_context: &'a M,
    block_number: BlockNumber,
    epoch_number: EpochNumber,
) -> Result<(), Error>
where
    M: BlockMedianTimeContext,
{
    let parent_hash = Arc::new(MockMedianTime::get_block_hash(block_number - 1));
    SinceVerifier::new(
        rtx,
        block_median_time_context,
        block_number,
        EpochNumberWithFraction::new(epoch_number, 0, 10),
        parent_hash.as_ref().to_owned(),
    )
    .verify()
}

#[test]
fn test_since() {
    let valids = vec![
        0x0000_0000_0000_0001,
        0x2000_0000_0000_0001,
        0x4000_0000_0000_0001,
        0x8000_0000_0000_0001,
        0xa000_0000_0000_0001,
        0xc000_0000_0000_0001,
    ];

    for v in valids.into_iter() {
        let since = Since(v);
        assert_eq!(since.flags_is_valid(), true);
    }

    let invalids = vec![
        0x0100_0000_0000_0001,
        0x1000_0000_0000_0001,
        0xd000_0000_0000_0001,
    ];

    for v in invalids.into_iter() {
        let since = Since(v);
        assert_eq!(since.flags_is_valid(), false);
    }
}

fn create_tx_with_lock(since: u64) -> TransactionView {
    TransactionBuilder::default()
        .inputs(vec![CellInput::new(
            OutPoint::new(h256!("0x1").pack(), 0),
            since,
        )])
        .build()
}

fn create_resolve_tx_with_transaction_info(
    tx: &TransactionView,
    transaction_info: TransactionInfo,
) -> ResolvedTransaction {
    ResolvedTransaction {
        transaction: tx.clone(),
        resolved_cell_deps: Vec::new(),
        resolved_inputs: vec![CellMetaBuilder::from_cell_output(
            CellOutput::new_builder()
                .capacity(capacity_bytes!(50).pack())
                .build(),
            Bytes::new(),
        )
        .transaction_info(transaction_info)
        .build()],
        resolved_dep_groups: vec![],
    }
}

#[test]
fn test_invalid_since_verify() {
    // use remain flags
    let tx = create_tx_with_lock(0x0100_0000_0000_0001);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );

    let median_time_context = MockMedianTime::new(vec![0; 11]);
    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 5, 1).unwrap_err(),
        TransactionError::InvalidSince { index: 0 },
    );
}

#[test]
fn test_valid_zero_length_since() {
    // use remain flags
    let tx = create_tx_with_lock(0xa000_0000_0000_0000);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );

    let median_time_context = MockMedianTime::new(vec![0; 11]);
    assert!(verify_since(&rtx, &median_time_context, 5, 1).is_ok(),);
}

#[test]
fn test_fraction_epoch_since_verify() {
    let tx = create_tx_with_lock(0x2000_0a00_0500_0010);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );
    let median_time_context = MockMedianTime::new(vec![0; 11]);
    let block_number = 1000;
    let parent_hash = Arc::new(MockMedianTime::get_block_hash(block_number - 1));

    let result = SinceVerifier::new(
        &rtx,
        &median_time_context,
        block_number,
        EpochNumberWithFraction::new(16, 1, 10),
        parent_hash.as_ref().to_owned(),
    )
    .verify();
    assert_error_eq!(result.unwrap_err(), TransactionError::Immature { index: 0 });

    let result = SinceVerifier::new(
        &rtx,
        &median_time_context,
        block_number,
        EpochNumberWithFraction::new(16, 5, 10),
        parent_hash.as_ref().to_owned(),
    )
    .verify();
    assert!(result.is_ok());
}

#[test]
pub fn test_absolute_block_number_lock() {
    // absolute lock until block number 0xa
    let tx = create_tx_with_lock(0x0000_0000_0000_000a);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );
    let median_time_context = MockMedianTime::new(vec![0; 11]);

    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 5, 1).unwrap_err(),
        TransactionError::Immature { index: 0 },
    );
    // spent after 10 height
    assert!(verify_since(&rtx, &median_time_context, 10, 1).is_ok());
}

#[test]
pub fn test_absolute_epoch_number_lock() {
    // absolute lock until epoch number 0xa
    let tx = create_tx_with_lock(0x2000_0100_0000_000a);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );

    let median_time_context = MockMedianTime::new(vec![0; 11]);
    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 5, 1).unwrap_err(),
        TransactionError::Immature { index: 0 },
    );
    // spent after 10 epoch
    assert!(verify_since(&rtx, &median_time_context, 100, 10).is_ok());
}

#[test]
pub fn test_relative_timestamp_lock() {
    // relative lock timestamp lock
    let tx = create_tx_with_lock(0xc000_0000_0000_0002);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );

    let median_time_context = MockMedianTime::new(vec![0; 11]);
    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 4, 1).unwrap_err(),
        TransactionError::Immature { index: 0 },
    );

    // spent after 1024 seconds
    // fake median time: 1124
    let median_time_context =
        MockMedianTime::new(vec![0, 100_000, 1_124_000, 2_000_000, 3_000_000]);
    assert!(verify_since(&rtx, &median_time_context, 4, 1).is_ok());
}

#[test]
pub fn test_relative_epoch() {
    // next epoch
    let tx = create_tx_with_lock(0xa000_1000_0000_0002);
    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );

    let median_time_context = MockMedianTime::new(vec![0; 11]);

    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 4, 1).unwrap_err(),
        TransactionError::Immature { index: 0 },
    );

    assert!(verify_since(&rtx, &median_time_context, 4, 2).is_ok());
}

#[test]
pub fn test_since_both() {
    // both
    let tx = TransactionBuilder::default()
        .inputs(vec![
            // absolute lock until epoch number 0xa
            CellInput::new(OutPoint::new(h256!("0x1").pack(), 0), 0x0000_0000_0000_000a),
            // relative lock until after 2 blocks
            CellInput::new(OutPoint::new(h256!("0x1").pack(), 0), 0xc000_0000_0000_0002),
        ])
        .build();

    let rtx = create_resolve_tx_with_transaction_info(
        &tx,
        MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
    );
    // spent after 1024 seconds and 4 blocks (less than 10 blocks)
    // fake median time: 1124
    let median_time_context =
        MockMedianTime::new(vec![0, 100_000, 1_124_000, 2_000_000, 3_000_000]);

    assert_error_eq!(
        verify_since(&rtx, &median_time_context, 4, 1).unwrap_err(),
        TransactionError::Immature { index: 0 },
    );
    // spent after 1024 seconds and 10 blocks
    // fake median time: 1124
    let median_time_context = MockMedianTime::new(vec![
        0, 1, 2, 3, 4, 100_000, 1_124_000, 2_000_000, 3_000_000, 4_000_000, 5_000_000, 6_000_000,
    ]);
    assert!(verify_since(&rtx, &median_time_context, 10, 1).is_ok());
}

#[test]
fn test_since_overflow() {
    // use max value for each flag
    for flag in &[
        0b0000_0000u64, // absolute & block
        0b1000_0000u64, // relative & block
        0b0010_0000u64, // absolute & epoch
        0b1010_0000u64, // relative & epoch
        0b0100_0000u64, // absolute & time
        0b1100_0000u64, // relative & time
    ] {
        let tx = create_tx_with_lock((flag << 56) + 0xffff_ffff_ffffu64);
        let rtx = create_resolve_tx_with_transaction_info(
            &tx,
            MockMedianTime::get_transaction_info(1, EpochNumberWithFraction::new(0, 0, 10), 1),
        );

        let median_time_context = MockMedianTime::new(vec![0; 11]);
        assert_error_eq!(
            verify_since(&rtx, &median_time_context, 5, 1).unwrap_err(),
            TransactionError::Immature { index: 0 },
        );
    }
}

#[test]
pub fn test_outputs_data_length_mismatch() {
    let transaction = TransactionBuilder::default()
        .output(Default::default())
        .build();
    let verifier = OutputsDataVerifier::new(&transaction);

    assert_error_eq!(
        verifier.verify().unwrap_err(),
        TransactionError::OutputsDataLengthMismatch {
            outputs_len: 1,
            outputs_data_len: 0
        },
    );

    let transaction = TransactionBuilder::default()
        .output(Default::default())
        .output_data(Default::default())
        .build();
    let verifier = OutputsDataVerifier::new(&transaction);

    assert!(verifier.verify().is_ok());
}