Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_P2SH_tests.cpp
// Copyright (c) 2012-2016 The Bitcoin Core developers | // Copyright (c) 2012-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "script/script.h" | |||||
#include "core_io.h" | #include "core_io.h" | ||||
#include "key.h" | #include "key.h" | ||||
#include "keystore.h" | #include "keystore.h" | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "script/ismine.h" | #include "script/ismine.h" | ||||
#include "script/script.h" | |||||
#include "script/script_error.h" | #include "script/script_error.h" | ||||
#include "script/sign.h" | #include "script/sign.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include <vector> | #include <vector> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for (int i = 0; i < 4; i++) { | ||||
evalScripts[i] = GetScriptForDestination(CScriptID(standardScripts[i])); | evalScripts[i] = GetScriptForDestination(CScriptID(standardScripts[i])); | ||||
} | } | ||||
CMutableTransaction txFrom; // Funding transaction: | CMutableTransaction txFrom; // Funding transaction: | ||||
std::string reason; | std::string reason; | ||||
txFrom.vout.resize(8); | txFrom.vout.resize(8); | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
txFrom.vout[i].scriptPubKey = evalScripts[i]; | txFrom.vout[i].scriptPubKey = evalScripts[i]; | ||||
txFrom.vout[i].nValue = COIN; | txFrom.vout[i].nValue = COIN.GetSatoshis(); | ||||
txFrom.vout[i + 4].scriptPubKey = standardScripts[i]; | txFrom.vout[i + 4].scriptPubKey = standardScripts[i]; | ||||
txFrom.vout[i + 4].nValue = COIN; | txFrom.vout[i + 4].nValue = COIN.GetSatoshis(); | ||||
} | } | ||||
BOOST_CHECK(IsStandardTx(txFrom, reason)); | BOOST_CHECK(IsStandardTx(txFrom, reason)); | ||||
CMutableTransaction txTo[8]; // Spending transactions | CMutableTransaction txTo[8]; // Spending transactions | ||||
for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
txTo[i].vin.resize(1); | txTo[i].vin.resize(1); | ||||
txTo[i].vout.resize(1); | txTo[i].vout.resize(1); | ||||
txTo[i].vin[0].prevout.n = i; | txTo[i].vin[0].prevout.n = i; | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(set) { | ||||
} | } | ||||
// Funding transaction: | // Funding transaction: | ||||
CMutableTransaction txFrom; | CMutableTransaction txFrom; | ||||
std::string reason; | std::string reason; | ||||
txFrom.vout.resize(4); | txFrom.vout.resize(4); | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
txFrom.vout[i].scriptPubKey = outer[i]; | txFrom.vout[i].scriptPubKey = outer[i]; | ||||
txFrom.vout[i].nValue = CENT; | txFrom.vout[i].nValue = CENT.GetSatoshis(); | ||||
} | } | ||||
BOOST_CHECK(IsStandardTx(txFrom, reason)); | BOOST_CHECK(IsStandardTx(txFrom, reason)); | ||||
// Spending transactions | // Spending transactions | ||||
CMutableTransaction txTo[4]; | CMutableTransaction txTo[4]; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
txTo[i].vin.resize(1); | txTo[i].vin.resize(1); | ||||
txTo[i].vout.resize(1); | txTo[i].vout.resize(1); | ||||
txTo[i].vin[0].prevout.n = i; | txTo[i].vin[0].prevout.n = i; | ||||
txTo[i].vin[0].prevout.hash = txFrom.GetId(); | txTo[i].vin[0].prevout.hash = txFrom.GetId(); | ||||
txTo[i].vout[0].nValue = 1 * CENT; | txTo[i].vout[0].nValue = 1 * CENT.GetSatoshis(); | ||||
txTo[i].vout[0].scriptPubKey = inner[i]; | txTo[i].vout[0].scriptPubKey = inner[i]; | ||||
BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), | ||||
strprintf("IsMine %d", i)); | strprintf("IsMine %d", i)); | ||||
} | } | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID), | SIGHASH_ALL | SIGHASH_FORKID), | ||||
strprintf("SignSignature %d", i)); | strprintf("SignSignature %d", i)); | ||||
▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines |