|
4 | 4 |
|
5 | 5 | #include <chainparams.h>
|
6 | 6 | #include <net.h>
|
| 7 | +#include <signet.h> |
7 | 8 | #include <validation.h>
|
8 | 9 |
|
9 | 10 | #include <test/util/setup_common.h>
|
@@ -58,6 +59,67 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
|
58 | 59 | BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000});
|
59 | 60 | }
|
60 | 61 |
|
| 62 | +BOOST_AUTO_TEST_CASE(signet_parse_tests) |
| 63 | +{ |
| 64 | + ArgsManager signet_argsman; |
| 65 | + signet_argsman.ForceSetArg("-signetchallenge", "51"); // set challenge to OP_TRUE |
| 66 | + const auto signet_params = CreateChainParams(signet_argsman, CBaseChainParams::SIGNET); |
| 67 | + CBlock block; |
| 68 | + BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{{OP_TRUE}}); |
| 69 | + CScript challenge{OP_TRUE}; |
| 70 | + |
| 71 | + // empty block is invalid |
| 72 | + BOOST_CHECK(!SignetTxs::Create(block, challenge)); |
| 73 | + BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 74 | + |
| 75 | + // no witness commitment |
| 76 | + CMutableTransaction cb; |
| 77 | + cb.vout.emplace_back(0, CScript{}); |
| 78 | + block.vtx.push_back(MakeTransactionRef(cb)); |
| 79 | + block.vtx.push_back(MakeTransactionRef(cb)); // Add dummy tx to excercise merkle root code |
| 80 | + BOOST_CHECK(!SignetTxs::Create(block, challenge)); |
| 81 | + BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 82 | + |
| 83 | + // no header is treated valid |
| 84 | + std::vector<uint8_t> witness_commitment_section_141{0xaa, 0x21, 0xa9, 0xed}; |
| 85 | + for (int i = 0; i < 32; ++i) { |
| 86 | + witness_commitment_section_141.push_back(0xff); |
| 87 | + } |
| 88 | + cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141; |
| 89 | + block.vtx.at(0) = MakeTransactionRef(cb); |
| 90 | + BOOST_CHECK(SignetTxs::Create(block, challenge)); |
| 91 | + BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 92 | + |
| 93 | + // no data after header, valid |
| 94 | + std::vector<uint8_t> witness_commitment_section_325{0xec, 0xc7, 0xda, 0xa2}; |
| 95 | + cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325; |
| 96 | + block.vtx.at(0) = MakeTransactionRef(cb); |
| 97 | + BOOST_CHECK(SignetTxs::Create(block, challenge)); |
| 98 | + BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 99 | + |
| 100 | + // Premature end of data, invalid |
| 101 | + witness_commitment_section_325.push_back(0x01); |
| 102 | + witness_commitment_section_325.push_back(0x51); |
| 103 | + cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325; |
| 104 | + block.vtx.at(0) = MakeTransactionRef(cb); |
| 105 | + BOOST_CHECK(!SignetTxs::Create(block, challenge)); |
| 106 | + BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 107 | + |
| 108 | + // has data, valid |
| 109 | + witness_commitment_section_325.push_back(0x00); |
| 110 | + cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325; |
| 111 | + block.vtx.at(0) = MakeTransactionRef(cb); |
| 112 | + BOOST_CHECK(SignetTxs::Create(block, challenge)); |
| 113 | + BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 114 | + |
| 115 | + // Extraneous data, invalid |
| 116 | + witness_commitment_section_325.push_back(0x00); |
| 117 | + cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325; |
| 118 | + block.vtx.at(0) = MakeTransactionRef(cb); |
| 119 | + BOOST_CHECK(!SignetTxs::Create(block, challenge)); |
| 120 | + BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus())); |
| 121 | +} |
| 122 | + |
61 | 123 | static bool ReturnFalse() { return false; }
|
62 | 124 | static bool ReturnTrue() { return true; }
|
63 | 125 |
|
|
0 commit comments