MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestBuilder

Class TestBuilder

src/test/script_tests.cpp:220–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218};
219
220class TestBuilder
221{
222private:
223 //! Actually executed script
224 CScript script;
225 //! The P2SH redeemscript
226 CScript redeemscript;
227 //! The Witness embedded script
228 CScript witscript;
229 CScriptWitness scriptWitness;
230 CTransactionRef creditTx;
231 CMutableTransaction spendTx;
232 bool havePush{false};
233 std::vector<unsigned char> push;
234 std::string comment;
235 script_verify_flags flags;
236 int scriptError{SCRIPT_ERR_OK};
237 CAmount nValue;
238
239 void DoPush()
240 {
241 if (havePush) {
242 spendTx.vin[0].scriptSig << push;
243 havePush = false;
244 }
245 }
246
247 void DoPush(const std::vector<unsigned char>& data)
248 {
249 DoPush();
250 push = data;
251 havePush = true;
252 }
253
254public:
255 TestBuilder(const CScript& script_, const std::string& comment_, script_verify_flags flags_, bool P2SH = false, WitnessMode wm = WitnessMode::NONE, int witnessversion = 0, CAmount nValue_ = 0) : script(script_), comment(comment_), flags(flags_), nValue(nValue_)
256 {
257 CScript scriptPubKey = script;
258 if (wm == WitnessMode::PKH) {
259 uint160 hash;
260 CHash160().Write(std::span{script}.subspan(1)).Finalize(hash);
261 script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(hash) << OP_EQUALVERIFY << OP_CHECKSIG;
262 scriptPubKey = CScript() << witnessversion << ToByteVector(hash);
263 } else if (wm == WitnessMode::SH) {
264 witscript = scriptPubKey;
265 uint256 hash;
266 CSHA256().Write(witscript.data(), witscript.size()).Finalize(hash.begin());
267 scriptPubKey = CScript() << witnessversion << ToByteVector(hash);
268 }
269 if (P2SH) {
270 redeemscript = scriptPubKey;
271 scriptPubKey = CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemscript)) << OP_EQUAL;
272 }
273 creditTx = MakeTransactionRef(BuildCreditingTransaction(scriptPubKey, nValue));
274 spendTx = BuildSpendingTransaction(CScript(), CScriptWitness(), *creditTx);
275 }
276
277 TestBuilder& ScriptError(ScriptError_t err)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 11

ParseHexFunction · 0.85
SignatureHashFunction · 0.85
NegateSignatureSFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
SignMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45
DoTestMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68