aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_block.py21
-rwxr-xr-xtest/functional/feature_coinstatsindex.py1
-rwxr-xr-xtest/functional/feature_rbf.py170
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py8
-rwxr-xr-xtest/functional/p2p_compactblocks_hb.py97
-rwxr-xr-xtest/functional/p2p_invalid_block.py19
-rwxr-xr-xtest/functional/rpc_setban.py31
-rw-r--r--test/functional/test_framework/blocktools.py5
-rwxr-xr-xtest/functional/test_framework/messages.py2
-rwxr-xr-xtest/functional/test_framework/test_framework.py4
-rw-r--r--test/functional/test_framework/wallet.py32
-rwxr-xr-xtest/functional/test_runner.py20
-rwxr-xr-xtest/functional/wallet_taproot.py153
-rw-r--r--test/lint/lint-spelling.ignore-words.txt1
-rw-r--r--test/util/data/bitcoin-util-test.json30
15 files changed, 454 insertions, 140 deletions
diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py
index 158efb52c9..389db73bc9 100755
--- a/test/functional/feature_block.py
+++ b/test/functional/feature_block.py
@@ -591,6 +591,8 @@ class FullBlockTest(BitcoinTestFramework):
b44.hashPrevBlock = self.tip.sha256
b44.nBits = 0x207fffff
b44.vtx.append(coinbase)
+ tx = self.create_and_sign_transaction(out[14], 1)
+ b44.vtx.append(tx)
b44.hashMerkleRoot = b44.calc_merkle_root()
b44.solve()
self.tip = b44
@@ -678,7 +680,7 @@ class FullBlockTest(BitcoinTestFramework):
# Test block timestamps
# -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15)
# \-> b54 (15)
- #
+ # -> b44 (14)\-> b48 ()
self.move_tip(43)
b53 = self.next_block(53, spend=out[14])
self.send_blocks([b53], False)
@@ -698,6 +700,21 @@ class FullBlockTest(BitcoinTestFramework):
self.send_blocks([b55], True)
self.save_spendable_output()
+ # The block which was previously rejected because of being "too far(3 hours)" must be accepted 2 hours later.
+ # The new block is only 1 hour into future now and we must reorg onto to the new longer chain.
+ # The new bestblock b48p is invalidated manually.
+ # -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15)
+ # \-> b54 (15)
+ # -> b44 (14)\-> b48 () -> b48p ()
+ self.log.info("Accept a previously rejected future block at a later time")
+ node.setmocktime(int(time.time()) + 2*60*60)
+ self.move_tip(48)
+ self.block_heights[b48.sha256] = self.block_heights[b44.sha256] + 1 # b48 is a parent of b44
+ b48p = self.next_block("48p")
+ self.send_blocks([b48, b48p], success=True) # Reorg to the longer chain
+ node.invalidateblock(b48p.hash) # mark b48p as invalid
+ node.setmocktime(0)
+
# Test Merkle tree malleability
#
# -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) -> b57p2 (16)
@@ -1308,7 +1325,7 @@ class FullBlockTest(BitcoinTestFramework):
return create_tx_with_script(spend_tx, n, amount=value, script_pub_key=script)
# sign a transaction, using the key we know about
- # this signs input 0 in tx, which is assumed to be spending output n in spend_tx
+ # this signs input 0 in tx, which is assumed to be spending output 0 in spend_tx
def sign_tx(self, tx, spend_tx):
scriptPubKey = bytearray(spend_tx.vout[0].scriptPubKey)
if (scriptPubKey[0] == OP_TRUE): # an anyone-can-spend
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py
index cf270b25ee..7488e3cb42 100755
--- a/test/functional/feature_coinstatsindex.py
+++ b/test/functional/feature_coinstatsindex.py
@@ -281,6 +281,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
# Add another block, so we don't depend on reconsiderblock remembering which
# blocks were touched by invalidateblock
index_node.generate(1)
+ self.sync_all()
# Ensure that removing and re-adding blocks yields consistent results
block = index_node.getblockhash(99)
diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py
index 0bb04ae267..b99b64e16d 100755
--- a/test/functional/feature_rbf.py
+++ b/test/functional/feature_rbf.py
@@ -7,17 +7,20 @@
from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
-from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
+from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, BIP125_SEQUENCE_NUMBER
from test_framework.script import CScript, OP_DROP
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round
from test_framework.script_util import DUMMY_P2WPKH_SCRIPT, DUMMY_2_P2WPKH_SCRIPT
+from test_framework.wallet import MiniWallet
MAX_REPLACEMENT_LIMIT = 100
+
def txToHex(tx):
return tx.serialize().hex()
+
def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
"""Create a txout with a given amount and scriptPubKey
@@ -26,12 +29,12 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
confirmed - txouts created will be confirmed in the blockchain;
unconfirmed otherwise.
"""
- fee = 1*COIN
- while node.getbalance() < satoshi_round((amount + fee)/COIN):
+ fee = 1 * COIN
+ while node.getbalance() < satoshi_round((amount + fee) / COIN):
node.generate(COINBASE_MATURITY)
new_addr = node.getnewaddress()
- txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))
+ txid = node.sendtoaddress(new_addr, satoshi_round((amount + fee) / COIN))
tx1 = node.getrawtransaction(txid, 1)
txid = int(txid, 16)
i, _ = next(filter(lambda vout: new_addr == vout[1]['scriptPubKey']['address'], enumerate(tx1['vout'])))
@@ -78,10 +81,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
self.skip_if_no_wallet()
def run_test(self):
- # Leave IBD
- self.nodes[0].generate(1)
-
- make_utxo(self.nodes[0], 1*COIN)
+ make_utxo(self.nodes[0], 1 * COIN)
# Ensure nodes are synced
self.sync_all()
@@ -123,7 +123,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_simple_doublespend(self):
"""Simple doublespend"""
- tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
# make_utxo may have generated a bunch of blocks, so we need to sync
# before we can spend the coins generated, or else the resulting
@@ -165,14 +165,14 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_doublespend_chain(self):
"""Doublespend of a long chain"""
- initial_nValue = 50*COIN
+ initial_nValue = 50 * COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
prevout = tx0_outpoint
remaining_value = initial_nValue
chain_txids = []
- while remaining_value > 10*COIN:
- remaining_value -= 1*COIN
+ while remaining_value > 10 * COIN:
+ remaining_value -= 1 * COIN
tx = CTransaction()
tx.vin = [CTxIn(prevout, nSequence=0)]
tx.vout = [CTxOut(remaining_value, CScript([1, OP_DROP] * 15 + [1]))]
@@ -205,10 +205,10 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_doublespend_tree(self):
"""Doublespend of a big tree of transactions"""
- initial_nValue = 50*COIN
+ initial_nValue = 50 * COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
- def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _total_txs=None):
+ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001 * COIN, _total_txs=None):
if _total_txs is None:
_total_txs = [0]
if _total_txs[0] >= max_txs:
@@ -239,7 +239,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
_total_txs=_total_txs):
yield x
- fee = int(0.0001*COIN)
+ fee = int(0.0001 * COIN)
n = MAX_REPLACEMENT_LIMIT
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
assert_equal(len(tree_txs), n)
@@ -267,8 +267,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Try again, but with more total transactions than the "max txs
# double-spent at once" anti-DoS limit.
- for n in (MAX_REPLACEMENT_LIMIT+1, MAX_REPLACEMENT_LIMIT*2):
- fee = int(0.0001*COIN)
+ for n in (MAX_REPLACEMENT_LIMIT + 1, MAX_REPLACEMENT_LIMIT * 2):
+ fee = int(0.0001 * COIN)
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
assert_equal(len(tree_txs), n)
@@ -286,7 +286,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_replacement_feeperkb(self):
"""Replacement requires fee-per-KB to be higher"""
- tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@@ -298,7 +298,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# rejected.
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
- tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))]
+ tx1b.vout = [CTxOut(int(0.001 * COIN), CScript([b'a' * 999000]))]
tx1b_hex = txToHex(tx1b)
# This will raise an exception due to insufficient fee
@@ -306,8 +306,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_spends_of_conflicting_outputs(self):
"""Replacements that spend conflicting tx outputs are rejected"""
- utxo1 = make_utxo(self.nodes[0], int(1.2*COIN))
- utxo2 = make_utxo(self.nodes[0], 3*COIN)
+ utxo1 = make_utxo(self.nodes[0], int(1.2 * COIN))
+ utxo2 = make_utxo(self.nodes[0], 3 * COIN)
tx1a = CTransaction()
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
@@ -346,8 +346,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_new_unconfirmed_inputs(self):
"""Replacements that add new unconfirmed inputs are rejected"""
- confirmed_utxo = make_utxo(self.nodes[0], int(1.1*COIN))
- unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1*COIN), False)
+ confirmed_utxo = make_utxo(self.nodes[0], int(1.1 * COIN))
+ unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1 * COIN), False)
tx1 = CTransaction()
tx1.vin = [CTxIn(confirmed_utxo)]
@@ -369,13 +369,13 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# transactions
# Start by creating a single transaction with many outputs
- initial_nValue = 10*COIN
+ initial_nValue = 10 * COIN
utxo = make_utxo(self.nodes[0], initial_nValue)
- fee = int(0.0001*COIN)
- split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
+ fee = int(0.0001 * COIN)
+ split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1))
outputs = []
- for _ in range(MAX_REPLACEMENT_LIMIT+1):
+ for _ in range(MAX_REPLACEMENT_LIMIT + 1):
outputs.append(CTxOut(split_value, CScript([1])))
splitting_tx = CTransaction()
@@ -387,7 +387,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
txid = int(txid, 16)
# Now spend each of those outputs individually
- for i in range(MAX_REPLACEMENT_LIMIT+1):
+ for i in range(MAX_REPLACEMENT_LIMIT + 1):
tx_i = CTransaction()
tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)]
tx_i.vout = [CTxOut(split_value - fee, DUMMY_P2WPKH_SCRIPT)]
@@ -397,9 +397,9 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Now create doublespend of the whole lot; should fail.
# Need a big enough fee to cover all spending transactions and have
# a higher fee rate
- double_spend_value = (split_value-100*fee)*(MAX_REPLACEMENT_LIMIT+1)
+ double_spend_value = (split_value - 100 * fee) * (MAX_REPLACEMENT_LIMIT + 1)
inputs = []
- for i in range(MAX_REPLACEMENT_LIMIT+1):
+ for i in range(MAX_REPLACEMENT_LIMIT + 1):
inputs.append(CTxIn(COutPoint(txid, i), nSequence=0))
double_tx = CTransaction()
double_tx.vin = inputs
@@ -418,7 +418,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_opt_in(self):
"""Replacing should only work if orig tx opted in"""
- tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
# Create a non-opting in transaction
tx1a = CTransaction()
@@ -439,7 +439,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception
assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
- tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
# Create a different non-opting in transaction
tx2a = CTransaction()
@@ -467,7 +467,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx3a = CTransaction()
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
- tx3a.vout = [CTxOut(int(0.9*COIN), CScript([b'c'])), CTxOut(int(0.9*COIN), CScript([b'd']))]
+ tx3a.vout = [CTxOut(int(0.9 * COIN), CScript([b'c'])), CTxOut(int(0.9 * COIN), CScript([b'd']))]
tx3a_hex = txToHex(tx3a)
tx3a_txid = self.nodes[0].sendrawtransaction(tx3a_hex, 0)
@@ -495,7 +495,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# correctly used by replacement logic
# 1. Check that feeperkb uses modified fees
- tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@@ -506,14 +506,14 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Higher fee, but the actual fee per KB is much lower.
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
- tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*740000]))]
+ tx1b.vout = [CTxOut(int(0.001 * COIN), CScript([b'a' * 740000]))]
tx1b_hex = txToHex(tx1b)
# Verify tx1b cannot replace tx1a.
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
# Use prioritisetransaction to set tx1a's fee to 0.
- self.nodes[0].prioritisetransaction(txid=tx1a_txid, fee_delta=int(-0.1*COIN))
+ self.nodes[0].prioritisetransaction(txid=tx1a_txid, fee_delta=int(-0.1 * COIN))
# Now tx1b should be able to replace tx1a
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, 0)
@@ -521,7 +521,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
assert tx1b_txid in self.nodes[0].getrawmempool()
# 2. Check that absolute fee checks use modified fee.
- tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
+ tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
@@ -540,7 +540,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx2b_hex, 0)
# Now prioritise tx2b to have a higher modified fee
- self.nodes[0].prioritisetransaction(txid=tx2b.hash, fee_delta=int(0.1*COIN))
+ self.nodes[0].prioritisetransaction(txid=tx2b.hash, fee_delta=int(0.1 * COIN))
# tx2b should now be accepted
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, 0)
@@ -550,11 +550,11 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_rpc(self):
us0 = self.nodes[0].listunspent()[0]
ins = [us0]
- outs = {self.nodes[0].getnewaddress() : Decimal(1.0000000)}
+ outs = {self.nodes[0].getnewaddress(): Decimal(1.0000000)}
rawtx0 = self.nodes[0].createrawtransaction(ins, outs, 0, True)
rawtx1 = self.nodes[0].createrawtransaction(ins, outs, 0, False)
- json0 = self.nodes[0].decoderawtransaction(rawtx0)
- json1 = self.nodes[0].decoderawtransaction(rawtx1)
+ json0 = self.nodes[0].decoderawtransaction(rawtx0)
+ json1 = self.nodes[0].decoderawtransaction(rawtx1)
assert_equal(json0["vin"][0]["sequence"], 4294967293)
assert_equal(json1["vin"][0]["sequence"], 4294967295)
@@ -562,74 +562,68 @@ class ReplaceByFeeTest(BitcoinTestFramework):
frawtx2a = self.nodes[0].fundrawtransaction(rawtx2, {"replaceable": True})
frawtx2b = self.nodes[0].fundrawtransaction(rawtx2, {"replaceable": False})
- json0 = self.nodes[0].decoderawtransaction(frawtx2a['hex'])
- json1 = self.nodes[0].decoderawtransaction(frawtx2b['hex'])
+ json0 = self.nodes[0].decoderawtransaction(frawtx2a['hex'])
+ json1 = self.nodes[0].decoderawtransaction(frawtx2b['hex'])
assert_equal(json0["vin"][0]["sequence"], 4294967293)
assert_equal(json1["vin"][0]["sequence"], 4294967294)
def test_no_inherited_signaling(self):
- # Send tx from which to conflict outputs later
- base_txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
- self.nodes[0].generate(1)
- self.sync_blocks()
+ wallet = MiniWallet(self.nodes[0])
+ wallet.scan_blocks(start=76, num=1)
+ confirmed_utxo = wallet.get_utxo()
# Create an explicitly opt-in parent transaction
- optin_parent_tx = self.nodes[0].createrawtransaction([{
- 'txid': base_txid,
- 'vout': 0,
- "sequence": 0xfffffffd,
- }], {self.nodes[0].getnewaddress(): Decimal("9.99998")})
-
- optin_parent_tx = self.nodes[0].signrawtransactionwithwallet(optin_parent_tx)
-
- # Broadcast parent tx
- optin_parent_txid = self.nodes[0].sendrawtransaction(hexstring=optin_parent_tx["hex"], maxfeerate=0)
- assert optin_parent_txid in self.nodes[0].getrawmempool()
-
- replacement_parent_tx = self.nodes[0].createrawtransaction([{
- 'txid': base_txid,
- 'vout': 0,
- "sequence": 0xfffffffd,
- }], {self.nodes[0].getnewaddress(): Decimal("9.90000")})
-
- replacement_parent_tx = self.nodes[0].signrawtransactionwithwallet(replacement_parent_tx)
+ optin_parent_tx = wallet.send_self_transfer(
+ from_node=self.nodes[0],
+ utxo_to_spend=confirmed_utxo,
+ sequence=BIP125_SEQUENCE_NUMBER,
+ fee_rate=Decimal('0.01'),
+ )
+ assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
+
+ replacement_parent_tx = wallet.create_self_transfer(
+ from_node=self.nodes[0],
+ utxo_to_spend=confirmed_utxo,
+ sequence=BIP125_SEQUENCE_NUMBER,
+ fee_rate=Decimal('0.02'),
+ )
# Test if parent tx can be replaced.
- res = self.nodes[0].testmempoolaccept(rawtxs=[replacement_parent_tx['hex']], maxfeerate=0)[0]
+ res = self.nodes[0].testmempoolaccept(rawtxs=[replacement_parent_tx['hex']])[0]
# Parent can be replaced.
assert_equal(res['allowed'], True)
# Create an opt-out child tx spending the opt-in parent
- optout_child_tx = self.nodes[0].createrawtransaction([{
- 'txid': optin_parent_txid,
- 'vout': 0,
- "sequence": 0xffffffff,
- }], {self.nodes[0].getnewaddress(): Decimal("9.99990")})
-
- optout_child_tx = self.nodes[0].signrawtransactionwithwallet(optout_child_tx)
-
- # Broadcast child tx
- optout_child_txid = self.nodes[0].sendrawtransaction(hexstring=optout_child_tx["hex"], maxfeerate=0)
- assert optout_child_txid in self.nodes[0].getrawmempool()
-
- replacement_child_tx = self.nodes[0].createrawtransaction([{
- 'txid': optin_parent_txid,
- 'vout': 0,
- "sequence": 0xffffffff,
- }], {self.nodes[0].getnewaddress(): Decimal("9.00000")})
-
- replacement_child_tx = self.nodes[0].signrawtransactionwithwallet(replacement_child_tx)
+ parent_utxo = wallet.get_utxo(txid=optin_parent_tx['txid'])
+ optout_child_tx = wallet.send_self_transfer(
+ from_node=self.nodes[0],
+ utxo_to_spend=parent_utxo,
+ sequence=0xffffffff,
+ fee_rate=Decimal('0.01'),
+ )
+
+ # Reports true due to inheritance
+ assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])
+
+ replacement_child_tx = wallet.create_self_transfer(
+ from_node=self.nodes[0],
+ utxo_to_spend=parent_utxo,
+ sequence=0xffffffff,
+ fee_rate=Decimal('0.02'),
+ mempool_valid=False,
+ )
# Broadcast replacement child tx
# BIP 125 :
# 1. The original transactions signal replaceability explicitly or through inheritance as described in the above
# Summary section.
- # The original transaction (`optout_child_tx`) doesn't signal RBF but its parent (`optin_parent_txid`) does.
+ # The original transaction (`optout_child_tx`) doesn't signal RBF but its parent (`optin_parent_tx`) does.
# The replacement transaction (`replacement_child_tx`) should be able to replace the original transaction.
# See CVE-2021-31876 for further explanations.
- assert optin_parent_txid in self.nodes[0].getrawmempool()
+ assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
assert_raises_rpc_error(-26, 'txn-mempool-conflict', self.nodes[0].sendrawtransaction, replacement_child_tx["hex"], 0)
+
if __name__ == '__main__':
ReplaceByFeeTest().main()
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index 30cd499b3f..22eec59600 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -10,10 +10,12 @@ from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
+ assert_greater_than_or_equal,
assert_raises_process_error,
assert_raises_rpc_error,
get_auth_cookie,
)
+import time
# The block reward of coinbaseoutput.nValue (50) BTC/block matures after
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
@@ -248,6 +250,12 @@ class TestBitcoinCli(BitcoinTestFramework):
self.nodes[0].wait_for_rpc_connection()
assert_equal(blocks, BLOCKS + 25)
+ self.log.info("Test -rpcwait option waits at most -rpcwaittimeout seconds for startup")
+ self.stop_node(0) # stop the node so we time out
+ start_time = time.time()
+ assert_raises_process_error(1, "Could not connect to the server", self.nodes[0].cli('-rpcwait', '-rpcwaittimeout=5').echo)
+ assert_greater_than_or_equal(time.time(), start_time + 5)
+
if __name__ == '__main__':
TestBitcoinCli().main()
diff --git a/test/functional/p2p_compactblocks_hb.py b/test/functional/p2p_compactblocks_hb.py
new file mode 100755
index 0000000000..a3d30a6f04
--- /dev/null
+++ b/test/functional/p2p_compactblocks_hb.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021 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 compact blocks HB selection logic."""
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import assert_equal
+
+
+class CompactBlocksConnectionTest(BitcoinTestFramework):
+ """Test class for verifying selection of HB peer connections."""
+
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 6
+
+ def peer_info(self, from_node, to_node):
+ """Query from_node for its getpeerinfo about to_node."""
+ for peerinfo in self.nodes[from_node].getpeerinfo():
+ if "(testnode%i)" % to_node in peerinfo['subver']:
+ return peerinfo
+ return None
+
+ def setup_network(self):
+ self.setup_nodes()
+ # Start network with everyone disconnected
+ self.sync_all()
+
+ def relay_block_through(self, peer):
+ """Relay a new block through peer peer, and return HB status between 1 and [2,3,4,5]."""
+ self.connect_nodes(peer, 0)
+ self.nodes[0].generate(1)
+ self.sync_blocks()
+ self.disconnect_nodes(peer, 0)
+ status_to = [self.peer_info(1, i)['bip152_hb_to'] for i in range(2, 6)]
+ status_from = [self.peer_info(i, 1)['bip152_hb_from'] for i in range(2, 6)]
+ assert_equal(status_to, status_from)
+ return status_to
+
+ def run_test(self):
+ self.log.info("Testing reserved high-bandwidth mode slot for outbound peer...")
+
+ # Connect everyone to node 0, and mine some blocks to get all nodes out of IBD.
+ for i in range(1, 6):
+ self.connect_nodes(i, 0)
+ self.nodes[0].generate(2)
+ self.sync_blocks()
+ for i in range(1, 6):
+ self.disconnect_nodes(i, 0)
+
+ # Construct network topology:
+ # - Node 0 is the block producer
+ # - Node 1 is the "target" node being tested
+ # - Nodes 2-5 are intermediaries.
+ # - Node 1 has an outbound connection to node 2
+ # - Node 1 has inbound connections from nodes 3-5
+ self.connect_nodes(3, 1)
+ self.connect_nodes(4, 1)
+ self.connect_nodes(5, 1)
+ self.connect_nodes(1, 2)
+
+ # Mine blocks subsequently relaying through nodes 3,4,5 (inbound to node 1)
+ for nodeid in range(3, 6):
+ status = self.relay_block_through(nodeid)
+ assert_equal(status, [False, nodeid >= 3, nodeid >= 4, nodeid >= 5])
+
+ # And again through each. This should not change HB status.
+ for nodeid in range(3, 6):
+ status = self.relay_block_through(nodeid)
+ assert_equal(status, [False, True, True, True])
+
+ # Now relay one block through peer 2 (outbound from node 1), so it should take HB status
+ # from one of the inbounds.
+ status = self.relay_block_through(2)
+ assert_equal(status[0], True)
+ assert_equal(sum(status), 3)
+
+ # Now relay again through nodes 3,4,5. Since 2 is outbound, it should remain HB.
+ for nodeid in range(3, 6):
+ status = self.relay_block_through(nodeid)
+ assert status[0]
+ assert status[nodeid - 2]
+ assert_equal(sum(status), 3)
+
+ # Reconnect peer 2, and retry. Now the three inbounds should be HB again.
+ self.disconnect_nodes(1, 2)
+ self.connect_nodes(1, 2)
+ for nodeid in range(3, 6):
+ status = self.relay_block_through(nodeid)
+ assert not status[0]
+ assert status[nodeid - 2]
+ assert_equal(status, [False, True, True, True])
+
+
+if __name__ == '__main__':
+ CompactBlocksConnectionTest().main()
diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py
index 483f25f48c..91666d0f08 100755
--- a/test/functional/p2p_invalid_block.py
+++ b/test/functional/p2p_invalid_block.py
@@ -9,8 +9,11 @@ In this test we connect to one node over p2p, and test block requests:
2) Invalid block with duplicated transaction should be re-requested.
3) Invalid block with bad coinbase value should be rejected and not
re-requested.
+4) Invalid block due to future timestamp is later accepted when that timestamp
+becomes valid.
"""
import copy
+import time
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
from test_framework.messages import COIN
@@ -18,6 +21,9 @@ from test_framework.p2p import P2PDataStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
+MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
+
+
class InvalidBlockRequestTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
@@ -133,5 +139,18 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
self.log.info("Test inflation by duplicating input")
peer.send_blocks_and_test([block4], node, success=False, reject_reason='bad-txns-inputs-duplicate')
+ self.log.info("Test accepting identical block after rejecting it due to a future timestamp.")
+ t = int(time.time())
+ node.setmocktime(t)
+ # Set block time +1 second past max future validity
+ block = create_block(tip, create_coinbase(height), t + MAX_FUTURE_BLOCK_TIME + 1)
+ block.hashMerkleRoot = block.calc_merkle_root()
+ block.solve()
+ # Need force_send because the block will get rejected without a getdata otherwise
+ peer.send_blocks_and_test([block], node, force_send=True, success=False, reject_reason='time-too-new')
+ node.setmocktime(t + 1)
+ peer.send_blocks_and_test([block], node, success=True)
+
+
if __name__ == '__main__':
InvalidBlockRequestTest().main()
diff --git a/test/functional/rpc_setban.py b/test/functional/rpc_setban.py
index fd5f8aa098..36873f964b 100755
--- a/test/functional/rpc_setban.py
+++ b/test/functional/rpc_setban.py
@@ -22,7 +22,7 @@ class SetBanTests(BitcoinTestFramework):
# Node 0 connects to Node 1, check that the noban permission is not granted
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
- assert(not 'noban' in peerinfo['permissions'])
+ assert not "noban" in peerinfo["permissions"]
# Node 0 get banned by Node 1
self.nodes[1].setban("127.0.0.1", "add")
@@ -36,27 +36,40 @@ class SetBanTests(BitcoinTestFramework):
self.restart_node(1, ['-whitelist=127.0.0.1'])
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
- assert('noban' in peerinfo['permissions'])
+ assert "noban" in peerinfo["permissions"]
# If we remove the ban, Node 0 should be able to reconnect even without noban permission
self.nodes[1].setban("127.0.0.1", "remove")
self.restart_node(1, [])
self.connect_nodes(0, 1)
peerinfo = self.nodes[1].getpeerinfo()[0]
- assert(not 'noban' in peerinfo['permissions'])
+ assert not "noban" in peerinfo["permissions"]
self.log.info("Test that a non-IP address can be banned/unbanned")
node = self.nodes[1]
tor_addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
ip_addr = "1.2.3.4"
- assert(not self.is_banned(node, tor_addr))
- assert(not self.is_banned(node, ip_addr))
+ assert not self.is_banned(node, tor_addr)
+ assert not self.is_banned(node, ip_addr)
+
node.setban(tor_addr, "add")
- assert(self.is_banned(node, tor_addr))
- assert(not self.is_banned(node, ip_addr))
+ assert self.is_banned(node, tor_addr)
+ assert not self.is_banned(node, ip_addr)
+
+ self.log.info("Test the ban list is preserved through restart")
+
+ self.restart_node(1)
+ assert self.is_banned(node, tor_addr)
+ assert not self.is_banned(node, ip_addr)
+
node.setban(tor_addr, "remove")
- assert(not self.is_banned(self.nodes[1], tor_addr))
- assert(not self.is_banned(node, ip_addr))
+ assert not self.is_banned(self.nodes[1], tor_addr)
+ assert not self.is_banned(node, ip_addr)
+
+ self.restart_node(1)
+ assert not self.is_banned(node, tor_addr)
+ assert not self.is_banned(node, ip_addr)
+
if __name__ == '__main__':
SetBanTests().main()
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index f35ea6c122..e91b44e776 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -181,11 +181,6 @@ def create_raw_transaction(node, txid, to_address, *, amount):
signed_psbt = wrpc.walletprocesspsbt(psbt)
psbt = signed_psbt['psbt']
final_psbt = node.finalizepsbt(psbt)
- if not final_psbt["complete"]:
- node.log.info(f'final_psbt={final_psbt}')
- for w in node.listwallets():
- wrpc = node.get_wallet_rpc(w)
- node.log.info(f'listunspent={wrpc.listunspent()}')
assert_equal(final_psbt["complete"], True)
return final_psbt['hex']
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py
index 5a9736a7a3..3d79174356 100755
--- a/test/functional/test_framework/messages.py
+++ b/test/functional/test_framework/messages.py
@@ -39,7 +39,7 @@ MAX_BLOOM_HASH_FUNCS = 50
COIN = 100000000 # 1 btc in satoshis
MAX_MONEY = 21000000 * COIN
-BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out
+BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is rbf-opt-in (BIP 125) and csv-opt-out (BIP 68)
MAX_PROTOCOL_MESSAGE_LENGTH = 4000000 # Maximum length of incoming protocol messages
MAX_HEADERS_RESULTS = 2000 # Number of headers sent in one getheaders result
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index a89a26caea..40360c54a0 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -194,6 +194,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
help="Run test using legacy wallets", dest='descriptors')
self.add_options(parser)
+ # Running TestShell in a Jupyter notebook causes an additional -f argument
+ # To keep TestShell from failing with an "unrecognized argument" error, we add a dummy "-f" argument
+ # source: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter/56349168#56349168
+ parser.add_argument("-f", "--fff", help="a dummy argument to fool ipython", default="1")
self.options = parser.parse_args()
self.options.previous_releases_path = previous_releases_path
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index 0962a5cb54..47ec6b0be2 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -88,12 +88,20 @@ class MiniWallet:
if out['scriptPubKey']['hex'] == self._scriptPubKey.hex():
self._utxos.append({'txid': tx['txid'], 'vout': out['n'], 'value': out['value']})
- def sign_tx(self, tx):
+ def sign_tx(self, tx, fixed_length=True):
"""Sign tx that has been created by MiniWallet in P2PK mode"""
assert self._priv_key is not None
(sighash, err) = LegacySignatureHash(CScript(self._scriptPubKey), tx, 0, SIGHASH_ALL)
assert err is None
- tx.vin[0].scriptSig = CScript([self._priv_key.sign_ecdsa(sighash) + bytes(bytearray([SIGHASH_ALL]))])
+ # for exact fee calculation, create only signatures with fixed size by default (>49.89% probability):
+ # 65 bytes: high-R val (33 bytes) + low-S val (32 bytes)
+ # with the DER header/skeleton data of 6 bytes added, this leads to a target size of 71 bytes
+ der_sig = b''
+ while not len(der_sig) == 71:
+ der_sig = self._priv_key.sign_ecdsa(sighash)
+ if not fixed_length:
+ break
+ tx.vin[0].scriptSig = CScript([der_sig + bytes(bytearray([SIGHASH_ALL]))])
def generate(self, num_blocks):
"""Generate blocks with coinbase outputs to the internal address, and append the outputs to the internal list"""
@@ -124,23 +132,26 @@ class MiniWallet:
else:
return self._utxos[index]
- def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, locktime=0):
+ def send_self_transfer(self, **kwargs):
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
- tx = self.create_self_transfer(fee_rate=fee_rate, from_node=from_node, utxo_to_spend=utxo_to_spend)
- self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
+ tx = self.create_self_transfer(**kwargs)
+ self.sendrawtransaction(from_node=kwargs['from_node'], tx_hex=tx['hex'])
return tx
- def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0):
+ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
- vsize = Decimal(96)
+ if self._priv_key is None:
+ vsize = Decimal(96) # anyone-can-spend
+ else:
+ vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
send_value = satoshi_round(utxo_to_spend['value'] - fee_rate * (vsize / 1000))
fee = utxo_to_spend['value'] - send_value
assert send_value > 0
tx = CTransaction()
- tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']))]
+ tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=sequence)]
tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
tx.nLockTime = locktime
if not self._address:
@@ -159,10 +170,7 @@ class MiniWallet:
tx_info = from_node.testmempoolaccept([tx_hex])[0]
assert_equal(mempool_valid, tx_info['allowed'])
if mempool_valid:
- # TODO: for P2PK, vsize is not constant due to varying scriptSig length,
- # so only check this for anyone-can-spend outputs right now
- if self._priv_key is None:
- assert_equal(tx_info['vsize'], vsize)
+ assert_equal(tx_info['vsize'], vsize)
assert_equal(tx_info['fees']['base'], fee)
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index c9a8cc5611..ad1acd2e2f 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -19,6 +19,7 @@ import datetime
import os
import time
import shutil
+import signal
import subprocess
import sys
import tempfile
@@ -173,6 +174,7 @@ BASE_SCRIPTS = [
'wallet_groups.py --legacy-wallet',
'p2p_addrv2_relay.py',
'wallet_groups.py --descriptors',
+ 'p2p_compactblocks_hb.py',
'p2p_disconnect_ban.py',
'rpc_decodescript.py',
'rpc_blockchain.py',
@@ -548,9 +550,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
all_passed = all(map(lambda test_result: test_result.was_successful, test_results)) and coverage_passed
- # This will be a no-op unless failfast is True in which case there may be dangling
- # processes which need to be killed.
- job_queue.kill_and_join()
+ # Clean up dangling processes if any. This may only happen with --failfast option.
+ # Killing the process group will also terminate the current process but that is
+ # not an issue
+ if len(job_queue.jobs):
+ os.killpg(os.getpgid(0), signal.SIGKILL)
sys.exit(not all_passed)
@@ -647,16 +651,6 @@ class TestHandler:
print('.', end='', flush=True)
dot_count += 1
- def kill_and_join(self):
- """Send SIGKILL to all jobs and block until all have ended."""
- procs = [i[2] for i in self.jobs]
-
- for proc in procs:
- proc.kill()
-
- for proc in procs:
- proc.wait()
-
class TestResult():
def __init__(self, name, status, time):
diff --git a/test/functional/wallet_taproot.py b/test/functional/wallet_taproot.py
index 5803c0cf54..0eac814c52 100755
--- a/test/functional/wallet_taproot.py
+++ b/test/functional/wallet_taproot.py
@@ -6,6 +6,7 @@
import random
+from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.descriptors import descsum_create
@@ -229,24 +230,95 @@ class WalletTaprootTest(BitcoinTestFramework):
if treefn is not None:
addr_r = self.make_addr(treefn, keys, i)
assert_equal(addr_g, addr_r)
+ desc_a = self.addr_gen.getaddressinfo(addr_g)['desc']
+ if desc.startswith("tr("):
+ assert desc_a.startswith("tr(")
+ rederive = self.nodes[1].deriveaddresses(desc_a)
+ assert_equal(len(rederive), 1)
+ assert_equal(rederive[0], addr_g)
# tr descriptors cannot be imported when Taproot is not active
result = self.privs_tr_enabled.importdescriptors([{"desc": desc, "timestamp": "now"}])
assert(result[0]["success"])
- result = self.privs_tr_disabled.importdescriptors([{"desc": desc, "timestamp": "now"}])
- assert(not result[0]["success"])
- assert_equal(result[0]["error"]["code"], -4)
- assert_equal(result[0]["error"]["message"], "Cannot import tr() descriptor when Taproot is not active")
result = self.pubs_tr_enabled.importdescriptors([{"desc": desc_pub, "timestamp": "now"}])
assert(result[0]["success"])
- result = self.pubs_tr_disabled.importdescriptors([{"desc": desc_pub, "timestamp": "now"}])
- assert(not result[0]["success"])
- assert_equal(result[0]["error"]["code"], -4)
- assert_equal(result[0]["error"]["message"], "Cannot import tr() descriptor when Taproot is not active")
+ if desc.startswith("tr"):
+ result = self.privs_tr_disabled.importdescriptors([{"desc": desc, "timestamp": "now"}])
+ assert(not result[0]["success"])
+ assert_equal(result[0]["error"]["code"], -4)
+ assert_equal(result[0]["error"]["message"], "Cannot import tr() descriptor when Taproot is not active")
+ result = self.pubs_tr_disabled.importdescriptors([{"desc": desc_pub, "timestamp": "now"}])
+ assert(not result[0]["success"])
+ assert_equal(result[0]["error"]["code"], -4)
+ assert_equal(result[0]["error"]["message"], "Cannot import tr() descriptor when Taproot is not active")
+
+ def do_test_sendtoaddress(self, comment, pattern, privmap, treefn, keys_pay, keys_change):
+ self.log.info("Testing %s through sendtoaddress" % comment)
+ desc_pay = self.make_desc(pattern, privmap, keys_pay)
+ desc_change = self.make_desc(pattern, privmap, keys_change)
+ desc_pay_pub = self.make_desc(pattern, privmap, keys_pay, True)
+ desc_change_pub = self.make_desc(pattern, privmap, keys_change, True)
+ assert_equal(self.nodes[0].getdescriptorinfo(desc_pay)['descriptor'], desc_pay_pub)
+ assert_equal(self.nodes[0].getdescriptorinfo(desc_change)['descriptor'], desc_change_pub)
+ result = self.rpc_online.importdescriptors([{"desc": desc_pay, "active": True, "timestamp": "now"}])
+ assert(result[0]['success'])
+ result = self.rpc_online.importdescriptors([{"desc": desc_change, "active": True, "timestamp": "now", "internal": True}])
+ assert(result[0]['success'])
+ for i in range(4):
+ addr_g = self.rpc_online.getnewaddress(address_type='bech32')
+ if treefn is not None:
+ addr_r = self.make_addr(treefn, keys_pay, i)
+ assert_equal(addr_g, addr_r)
+ boring_balance = int(self.boring.getbalance() * 100000000)
+ to_amnt = random.randrange(1000000, boring_balance)
+ self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ test_balance = int(self.rpc_online.getbalance() * 100000000)
+ ret_amnt = random.randrange(100000, test_balance)
+ res = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=Decimal(ret_amnt) / 100000000, subtractfeefromamount=True)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ assert(self.rpc_online.gettransaction(res)["confirmations"] > 0)
+
+ def do_test_psbt(self, comment, pattern, privmap, treefn, keys_pay, keys_change):
+ self.log.info("Testing %s through PSBT" % comment)
+ desc_pay = self.make_desc(pattern, privmap, keys_pay, False)
+ desc_change = self.make_desc(pattern, privmap, keys_change, False)
+ desc_pay_pub = self.make_desc(pattern, privmap, keys_pay, True)
+ desc_change_pub = self.make_desc(pattern, privmap, keys_change, True)
+ assert_equal(self.nodes[0].getdescriptorinfo(desc_pay)['descriptor'], desc_pay_pub)
+ assert_equal(self.nodes[0].getdescriptorinfo(desc_change)['descriptor'], desc_change_pub)
+ result = self.psbt_online.importdescriptors([{"desc": desc_pay_pub, "active": True, "timestamp": "now"}])
+ assert(result[0]['success'])
+ result = self.psbt_online.importdescriptors([{"desc": desc_change_pub, "active": True, "timestamp": "now", "internal": True}])
+ assert(result[0]['success'])
+ result = self.psbt_offline.importdescriptors([{"desc": desc_pay, "active": True, "timestamp": "now"}])
+ assert(result[0]['success'])
+ result = self.psbt_offline.importdescriptors([{"desc": desc_change, "active": True, "timestamp": "now", "internal": True}])
+ assert(result[0]['success'])
+ for i in range(4):
+ addr_g = self.psbt_online.getnewaddress(address_type='bech32')
+ if treefn is not None:
+ addr_r = self.make_addr(treefn, keys_pay, i)
+ assert_equal(addr_g, addr_r)
+ boring_balance = int(self.boring.getbalance() * 100000000)
+ to_amnt = random.randrange(1000000, boring_balance)
+ self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ test_balance = int(self.psbt_online.getbalance() * 100000000)
+ ret_amnt = random.randrange(100000, test_balance)
+ psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): Decimal(ret_amnt) / 100000000}], None, {"subtractFeeFromOutputs":[0]})['psbt']
+ res = self.psbt_offline.walletprocesspsbt(psbt)
+ assert(res['complete'])
+ rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex']
+ txid = self.nodes[0].sendrawtransaction(rawtx)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0)
def do_test(self, comment, pattern, privmap, treefn, nkeys):
- keys = self.rand_keys(nkeys)
- self.do_test_addr(comment, pattern, privmap, treefn, keys)
+ keys = self.rand_keys(nkeys * 4)
+ self.do_test_addr(comment, pattern, privmap, treefn, keys[0:nkeys])
+ self.do_test_sendtoaddress(comment, pattern, privmap, treefn, keys[0:nkeys], keys[nkeys:2*nkeys])
+ self.do_test_psbt(comment, pattern, privmap, treefn, keys[2*nkeys:3*nkeys], keys[3*nkeys:4*nkeys])
def run_test(self):
self.log.info("Creating wallets...")
@@ -258,8 +330,20 @@ class WalletTaprootTest(BitcoinTestFramework):
self.pubs_tr_enabled = self.nodes[0].get_wallet_rpc("pubs_tr_enabled")
self.nodes[2].createwallet(wallet_name="pubs_tr_disabled", descriptors=True, blank=True, disable_private_keys=True)
self.pubs_tr_disabled=self.nodes[2].get_wallet_rpc("pubs_tr_disabled")
+ self.nodes[0].createwallet(wallet_name="boring")
self.nodes[0].createwallet(wallet_name="addr_gen", descriptors=True, disable_private_keys=True, blank=True)
+ self.nodes[0].createwallet(wallet_name="rpc_online", descriptors=True, blank=True)
+ self.nodes[0].createwallet(wallet_name="psbt_online", descriptors=True, disable_private_keys=True, blank=True)
+ self.nodes[1].createwallet(wallet_name="psbt_offline", descriptors=True, blank=True)
+ self.boring = self.nodes[0].get_wallet_rpc("boring")
self.addr_gen = self.nodes[0].get_wallet_rpc("addr_gen")
+ self.rpc_online = self.nodes[0].get_wallet_rpc("rpc_online")
+ self.psbt_online = self.nodes[0].get_wallet_rpc("psbt_online")
+ self.psbt_offline = self.nodes[1].get_wallet_rpc("psbt_offline")
+
+ self.log.info("Mining blocks...")
+ gen_addr = self.boring.getnewaddress()
+ self.nodes[0].generatetoaddress(101, gen_addr)
self.do_test(
"tr(XPRV)",
@@ -276,6 +360,13 @@ class WalletTaprootTest(BitcoinTestFramework):
1
)
self.do_test(
+ "wpkh(XPRV)",
+ "wpkh($1/*)",
+ [True],
+ None,
+ 1
+ )
+ self.do_test(
"tr(XPRV,{H,{H,XPUB}})",
"tr($1/*,{pk($H),{pk($H),pk($2/*)}})",
[True, False],
@@ -283,12 +374,54 @@ class WalletTaprootTest(BitcoinTestFramework):
2
)
self.do_test(
+ "wsh(multi(1,XPRV,XPUB))",
+ "wsh(multi(1,$1/*,$2/*))",
+ [True, False],
+ None,
+ 2
+ )
+ self.do_test(
+ "tr(XPRV,{XPUB,XPUB})",
+ "tr($1/*,{pk($2/*),pk($2/*)})",
+ [True, False],
+ lambda k1, k2: (key(k1), [pk(k2), pk(k2)]),
+ 2
+ )
+ self.do_test(
+ "tr(XPRV,{{XPUB,H},{H,XPUB}})",
+ "tr($1/*,{{pk($2/*),pk($H)},{pk($H),pk($2/*)}})",
+ [True, False],
+ lambda k1, k2: (key(k1), [[pk(k2), pk(H_POINT)], [pk(H_POINT), pk(k2)]]),
+ 2
+ )
+ self.do_test(
"tr(XPUB,{{H,{H,XPUB}},{H,{H,{H,XPRV}}}})",
"tr($1/*,{{pk($H),{pk($H),pk($2/*)}},{pk($H),{pk($H),{pk($H),pk($3/*)}}}})",
[False, False, True],
lambda k1, k2, k3: (key(k1), [[pk(H_POINT), [pk(H_POINT), pk(k2)]], [pk(H_POINT), [pk(H_POINT), [pk(H_POINT), pk(k3)]]]]),
3
)
+ self.do_test(
+ "tr(XPRV,{XPUB,{{XPUB,{H,H}},{{H,H},XPUB}}})",
+ "tr($1/*,{pk($2/*),{{pk($2/*),{pk($H),pk($H)}},{{pk($H),pk($H)},pk($2/*)}}})",
+ [True, False],
+ lambda k1, k2: (key(k1), [pk(k2), [[pk(k2), [pk(H_POINT), pk(H_POINT)]], [[pk(H_POINT), pk(H_POINT)], pk(k2)]]]),
+ 2
+ )
+
+ self.log.info("Sending everything back...")
+
+ txid = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=self.rpc_online.getbalance(), subtractfeefromamount=True)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ assert(self.rpc_online.gettransaction(txid)["confirmations"] > 0)
+
+ psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): self.psbt_online.getbalance()}], None, {"subtractFeeFromOutputs": [0]})['psbt']
+ res = self.psbt_offline.walletprocesspsbt(psbt)
+ assert(res['complete'])
+ rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex']
+ txid = self.nodes[0].sendrawtransaction(rawtx)
+ self.nodes[0].generatetoaddress(1, self.boring.getnewaddress())
+ assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0)
if __name__ == '__main__':
WalletTaprootTest().main()
diff --git a/test/lint/lint-spelling.ignore-words.txt b/test/lint/lint-spelling.ignore-words.txt
index 267c06ea20..9906b15e9a 100644
--- a/test/lint/lint-spelling.ignore-words.txt
+++ b/test/lint/lint-spelling.ignore-words.txt
@@ -7,6 +7,7 @@ hights
hist
inout
invokable
+keypair
mor
nin
ser
diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json
index 0a9846b4be..a648c0287a 100644
--- a/test/util/data/bitcoin-util-test.json
+++ b/test/util/data/bitcoin-util-test.json
@@ -1,4 +1,34 @@
[
+ { "exec": "./bitcoin-util",
+ "args": ["foo"],
+ "return_code": 1,
+ "error_txt": "Error parsing command line arguments: Invalid command 'foo'",
+ "description": ""
+ },
+ { "exec": "./bitcoin-util",
+ "args": ["help"],
+ "return_code": 1,
+ "error_txt": "Error parsing command line arguments: Invalid command 'help'",
+ "description": "`help` raises an error. Use `-help`"
+ },
+ { "exec": "./bitcoin-util",
+ "args": ["grind"],
+ "return_code": 1,
+ "error_txt": "Must specify block header to grind",
+ "description": ""
+ },
+ { "exec": "./bitcoin-util",
+ "args": ["grind", "1", "2"],
+ "return_code": 1,
+ "error_txt": "Must specify block header to grind",
+ "description": ""
+ },
+ { "exec": "./bitcoin-util",
+ "args": ["grind", "aa"],
+ "return_code": 1,
+ "error_txt": "Could not decode block header",
+ "description": ""
+ },
{ "exec": "./bitcoin-tx",
"args": ["-create", "nversion=1"],
"output_cmp": "blanktxv1.hex",