Skip to content

Commit fa29b5a

Browse files
author
MarcoFalke
committed
test: Add signet witness commitment section parse tests
1 parent fa23308 commit fa29b5a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/test/validation_tests.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <chainparams.h>
66
#include <net.h>
7+
#include <signet.h>
78
#include <validation.h>
89

910
#include <test/util/setup_common.h>
@@ -58,6 +59,67 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
5859
BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000});
5960
}
6061

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+
61123
static bool ReturnFalse() { return false; }
62124
static bool ReturnTrue() { return true; }
63125

0 commit comments

Comments
 (0)