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

Class TestBuilder

src/test/script_tests.cpp:287–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

add_replay_tests_modeFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 11

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

Tested by 2

add_replay_tests_modeFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68