Changeset View
Changeset View
Standalone View
Standalone View
src/test/transaction_tests.cpp
Show First 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// Helper: create two dummy transactions, each with | // Helper: create two dummy transactions, each with | ||||
// two outputs. The first has 11 and 50 CENT outputs | // two outputs. The first has 11 and 50 CENT outputs | ||||
// paid to a TX_PUBKEY, the second 21 and 22 CENT outputs | // paid to a TX_PUBKEY, the second 21 and 22 CENT outputs | ||||
// paid to a TX_PUBKEYHASH. | // paid to a TX_PUBKEYHASH. | ||||
// | // | ||||
static std::vector<CMutableTransaction> | static std::vector<CMutableTransaction> | ||||
SetupDummyInputs(CBasicKeyStore &keystoreRet, CCoinsViewCache &coinsRet) { | SetupDummyInputs(FillableSigningProvider &keystoreRet, | ||||
CCoinsViewCache &coinsRet) { | |||||
std::vector<CMutableTransaction> dummyTransactions; | std::vector<CMutableTransaction> dummyTransactions; | ||||
dummyTransactions.resize(2); | dummyTransactions.resize(2); | ||||
// Add some keys to the keystore: | // Add some keys to the keystore: | ||||
CKey key[4]; | CKey key[4]; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
key[i].MakeNewKey(i % 2); | key[i].MakeNewKey(i % 2); | ||||
keystoreRet.AddKey(key[i]); | keystoreRet.AddKey(key[i]); | ||||
Show All 17 Lines | SetupDummyInputs(FillableSigningProvider &keystoreRet, | ||||
dummyTransactions[1].vout[1].scriptPubKey = | dummyTransactions[1].vout[1].scriptPubKey = | ||||
GetScriptForDestination(PKHash(key[3].GetPubKey())); | GetScriptForDestination(PKHash(key[3].GetPubKey())); | ||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); | AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); | ||||
return dummyTransactions; | return dummyTransactions; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_Get) { | BOOST_AUTO_TEST_CASE(test_Get) { | ||||
CBasicKeyStore keystore; | FillableSigningProvider keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = | ||||
SetupDummyInputs(keystore, coins); | SetupDummyInputs(keystore, coins); | ||||
CMutableTransaction t1; | CMutableTransaction t1; | ||||
t1.vin.resize(3); | t1.vin.resize(3); | ||||
t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
Show All 9 Lines | BOOST_AUTO_TEST_CASE(test_Get) { | ||||
t1.vout[0].scriptPubKey << OP_1; | t1.vout[0].scriptPubKey << OP_1; | ||||
BOOST_CHECK(AreInputsStandard(CTransaction(t1), coins, | BOOST_CHECK(AreInputsStandard(CTransaction(t1), coins, | ||||
STANDARD_SCRIPT_VERIFY_FLAGS)); | STANDARD_SCRIPT_VERIFY_FLAGS)); | ||||
BOOST_CHECK_EQUAL(coins.GetValueIn(CTransaction(t1)), | BOOST_CHECK_EQUAL(coins.GetValueIn(CTransaction(t1)), | ||||
(50 + 21 + 22) * CENT); | (50 + 21 + 22) * CENT); | ||||
} | } | ||||
static void CreateCreditAndSpend(const CBasicKeyStore &keystore, | static void CreateCreditAndSpend(const FillableSigningProvider &keystore, | ||||
const CScript &outscript, | const CScript &outscript, | ||||
CTransactionRef &output, | CTransactionRef &output, | ||||
CMutableTransaction &input, | CMutableTransaction &input, | ||||
bool success = true) { | bool success = true) { | ||||
CMutableTransaction outputm; | CMutableTransaction outputm; | ||||
outputm.nVersion = 1; | outputm.nVersion = 1; | ||||
outputm.vin.resize(1); | outputm.vin.resize(1); | ||||
outputm.vin[0].prevout = COutPoint(); | outputm.vin[0].prevout = COutPoint(); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | static void ReplaceRedeemScript(CScript &script, const CScript &redeemScript) { | ||||
stack.back() = | stack.back() = | ||||
std::vector<uint8_t>(redeemScript.begin(), redeemScript.end()); | std::vector<uint8_t>(redeemScript.begin(), redeemScript.end()); | ||||
script = PushAll(stack); | script = PushAll(stack); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_big_transaction) { | BOOST_AUTO_TEST_CASE(test_big_transaction) { | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(false); | key.MakeNewKey(false); | ||||
CBasicKeyStore keystore; | FillableSigningProvider keystore; | ||||
keystore.AddKeyPubKey(key, key.GetPubKey()); | keystore.AddKeyPubKey(key, key.GetPubKey()); | ||||
CScript scriptPubKey = CScript() | CScript scriptPubKey = CScript() | ||||
<< ToByteVector(key.GetPubKey()) << OP_CHECKSIG; | << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; | ||||
std::vector<SigHashType> sigHashes; | std::vector<SigHashType> sigHashes; | ||||
sigHashes.emplace_back(SIGHASH_NONE | SIGHASH_FORKID); | sigHashes.emplace_back(SIGHASH_NONE | SIGHASH_FORKID); | ||||
sigHashes.emplace_back(SIGHASH_SINGLE | SIGHASH_FORKID); | sigHashes.emplace_back(SIGHASH_SINGLE | SIGHASH_FORKID); | ||||
sigHashes.emplace_back(SIGHASH_ALL | SIGHASH_FORKID); | sigHashes.emplace_back(SIGHASH_ALL | SIGHASH_FORKID); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | SignatureData CombineSignatures(const CMutableTransaction &input1, | ||||
ProduceSignature( | ProduceSignature( | ||||
DUMMY_SIGNING_PROVIDER, | DUMMY_SIGNING_PROVIDER, | ||||
MutableTransactionSignatureCreator(&input1, 0, tx->vout[0].nValue), | MutableTransactionSignatureCreator(&input1, 0, tx->vout[0].nValue), | ||||
tx->vout[0].scriptPubKey, sigdata); | tx->vout[0].scriptPubKey, sigdata); | ||||
return sigdata; | return sigdata; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_witness) { | BOOST_AUTO_TEST_CASE(test_witness) { | ||||
CBasicKeyStore keystore, keystore2; | FillableSigningProvider keystore, keystore2; | ||||
CKey key1, key2, key3, key1L, key2L; | CKey key1, key2, key3, key1L, key2L; | ||||
CPubKey pubkey1, pubkey2, pubkey3, pubkey1L, pubkey2L; | CPubKey pubkey1, pubkey2, pubkey3, pubkey1L, pubkey2L; | ||||
key1.MakeNewKey(true); | key1.MakeNewKey(true); | ||||
key2.MakeNewKey(true); | key2.MakeNewKey(true); | ||||
key3.MakeNewKey(true); | key3.MakeNewKey(true); | ||||
key1L.MakeNewKey(false); | key1L.MakeNewKey(false); | ||||
key2L.MakeNewKey(false); | key2L.MakeNewKey(false); | ||||
pubkey1 = key1.GetPubKey(); | pubkey1 = key1.GetPubKey(); | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_witness) { | ||||
BOOST_CHECK(*output1 == *output2); | BOOST_CHECK(*output1 == *output2); | ||||
UpdateInput(input1.vin[0], CombineSignatures(input1, input2, output1)); | UpdateInput(input1.vin[0], CombineSignatures(input1, input2, output1)); | ||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true); | CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true); | ||||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true); | CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_IsStandard) { | BOOST_AUTO_TEST_CASE(test_IsStandard) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBasicKeyStore keystore; | FillableSigningProvider keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = | ||||
SetupDummyInputs(keystore, coins); | SetupDummyInputs(keystore, coins); | ||||
CMutableTransaction t; | CMutableTransaction t; | ||||
t.vin.resize(1); | t.vin.resize(1); | ||||
t.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | t.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |