MCPcopy Create free account
hub / github.com/LUX-Core/lux / TestBuilder

Class TestBuilder

src/test/script_tests.cpp:279–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277};
278
279class TestBuilder
280{
281private:
282 //! Actually executed script
283 CScript script;
284 //! The P2SH redeemscript
285 CScript redeemscript;
286 //! The Witness embedded script
287 CScript witscript;
288 CScriptWitness scriptWitness;
289 CTransactionRef creditTx;
290 CMutableTransaction spendTx;
291 bool havePush;
292 std::vector<unsigned char> push;
293 std::string comment;
294 int flags;
295 int scriptError;
296 CAmount nValue;
297
298 void DoPush()
299 {
300 if (havePush) {
301 spendTx.vin[0].scriptSig << push;
302 havePush = false;
303 }
304 }
305
306 void DoPush(const std::vector<unsigned char>& data)
307 {
308 DoPush();
309 push = data;
310 havePush = true;
311 }
312
313public:
314 TestBuilder(const CScript& script_, const std::string& comment_, int flags_, bool P2SH = false, WitnessMode wm = WitnessMode::NONE, int witnessversion = 0, CAmount nValue_ = 0) : script(script_), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK), nValue(nValue_)
315 {
316 CScript scriptPubKey = script;
317 if (wm == WitnessMode::PKH) {
318 uint160 hash;
319 CHash160().Write(&script[1], script.size() - 1).Finalize(hash.begin());
320 script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(hash) << OP_EQUALVERIFY << OP_CHECKSIG;
321 scriptPubKey = CScript() << witnessversion << ToByteVector(hash);
322 } else if (wm == WitnessMode::SH) {
323 witscript = scriptPubKey;
324 uint256 hash;
325 CSHA256().Write(&witscript[0], witscript.size()).Finalize(hash.begin());
326 scriptPubKey = CScript() << witnessversion << ToByteVector(hash);
327 }
328 if (P2SH) {
329 redeemscript = scriptPubKey;
330 scriptPubKey = CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemscript)) << OP_EQUAL;
331 }
332 creditTx = MakeTransactionRef(BuildCreditingTransaction(scriptPubKey, nValue));
333 spendTx = BuildSpendingTransaction(CScript(), CScriptWitness(), *creditTx);
334 }
335
336 TestBuilder& ScriptError(ScriptError_t err)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 11

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68