@@ -72,17 +72,16 @@ static std::map<std::string, unsigned int> mapFlagNames = {
72
72
73
73
unsigned int ParseScriptFlags (std::string strFlags)
74
74
{
75
- if (strFlags.empty () || strFlags == " NONE" ) return 0 ;
76
- unsigned int flags = 0 ;
77
- std::vector<std::string> words = SplitString (strFlags, ' ,' );
75
+ unsigned int flags = SCRIPT_VERIFY_NONE;
76
+ if (strFlags.empty () || strFlags == " NONE" ) return flags;
78
77
78
+ std::vector<std::string> words = SplitString (strFlags, ' ,' );
79
79
for (const std::string& word : words)
80
80
{
81
81
if (!mapFlagNames.count (word))
82
82
BOOST_ERROR (" Bad test: unknown verification flag '" << word << " '" );
83
83
flags |= mapFlagNames[word];
84
84
}
85
-
86
85
return flags;
87
86
}
88
87
@@ -98,7 +97,7 @@ bool CheckMapFlagNames()
98
97
99
98
std::string FormatScriptFlags (unsigned int flags)
100
99
{
101
- if (flags == 0 ) {
100
+ if (flags == SCRIPT_VERIFY_NONE ) {
102
101
return " " ;
103
102
}
104
103
std::string ret;
@@ -370,6 +369,41 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
370
369
}
371
370
}
372
371
372
+ BOOST_AUTO_TEST_CASE (tx_no_inputs)
373
+ {
374
+ CMutableTransaction empty;
375
+
376
+ TxValidationState state;
377
+ BOOST_CHECK_MESSAGE (!CheckTransaction (CTransaction (empty), state), " Transaction with no inputs should be invalid." );
378
+ BOOST_CHECK (state.GetRejectReason () == " bad-txns-vin-empty" );
379
+ }
380
+
381
+ BOOST_AUTO_TEST_CASE (tx_oversized)
382
+ {
383
+ auto createTransaction =[](size_t payloadSize) {
384
+ CMutableTransaction tx;
385
+ tx.vin .resize (1 );
386
+ tx.vout .emplace_back (1 , CScript () << OP_RETURN << std::vector<unsigned char >(payloadSize));
387
+ return CTransaction (tx);
388
+ };
389
+ const auto maxTransactionSize = MAX_BLOCK_WEIGHT / WITNESS_SCALE_FACTOR;
390
+ const auto oversizedTransactionBaseSize = ::GetSerializeSize (TX_NO_WITNESS (createTransaction (maxTransactionSize))) - maxTransactionSize;
391
+
392
+ auto maxPayloadSize = maxTransactionSize - oversizedTransactionBaseSize;
393
+ {
394
+ TxValidationState state;
395
+ CheckTransaction (createTransaction (maxPayloadSize), state);
396
+ BOOST_CHECK (state.GetRejectReason () != " bad-txns-oversize" );
397
+ }
398
+
399
+ maxPayloadSize += 1 ;
400
+ {
401
+ TxValidationState state;
402
+ BOOST_CHECK_MESSAGE (!CheckTransaction (createTransaction (maxPayloadSize), state), " Oversized transaction should be invalid" );
403
+ BOOST_CHECK (state.GetRejectReason () == " bad-txns-oversize" );
404
+ }
405
+ }
406
+
373
407
BOOST_AUTO_TEST_CASE (basic_transaction_tests)
374
408
{
375
409
// Random real transaction (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
@@ -615,11 +649,11 @@ BOOST_AUTO_TEST_CASE(test_witness)
615
649
// Normal pay-to-compressed-pubkey.
616
650
CreateCreditAndSpend (keystore, scriptPubkey1, output1, input1);
617
651
CreateCreditAndSpend (keystore, scriptPubkey2, output2, input2);
618
- CheckWithFlag (output1, input1, 0 , true );
652
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
619
653
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
620
654
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
621
655
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
622
- CheckWithFlag (output1, input2, 0 , false );
656
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , false );
623
657
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, false );
624
658
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
625
659
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
@@ -628,23 +662,23 @@ BOOST_AUTO_TEST_CASE(test_witness)
628
662
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (scriptPubkey1)), output1, input1);
629
663
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (scriptPubkey2)), output2, input2);
630
664
ReplaceRedeemScript (input2.vin [0 ].scriptSig , scriptPubkey1);
631
- CheckWithFlag (output1, input1, 0 , true );
665
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
632
666
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
633
667
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
634
668
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
635
- CheckWithFlag (output1, input2, 0 , true );
669
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , true );
636
670
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, false );
637
671
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
638
672
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
639
673
640
674
// Witness pay-to-compressed-pubkey (v0).
641
675
CreateCreditAndSpend (keystore, destination_script_1, output1, input1);
642
676
CreateCreditAndSpend (keystore, destination_script_2, output2, input2);
643
- CheckWithFlag (output1, input1, 0 , true );
677
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
644
678
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
645
679
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
646
680
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
647
- CheckWithFlag (output1, input2, 0 , true );
681
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , true );
648
682
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, true );
649
683
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
650
684
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
@@ -653,23 +687,23 @@ BOOST_AUTO_TEST_CASE(test_witness)
653
687
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (destination_script_1)), output1, input1);
654
688
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (destination_script_2)), output2, input2);
655
689
ReplaceRedeemScript (input2.vin [0 ].scriptSig , destination_script_1);
656
- CheckWithFlag (output1, input1, 0 , true );
690
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
657
691
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
658
692
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
659
693
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
660
- CheckWithFlag (output1, input2, 0 , true );
694
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , true );
661
695
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, true );
662
696
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
663
697
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
664
698
665
699
// Normal pay-to-uncompressed-pubkey.
666
700
CreateCreditAndSpend (keystore, scriptPubkey1L, output1, input1);
667
701
CreateCreditAndSpend (keystore, scriptPubkey2L, output2, input2);
668
- CheckWithFlag (output1, input1, 0 , true );
702
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
669
703
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
670
704
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
671
705
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
672
- CheckWithFlag (output1, input2, 0 , false );
706
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , false );
673
707
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, false );
674
708
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
675
709
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
@@ -678,11 +712,11 @@ BOOST_AUTO_TEST_CASE(test_witness)
678
712
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (scriptPubkey1L)), output1, input1);
679
713
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (scriptPubkey2L)), output2, input2);
680
714
ReplaceRedeemScript (input2.vin [0 ].scriptSig , scriptPubkey1L);
681
- CheckWithFlag (output1, input1, 0 , true );
715
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
682
716
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, true );
683
717
CheckWithFlag (output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true );
684
718
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
685
- CheckWithFlag (output1, input2, 0 , true );
719
+ CheckWithFlag (output1, input2, SCRIPT_VERIFY_NONE , true );
686
720
CheckWithFlag (output1, input2, SCRIPT_VERIFY_P2SH, false );
687
721
CheckWithFlag (output1, input2, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, false );
688
722
CheckWithFlag (output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false );
@@ -697,19 +731,19 @@ BOOST_AUTO_TEST_CASE(test_witness)
697
731
698
732
// Normal 2-of-2 multisig
699
733
CreateCreditAndSpend (keystore, scriptMulti, output1, input1, false );
700
- CheckWithFlag (output1, input1, 0 , false );
734
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , false );
701
735
CreateCreditAndSpend (keystore2, scriptMulti, output2, input2, false );
702
- CheckWithFlag (output2, input2, 0 , false );
736
+ CheckWithFlag (output2, input2, SCRIPT_VERIFY_NONE , false );
703
737
BOOST_CHECK (*output1 == *output2);
704
738
UpdateInput (input1.vin [0 ], CombineSignatures (input1, input2, output1));
705
739
CheckWithFlag (output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true );
706
740
707
741
// P2SH 2-of-2 multisig
708
742
CreateCreditAndSpend (keystore, GetScriptForDestination (ScriptHash (scriptMulti)), output1, input1, false );
709
- CheckWithFlag (output1, input1, 0 , true );
743
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
710
744
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH, false );
711
745
CreateCreditAndSpend (keystore2, GetScriptForDestination (ScriptHash (scriptMulti)), output2, input2, false );
712
- CheckWithFlag (output2, input2, 0 , true );
746
+ CheckWithFlag (output2, input2, SCRIPT_VERIFY_NONE , true );
713
747
CheckWithFlag (output2, input2, SCRIPT_VERIFY_P2SH, false );
714
748
BOOST_CHECK (*output1 == *output2);
715
749
UpdateInput (input1.vin [0 ], CombineSignatures (input1, input2, output1));
@@ -718,10 +752,10 @@ BOOST_AUTO_TEST_CASE(test_witness)
718
752
719
753
// Witness 2-of-2 multisig
720
754
CreateCreditAndSpend (keystore, destination_script_multi, output1, input1, false );
721
- CheckWithFlag (output1, input1, 0 , true );
755
+ CheckWithFlag (output1, input1, SCRIPT_VERIFY_NONE , true );
722
756
CheckWithFlag (output1, input1, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false );
723
757
CreateCreditAndSpend (keystore2, destination_script_multi, output2, input2, false );
724
- CheckWithFlag (output2, input2, 0 , true );
758
+ CheckWithFlag (output2, input2, SCRIPT_VERIFY_NONE , true );
725
759
CheckWithFlag (output2, input2, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false );
726
760
BOOST_CHECK (*output1 == *output2);
727
761
UpdateInput (input1.vin [0 ], CombineSignatures (input1, input2, output1));
0 commit comments