mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Merge pull request #5074 from Munkybooty/backports-0.20-pr9
backport: v0.20 pr9
This commit is contained in:
commit
714ace4591
@ -6,47 +6,10 @@
|
|||||||
#include <coins.h>
|
#include <coins.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
|
#include <test/util/transaction_utils.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// FIXME: Dedup with SetupDummyInputs in test/transaction_tests.cpp.
|
|
||||||
//
|
|
||||||
// Helper: create two dummy transactions, each with
|
|
||||||
// two outputs. The first has 11 and 50 COIN outputs
|
|
||||||
// paid to a TxoutType::PUBKEY, the second 21 and 22 COIN outputs
|
|
||||||
// paid to a TxoutType::PUBKEYHASH.
|
|
||||||
//
|
|
||||||
static std::vector<CMutableTransaction>
|
|
||||||
SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet)
|
|
||||||
{
|
|
||||||
std::vector<CMutableTransaction> dummyTransactions;
|
|
||||||
dummyTransactions.resize(2);
|
|
||||||
|
|
||||||
// Add some keys to the keystore:
|
|
||||||
CKey key[4];
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
key[i].MakeNewKey(i % 2);
|
|
||||||
keystoreRet.AddKey(key[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create some dummy input transactions
|
|
||||||
dummyTransactions[0].vout.resize(2);
|
|
||||||
dummyTransactions[0].vout[0].nValue = 11 * COIN;
|
|
||||||
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
|
||||||
dummyTransactions[0].vout[1].nValue = 50 * COIN;
|
|
||||||
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
|
||||||
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0);
|
|
||||||
|
|
||||||
dummyTransactions[1].vout.resize(2);
|
|
||||||
dummyTransactions[1].vout[0].nValue = 21 * COIN;
|
|
||||||
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
|
||||||
dummyTransactions[1].vout[1].nValue = 22 * COIN;
|
|
||||||
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
|
|
||||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
|
|
||||||
|
|
||||||
return dummyTransactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
|
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
|
||||||
// laanwj, "replicating the actual usage patterns of the client is hard though,
|
// laanwj, "replicating the actual usage patterns of the client is hard though,
|
||||||
// many times micro-benchmarks of the database showed completely different
|
// many times micro-benchmarks of the database showed completely different
|
||||||
@ -61,7 +24,8 @@ static void CCoinsCaching(benchmark::Bench& bench)
|
|||||||
FillableSigningProvider keystore;
|
FillableSigningProvider keystore;
|
||||||
CCoinsView coinsDummy;
|
CCoinsView coinsDummy;
|
||||||
CCoinsViewCache coins(&coinsDummy);
|
CCoinsViewCache coins(&coinsDummy);
|
||||||
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
|
std::vector<CMutableTransaction> dummyTransactions =
|
||||||
|
SetupDummyInputs(keystore, coins, {11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN});
|
||||||
|
|
||||||
CMutableTransaction t1;
|
CMutableTransaction t1;
|
||||||
t1.vin.resize(3);
|
t1.vin.resize(3);
|
||||||
|
@ -507,8 +507,9 @@ static UniValue setmocktime(const JSONRPCRequest& request)
|
|||||||
RPCExamples{""},
|
RPCExamples{""},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if (!Params().MineBlocksOnDemand())
|
if (!Params().IsMockableChain()) {
|
||||||
throw std::runtime_error("setmocktime for regression testing (-regtest mode) only");
|
throw std::runtime_error("setmocktime is for regression testing (-regtest mode) only");
|
||||||
|
}
|
||||||
|
|
||||||
// For now, don't change mocktime if we're in the middle of validation, as
|
// For now, don't change mocktime if we're in the middle of validation, as
|
||||||
// this could have an effect on mempool time-based eviction, as well as
|
// this could have an effect on mempool time-based eviction, as well as
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <script/script_error.h>
|
#include <script/script_error.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
#include <test/util/transaction_utils.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -252,50 +253,13 @@ BOOST_AUTO_TEST_CASE(basic_transaction_tests)
|
|||||||
BOOST_CHECK_MESSAGE(!CheckTransaction(CTransaction(tx), state) || !state.IsValid(), "Transaction with duplicate txins should be invalid.");
|
BOOST_CHECK_MESSAGE(!CheckTransaction(CTransaction(tx), state) || !state.IsValid(), "Transaction with duplicate txins should be invalid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Helper: create two dummy transactions, each with
|
|
||||||
// two outputs. The first has 11 and 50 CENT outputs
|
|
||||||
// paid to a TxoutType::PUBKEY, the second 21 and 22 CENT outputs
|
|
||||||
// paid to a TxoutType::PUBKEYHASH.
|
|
||||||
//
|
|
||||||
static std::vector<CMutableTransaction>
|
|
||||||
SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet)
|
|
||||||
{
|
|
||||||
std::vector<CMutableTransaction> dummyTransactions;
|
|
||||||
dummyTransactions.resize(2);
|
|
||||||
|
|
||||||
// Add some keys to the keystore:
|
|
||||||
CKey key[4];
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
key[i].MakeNewKey(i % 2);
|
|
||||||
keystoreRet.AddKey(key[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create some dummy input transactions
|
|
||||||
dummyTransactions[0].vout.resize(2);
|
|
||||||
dummyTransactions[0].vout[0].nValue = 11*CENT;
|
|
||||||
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
|
||||||
dummyTransactions[0].vout[1].nValue = 50*CENT;
|
|
||||||
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
|
||||||
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0);
|
|
||||||
|
|
||||||
dummyTransactions[1].vout.resize(2);
|
|
||||||
dummyTransactions[1].vout[0].nValue = 21*CENT;
|
|
||||||
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
|
||||||
dummyTransactions[1].vout[1].nValue = 22*CENT;
|
|
||||||
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
|
|
||||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
|
|
||||||
|
|
||||||
return dummyTransactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_Get)
|
BOOST_AUTO_TEST_CASE(test_Get)
|
||||||
{
|
{
|
||||||
FillableSigningProvider keystore;
|
FillableSigningProvider keystore;
|
||||||
CCoinsView coinsDummy;
|
CCoinsView coinsDummy;
|
||||||
CCoinsViewCache coins(&coinsDummy);
|
CCoinsViewCache coins(&coinsDummy);
|
||||||
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
|
std::vector<CMutableTransaction> dummyTransactions =
|
||||||
|
SetupDummyInputs(keystore, coins, {11*CENT, 50*CENT, 21*CENT, 22*CENT});
|
||||||
|
|
||||||
CMutableTransaction t1;
|
CMutableTransaction t1;
|
||||||
t1.vin.resize(3);
|
t1.vin.resize(3);
|
||||||
@ -321,7 +285,8 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
|||||||
FillableSigningProvider keystore;
|
FillableSigningProvider keystore;
|
||||||
CCoinsView coinsDummy;
|
CCoinsView coinsDummy;
|
||||||
CCoinsViewCache coins(&coinsDummy);
|
CCoinsViewCache coins(&coinsDummy);
|
||||||
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
|
std::vector<CMutableTransaction> dummyTransactions =
|
||||||
|
SetupDummyInputs(keystore, coins, {11*CENT, 50*CENT, 21*CENT, 22*CENT});
|
||||||
|
|
||||||
CMutableTransaction t;
|
CMutableTransaction t;
|
||||||
t.vin.resize(1);
|
t.vin.resize(1);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <test/util/transaction_utils.h>
|
#include <test/util/transaction_utils.h>
|
||||||
|
#include <coins.h>
|
||||||
|
#include <script/signingprovider.h>
|
||||||
|
|
||||||
CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue)
|
CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue)
|
||||||
{
|
{
|
||||||
@ -36,3 +38,33 @@ CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTr
|
|||||||
|
|
||||||
return txSpend;
|
return txSpend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues)
|
||||||
|
{
|
||||||
|
std::vector<CMutableTransaction> dummyTransactions;
|
||||||
|
dummyTransactions.resize(2);
|
||||||
|
|
||||||
|
// Add some keys to the keystore:
|
||||||
|
CKey key[4];
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
key[i].MakeNewKey(i % 2);
|
||||||
|
keystoreRet.AddKey(key[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create some dummy input transactions
|
||||||
|
dummyTransactions[0].vout.resize(2);
|
||||||
|
dummyTransactions[0].vout[0].nValue = nValues[0];
|
||||||
|
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||||
|
dummyTransactions[0].vout[1].nValue = nValues[1];
|
||||||
|
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
||||||
|
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0);
|
||||||
|
|
||||||
|
dummyTransactions[1].vout.resize(2);
|
||||||
|
dummyTransactions[1].vout[0].nValue = nValues[2];
|
||||||
|
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
||||||
|
dummyTransactions[1].vout[1].nValue = nValues[3];
|
||||||
|
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
|
||||||
|
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
|
||||||
|
|
||||||
|
return dummyTransactions;
|
||||||
|
}
|
||||||
|
@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
class FillableSigningProvider;
|
||||||
|
class CCoinsViewCache;
|
||||||
|
|
||||||
// create crediting transaction
|
// create crediting transaction
|
||||||
// [1 coinbase input => 1 output with given scriptPubkey and value]
|
// [1 coinbase input => 1 output with given scriptPubkey and value]
|
||||||
CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0);
|
CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0);
|
||||||
@ -16,4 +21,9 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int n
|
|||||||
// 1 output with empty scriptPubKey, full value of referenced transaction]
|
// 1 output with empty scriptPubKey, full value of referenced transaction]
|
||||||
CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTransaction& txCredit);
|
CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTransaction& txCredit);
|
||||||
|
|
||||||
|
// Helper: create two dummy transactions, each with two outputs.
|
||||||
|
// The first has nValues[0] and nValues[1] outputs paid to a TX_PUBKEY,
|
||||||
|
// the second nValues[2] and nValues[3] outputs paid to a TX_PUBKEYHASH.
|
||||||
|
std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues);
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
#endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
||||||
|
@ -386,7 +386,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
|
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
|
||||||
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
|
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
|
||||||
for bip113tx in [bip113signed1, bip113signed2]:
|
for bip113tx in [bip113signed1, bip113signed2]:
|
||||||
self.send_blocks([self.create_test_block([bip113tx])], success=False)
|
self.send_blocks([self.create_test_block([bip113tx])], success=False, reject_reason='bad-txns-nonfinal')
|
||||||
# BIP 113 tests should now pass if the locktime is < MTP
|
# BIP 113 tests should now pass if the locktime is < MTP
|
||||||
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
|
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
|
||||||
bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
|
bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
|
||||||
@ -418,11 +418,11 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
# All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
|
# All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
|
||||||
bip68timetxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']]
|
bip68timetxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']]
|
||||||
for tx in bip68timetxs:
|
for tx in bip68timetxs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False, reject_reason='bad-txns-nonfinal')
|
||||||
|
|
||||||
bip68heighttxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']]
|
bip68heighttxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']]
|
||||||
for tx in bip68heighttxs:
|
for tx in bip68heighttxs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False, reject_reason='bad-txns-nonfinal')
|
||||||
|
|
||||||
# Advance one block to 581
|
# Advance one block to 581
|
||||||
test_blocks = self.generate_blocks(1, 1234)
|
test_blocks = self.generate_blocks(1, 1234)
|
||||||
@ -433,7 +433,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
self.send_blocks([self.create_test_block(bip68success_txs)])
|
self.send_blocks([self.create_test_block(bip68success_txs)])
|
||||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
|
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
|
||||||
for tx in bip68heighttxs:
|
for tx in bip68heighttxs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False, reject_reason='bad-txns-nonfinal')
|
||||||
|
|
||||||
# Advance one block to 582
|
# Advance one block to 582
|
||||||
test_blocks = self.generate_blocks(1, 1234)
|
test_blocks = self.generate_blocks(1, 1234)
|
||||||
@ -448,7 +448,8 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
self.log.info("Test version 1 txs")
|
self.log.info("Test version 1 txs")
|
||||||
|
|
||||||
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
|
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
|
||||||
self.send_blocks([self.create_test_block([bip112tx_special_v1])], success=False)
|
self.send_blocks([self.create_test_block([bip112tx_special_v1])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Negative locktime)')
|
||||||
self.send_blocks([self.create_test_block([bip112tx_emptystack_v1])], success=False,
|
self.send_blocks([self.create_test_block([bip112tx_emptystack_v1])], success=False,
|
||||||
reject_reason='non-mandatory-script-verify-flag (Operation not valid with the current stack size)')
|
reject_reason='non-mandatory-script-verify-flag (Operation not valid with the current stack size)')
|
||||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
|
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
|
||||||
@ -461,15 +462,17 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
|
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
|
||||||
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_v1)
|
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_v1)
|
||||||
fail_txs += all_rlt_txs(bip112txs_vary_nSequence_9_v1)
|
fail_txs += all_rlt_txs(bip112txs_vary_nSequence_9_v1)
|
||||||
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
|
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v1 if not tx['sdf']]
|
||||||
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
|
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
|
||||||
for tx in fail_txs:
|
for tx in fail_txs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Locktime requirement not satisfied)')
|
||||||
|
|
||||||
self.log.info("Test version 2 txs")
|
self.log.info("Test version 2 txs")
|
||||||
|
|
||||||
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
|
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
|
||||||
self.send_blocks([self.create_test_block([bip112tx_special_v2])], success=False)
|
self.send_blocks([self.create_test_block([bip112tx_special_v2])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Negative locktime)')
|
||||||
self.send_blocks([self.create_test_block([bip112tx_emptystack_v2])], success=False,
|
self.send_blocks([self.create_test_block([bip112tx_emptystack_v2])], success=False,
|
||||||
reject_reason='non-mandatory-script-verify-flag (Operation not valid with the current stack size)')
|
reject_reason='non-mandatory-script-verify-flag (Operation not valid with the current stack size)')
|
||||||
|
|
||||||
@ -486,18 +489,21 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||||||
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2)
|
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2)
|
||||||
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']]
|
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']]
|
||||||
for tx in fail_txs:
|
for tx in fail_txs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Locktime requirement not satisfied)')
|
||||||
|
|
||||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
|
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
|
||||||
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if tx['sdf']]
|
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if tx['sdf']]
|
||||||
for tx in fail_txs:
|
for tx in fail_txs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Locktime requirement not satisfied)')
|
||||||
|
|
||||||
# If sequencelock types mismatch, tx should fail
|
# If sequencelock types mismatch, tx should fail
|
||||||
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']]
|
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']]
|
||||||
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]
|
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]
|
||||||
for tx in fail_txs:
|
for tx in fail_txs:
|
||||||
self.send_blocks([self.create_test_block([tx])], success=False)
|
self.send_blocks([self.create_test_block([tx])], success=False,
|
||||||
|
reject_reason='non-mandatory-script-verify-flag (Locktime requirement not satisfied)')
|
||||||
|
|
||||||
# Remaining txs should pass, just test masking works properly
|
# Remaining txs should pass, just test masking works properly
|
||||||
success_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']]
|
success_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']]
|
||||||
|
62
test/functional/rpc_getdescriptorinfo.py
Executable file
62
test/functional/rpc_getdescriptorinfo.py
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright (c) 2019 The Bitcoin Core developers
|
||||||
|
# Distributed under the MIT software license, see the accompanying
|
||||||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
"""Test getdescriptorinfo RPC.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
from test_framework.descriptors import descsum_create
|
||||||
|
from test_framework.util import (
|
||||||
|
assert_equal,
|
||||||
|
assert_raises_rpc_error,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DescriptorTest(BitcoinTestFramework):
|
||||||
|
def set_test_params(self):
|
||||||
|
self.num_nodes = 1
|
||||||
|
self.extra_args = [["-disablewallet"]]
|
||||||
|
self.wallet_names = []
|
||||||
|
|
||||||
|
def test_desc(self, desc, isrange, issolvable, hasprivatekeys):
|
||||||
|
info = self.nodes[0].getdescriptorinfo(desc)
|
||||||
|
assert_equal(info, self.nodes[0].getdescriptorinfo(descsum_create(desc)))
|
||||||
|
assert_equal(info['descriptor'], descsum_create(desc))
|
||||||
|
assert_equal(info['isrange'], isrange)
|
||||||
|
assert_equal(info['issolvable'], issolvable)
|
||||||
|
assert_equal(info['hasprivatekeys'], hasprivatekeys)
|
||||||
|
|
||||||
|
def run_test(self):
|
||||||
|
assert_raises_rpc_error(-1, 'getdescriptorinfo', self.nodes[0].getdescriptorinfo)
|
||||||
|
assert_raises_rpc_error(-3, 'Expected type string', self.nodes[0].getdescriptorinfo, 1)
|
||||||
|
assert_raises_rpc_error(-5, 'is not a valid descriptor function', self.nodes[0].getdescriptorinfo, '')
|
||||||
|
|
||||||
|
# P2PK output with the specified public key.
|
||||||
|
self.test_desc('pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# P2PKH output with the specified public key.
|
||||||
|
self.test_desc('pkh(02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5)', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# P2SH-P2PKH output with the specified public key.
|
||||||
|
self.test_desc('sh(pkh(03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556))', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# Any P2PK, P2PKH, or P2SH-P2PKH output with the specified public key.
|
||||||
|
self.test_desc('combo(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A bare *1-of-2* multisig output with keys in the specified order.
|
||||||
|
self.test_desc('multi(1,022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4,025cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc)', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A P2SH *2-of-2* multisig output with keys in the specified order.
|
||||||
|
self.test_desc('sh(multi(2,022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01,03acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe))', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A P2WSH *2-of-3* multisig output with keys in the specified order.
|
||||||
|
self.test_desc('sh(multi(2,03a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7,03774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb,03d01115d548e7561b15c38f004d734633687cf4419620095bc5b0f47070afe85a))', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A P2SH-P2SH *1-of-3* multisig output with keys in the specified order.
|
||||||
|
self.test_desc('sh(multi(1,03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8,03499fdf9e895e719cfd64e67f07d38e3226aa7b63678949e6e49b241a60e823e4,02d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e))', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A P2PK output with the public key of the specified xpub.
|
||||||
|
self.test_desc('pk(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B)', isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A P2PKH output with child key *1'/2* of the specified xpub.
|
||||||
|
self.test_desc("pkh(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1'/2)", isrange=False, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A set of P2PKH outputs, but additionally specifies that the specified xpub is a child of a master with fingerprint `d34db33f`, and derived using path `44'/0'/0'`.
|
||||||
|
self.test_desc("pkh([d34db33f/44'/0'/0']tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/*)", isrange=True, issolvable=True, hasprivatekeys=False)
|
||||||
|
# A set of *1-of-2* P2SH multisig outputs where the first multisig key is the *1/0/`i`* child of the first specified xpub and the second multisig key is the *0/0/`i`* child of the second specified xpub, and `i` is any number in a configurable range (`0-1000` by default).
|
||||||
|
self.test_desc("sh(multi(1,tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/0/*,tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/0/0/*))", isrange=True, issolvable=True, hasprivatekeys=False)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
DescriptorTest().main()
|
@ -262,6 +262,7 @@ BASE_SCRIPTS = [
|
|||||||
'wallet_startup.py',
|
'wallet_startup.py',
|
||||||
'feature_config_args.py',
|
'feature_config_args.py',
|
||||||
'feature_settings.py',
|
'feature_settings.py',
|
||||||
|
'rpc_getdescriptorinfo.py',
|
||||||
'rpc_help.py',
|
'rpc_help.py',
|
||||||
'feature_help.py',
|
'feature_help.py',
|
||||||
# Don't append tests at the end to avoid merge conflicts
|
# Don't append tests at the end to avoid merge conflicts
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (c) 2017 The Bitcoin Core developers
|
# Copyright (c) 2017 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.
|
||||||
"""Test the listsincelast RPC."""
|
"""Test the listsinceblock RPC."""
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.messages import BIP125_SEQUENCE_NUMBER
|
from test_framework.messages import BIP125_SEQUENCE_NUMBER
|
||||||
@ -37,6 +37,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
self.double_spends_filtered()
|
self.double_spends_filtered()
|
||||||
|
|
||||||
def test_no_blockhash(self):
|
def test_no_blockhash(self):
|
||||||
|
self.log.info("Test no blockhash")
|
||||||
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
|
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
|
||||||
blockhash, = self.nodes[2].generate(1)
|
blockhash, = self.nodes[2].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
@ -60,6 +61,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
"transactions": txs})
|
"transactions": txs})
|
||||||
|
|
||||||
def test_invalid_blockhash(self):
|
def test_invalid_blockhash(self):
|
||||||
|
self.log.info("Test invalid blockhash")
|
||||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
||||||
"42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4")
|
"42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4")
|
||||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock,
|
||||||
@ -95,6 +97,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
This test only checks that [tx0] is present.
|
This test only checks that [tx0] is present.
|
||||||
'''
|
'''
|
||||||
|
self.log.info("Test reorg")
|
||||||
|
|
||||||
# Split network into two
|
# Split network into two
|
||||||
self.split_network()
|
self.split_network()
|
||||||
@ -105,7 +108,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
# generate on both sides
|
# generate on both sides
|
||||||
lastblockhash = self.nodes[1].generate(6)[5]
|
lastblockhash = self.nodes[1].generate(6)[5]
|
||||||
self.nodes[2].generate(7)
|
self.nodes[2].generate(7)
|
||||||
self.log.info('lastblockhash=%s' % (lastblockhash))
|
self.log.debug('lastblockhash={}'.format(lastblockhash))
|
||||||
|
|
||||||
self.sync_all(self.nodes[:2])
|
self.sync_all(self.nodes[:2])
|
||||||
self.sync_all(self.nodes[2:])
|
self.sync_all(self.nodes[2:])
|
||||||
@ -150,6 +153,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
until the fork point, and to include all transactions that relate to the
|
until the fork point, and to include all transactions that relate to the
|
||||||
node wallet.
|
node wallet.
|
||||||
'''
|
'''
|
||||||
|
self.log.info("Test double spend")
|
||||||
|
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
@ -229,6 +233,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
3. It is listed with a confirmation count of 2 (bb3, bb4), not
|
3. It is listed with a confirmation count of 2 (bb3, bb4), not
|
||||||
3 (aa1, aa2, aa3).
|
3 (aa1, aa2, aa3).
|
||||||
'''
|
'''
|
||||||
|
self.log.info("Test double send")
|
||||||
|
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
@ -296,6 +301,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
|||||||
`listsinceblock` was returning conflicted transactions even if they
|
`listsinceblock` was returning conflicted transactions even if they
|
||||||
occurred before the specified cutoff blockhash
|
occurred before the specified cutoff blockhash
|
||||||
'''
|
'''
|
||||||
|
self.log.info("Test spends filtered")
|
||||||
spending_node = self.nodes[2]
|
spending_node = self.nodes[2]
|
||||||
double_spending_node = self.nodes[3]
|
double_spending_node = self.nodes[3]
|
||||||
dest_address = spending_node.getnewaddress()
|
dest_address = spending_node.getnewaddress()
|
||||||
|
@ -18,3 +18,5 @@ crypted
|
|||||||
fo
|
fo
|
||||||
stoll
|
stoll
|
||||||
hist
|
hist
|
||||||
|
ser
|
||||||
|
unselect
|
||||||
|
Loading…
Reference in New Issue
Block a user