aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/README.md4
-rwxr-xr-xtest/functional/feature_blockfilterindex_prune.py10
-rwxr-xr-xtest/functional/feature_cltv.py41
-rwxr-xr-xtest/functional/feature_coinstatsindex.py313
-rwxr-xr-xtest/functional/feature_config_args.py2
-rwxr-xr-xtest/functional/feature_csv_activation.py213
-rwxr-xr-xtest/functional/feature_dersig.py26
-rwxr-xr-xtest/functional/feature_includeconf.py9
-rwxr-xr-xtest/functional/feature_notifications.py2
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py2
-rwxr-xr-xtest/functional/mempool_spend_coinbase.py35
-rwxr-xr-xtest/functional/p2p_addr_relay.py170
-rwxr-xr-xtest/functional/p2p_blocksonly.py32
-rwxr-xr-xtest/functional/p2p_filter.py3
-rwxr-xr-xtest/functional/p2p_invalid_messages.py10
-rwxr-xr-xtest/functional/p2p_segwit.py46
-rwxr-xr-x[-rw-r--r--]test/functional/rpc_addresses_deprecation.py0
-rwxr-xr-xtest/functional/rpc_blockchain.py2
-rwxr-xr-xtest/functional/rpc_dumptxoutset.py2
-rwxr-xr-xtest/functional/rpc_fundrawtransaction.py59
-rwxr-xr-xtest/functional/rpc_misc.py20
-rwxr-xr-xtest/functional/rpc_net.py74
-rwxr-xr-xtest/functional/rpc_psbt.py24
-rw-r--r--test/functional/test_framework/blocktools.py11
-rwxr-xr-xtest/functional/test_framework/p2p.py10
-rwxr-xr-xtest/functional/test_framework/test_framework.py7
-rwxr-xr-xtest/functional/test_framework/test_node.py1
-rw-r--r--test/functional/test_framework/wallet.py108
-rwxr-xr-xtest/functional/test_runner.py1
-rwxr-xr-xtest/functional/wallet_basic.py47
-rwxr-xr-xtest/functional/wallet_bumpfee.py15
-rwxr-xr-xtest/functional/wallet_importdescriptors.py71
-rwxr-xr-xtest/functional/wallet_send.py72
-rwxr-xr-xtest/lint/commit-script-check.sh4
-rwxr-xr-xtest/lint/lint-circular-dependencies.sh1
-rwxr-xr-xtest/lint/lint-filenames.sh24
-rwxr-xr-xtest/lint/lint-files.py203
-rwxr-xr-xtest/lint/lint-files.sh7
-rwxr-xr-xtest/lint/lint-include-guards.sh2
-rwxr-xr-xtest/lint/lint-locale-dependence.sh2
-rwxr-xr-xtest/lint/lint-shebang.sh24
-rw-r--r--test/sanitizer_suppressions/ubsan5
42 files changed, 1333 insertions, 381 deletions
diff --git a/test/README.md b/test/README.md
index 17bf8a1406..ab34ce42dc 100644
--- a/test/README.md
+++ b/test/README.md
@@ -262,7 +262,7 @@ Use the `-v` option for verbose output.
|-----------|:----------:|:-------------------------------------------:|--------------
| [`lint-python.sh`](lint/lint-python.sh) | [flake8](https://gitlab.com/pycqa/flake8) | [3.8.3](https://github.com/bitcoin/bitcoin/pull/19348) | `pip3 install flake8==3.8.3`
| [`lint-python.sh`](lint/lint-python.sh) | [mypy](https://github.com/python/mypy) | [0.781](https://github.com/bitcoin/bitcoin/pull/19348) | `pip3 install mypy==0.781`
-| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck) | [0.7.1](https://github.com/bitcoin/bitcoin/pull/19348) | [details...](https://github.com/koalaman/shellcheck#installing)
+| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck) | [0.7.2](https://github.com/bitcoin/bitcoin/pull/21749) | [details...](https://github.com/koalaman/shellcheck#installing)
| [`lint-shell.sh`](lint/lint-shell.sh) | [yq](https://github.com/kislyuk/yq) | default | `pip3 install yq`
| [`lint-spelling.sh`](lint/lint-spelling.sh) | [codespell](https://github.com/codespell-project/codespell) | [2.0.0](https://github.com/bitcoin/bitcoin/pull/20817) | `pip3 install codespell==2.0.0`
@@ -273,7 +273,7 @@ Please be aware that on Linux distributions all dependencies are usually availab
Individual tests can be run by directly calling the test script, e.g.:
```
-test/lint/lint-filenames.sh
+test/lint/lint-files.sh
```
You can run all the shell-based lint tests by running:
diff --git a/test/functional/feature_blockfilterindex_prune.py b/test/functional/feature_blockfilterindex_prune.py
index d13d191b20..28d8f2fbbc 100755
--- a/test/functional/feature_blockfilterindex_prune.py
+++ b/test/functional/feature_blockfilterindex_prune.py
@@ -33,7 +33,7 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
self.log.info("prune some blocks")
pruneheight = self.nodes[0].pruneblockchain(400)
- assert_equal(pruneheight, 250)
+ assert_equal(pruneheight, 248)
self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
@@ -54,11 +54,13 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
self.stop_node(0)
self.log.info("make sure we get an init error when starting the node again with block filters")
- with self.nodes[0].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]):
- self.nodes[0].assert_start_raises_init_error(extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"])
+ self.nodes[0].assert_start_raises_init_error(
+ extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"],
+ expected_msg="Error: basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)",
+ )
self.log.info("make sure the node starts again with the -reindex arg")
- self.start_node(0, extra_args = ["-fastprune", "-prune=1", "-blockfilterindex", "-reindex"])
+ self.start_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex", "-reindex"])
if __name__ == '__main__':
diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py
index f2130fb588..d25aaa070d 100755
--- a/test/functional/feature_cltv.py
+++ b/test/functional/feature_cltv.py
@@ -11,11 +11,9 @@ Test that the CHECKLOCKTIMEVERIFY soft-fork activates at (regtest) block height
from test_framework.blocktools import (
create_block,
create_coinbase,
- create_transaction,
)
from test_framework.messages import (
CTransaction,
- ToHex,
msg_block,
)
from test_framework.p2p import P2PInterface
@@ -27,13 +25,12 @@ from test_framework.script import (
OP_DROP,
)
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import (
- assert_equal,
- hex_str_to_bytes,
+from test_framework.util import assert_equal
+from test_framework.wallet import (
+ MiniWallet,
+ MiniWalletMode,
)
-from io import BytesIO
-
CLTV_HEIGHT = 1351
@@ -41,19 +38,14 @@ CLTV_HEIGHT = 1351
# 1) prepending a given script to the scriptSig of vin 0 and
# 2) (optionally) modify the nSequence of vin 0 and the tx's nLockTime
def cltv_modify_tx(node, tx, prepend_scriptsig, nsequence=None, nlocktime=None):
+ assert_equal(len(tx.vin), 1)
if nsequence is not None:
tx.vin[0].nSequence = nsequence
tx.nLockTime = nlocktime
- # Need to re-sign, since nSequence and nLockTime changed
- signed_result = node.signrawtransactionwithwallet(ToHex(tx))
- new_tx = CTransaction()
- new_tx.deserialize(BytesIO(hex_str_to_bytes(signed_result['hex'])))
- else:
- new_tx = tx
-
- new_tx.vin[0].scriptSig = CScript(prepend_scriptsig + list(CScript(new_tx.vin[0].scriptSig)))
- return new_tx
+ tx.vin[0].scriptSig = CScript(prepend_scriptsig + list(CScript(tx.vin[0].scriptSig)))
+ tx.rehash()
+ return tx
def cltv_invalidate(node, tx, failure_reason):
@@ -98,9 +90,6 @@ class BIP65Test(BitcoinTestFramework):
self.setup_clean_chain = True
self.rpc_timeout = 480
- def skip_test_if_missing_module(self):
- self.skip_if_no_wallet()
-
def test_cltv_info(self, *, is_active):
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip65'], {
"active": is_active,
@@ -111,22 +100,21 @@ class BIP65Test(BitcoinTestFramework):
def run_test(self):
peer = self.nodes[0].add_p2p_connection(P2PInterface())
+ wallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_OP_TRUE)
self.test_cltv_info(is_active=False)
self.log.info("Mining %d blocks", CLTV_HEIGHT - 2)
- self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(CLTV_HEIGHT - 2)]
- self.nodeaddress = self.nodes[0].getnewaddress()
+ wallet.generate(10)
+ self.nodes[0].generate(CLTV_HEIGHT - 2 - 10)
self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block")
# create one invalid tx per CLTV failure reason (5 in total) and collect them
invalid_ctlv_txs = []
for i in range(5):
- spendtx = create_transaction(self.nodes[0], self.coinbase_txids[i],
- self.nodeaddress, amount=1.0)
+ spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
- spendtx.rehash()
invalid_ctlv_txs.append(spendtx)
tip = self.nodes[0].getbestblockhash()
@@ -160,10 +148,8 @@ class BIP65Test(BitcoinTestFramework):
# create and test one invalid tx per CLTV failure reason (5 in total)
for i in range(5):
- spendtx = create_transaction(self.nodes[0], self.coinbase_txids[10+i],
- self.nodeaddress, amount=1.0)
+ spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
- spendtx.rehash()
expected_cltv_reject_reason = [
"non-mandatory-script-verify-flag (Operation not valid with the current stack size)",
@@ -197,7 +183,6 @@ class BIP65Test(BitcoinTestFramework):
self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted")
spendtx = cltv_validate(self.nodes[0], spendtx, CLTV_HEIGHT - 1)
- spendtx.rehash()
block.vtx.pop(1)
block.vtx.append(spendtx)
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py
new file mode 100755
index 0000000000..d3adde5cc5
--- /dev/null
+++ b/test/functional/feature_coinstatsindex.py
@@ -0,0 +1,313 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020 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 coinstatsindex across nodes.
+
+Test that the values returned by gettxoutsetinfo are consistent
+between a node running the coinstatsindex and a node without
+the index.
+"""
+
+from decimal import Decimal
+
+from test_framework.blocktools import (
+ create_block,
+ create_coinbase,
+)
+from test_framework.messages import (
+ COIN,
+ COutPoint,
+ CTransaction,
+ CTxIn,
+ CTxOut,
+ ToHex,
+)
+from test_framework.script import (
+ CScript,
+ OP_FALSE,
+ OP_RETURN,
+)
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_raises_rpc_error,
+ try_rpc,
+)
+
+class CoinStatsIndexTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 2
+ self.supports_cli = False
+ self.extra_args = [
+ [],
+ ["-coinstatsindex"]
+ ]
+
+ def skip_test_if_missing_module(self):
+ self.skip_if_no_wallet()
+
+ def run_test(self):
+ self._test_coin_stats_index()
+ self._test_use_index_option()
+ self._test_reorg_index()
+ self._test_index_rejects_hash_serialized()
+
+ def block_sanity_check(self, block_info):
+ block_subsidy = 50
+ assert_equal(
+ block_info['prevout_spent'] + block_subsidy,
+ block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] + block_info['unspendable']
+ )
+
+ def _test_coin_stats_index(self):
+ node = self.nodes[0]
+ index_node = self.nodes[1]
+ # Both none and muhash options allow the usage of the index
+ index_hash_options = ['none', 'muhash']
+
+ # Generate a normal transaction and mine it
+ node.generate(101)
+ address = self.nodes[0].get_deterministic_priv_key().address
+ node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
+ node.generate(1)
+
+ self.sync_blocks(timeout=120)
+
+ self.log.info("Test that gettxoutsetinfo() output is consistent with or without coinstatsindex option")
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", node.gettxoutsetinfo))
+ res0 = node.gettxoutsetinfo('none')
+
+ # The fields 'disk_size' and 'transactions' do not exist on the index
+ del res0['disk_size'], res0['transactions']
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ res1 = index_node.gettxoutsetinfo(hash_option)
+ # The fields 'block_info' and 'total_unspendable_amount' only exist on the index
+ del res1['block_info'], res1['total_unspendable_amount']
+ res1.pop('muhash', None)
+
+ # Everything left should be the same
+ assert_equal(res1, res0)
+
+ self.log.info("Test that gettxoutsetinfo() can get fetch data on specific heights with index")
+
+ # Generate a new tip
+ node.generate(5)
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ # Fetch old stats by height
+ res2 = index_node.gettxoutsetinfo(hash_option, 102)
+ del res2['block_info'], res2['total_unspendable_amount']
+ res2.pop('muhash', None)
+ assert_equal(res0, res2)
+
+ # Fetch old stats by hash
+ res3 = index_node.gettxoutsetinfo(hash_option, res0['bestblock'])
+ del res3['block_info'], res3['total_unspendable_amount']
+ res3.pop('muhash', None)
+ assert_equal(res0, res3)
+
+ # It does not work without coinstatsindex
+ assert_raises_rpc_error(-8, "Querying specific block heights requires coinstatsindex", node.gettxoutsetinfo, hash_option, 102)
+
+ self.log.info("Test gettxoutsetinfo() with index and verbose flag")
+
+ for hash_option in index_hash_options:
+ # Genesis block is unspendable
+ res4 = index_node.gettxoutsetinfo(hash_option, 0)
+ assert_equal(res4['total_unspendable_amount'], 50)
+ assert_equal(res4['block_info'], {
+ 'unspendable': 50,
+ 'prevout_spent': 0,
+ 'new_outputs_ex_coinbase': 0,
+ 'coinbase': 0,
+ 'unspendables': {
+ 'genesis_block': 50,
+ 'bip30': 0,
+ 'scripts': 0,
+ 'unclaimed_rewards': 0
+ }
+ })
+ self.block_sanity_check(res4['block_info'])
+
+ # Test an older block height that included a normal tx
+ res5 = index_node.gettxoutsetinfo(hash_option, 102)
+ assert_equal(res5['total_unspendable_amount'], 50)
+ assert_equal(res5['block_info'], {
+ 'unspendable': 0,
+ 'prevout_spent': 50,
+ 'new_outputs_ex_coinbase': Decimal('49.99995560'),
+ 'coinbase': Decimal('50.00004440'),
+ 'unspendables': {
+ 'genesis_block': 0,
+ 'bip30': 0,
+ 'scripts': 0,
+ 'unclaimed_rewards': 0
+ }
+ })
+ self.block_sanity_check(res5['block_info'])
+
+ # Generate and send a normal tx with two outputs
+ tx1_inputs = []
+ tx1_outputs = {self.nodes[0].getnewaddress(): 21, self.nodes[0].getnewaddress(): 42}
+ raw_tx1 = self.nodes[0].createrawtransaction(tx1_inputs, tx1_outputs)
+ funded_tx1 = self.nodes[0].fundrawtransaction(raw_tx1)
+ signed_tx1 = self.nodes[0].signrawtransactionwithwallet(funded_tx1['hex'])
+ tx1_txid = self.nodes[0].sendrawtransaction(signed_tx1['hex'])
+
+ # Find the right position of the 21 BTC output
+ tx1_final = self.nodes[0].gettransaction(tx1_txid)
+ for output in tx1_final['details']:
+ if output['amount'] == Decimal('21.00000000') and output['category'] == 'receive':
+ n = output['vout']
+
+ # Generate and send another tx with an OP_RETURN output (which is unspendable)
+ tx2 = CTransaction()
+ tx2.vin.append(CTxIn(COutPoint(int(tx1_txid, 16), n), b''))
+ tx2.vout.append(CTxOut(int(20.99 * COIN), CScript([OP_RETURN] + [OP_FALSE]*30)))
+ tx2_hex = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))['hex']
+ self.nodes[0].sendrawtransaction(tx2_hex)
+
+ # Include both txs in a block
+ self.nodes[0].generate(1)
+ self.sync_all()
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ # Check all amounts were registered correctly
+ res6 = index_node.gettxoutsetinfo(hash_option, 108)
+ assert_equal(res6['total_unspendable_amount'], Decimal('70.98999999'))
+ assert_equal(res6['block_info'], {
+ 'unspendable': Decimal('20.98999999'),
+ 'prevout_spent': 111,
+ 'new_outputs_ex_coinbase': Decimal('89.99993620'),
+ 'coinbase': Decimal('50.01006381'),
+ 'unspendables': {
+ 'genesis_block': 0,
+ 'bip30': 0,
+ 'scripts': Decimal('20.98999999'),
+ 'unclaimed_rewards': 0
+ }
+ })
+ self.block_sanity_check(res6['block_info'])
+
+ # Create a coinbase that does not claim full subsidy and also
+ # has two outputs
+ cb = create_coinbase(109, nValue=35)
+ cb.vout.append(CTxOut(5 * COIN, CScript([OP_FALSE])))
+ cb.rehash()
+
+ # Generate a block that includes previous coinbase
+ tip = self.nodes[0].getbestblockhash()
+ block_time = self.nodes[0].getblock(tip)['time'] + 1
+ block = create_block(int(tip, 16), cb, block_time)
+ block.solve()
+ self.nodes[0].submitblock(ToHex(block))
+ self.sync_all()
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ res7 = index_node.gettxoutsetinfo(hash_option, 109)
+ assert_equal(res7['total_unspendable_amount'], Decimal('80.98999999'))
+ assert_equal(res7['block_info'], {
+ 'unspendable': 10,
+ 'prevout_spent': 0,
+ 'new_outputs_ex_coinbase': 0,
+ 'coinbase': 40,
+ 'unspendables': {
+ 'genesis_block': 0,
+ 'bip30': 0,
+ 'scripts': 0,
+ 'unclaimed_rewards': 10
+ }
+ })
+ self.block_sanity_check(res7['block_info'])
+
+ self.log.info("Test that the index is robust across restarts")
+
+ res8 = index_node.gettxoutsetinfo('muhash')
+ self.restart_node(1, extra_args=self.extra_args[1])
+ res9 = index_node.gettxoutsetinfo('muhash')
+ assert_equal(res8, res9)
+
+ index_node.generate(1)
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ res10 = index_node.gettxoutsetinfo('muhash')
+ assert(res8['txouts'] < res10['txouts'])
+
+ def _test_use_index_option(self):
+ self.log.info("Test use_index option for nodes running the index")
+
+ self.connect_nodes(0, 1)
+ self.nodes[0].waitforblockheight(110)
+ res = self.nodes[0].gettxoutsetinfo('muhash')
+ option_res = self.nodes[1].gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
+ del res['disk_size'], option_res['disk_size']
+ assert_equal(res, option_res)
+
+ def _test_reorg_index(self):
+ self.log.info("Test that index can handle reorgs")
+
+ # Generate two block, let the index catch up, then invalidate the blocks
+ index_node = self.nodes[1]
+ reorg_blocks = index_node.generatetoaddress(2, index_node.getnewaddress())
+ reorg_block = reorg_blocks[1]
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ res_invalid = index_node.gettxoutsetinfo('muhash')
+ index_node.invalidateblock(reorg_blocks[0])
+ assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)
+
+ # Add two new blocks
+ block = index_node.generate(2)[1]
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
+
+ # Test that the result of the reorged block is not returned for its old block height
+ res2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)
+ assert_equal(res["bestblock"], block)
+ assert_equal(res["muhash"], res2["muhash"])
+ assert(res["muhash"] != res_invalid["muhash"])
+
+ # Test that requesting reorged out block by hash is still returning correct results
+ res_invalid2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=reorg_block)
+ assert_equal(res_invalid2["muhash"], res_invalid["muhash"])
+ assert(res["muhash"] != res_invalid2["muhash"])
+
+ # Add another block, so we don't depend on reconsiderblock remembering which
+ # blocks were touched by invalidateblock
+ index_node.generate(1)
+
+ # Ensure that removing and re-adding blocks yields consistent results
+ block = index_node.getblockhash(99)
+ index_node.invalidateblock(block)
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ index_node.reconsiderblock(block)
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ res3 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)
+ assert_equal(res2, res3)
+
+ self.log.info("Test that a node aware of stale blocks syncs them as well")
+ node = self.nodes[0]
+ # Ensure the node is aware of a stale block prior to restart
+ node.getblock(reorg_block)
+
+ self.restart_node(0, ["-coinstatsindex"])
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", node.gettxoutsetinfo, 'muhash'))
+ assert_raises_rpc_error(-32603, "Unable to read UTXO set", node.gettxoutsetinfo, 'muhash', reorg_block)
+
+ def _test_index_rejects_hash_serialized(self):
+ self.log.info("Test that the rpc raises if the legacy hash is passed with the index")
+
+ msg = "hash_serialized_2 hash type cannot be queried for a specific block"
+ assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111)
+
+ for use_index in {True, False, None}:
+ assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111, use_index=use_index)
+
+
+if __name__ == '__main__':
+ CoinStatsIndexTest().main()
diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py
index a0bcd9f12a..de9d0d2e80 100755
--- a/test/functional/feature_config_args.py
+++ b/test/functional/feature_config_args.py
@@ -165,6 +165,7 @@ class ConfArgsTest(BitcoinTestFramework):
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"0 addresses found from DNS seeds",
+ "opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
]):
self.start_node(0, extra_args=['-dnsseed=1', '-fixedseeds=1', f'-mocktime={start}'])
with self.nodes[0].assert_debug_log(expected_msgs=[
@@ -206,6 +207,7 @@ class ConfArgsTest(BitcoinTestFramework):
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"DNS seeding disabled",
+ "opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
]):
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1', '-addnode=fakenodeaddr', f'-mocktime={start}'])
with self.nodes[0].assert_debug_log(expected_msgs=[
diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py
index 8fa3f52de8..5081867319 100755
--- a/test/functional/feature_csv_activation.py
+++ b/test/functional/feature_csv_activation.py
@@ -37,13 +37,13 @@ bip112txs_vary_OP_CSV_9 - 16 txs with nSequence = 9 evaluated against varying {r
bip112tx_special - test negative argument to OP_CSV
bip112tx_emptystack - test empty stack (= no argument) OP_CSV
"""
-from decimal import Decimal
from itertools import product
-from io import BytesIO
import time
-from test_framework.blocktools import create_coinbase, create_block, create_transaction
-from test_framework.messages import ToHex, CTransaction
+from test_framework.blocktools import (
+ create_block,
+ create_coinbase,
+)
from test_framework.p2p import P2PDataStore
from test_framework.script import (
CScript,
@@ -53,9 +53,12 @@ from test_framework.script import (
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
- hex_str_to_bytes,
softfork_active,
)
+from test_framework.wallet import (
+ MiniWallet,
+ MiniWalletMode,
+)
TESTING_TX_COUNT = 83 # Number of testing transactions: 1 BIP113 tx, 16 BIP68 txs, 66 BIP112 txs (see comments above)
COINBASE_BLOCK_COUNT = TESTING_TX_COUNT # Number of coinbase blocks we need to generate as inputs for our txs
@@ -83,66 +86,6 @@ def relative_locktime(sdf, srhb, stf, srlb):
def all_rlt_txs(txs):
return [tx['tx'] for tx in txs]
-def sign_transaction(node, unsignedtx):
- rawtx = ToHex(unsignedtx)
- signresult = node.signrawtransactionwithwallet(rawtx)
- tx = CTransaction()
- f = BytesIO(hex_str_to_bytes(signresult['hex']))
- tx.deserialize(f)
- return tx
-
-def create_bip112special(node, input, txversion, address):
- tx = create_transaction(node, input, address, amount=Decimal("49.98"))
- tx.nVersion = txversion
- signtx = sign_transaction(node, tx)
- signtx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
- return signtx
-
-def create_bip112emptystack(node, input, txversion, address):
- tx = create_transaction(node, input, address, amount=Decimal("49.98"))
- tx.nVersion = txversion
- signtx = sign_transaction(node, tx)
- signtx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(signtx.vin[0].scriptSig)))
- return signtx
-
-def send_generic_input_tx(node, coinbases, address):
- return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49.99")))))
-
-def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0):
- """Returns a list of bip68 transactions with different bits set."""
- txs = []
- assert len(bip68inputs) >= 16
- for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
- locktime = relative_locktime(sdf, srhb, stf, srlb)
- tx = create_transaction(node, bip68inputs[i], address, amount=Decimal("49.98"))
- tx.nVersion = txversion
- tx.vin[0].nSequence = locktime + locktime_delta
- tx = sign_transaction(node, tx)
- tx.rehash()
- txs.append({'tx': tx, 'sdf': sdf, 'stf': stf})
-
- return txs
-
-def create_bip112txs(node, bip112inputs, varyOP_CSV, txversion, address, locktime_delta=0):
- """Returns a list of bip68 transactions with different bits set."""
- txs = []
- assert len(bip112inputs) >= 16
- for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
- locktime = relative_locktime(sdf, srhb, stf, srlb)
- tx = create_transaction(node, bip112inputs[i], address, amount=Decimal("49.98"))
- if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed
- tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
- else: # vary nSequence instead, OP_CSV is fixed
- tx.vin[0].nSequence = locktime + locktime_delta
- tx.nVersion = txversion
- signtx = sign_transaction(node, tx)
- if (varyOP_CSV):
- signtx.vin[0].scriptSig = CScript([locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
- else:
- signtx.vin[0].scriptSig = CScript([BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
- tx.rehash()
- txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf})
- return txs
class BIP68_112_113Test(BitcoinTestFramework):
def set_test_params(self):
@@ -150,13 +93,69 @@ class BIP68_112_113Test(BitcoinTestFramework):
self.setup_clean_chain = True
self.extra_args = [[
'-whitelist=noban@127.0.0.1',
- '-addresstype=legacy',
'-par=1', # Use only one script thread to get the exact reject reason for testing
]]
self.supports_cli = False
- def skip_test_if_missing_module(self):
- self.skip_if_no_wallet()
+ def create_self_transfer_from_utxo(self, input_tx):
+ utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
+ tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx']
+ return tx
+
+ def create_bip112special(self, input, txversion):
+ tx = self.create_self_transfer_from_utxo(input)
+ tx.nVersion = txversion
+ self.miniwallet.sign_tx(tx)
+ tx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig)))
+ return tx
+
+ def create_bip112emptystack(self, input, txversion):
+ tx = self.create_self_transfer_from_utxo(input)
+ tx.nVersion = txversion
+ self.miniwallet.sign_tx(tx)
+ tx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(tx.vin[0].scriptSig)))
+ return tx
+
+ def send_generic_input_tx(self, coinbases):
+ input_txid = self.nodes[0].getblock(coinbases.pop(), 2)['tx'][0]['txid']
+ utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid)
+ return self.miniwallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
+
+ def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0):
+ """Returns a list of bip68 transactions with different bits set."""
+ txs = []
+ assert len(bip68inputs) >= 16
+ for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
+ locktime = relative_locktime(sdf, srhb, stf, srlb)
+ tx = self.create_self_transfer_from_utxo(bip68inputs[i])
+ tx.nVersion = txversion
+ tx.vin[0].nSequence = locktime + locktime_delta
+ self.miniwallet.sign_tx(tx)
+ tx.rehash()
+ txs.append({'tx': tx, 'sdf': sdf, 'stf': stf})
+
+ return txs
+
+ def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0):
+ """Returns a list of bip68 transactions with different bits set."""
+ txs = []
+ assert len(bip112inputs) >= 16
+ for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)):
+ locktime = relative_locktime(sdf, srhb, stf, srlb)
+ tx = self.create_self_transfer_from_utxo(bip112inputs[i])
+ if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed
+ tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
+ else: # vary nSequence instead, OP_CSV is fixed
+ tx.vin[0].nSequence = locktime + locktime_delta
+ tx.nVersion = txversion
+ self.miniwallet.sign_tx(tx)
+ if (varyOP_CSV):
+ tx.vin[0].scriptSig = CScript([locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig)))
+ else:
+ tx.vin[0].scriptSig = CScript([BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig)))
+ tx.rehash()
+ txs.append({'tx': tx, 'sdf': sdf, 'stf': stf})
+ return txs
def generate_blocks(self, number):
test_blocks = []
@@ -185,16 +184,16 @@ class BIP68_112_113Test(BitcoinTestFramework):
def run_test(self):
self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore())
+ self.miniwallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_P2PK)
self.log.info("Generate blocks in the past for coinbase outputs.")
long_past_time = int(time.time()) - 600 * 1000 # enough to build up to 1000 blocks 10 minutes apart without worrying about getting into the future
self.nodes[0].setmocktime(long_past_time - 100) # enough so that the generated blocks will still all be before long_past_time
- self.coinbase_blocks = self.nodes[0].generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs
+ self.coinbase_blocks = self.miniwallet.generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs
self.nodes[0].setmocktime(0) # set time back to present so yielded blocks aren't in the future as we advance last_block_time
self.tipheight = COINBASE_BLOCK_COUNT # height of the next block to build
self.last_block_time = long_past_time
self.tip = int(self.nodes[0].getbestblockhash(), 16)
- self.nodeaddress = self.nodes[0].getnewaddress()
# Activation height is hardcoded
# We advance to block height five below BIP112 activation for the following tests
@@ -209,14 +208,14 @@ class BIP68_112_113Test(BitcoinTestFramework):
# 16 normal inputs
bip68inputs = []
for _ in range(16):
- bip68inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
+ bip68inputs.append(self.send_generic_input_tx(self.coinbase_blocks))
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
bip112basicinputs = []
for _ in range(2):
inputs = []
for _ in range(16):
- inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
+ inputs.append(self.send_generic_input_tx(self.coinbase_blocks))
bip112basicinputs.append(inputs)
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
@@ -224,16 +223,16 @@ class BIP68_112_113Test(BitcoinTestFramework):
for _ in range(2):
inputs = []
for _ in range(16):
- inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
+ inputs.append(self.send_generic_input_tx(self.coinbase_blocks))
bip112diverseinputs.append(inputs)
# 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
- bip112specialinput = send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress)
+ bip112specialinput = self.send_generic_input_tx(self.coinbase_blocks)
# 1 special input with (empty stack) OP_CSV (actually will be prepended to spending scriptSig)
- bip112emptystackinput = send_generic_input_tx(self.nodes[0],self.coinbase_blocks, self.nodeaddress)
+ bip112emptystackinput = self.send_generic_input_tx(self.coinbase_blocks)
# 1 normal input
- bip113input = send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress)
+ bip113input = self.send_generic_input_tx(self.coinbase_blocks)
self.nodes[0].setmocktime(self.last_block_time + 600)
inputblockhash = self.nodes[0].generate(1)[0] # 1 block generated for inputs to be in chain at height 431
@@ -253,36 +252,36 @@ class BIP68_112_113Test(BitcoinTestFramework):
# Test both version 1 and version 2 transactions for all tests
# BIP113 test transaction will be modified before each use to put in appropriate block time
- bip113tx_v1 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98"))
+ bip113tx_v1 = self.create_self_transfer_from_utxo(bip113input)
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE
bip113tx_v1.nVersion = 1
- bip113tx_v2 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98"))
+ bip113tx_v2 = self.create_self_transfer_from_utxo(bip113input)
bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE
bip113tx_v2.nVersion = 2
# For BIP68 test all 16 relative sequence locktimes
- bip68txs_v1 = create_bip68txs(self.nodes[0], bip68inputs, 1, self.nodeaddress)
- bip68txs_v2 = create_bip68txs(self.nodes[0], bip68inputs, 2, self.nodeaddress)
+ bip68txs_v1 = self.create_bip68txs(bip68inputs, 1)
+ bip68txs_v2 = self.create_bip68txs(bip68inputs, 2)
# For BIP112 test:
# 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs
- bip112txs_vary_nSequence_v1 = create_bip112txs(self.nodes[0], bip112basicinputs[0], False, 1, self.nodeaddress)
- bip112txs_vary_nSequence_v2 = create_bip112txs(self.nodes[0], bip112basicinputs[0], False, 2, self.nodeaddress)
+ bip112txs_vary_nSequence_v1 = self.create_bip112txs(bip112basicinputs[0], False, 1)
+ bip112txs_vary_nSequence_v2 = self.create_bip112txs(bip112basicinputs[0], False, 2)
# 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs
- bip112txs_vary_nSequence_9_v1 = create_bip112txs(self.nodes[0], bip112basicinputs[1], False, 1, self.nodeaddress, -1)
- bip112txs_vary_nSequence_9_v2 = create_bip112txs(self.nodes[0], bip112basicinputs[1], False, 2, self.nodeaddress, -1)
+ bip112txs_vary_nSequence_9_v1 = self.create_bip112txs(bip112basicinputs[1], False, 1, -1)
+ bip112txs_vary_nSequence_9_v2 = self.create_bip112txs(bip112basicinputs[1], False, 2, -1)
# sequence lock time of 10 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
- bip112txs_vary_OP_CSV_v1 = create_bip112txs(self.nodes[0], bip112diverseinputs[0], True, 1, self.nodeaddress)
- bip112txs_vary_OP_CSV_v2 = create_bip112txs(self.nodes[0], bip112diverseinputs[0], True, 2, self.nodeaddress)
+ bip112txs_vary_OP_CSV_v1 = self.create_bip112txs(bip112diverseinputs[0], True, 1)
+ bip112txs_vary_OP_CSV_v2 = self.create_bip112txs(bip112diverseinputs[0], True, 2)
# sequence lock time of 9 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
- bip112txs_vary_OP_CSV_9_v1 = create_bip112txs(self.nodes[0], bip112diverseinputs[1], True, 1, self.nodeaddress, -1)
- bip112txs_vary_OP_CSV_9_v2 = create_bip112txs(self.nodes[0], bip112diverseinputs[1], True, 2, self.nodeaddress, -1)
+ bip112txs_vary_OP_CSV_9_v1 = self.create_bip112txs(bip112diverseinputs[1], True, 1, -1)
+ bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs(bip112diverseinputs[1], True, 2, -1)
# -1 OP_CSV OP_DROP input
- bip112tx_special_v1 = create_bip112special(self.nodes[0], bip112specialinput, 1, self.nodeaddress)
- bip112tx_special_v2 = create_bip112special(self.nodes[0], bip112specialinput, 2, self.nodeaddress)
+ bip112tx_special_v1 = self.create_bip112special(bip112specialinput, 1)
+ bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2)
# (empty stack) OP_CSV input
- bip112tx_emptystack_v1 = create_bip112emptystack(self.nodes[0], bip112emptystackinput, 1, self.nodeaddress)
- bip112tx_emptystack_v2 = create_bip112emptystack(self.nodes[0], bip112emptystackinput, 2, self.nodeaddress)
+ bip112tx_emptystack_v1 = self.create_bip112emptystack(bip112emptystackinput, 1)
+ bip112tx_emptystack_v2 = self.create_bip112emptystack(bip112emptystackinput, 2)
self.log.info("TESTING")
@@ -292,8 +291,8 @@ class BIP68_112_113Test(BitcoinTestFramework):
success_txs = []
# BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
- bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
- success_txs.append(bip113signed1)
+ self.miniwallet.sign_tx(bip113tx_v1)
+ success_txs.append(bip113tx_v1)
success_txs.append(bip112tx_special_v1)
success_txs.append(bip112tx_emptystack_v1)
# add BIP 68 txs
@@ -312,8 +311,8 @@ class BIP68_112_113Test(BitcoinTestFramework):
success_txs = []
# BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed
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)
- success_txs.append(bip113signed2)
+ self.miniwallet.sign_tx(bip113tx_v2)
+ success_txs.append(bip113tx_v2)
success_txs.append(bip112tx_special_v2)
success_txs.append(bip112tx_emptystack_v2)
# add BIP 68 txs
@@ -338,17 +337,22 @@ class BIP68_112_113Test(BitcoinTestFramework):
self.log.info("BIP 113 tests")
# BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
- bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
+ self.miniwallet.sign_tx(bip113tx_v1)
+ bip113tx_v1.rehash()
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)
- for bip113tx in [bip113signed1, bip113signed2]:
+ self.miniwallet.sign_tx(bip113tx_v2)
+ bip113tx_v2.rehash()
+ for bip113tx in [bip113tx_v1, bip113tx_v2]:
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
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
- bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
+ self.miniwallet.sign_tx(bip113tx_v1)
+ bip113tx_v1.rehash()
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
- bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
- for bip113tx in [bip113signed1, bip113signed2]:
+ self.miniwallet.sign_tx(bip113tx_v2)
+ bip113tx_v2.rehash()
+ for bip113tx in [bip113tx_v1, bip113tx_v2]:
self.send_blocks([self.create_test_block([bip113tx])])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
@@ -471,8 +475,9 @@ class BIP68_112_113Test(BitcoinTestFramework):
time_txs = []
for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]:
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG
- signtx = sign_transaction(self.nodes[0], tx)
- time_txs.append(signtx)
+ self.miniwallet.sign_tx(tx)
+ tx.rehash()
+ time_txs.append(tx)
self.send_blocks([self.create_test_block(time_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py
index 3b430139b1..eb027c554a 100755
--- a/test/functional/feature_dersig.py
+++ b/test/functional/feature_dersig.py
@@ -7,7 +7,10 @@
Test that the DERSIG soft-fork activates at (regtest) height 1251.
"""
-from test_framework.blocktools import create_coinbase, create_block, create_transaction
+from test_framework.blocktools import (
+ create_block,
+ create_coinbase,
+)
from test_framework.messages import msg_block
from test_framework.p2p import P2PInterface
from test_framework.script import CScript
@@ -15,6 +18,10 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)
+from test_framework.wallet import (
+ MiniWallet,
+ MiniWalletMode,
+)
DERSIG_HEIGHT = 1251
@@ -46,8 +53,9 @@ class BIP66Test(BitcoinTestFramework):
self.setup_clean_chain = True
self.rpc_timeout = 240
- def skip_test_if_missing_module(self):
- self.skip_if_no_wallet()
+ def create_tx(self, input_txid):
+ utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid, mark_as_spent=False)
+ return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
def test_dersig_info(self, *, is_active):
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],
@@ -60,17 +68,16 @@ class BIP66Test(BitcoinTestFramework):
def run_test(self):
peer = self.nodes[0].add_p2p_connection(P2PInterface())
+ self.miniwallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_P2PK)
self.test_dersig_info(is_active=False)
self.log.info("Mining %d blocks", DERSIG_HEIGHT - 2)
- self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(DERSIG_HEIGHT - 2)]
- self.nodeaddress = self.nodes[0].getnewaddress()
+ self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.miniwallet.generate(DERSIG_HEIGHT - 2)]
self.log.info("Test that a transaction with non-DER signature can still appear in a block")
- spendtx = create_transaction(self.nodes[0], self.coinbase_txids[0],
- self.nodeaddress, amount=1.0)
+ spendtx = self.create_tx(self.coinbase_txids[0])
unDERify(spendtx)
spendtx.rehash()
@@ -104,8 +111,7 @@ class BIP66Test(BitcoinTestFramework):
self.log.info("Test that transactions with non-DER signatures cannot appear in a block")
block.nVersion = 3
- spendtx = create_transaction(self.nodes[0], self.coinbase_txids[1],
- self.nodeaddress, amount=1.0)
+ spendtx = self.create_tx(self.coinbase_txids[1])
unDERify(spendtx)
spendtx.rehash()
@@ -133,7 +139,7 @@ class BIP66Test(BitcoinTestFramework):
peer.sync_with_ping()
self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")
- block.vtx[1] = create_transaction(self.nodes[0], self.coinbase_txids[1], self.nodeaddress, amount=1.0)
+ block.vtx[1] = self.create_tx(self.coinbase_txids[1])
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
block.solve()
diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py
index f22b7f266a..448182eded 100755
--- a/test/functional/feature_includeconf.py
+++ b/test/functional/feature_includeconf.py
@@ -42,7 +42,14 @@ class IncludeConfTest(BitcoinTestFramework):
self.log.info("-includeconf cannot be used as command-line arg")
self.stop_node(0)
- self.nodes[0].assert_start_raises_init_error(extra_args=["-includeconf=relative2.conf"], expected_msg="Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=relative2.conf")
+ self.nodes[0].assert_start_raises_init_error(
+ extra_args=['-noincludeconf=0'],
+ expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=true',
+ )
+ self.nodes[0].assert_start_raises_init_error(
+ extra_args=['-includeconf=relative2.conf', '-includeconf=no_warn.conf'],
+ expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf="relative2.conf"',
+ )
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
diff --git a/test/functional/feature_notifications.py b/test/functional/feature_notifications.py
index 4e2de1daf4..6fc8773ee3 100755
--- a/test/functional/feature_notifications.py
+++ b/test/functional/feature_notifications.py
@@ -166,6 +166,8 @@ class NotificationsTest(BitcoinTestFramework):
# Should now verify contents of each file
for tx_id, blockheight, blockhash in tx_details:
fname = os.path.join(self.walletnotify_dir, notify_outputname(self.wallet, tx_id))
+ # Wait for the cached writes to hit storage
+ self.wait_until(lambda: os.path.getsize(fname) > 0, timeout=10)
with open(fname, 'rt', encoding='utf-8') as f:
text = f.read()
# Universal newline ensures '\n' on 'nt'
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index 2cf0ef2251..b5ce18a48b 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -151,7 +151,7 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_equal(cli_get_info['balance'], amounts[1])
self.log.info("Test -getinfo with -rpcwallet=unloaded wallet returns no balances")
- cli_get_info = self.nodes[0].cli('-getinfo', rpcwallet3).send_cli()
+ cli_get_info_keys = self.nodes[0].cli('-getinfo', rpcwallet3).send_cli().keys()
assert 'balance' not in cli_get_info_keys
assert 'balances' not in cli_get_info_keys
diff --git a/test/functional/mempool_spend_coinbase.py b/test/functional/mempool_spend_coinbase.py
index a249a73315..b900aa0b9c 100755
--- a/test/functional/mempool_spend_coinbase.py
+++ b/test/functional/mempool_spend_coinbase.py
@@ -20,40 +20,41 @@ from test_framework.wallet import MiniWallet
class MempoolSpendCoinbaseTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
- self.setup_clean_chain = True
def run_test(self):
wallet = MiniWallet(self.nodes[0])
- wallet.generate(200)
- chain_height = self.nodes[0].getblockcount()
- assert_equal(chain_height, 200)
+ # Invalidate two blocks, so that miniwallet has access to a coin that will mature in the next block
+ chain_height = 198
+ self.nodes[0].invalidateblock(self.nodes[0].getblockhash(chain_height + 1))
+ assert_equal(chain_height, self.nodes[0].getblockcount())
# Coinbase at height chain_height-100+1 ok in mempool, should
# get mined. Coinbase at height chain_height-100+2 is
# too immature to spend.
- b = [self.nodes[0].getblockhash(n) for n in range(101, 103)]
- coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b]
- utxo_101 = wallet.get_utxo(txid=coinbase_txids[0])
- utxo_102 = wallet.get_utxo(txid=coinbase_txids[1])
+ wallet.scan_blocks(start=chain_height - 100 + 1, num=1)
+ utxo_mature = wallet.get_utxo()
+ wallet.scan_blocks(start=chain_height - 100 + 2, num=1)
+ utxo_immature = wallet.get_utxo()
- spend_101_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_101)["txid"]
+ spend_mature_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_mature)["txid"]
- # coinbase at height 102 should be too immature to spend
+ # other coinbase should be too immature to spend
+ immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_immature, mempool_valid=False)
assert_raises_rpc_error(-26,
"bad-txns-premature-spend-of-coinbase",
- lambda: wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102))
+ lambda: self.nodes[0].sendrawtransaction(immature_tx['hex']))
- # mempool should have just spend_101:
- assert_equal(self.nodes[0].getrawmempool(), [spend_101_id])
+ # mempool should have just the mature one
+ assert_equal(self.nodes[0].getrawmempool(), [spend_mature_id])
- # mine a block, spend_101 should get confirmed
+ # mine a block, mature one should get confirmed
self.nodes[0].generate(1)
assert_equal(set(self.nodes[0].getrawmempool()), set())
- # ... and now height 102 can be spent:
- spend_102_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102)["txid"]
- assert_equal(self.nodes[0].getrawmempool(), [spend_102_id])
+ # ... and now previously immature can be spent:
+ spend_new_id = self.nodes[0].sendrawtransaction(immature_tx['hex'])
+ assert_equal(self.nodes[0].getrawmempool(), [spend_new_id])
if __name__ == '__main__':
diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py
index 69821763bd..87297989ba 100755
--- a/test/functional/p2p_addr_relay.py
+++ b/test/functional/p2p_addr_relay.py
@@ -11,6 +11,7 @@ from test_framework.messages import (
NODE_NETWORK,
NODE_WITNESS,
msg_addr,
+ msg_getaddr
)
from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
@@ -19,18 +20,6 @@ from test_framework.util import (
)
import time
-# Keep this with length <= 10. Addresses from larger messages are not relayed.
-ADDRS = []
-num_ipv4_addrs = 10
-
-for i in range(num_ipv4_addrs):
- addr = CAddress()
- addr.time = int(time.time()) + i
- addr.nServices = NODE_NETWORK | NODE_WITNESS
- addr.ip = "123.123.123.{}".format(i % 256)
- addr.port = 8333 + i
- ADDRS.append(addr)
-
class AddrReceiver(P2PInterface):
num_ipv4_received = 0
@@ -44,36 +33,87 @@ class AddrReceiver(P2PInterface):
self.num_ipv4_received += 1
+class GetAddrStore(P2PInterface):
+ getaddr_received = False
+ num_ipv4_received = 0
+
+ def on_getaddr(self, message):
+ self.getaddr_received = True
+
+ def on_addr(self, message):
+ for addr in message.addrs:
+ self.num_ipv4_received += 1
+
+ def addr_received(self):
+ return self.num_ipv4_received != 0
+
+
class AddrTest(BitcoinTestFramework):
+ counter = 0
+ mocktime = int(time.time())
+
def set_test_params(self):
self.num_nodes = 1
def run_test(self):
- self.log.info('Create connection that sends addr messages')
- addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
+ self.oversized_addr_test()
+ self.relay_tests()
+ self.getaddr_tests()
+ self.blocksonly_mode_tests()
+
+ def setup_addr_msg(self, num):
+ addrs = []
+ for i in range(num):
+ addr = CAddress()
+ addr.time = self.mocktime + i
+ addr.nServices = NODE_NETWORK | NODE_WITNESS
+ addr.ip = f"123.123.123.{self.counter % 256}"
+ addr.port = 8333 + i
+ addrs.append(addr)
+ self.counter += 1
+
msg = msg_addr()
+ msg.addrs = addrs
+ return msg
+
+ def send_addr_msg(self, source, msg, receivers):
+ source.send_and_ping(msg)
+ # pop m_next_addr_send timer
+ self.mocktime += 5 * 60
+ self.nodes[0].setmocktime(self.mocktime)
+ for peer in receivers:
+ peer.sync_send_with_ping()
- self.log.info('Send too-large addr message')
- msg.addrs = ADDRS * 101 # more than 1000 addresses in one message
+ def oversized_addr_test(self):
+ self.log.info('Send an addr message that is too large')
+ addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
+
+ msg = self.setup_addr_msg(1010)
with self.nodes[0].assert_debug_log(['addr message size = 1010']):
addr_source.send_and_ping(msg)
+ self.nodes[0].disconnect_p2ps()
+
+ def relay_tests(self):
+ self.log.info('Test address relay')
self.log.info('Check that addr message content is relayed and added to addrman')
+ addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
num_receivers = 7
receivers = []
for _ in range(num_receivers):
receivers.append(self.nodes[0].add_p2p_connection(AddrReceiver()))
- msg.addrs = ADDRS
+
+ # Keep this with length <= 10. Addresses from larger messages are not
+ # relayed.
+ num_ipv4_addrs = 10
+ msg = self.setup_addr_msg(num_ipv4_addrs)
with self.nodes[0].assert_debug_log(
[
'Added {} addresses from 127.0.0.1: 0 tried'.format(num_ipv4_addrs),
- 'received: addr (301 bytes) peer=0',
+ 'received: addr (301 bytes) peer=1',
]
):
- addr_source.send_and_ping(msg)
- self.nodes[0].setmocktime(int(time.time()) + 30 * 60)
- for receiver in receivers:
- receiver.sync_with_ping()
+ self.send_addr_msg(addr_source, msg, receivers)
total_ipv4_received = sum(r.num_ipv4_received for r in receivers)
@@ -82,6 +122,92 @@ class AddrTest(BitcoinTestFramework):
ipv4_branching_factor = 2
assert_equal(total_ipv4_received, num_ipv4_addrs * ipv4_branching_factor)
+ self.nodes[0].disconnect_p2ps()
+
+ self.log.info('Check relay of addresses received from outbound peers')
+ inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver())
+ full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type="outbound-full-relay")
+ msg = self.setup_addr_msg(2)
+ self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
+ self.log.info('Check that the first addr message received from an outbound peer is not relayed')
+ # Currently, there is a flag that prevents the first addr message received
+ # from a new outbound peer to be relayed to others. Originally meant to prevent
+ # large GETADDR responses from being relayed, it now typically affects the self-announcement
+ # of the outbound peer which is often sent before the GETADDR response.
+ assert_equal(inbound_peer.num_ipv4_received, 0)
+
+ self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
+ msg2 = self.setup_addr_msg(2)
+ self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
+ assert_equal(inbound_peer.num_ipv4_received, 2)
+
+ self.log.info('Check address relay to outbound peers')
+ block_relay_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=1, connection_type="block-relay-only")
+ msg3 = self.setup_addr_msg(2)
+ self.send_addr_msg(inbound_peer, msg3, [full_outbound_peer, block_relay_peer])
+
+ self.log.info('Check that addresses are relayed to full outbound peers')
+ assert_equal(full_outbound_peer.num_ipv4_received, 2)
+ self.log.info('Check that addresses are not relayed to block-relay-only outbound peers')
+ assert_equal(block_relay_peer.num_ipv4_received, 0)
+
+ self.nodes[0].disconnect_p2ps()
+
+ def getaddr_tests(self):
+ self.log.info('Test getaddr behavior')
+ self.log.info('Check that we send a getaddr message upon connecting to an outbound-full-relay peer')
+ full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type="outbound-full-relay")
+ full_outbound_peer.sync_with_ping()
+ assert full_outbound_peer.getaddr_received
+
+ self.log.info('Check that we do not send a getaddr message upon connecting to a block-relay-only peer')
+ block_relay_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=1, connection_type="block-relay-only")
+ block_relay_peer.sync_with_ping()
+ assert_equal(block_relay_peer.getaddr_received, False)
+
+ self.log.info('Check that we answer getaddr messages only from inbound peers')
+ inbound_peer = self.nodes[0].add_p2p_connection(GetAddrStore())
+ inbound_peer.sync_with_ping()
+
+ # Add some addresses to addrman
+ for i in range(1000):
+ first_octet = i >> 8
+ second_octet = i % 256
+ a = f"{first_octet}.{second_octet}.1.1"
+ self.nodes[0].addpeeraddress(a, 8333)
+
+ full_outbound_peer.send_and_ping(msg_getaddr())
+ block_relay_peer.send_and_ping(msg_getaddr())
+ inbound_peer.send_and_ping(msg_getaddr())
+
+ self.mocktime += 5 * 60
+ self.nodes[0].setmocktime(self.mocktime)
+ inbound_peer.wait_until(inbound_peer.addr_received)
+
+ assert_equal(full_outbound_peer.num_ipv4_received, 0)
+ assert_equal(block_relay_peer.num_ipv4_received, 0)
+ assert inbound_peer.num_ipv4_received > 100
+
+ self.nodes[0].disconnect_p2ps()
+
+ def blocksonly_mode_tests(self):
+ self.log.info('Test addr relay in -blocksonly mode')
+ self.restart_node(0, ["-blocksonly"])
+ self.mocktime = int(time.time())
+
+ self.log.info('Check that we send getaddr messages')
+ full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type="outbound-full-relay")
+ full_outbound_peer.sync_with_ping()
+ assert full_outbound_peer.getaddr_received
+
+ self.log.info('Check that we relay address messages')
+ addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
+ msg = self.setup_addr_msg(2)
+ self.send_addr_msg(addr_source, msg, [full_outbound_peer])
+ assert_equal(full_outbound_peer.num_ipv4_received, 2)
+
+ self.nodes[0].disconnect_p2ps()
+
if __name__ == '__main__':
AddrTest().main()
diff --git a/test/functional/p2p_blocksonly.py b/test/functional/p2p_blocksonly.py
index 6584efae79..ab2556cd72 100755
--- a/test/functional/p2p_blocksonly.py
+++ b/test/functional/p2p_blocksonly.py
@@ -6,22 +6,25 @@
import time
-from test_framework.blocktools import create_transaction
from test_framework.messages import msg_tx
from test_framework.p2p import P2PInterface, P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
+from test_framework.wallet import MiniWallet
class P2PBlocksOnly(BitcoinTestFramework):
def set_test_params(self):
+ self.setup_clean_chain = True
self.num_nodes = 1
self.extra_args = [["-blocksonly"]]
- def skip_test_if_missing_module(self):
- self.skip_if_no_wallet()
-
def run_test(self):
+ self.miniwallet = MiniWallet(self.nodes[0])
+ # Add enough mature utxos to the wallet, so that all txs spend confirmed coins
+ self.miniwallet.generate(2)
+ self.nodes[0].generate(100)
+
self.blocksonly_mode_tests()
self.blocks_relay_conn_tests()
@@ -30,14 +33,14 @@ class P2PBlocksOnly(BitcoinTestFramework):
assert_equal(self.nodes[0].getnetworkinfo()['localrelay'], False)
self.nodes[0].add_p2p_connection(P2PInterface())
- tx, txid, tx_hex = self.check_p2p_tx_violation()
+ tx, txid, wtxid, tx_hex = self.check_p2p_tx_violation()
self.log.info('Check that txs from rpc are not rejected and relayed to other peers')
tx_relay_peer = self.nodes[0].add_p2p_connection(P2PInterface())
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True)
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True)
- with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer=1'.format(txid)]):
+ with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer=1'.format(wtxid)]):
self.nodes[0].sendrawtransaction(tx_hex)
tx_relay_peer.wait_for_tx(txid)
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
@@ -79,7 +82,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
# Ensure we disconnect if a block-relay-only connection sends us a transaction
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="block-relay-only")
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], False)
- _, txid, tx_hex = self.check_p2p_tx_violation(index=2)
+ _, txid, _, tx_hex = self.check_p2p_tx_violation(index=2)
self.log.info("Check that txs from RPC are not sent to blockrelay connection")
conn = self.nodes[0].add_outbound_p2p_connection(P2PTxInvStore(), p2p_idx=1, connection_type="block-relay-only")
@@ -89,29 +92,24 @@ class P2PBlocksOnly(BitcoinTestFramework):
# Bump time forward to ensure nNextInvSend timer pops
self.nodes[0].setmocktime(int(time.time()) + 60)
- # Calling sync_with_ping twice requires that the node calls
- # `ProcessMessage` twice, and thus ensures `SendMessages` must have
- # been called at least once
- conn.sync_with_ping()
- conn.sync_with_ping()
+ conn.sync_send_with_ping()
assert(int(txid, 16) not in conn.get_invs())
def check_p2p_tx_violation(self, index=1):
self.log.info('Check that txs from P2P are rejected and result in disconnect')
input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(index), 2)['tx'][0]['txid']
- tx = create_transaction(self.nodes[0], input_txid, self.nodes[0].getnewaddress(), amount=(50 - 0.001))
- txid = tx.rehash()
- tx_hex = tx.serialize().hex()
+ utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid)
+ spendtx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']):
- self.nodes[0].p2ps[0].send_message(msg_tx(tx))
+ self.nodes[0].p2ps[0].send_message(msg_tx(spendtx['tx']))
self.nodes[0].p2ps[0].wait_for_disconnect()
assert_equal(self.nodes[0].getmempoolinfo()['size'], 0)
# Remove the disconnected peer
del self.nodes[0].p2ps[0]
- return tx, txid, tx_hex
+ return spendtx['tx'], spendtx['txid'], spendtx['wtxid'], spendtx['hex']
if __name__ == '__main__':
diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py
index 4bee33f825..359cfb9c34 100755
--- a/test/functional/p2p_filter.py
+++ b/test/functional/p2p_filter.py
@@ -174,8 +174,7 @@ class FilterTest(BitcoinTestFramework):
filter_peer.merkleblock_received = False
filter_peer.tx_received = False
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 90)
- filter_peer.sync_with_ping()
- filter_peer.sync_with_ping()
+ filter_peer.sync_send_with_ping()
assert not filter_peer.merkleblock_received
assert not filter_peer.tx_received
diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py
index c0b3c2cb12..788a81d4af 100755
--- a/test/functional/p2p_invalid_messages.py
+++ b/test/functional/p2p_invalid_messages.py
@@ -37,7 +37,7 @@ VALID_DATA_LIMIT = MAX_PROTOCOL_MESSAGE_LENGTH - 5 # Account for the 5-byte len
class msg_unrecognized:
"""Nonsensical message. Modeled after similar types in test_framework.messages."""
- msgtype = b'badmsg'
+ msgtype = b'badmsg\x01'
def __init__(self, *, str_data):
self.str_data = str_data.encode() if not isinstance(str_data, bytes) else str_data
@@ -104,7 +104,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_magic_bytes(self):
self.log.info("Test message with invalid magic bytes disconnects peer")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- with self.nodes[0].assert_debug_log(['HEADER ERROR - MESSAGESTART (badmsg, 2 bytes), received ffffffff']):
+ with self.nodes[0].assert_debug_log(['Header error: Wrong MessageStart ffffffff received']):
msg = conn.build_message(msg_unrecognized(str_data="d"))
# modify magic bytes
msg = b'\xff' * 4 + msg[4:]
@@ -115,7 +115,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_checksum(self):
self.log.info("Test message with invalid checksum logs an error")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- with self.nodes[0].assert_debug_log(['CHECKSUM ERROR (badmsg, 2 bytes), expected 78df0a04 was ffffffff']):
+ with self.nodes[0].assert_debug_log(['Header error: Wrong checksum (badmsg, 2 bytes), expected 78df0a04 was ffffffff']):
msg = conn.build_message(msg_unrecognized(str_data="d"))
# Checksum is after start bytes (4B), message type (12B), len (4B)
cut_len = 4 + 12 + 4
@@ -130,7 +130,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_size(self):
self.log.info("Test message with oversized payload disconnects peer")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- with self.nodes[0].assert_debug_log(['HEADER ERROR - SIZE (badmsg, 4000001 bytes)']):
+ with self.nodes[0].assert_debug_log(['Header error: Size too large (badmsg, 4000001 bytes)']):
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
msg = conn.build_message(msg)
conn.send_raw_message(msg)
@@ -140,7 +140,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_msgtype(self):
self.log.info("Test message with invalid message type logs an error")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- with self.nodes[0].assert_debug_log(['HEADER ERROR - COMMAND']):
+ with self.nodes[0].assert_debug_log(['Header error: Invalid message type']):
msg = msg_unrecognized(str_data="d")
msg = conn.build_message(msg)
# Modify msgtype
diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
index 54891b07e1..9d32c1cb86 100755
--- a/test/functional/p2p_segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -164,7 +164,7 @@ class TestP2PConn(P2PInterface):
def on_wtxidrelay(self, message):
self.last_wtxidrelay.append(message)
- def announce_tx_and_wait_for_getdata(self, tx, timeout=60, success=True, use_wtxid=False):
+ def announce_tx_and_wait_for_getdata(self, tx, success=True, use_wtxid=False):
if success:
# sanity check
assert (self.wtxidrelay and use_wtxid) or (not self.wtxidrelay and not use_wtxid)
@@ -178,11 +178,11 @@ class TestP2PConn(P2PInterface):
if success:
if use_wtxid:
- self.wait_for_getdata([wtxid], timeout)
+ self.wait_for_getdata([wtxid])
else:
- self.wait_for_getdata([tx.sha256], timeout)
+ self.wait_for_getdata([tx.sha256])
else:
- time.sleep(timeout)
+ time.sleep(5)
assert not self.last_message.get("getdata")
def announce_block_and_wait_for_getdata(self, block, use_header, timeout=60):
@@ -604,7 +604,7 @@ class SegWitTest(BitcoinTestFramework):
# Since we haven't delivered the tx yet, inv'ing the same tx from
# a witness transaction ought not result in a getdata.
- self.test_node.announce_tx_and_wait_for_getdata(tx, timeout=2, success=False)
+ self.test_node.announce_tx_and_wait_for_getdata(tx, success=False)
# Delivering this transaction with witness should fail (no matter who
# its from)
@@ -1461,7 +1461,7 @@ class SegWitTest(BitcoinTestFramework):
self.std_node.announce_tx_and_wait_for_getdata(tx3)
test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, reason="bad-txns-nonstandard-inputs")
# Now the node will no longer ask for getdata of this transaction when advertised by same txid
- self.std_node.announce_tx_and_wait_for_getdata(tx3, timeout=5, success=False)
+ self.std_node.announce_tx_and_wait_for_getdata(tx3, success=False)
# Spending a higher version witness output is not allowed by policy,
# even with fRequireStandard=false.
@@ -1956,22 +1956,34 @@ class SegWitTest(BitcoinTestFramework):
def test_upgrade_after_activation(self):
"""Test the behavior of starting up a segwit-aware node after the softfork has activated."""
- self.restart_node(2, extra_args=["-segwitheight={}".format(SEGWIT_HEIGHT)])
+ # All nodes are caught up and node 2 is a pre-segwit node that will soon upgrade.
+ for n in range(2):
+ assert_equal(self.nodes[n].getblockcount(), self.nodes[2].getblockcount())
+ assert softfork_active(self.nodes[n], "segwit")
+ assert SEGWIT_HEIGHT < self.nodes[2].getblockcount()
+ assert 'segwit' not in self.nodes[2].getblockchaininfo()['softforks']
+
+ # Restarting node 2 should result in a shutdown because the blockchain consists of
+ # insufficiently validated blocks per segwit consensus rules.
+ self.stop_node(2)
+ self.nodes[2].assert_start_raises_init_error(
+ extra_args=[f"-segwitheight={SEGWIT_HEIGHT}"],
+ expected_msg=f": Witness data for blocks after height {SEGWIT_HEIGHT} requires validation. Please restart with -reindex..\nPlease restart with -reindex or -reindex-chainstate to recover.",
+ )
+
+ # As directed, the user restarts the node with -reindex
+ self.start_node(2, extra_args=["-reindex", f"-segwitheight={SEGWIT_HEIGHT}"])
+
+ # With the segwit consensus rules, the node is able to validate only up to SEGWIT_HEIGHT - 1
+ assert_equal(self.nodes[2].getblockcount(), SEGWIT_HEIGHT - 1)
self.connect_nodes(0, 2)
# We reconnect more than 100 blocks, give it plenty of time
+ # sync_blocks() also verifies the best block hash is the same for all nodes
self.sync_blocks(timeout=240)
- # Make sure that this peer thinks segwit has activated.
- assert softfork_active(self.nodes[2], 'segwit')
-
- # Make sure this peer's blocks match those of node0.
- height = self.nodes[2].getblockcount()
- while height >= 0:
- block_hash = self.nodes[2].getblockhash(height)
- assert_equal(block_hash, self.nodes[0].getblockhash(height))
- assert_equal(self.nodes[0].getblock(block_hash), self.nodes[2].getblock(block_hash))
- height -= 1
+ # The upgraded node should now have segwit activated
+ assert softfork_active(self.nodes[2], "segwit")
@subtest # type: ignore
def test_witness_sigops(self):
diff --git a/test/functional/rpc_addresses_deprecation.py b/test/functional/rpc_addresses_deprecation.py
index bc0559f3b5..bc0559f3b5 100644..100755
--- a/test/functional/rpc_addresses_deprecation.py
+++ b/test/functional/rpc_addresses_deprecation.py
diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py
index ac53a280b4..00324347ed 100755
--- a/test/functional/rpc_blockchain.py
+++ b/test/functional/rpc_blockchain.py
@@ -275,7 +275,7 @@ class BlockchainTest(BitcoinTestFramework):
assert 'muhash' in res6
assert(res['hash_serialized_2'] != res6['muhash'])
- # muhash should not be included in gettxoutset unless requested.
+ # muhash should not be returned unless requested.
for r in [res, res2, res3, res4, res5]:
assert 'muhash' not in r
diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py
index e65787ce08..dc469ba552 100755
--- a/test/functional/rpc_dumptxoutset.py
+++ b/test/functional/rpc_dumptxoutset.py
@@ -41,7 +41,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
digest = hashlib.sha256(f.read()).hexdigest()
# UTXO snapshot hash should be deterministic based on mocked time.
assert_equal(
- digest, 'be032e5f248264ba08e11099ac09dbd001f6f87ffc68bf0f87043d8146d50664')
+ digest, '7ae82c986fa5445678d2a21453bb1c86d39e47af13da137640c2b1cf8093691c')
# Specifying a path to an existing file will fail.
assert_raises_rpc_error(
diff --git a/test/functional/rpc_fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py
index 5129ecb895..4b07a32c54 100755
--- a/test/functional/rpc_fundrawtransaction.py
+++ b/test/functional/rpc_fundrawtransaction.py
@@ -5,6 +5,8 @@
"""Test the fundrawtransaction RPC."""
from decimal import Decimal
+from itertools import product
+
from test_framework.descriptors import descsum_create
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
@@ -96,6 +98,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.test_option_subtract_fee_from_outputs()
self.test_subtract_fee_with_presets()
self.test_transaction_too_large()
+ self.test_include_unsafe()
def test_change_position(self):
"""Ensure setting changePosition in fundraw with an exact match is handled properly."""
@@ -723,17 +726,16 @@ class RawTransactionsTest(BitcoinTestFramework):
result2 = node.fundrawtransaction(rawtx, {"feeRate": 2 * self.min_relay_tx_fee})
result3 = node.fundrawtransaction(rawtx, {"fee_rate": 10 * btc_kvb_to_sat_vb * self.min_relay_tx_fee})
result4 = node.fundrawtransaction(rawtx, {"feeRate": str(10 * self.min_relay_tx_fee)})
- # Test that funding non-standard "zero-fee" transactions is valid.
- result5 = self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 0})
- result6 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 0})
result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex'])
- assert_fee_amount(result1['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
+ assert_fee_amount(result1['fee'], count_bytes(result1['hex']), 2 * result_fee_rate)
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
- assert_fee_amount(result4['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
- assert_fee_amount(result5['fee'], count_bytes(result5['hex']), 0)
- assert_fee_amount(result6['fee'], count_bytes(result6['hex']), 0)
+ assert_fee_amount(result4['fee'], count_bytes(result4['hex']), 10 * result_fee_rate)
+
+ # Test that funding non-standard "zero-fee" transactions is valid.
+ for param, zero_value in product(["fee_rate", "feeRate"], [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]):
+ assert_equal(self.nodes[3].fundrawtransaction(rawtx, {param: zero_value})["fee"], 0)
# With no arguments passed, expect fee of 141 satoshis.
assert_approx(node.fundrawtransaction(rawtx)["fee"], vexp=0.00000141, vspan=0.00000001)
@@ -767,11 +769,16 @@ class RawTransactionsTest(BitcoinTestFramework):
node.fundrawtransaction, rawtx, {param: -1, "add_inputs": True})
assert_raises_rpc_error(-3, "Amount is not a number or string",
node.fundrawtransaction, rawtx, {param: {"foo": "bar"}, "add_inputs": True})
+ # Test fee rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ assert_raises_rpc_error(-3, "Invalid amount", node.fundrawtransaction, rawtx, {param: invalid_value, "add_inputs": True})
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
assert_raises_rpc_error(-3, "Invalid amount",
- node.fundrawtransaction, rawtx, {param: "", "add_inputs": True})
+ node.fundrawtransaction, rawtx, {"fee_rate": invalid_value, "add_inputs": True})
self.log.info("Test min fee rate checks are bypassed with fundrawtxn, e.g. a fee_rate under 1 sat/vB is allowed")
- node.fundrawtransaction(rawtx, {"fee_rate": 0.99999999, "add_inputs": True})
+ node.fundrawtransaction(rawtx, {"fee_rate": 0.999, "add_inputs": True})
node.fundrawtransaction(rawtx, {"feeRate": 0.00000999, "add_inputs": True})
self.log.info("- raises RPC error if both feeRate and fee_rate are passed")
@@ -928,6 +935,40 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[0].generate(10)
assert_raises_rpc_error(-4, "Transaction too large", recipient.fundrawtransaction, rawtx)
+ def test_include_unsafe(self):
+ self.log.info("Test fundrawtxn with unsafe inputs")
+
+ self.nodes[0].createwallet("unsafe")
+ wallet = self.nodes[0].get_wallet_rpc("unsafe")
+
+ # We receive unconfirmed funds from external keys (unsafe outputs).
+ addr = wallet.getnewaddress()
+ txid1 = self.nodes[2].sendtoaddress(addr, 6)
+ txid2 = self.nodes[2].sendtoaddress(addr, 4)
+ self.sync_all()
+ vout1 = find_vout_for_address(wallet, txid1, addr)
+ vout2 = find_vout_for_address(wallet, txid2, addr)
+
+ # Unsafe inputs are ignored by default.
+ rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 5}])
+ assert_raises_rpc_error(-4, "Insufficient funds", wallet.fundrawtransaction, rawtx)
+
+ # But we can opt-in to use them for funding.
+ fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
+ tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
+ assert any([txin['txid'] == txid1 and txin['vout'] == vout1 for txin in tx_dec['vin']])
+ signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
+ wallet.sendrawtransaction(signedtx['hex'])
+
+ # And we can also use them once they're confirmed.
+ self.nodes[0].generate(1)
+ rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 3}])
+ fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
+ tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
+ assert any([txin['txid'] == txid2 and txin['vout'] == vout2 for txin in tx_dec['vin']])
+ signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
+ wallet.sendrawtransaction(signedtx['hex'])
+
if __name__ == '__main__':
RawTransactionsTest().main()
diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py
index 1398d1237f..52c8fa883d 100755
--- a/test/functional/rpc_misc.py
+++ b/test/functional/rpc_misc.py
@@ -61,30 +61,30 @@ class RpcMiscTest(BitcoinTestFramework):
node.logging(include=['qt'])
assert_equal(node.logging()['qt'], True)
+ self.log.info("test echoipc (testing spawned process in multiprocess build)")
+ assert_equal(node.echoipc("hello"), "hello")
+
self.log.info("test getindexinfo")
# Without any indices running the RPC returns an empty object
assert_equal(node.getindexinfo(), {})
# Restart the node with indices and wait for them to sync
- self.restart_node(0, ["-txindex", "-blockfilterindex"])
+ self.restart_node(0, ["-txindex", "-blockfilterindex", "-coinstatsindex"])
self.wait_until(lambda: all(i["synced"] for i in node.getindexinfo().values()))
# Returns a list of all running indices by default
+ values = {"synced": True, "best_block_height": 200}
assert_equal(
node.getindexinfo(),
{
- "txindex": {"synced": True, "best_block_height": 200},
- "basic block filter index": {"synced": True, "best_block_height": 200}
+ "txindex": values,
+ "basic block filter index": values,
+ "coinstatsindex": values,
}
)
-
# Specifying an index by name returns only the status of that index
- assert_equal(
- node.getindexinfo("txindex"),
- {
- "txindex": {"synced": True, "best_block_height": 200},
- }
- )
+ for i in {"txindex", "basic block filter index", "coinstatsindex"}:
+ assert_equal(node.getindexinfo(i), {i: values})
# Specifying an unknown index name returns an empty result
assert_equal(node.getindexinfo("foo"), {})
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
index 16d7958712..9a2817a6ee 100755
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -69,6 +69,7 @@ class NetTest(BitcoinTestFramework):
self.test_getaddednodeinfo()
self.test_service_flags()
self.test_getnodeaddresses()
+ self.test_addpeeraddress()
def test_connection_count(self):
self.log.info("Test getconnectioncount")
@@ -187,43 +188,78 @@ class NetTest(BitcoinTestFramework):
def test_getnodeaddresses(self):
self.log.info("Test getnodeaddresses")
self.nodes[0].add_p2p_connection(P2PInterface())
+ services = NODE_NETWORK | NODE_WITNESS
- # Add some addresses to the Address Manager over RPC. Due to the way
- # bucket and bucket position are calculated, some of these addresses
- # will collide.
+ # Add an IPv6 address to the address manager.
+ ipv6_addr = "1233:3432:2434:2343:3234:2345:6546:4534"
+ self.nodes[0].addpeeraddress(address=ipv6_addr, port=8333)
+
+ # Add 10,000 IPv4 addresses to the address manager. Due to the way bucket
+ # and bucket positions are calculated, some of these addresses will collide.
imported_addrs = []
for i in range(10000):
first_octet = i >> 8
second_octet = i % 256
- a = "{}.{}.1.1".format(first_octet, second_octet) # IPV4
+ a = f"{first_octet}.{second_octet}.1.1"
imported_addrs.append(a)
self.nodes[0].addpeeraddress(a, 8333)
- # Obtain addresses via rpc call and check they were ones sent in before.
- #
- # Maximum possible addresses in addrman is 10000, although actual
- # number will usually be less due to bucket and bucket position
- # collisions.
- node_addresses = self.nodes[0].getnodeaddresses(0)
+ # Fetch the addresses via the RPC and test the results.
+ assert_equal(len(self.nodes[0].getnodeaddresses()), 1) # default count is 1
+ assert_equal(len(self.nodes[0].getnodeaddresses(count=2)), 2)
+ assert_equal(len(self.nodes[0].getnodeaddresses(network="ipv4", count=8)), 8)
+
+ # Maximum possible addresses in AddrMan is 10000. The actual number will
+ # usually be less due to bucket and bucket position collisions.
+ node_addresses = self.nodes[0].getnodeaddresses(0, "ipv4")
assert_greater_than(len(node_addresses), 5000)
assert_greater_than(10000, len(node_addresses))
for a in node_addresses:
assert_greater_than(a["time"], 1527811200) # 1st June 2018
- assert_equal(a["services"], NODE_NETWORK | NODE_WITNESS)
+ assert_equal(a["services"], services)
assert a["address"] in imported_addrs
assert_equal(a["port"], 8333)
assert_equal(a["network"], "ipv4")
- node_addresses = self.nodes[0].getnodeaddresses(1)
- assert_equal(len(node_addresses), 1)
+ # Test the IPv6 address.
+ res = self.nodes[0].getnodeaddresses(0, "ipv6")
+ assert_equal(len(res), 1)
+ assert_equal(res[0]["address"], ipv6_addr)
+ assert_equal(res[0]["network"], "ipv6")
+ assert_equal(res[0]["port"], 8333)
+ assert_equal(res[0]["services"], services)
- assert_raises_rpc_error(-8, "Address count out of range", self.nodes[0].getnodeaddresses, -1)
+ # Test for the absence of onion and I2P addresses.
+ for network in ["onion", "i2p"]:
+ assert_equal(self.nodes[0].getnodeaddresses(0, network), [])
- # addrman's size cannot be known reliably after insertion, as hash collisions may occur
- # so only test that requesting a large number of addresses returns less than that
- LARGE_REQUEST_COUNT = 10000
- node_addresses = self.nodes[0].getnodeaddresses(LARGE_REQUEST_COUNT)
- assert_greater_than(LARGE_REQUEST_COUNT, len(node_addresses))
+ # Test invalid arguments.
+ assert_raises_rpc_error(-8, "Address count out of range", self.nodes[0].getnodeaddresses, -1)
+ assert_raises_rpc_error(-8, "Network not recognized: Foo", self.nodes[0].getnodeaddresses, 1, "Foo")
+
+ def test_addpeeraddress(self):
+ self.log.info("Test addpeeraddress")
+ node = self.nodes[1]
+
+ self.log.debug("Test that addpeerinfo is a hidden RPC")
+ # It is hidden from general help, but its detailed help may be called directly.
+ assert "addpeerinfo" not in node.help()
+ assert "addpeerinfo" in node.help("addpeerinfo")
+
+ self.log.debug("Test that adding an empty address fails")
+ assert_equal(node.addpeeraddress(address="", port=8333), {"success": False})
+ assert_equal(node.getnodeaddresses(count=0), [])
+
+ self.log.debug("Test that adding a valid address succeeds")
+ assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": True})
+ addrs = node.getnodeaddresses(count=0)
+ assert_equal(len(addrs), 1)
+ assert_equal(addrs[0]["address"], "1.2.3.4")
+ assert_equal(addrs[0]["port"], 8333)
+
+ self.log.debug("Test that adding the same address again when already present fails")
+ assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": False})
+ assert_equal(len(node.getnodeaddresses(count=0)), 1)
if __name__ == '__main__':
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index 079a3bd3ba..cf4d8a134c 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -6,6 +6,8 @@
"""
from decimal import Decimal
+from itertools import product
+
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_approx,
@@ -193,14 +195,14 @@ class PSBTTest(BitcoinTestFramework):
assert_approx(res2["fee"], 0.055, 0.005)
self.log.info("Test min fee rate checks with walletcreatefundedpsbt are bypassed, e.g. a fee_rate under 1 sat/vB is allowed")
- res3 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"fee_rate": "0.99999999", "add_inputs": True})
+ res3 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"fee_rate": "0.999", "add_inputs": True})
assert_approx(res3["fee"], 0.00000381, 0.0000001)
res4 = self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {"feeRate": 0.00000999, "add_inputs": True})
assert_approx(res4["fee"], 0.00000381, 0.0000001)
self.log.info("Test min fee rate checks with walletcreatefundedpsbt are bypassed and that funding non-standard 'zero-fee' transactions is valid")
- for param in ["fee_rate", "feeRate"]:
- assert_equal(self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {param: 0, "add_inputs": True})["fee"], 0)
+ for param, zero_value in product(["fee_rate", "feeRate"], [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]):
+ assert_equal(0, self.nodes[1].walletcreatefundedpsbt(inputs, outputs, 0, {param: zero_value, "add_inputs": True})["fee"])
self.log.info("Test invalid fee rate settings")
for param, value in {("fee_rate", 100000), ("feeRate", 1)}:
@@ -210,8 +212,14 @@ class PSBTTest(BitcoinTestFramework):
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {param: -1, "add_inputs": True})
assert_raises_rpc_error(-3, "Amount is not a number or string",
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {param: {"foo": "bar"}, "add_inputs": True})
+ # Test fee rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ assert_raises_rpc_error(-3, "Invalid amount",
+ self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {param: invalid_value, "add_inputs": True})
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
assert_raises_rpc_error(-3, "Invalid amount",
- self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {param: "", "add_inputs": True})
+ self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"fee_rate": invalid_value, "add_inputs": True})
self.log.info("- raises RPC error if both feeRate and fee_rate are passed")
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (sat/vB) and feeRate (BTC/kvB)",
@@ -394,6 +402,14 @@ class PSBTTest(BitcoinTestFramework):
# We don't care about the decode result, but decoding must succeed.
self.nodes[0].decodepsbt(double_processed_psbt["psbt"])
+ # Make sure unsafe inputs are included if specified
+ self.nodes[2].createwallet(wallet_name="unsafe")
+ wunsafe = self.nodes[2].get_wallet_rpc("unsafe")
+ self.nodes[0].sendtoaddress(wunsafe.getnewaddress(), 2)
+ self.sync_mempools()
+ assert_raises_rpc_error(-4, "Insufficient funds", wunsafe.walletcreatefundedpsbt, [], [{self.nodes[0].getnewaddress(): 1}])
+ wunsafe.walletcreatefundedpsbt([], [{self.nodes[0].getnewaddress(): 1}], 0, {"include_unsafe": True})
+
# BIP 174 Test Vectors
# Check that unknown values are just passed through
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index e691b63df6..d08e025178 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -115,7 +115,7 @@ def script_BIP34_coinbase_height(height):
return CScript([CScriptNum(height)])
-def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0):
+def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0, nValue=50):
"""Create a coinbase transaction.
If pubkey is passed in, the coinbase output will be a P2PK output;
@@ -126,10 +126,11 @@ def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0):
coinbase = CTransaction()
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), script_BIP34_coinbase_height(height), 0xffffffff))
coinbaseoutput = CTxOut()
- coinbaseoutput.nValue = 50 * COIN
- halvings = int(height / 150) # regtest
- coinbaseoutput.nValue >>= halvings
- coinbaseoutput.nValue += fees
+ coinbaseoutput.nValue = nValue * COIN
+ if nValue == 50:
+ halvings = int(height / 150) # regtest
+ coinbaseoutput.nValue >>= halvings
+ coinbaseoutput.nValue += fees
if pubkey is not None:
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
else:
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
index 05099f3339..cc80b543cd 100755
--- a/test/functional/test_framework/p2p.py
+++ b/test/functional/test_framework/p2p.py
@@ -539,8 +539,16 @@ class P2PInterface(P2PConnection):
self.send_message(message)
self.sync_with_ping(timeout=timeout)
- # Sync up with the node
+ def sync_send_with_ping(self, timeout=60):
+ """Ensure SendMessages is called on this connection"""
+ # Calling sync_with_ping twice requires that the node calls
+ # `ProcessMessage` twice, and thus ensures `SendMessages` must have
+ # been called at least once
+ self.sync_with_ping()
+ self.sync_with_ping()
+
def sync_with_ping(self, timeout=60):
+ """Ensure ProcessMessages is called on this connection"""
self.send_message(msg_ping(nonce=self.ping_counter))
def test_function():
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 02eb10b5a4..a89a26caea 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -739,11 +739,12 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
# block in the cache does not age too much (have an old tip age).
# This is needed so that we are out of IBD when the test starts,
# see the tip age check in IsInitialBlockDownload().
- gen_addresses = [k.address for k in TestNode.PRIV_KEYS] + [ADDRESS_BCRT1_P2WSH_OP_TRUE]
+ gen_addresses = [k.address for k in TestNode.PRIV_KEYS][:3] + [ADDRESS_BCRT1_P2WSH_OP_TRUE]
+ assert_equal(len(gen_addresses), 4)
for i in range(8):
cache_node.generatetoaddress(
nblocks=25 if i != 7 else 24,
- address=gen_addresses[i % 4],
+ address=gen_addresses[i % len(gen_addresses)],
)
assert_equal(cache_node.getblockchaininfo()["blocks"], 199)
@@ -757,7 +758,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
os.rmdir(cache_path('wallets')) # Remove empty wallets dir
for entry in os.listdir(cache_path()):
- if entry not in ['chainstate', 'blocks']: # Only keep chainstate and blocks folder
+ if entry not in ['chainstate', 'blocks', 'indexes']: # Only indexes, chainstate and blocks folders
os.remove(cache_path(entry))
for i in range(self.num_nodes):
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index ce9c1bc024..c17c16f797 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -491,6 +491,7 @@ class TestNode():
self.start(extra_args, stdout=log_stdout, stderr=log_stderr, *args, **kwargs)
ret = self.process.wait(timeout=self.rpc_timeout)
self.log.debug(self._node_msg(f'bitcoind exited with status {ret} during initialization'))
+ assert ret != 0 # Exit code must indicate failure
self.running = False
self.process = None
# Check stderr for expected message
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index a906a21dd0..05bda5d899 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -5,7 +5,9 @@
"""A limited-functionality wallet, which may replace a real wallet in tests"""
from decimal import Decimal
+from enum import Enum
from test_framework.address import ADDRESS_BCRT1_P2WSH_OP_TRUE
+from test_framework.key import ECKey
from test_framework.messages import (
COIN,
COutPoint,
@@ -16,7 +18,11 @@ from test_framework.messages import (
)
from test_framework.script import (
CScript,
+ LegacySignatureHash,
+ OP_CHECKSIG,
OP_TRUE,
+ OP_NOP,
+ SIGHASH_ALL,
)
from test_framework.util import (
assert_equal,
@@ -25,25 +31,72 @@ from test_framework.util import (
)
+class MiniWalletMode(Enum):
+ """Determines the transaction type the MiniWallet is creating and spending.
+
+ For most purposes, the default mode ADDRESS_OP_TRUE should be sufficient;
+ it simply uses a fixed bech32 P2WSH address whose coins are spent with a
+ witness stack of OP_TRUE, i.e. following an anyone-can-spend policy.
+ However, if the transactions need to be modified by the user (e.g. prepending
+ scriptSig for testing opcodes that are activated by a soft-fork), or the txs
+ should contain an actual signature, the raw modes RAW_OP_TRUE and RAW_P2PK
+ can be useful. Summary of modes:
+
+ | output | | tx is | can modify | needs
+ mode | description | address | standard | scriptSig | signing
+ ----------------+-------------------+-----------+----------+------------+----------
+ ADDRESS_OP_TRUE | anyone-can-spend | bech32 | yes | no | no
+ RAW_OP_TRUE | anyone-can-spend | - (raw) | no | yes | no
+ RAW_P2PK | pay-to-public-key | - (raw) | yes | yes | yes
+ """
+ ADDRESS_OP_TRUE = 1
+ RAW_OP_TRUE = 2
+ RAW_P2PK = 3
+
+
class MiniWallet:
- def __init__(self, test_node):
+ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE):
self._test_node = test_node
self._utxos = []
- self._address = ADDRESS_BCRT1_P2WSH_OP_TRUE
- self._scriptPubKey = hex_str_to_bytes(self._test_node.validateaddress(self._address)['scriptPubKey'])
+ self._priv_key = None
+ self._address = None
+
+ assert isinstance(mode, MiniWalletMode)
+ if mode == MiniWalletMode.RAW_OP_TRUE:
+ self._scriptPubKey = bytes(CScript([OP_TRUE]))
+ elif mode == MiniWalletMode.RAW_P2PK:
+ # use simple deterministic private key (k=1)
+ self._priv_key = ECKey()
+ self._priv_key.set((1).to_bytes(32, 'big'), True)
+ pub_key = self._priv_key.get_pubkey()
+ self._scriptPubKey = bytes(CScript([pub_key.get_bytes(), OP_CHECKSIG]))
+ elif mode == MiniWalletMode.ADDRESS_OP_TRUE:
+ self._address = ADDRESS_BCRT1_P2WSH_OP_TRUE
+ self._scriptPubKey = hex_str_to_bytes(self._test_node.validateaddress(self._address)['scriptPubKey'])
def scan_blocks(self, *, start=1, num):
"""Scan the blocks for self._address outputs and add them to self._utxos"""
for i in range(start, start + num):
block = self._test_node.getblock(blockhash=self._test_node.getblockhash(i), verbosity=2)
for tx in block['tx']:
- for out in tx['vout']:
- if out['scriptPubKey']['hex'] == self._scriptPubKey.hex():
- self._utxos.append({'txid': tx['txid'], 'vout': out['n'], 'value': out['value']})
+ self.scan_tx(tx)
+
+ def scan_tx(self, tx):
+ """Scan the tx for self._scriptPubKey outputs and add them to self._utxos"""
+ for out in tx['vout']:
+ if out['scriptPubKey']['hex'] == self._scriptPubKey.hex():
+ self._utxos.append({'txid': tx['txid'], 'vout': out['n'], 'value': out['value']})
+
+ def sign_tx(self, tx):
+ """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]))])
def generate(self, num_blocks):
"""Generate blocks with coinbase outputs to the internal address, and append the outputs to the internal list"""
- blocks = self._test_node.generatetoaddress(num_blocks, self._address)
+ blocks = self._test_node.generatetodescriptor(num_blocks, f'raw({self._scriptPubKey.hex()})')
for b in blocks:
cb_tx = self._test_node.getblock(blockhash=b, verbosity=2)['tx'][0]
self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']})
@@ -52,7 +105,7 @@ class MiniWallet:
def get_address(self):
return self._address
- def get_utxo(self, *, txid=''):
+ def get_utxo(self, *, txid='', mark_as_spent=True):
"""
Returns a utxo and marks it as spent (pops it from the internal list)
@@ -65,10 +118,19 @@ class MiniWallet:
if txid:
utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos))
index = self._utxos.index(utxo)
- return self._utxos.pop(index)
+ if mark_as_spent:
+ return self._utxos.pop(index)
+ else:
+ return self._utxos[index]
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
"""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'])
+ return tx
+
+ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True):
+ """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)
@@ -79,13 +141,29 @@ class MiniWallet:
tx = CTransaction()
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']))]
tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
- tx.wit.vtxinwit = [CTxInWitness()]
- tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
+ if not self._address:
+ # raw script
+ if self._priv_key is not None:
+ # P2PK, need to sign
+ self.sign_tx(tx)
+ else:
+ # anyone-can-spend
+ tx.vin[0].scriptSig = CScript([OP_NOP] * 35) # pad to identical size
+ else:
+ tx.wit.vtxinwit = [CTxInWitness()]
+ tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
tx_hex = tx.serialize().hex()
tx_info = from_node.testmempoolaccept([tx_hex])[0]
- self._utxos.append({'txid': tx_info['txid'], 'vout': 0, 'value': send_value})
+ 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['fees']['base'], fee)
+ return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
+
+ def sendrawtransaction(self, *, from_node, tx_hex):
from_node.sendrawtransaction(tx_hex)
- 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}
+ self.scan_tx(from_node.decoderawtransaction(tx_hex))
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index bd58f2cd51..00527e78f1 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -281,6 +281,7 @@ BASE_SCRIPTS = [
'rpc_scantxoutset.py',
'feature_logging.py',
'feature_anchors.py',
+ 'feature_coinstatsindex.py',
'p2p_node_network_limited.py',
'p2p_permissions.py',
'feature_blocksdir.py',
diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py
index 46eecae611..4a1d25bbc5 100755
--- a/test/functional/wallet_basic.py
+++ b/test/functional/wallet_basic.py
@@ -15,6 +15,7 @@ from test_framework.util import (
)
from test_framework.wallet_util import test_address
+NOT_A_NUMBER_OR_STRING = "Amount is not a number or string"
OUT_OF_RANGE = "Amount out of range"
@@ -264,12 +265,25 @@ class WalletTest(BitcoinTestFramework):
# Test setting explicit fee rate just below the minimum.
self.log.info("Test sendmany raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
- self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0.99999999)
-
- self.log.info("Test sendmany raises if fee_rate of 0 or -1 is passed")
- assert_raises_rpc_error(-6, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
- self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0)
+ self.nodes[2].sendmany, amounts={address: 10}, fee_rate=0.999)
+
+ self.log.info("Test sendmany raises if an invalid fee_rate is passed")
+ # Test fee_rate with zero values.
+ msg = "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
+ for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:
+ assert_raises_rpc_error(-6, msg, self.nodes[2].sendmany, amounts={address: 1}, fee_rate=zero_value)
+ msg = "Invalid amount"
+ # Test fee_rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ assert_raises_rpc_error(-3, msg, self.nodes[2].sendmany, amounts={address: 1.0}, fee_rate=invalid_value)
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
+ assert_raises_rpc_error(-3, msg, self.nodes[2].sendmany, amounts={address: 10}, fee_rate=invalid_value)
+ # Test fee_rate out of range (negative number).
assert_raises_rpc_error(-3, OUT_OF_RANGE, self.nodes[2].sendmany, amounts={address: 10}, fee_rate=-1)
+ # Test type error.
+ for invalid_value in [True, {"foo": "bar"}]:
+ assert_raises_rpc_error(-3, NOT_A_NUMBER_OR_STRING, self.nodes[2].sendmany, amounts={address: 10}, fee_rate=invalid_value)
self.log.info("Test sendmany raises if an invalid conf_target or estimate_mode is passed")
for target, mode in product([-1, 0, 1009], ["economical", "conservative"]):
@@ -447,12 +461,25 @@ class WalletTest(BitcoinTestFramework):
# Test setting explicit fee rate just below the minimum.
self.log.info("Test sendtoaddress raises 'fee rate too low' if fee_rate of 0.99999999 is passed")
assert_raises_rpc_error(-6, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
- self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=0.99999999)
-
- self.log.info("Test sendtoaddress raises if fee_rate of 0 or -1 is passed")
- assert_raises_rpc_error(-6, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)",
- self.nodes[2].sendtoaddress, address=address, amount=10, fee_rate=0)
+ self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=0.999)
+
+ self.log.info("Test sendtoaddress raises if an invalid fee_rate is passed")
+ # Test fee_rate with zero values.
+ msg = "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
+ for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:
+ assert_raises_rpc_error(-6, msg, self.nodes[2].sendtoaddress, address=address, amount=1, fee_rate=zero_value)
+ msg = "Invalid amount"
+ # Test fee_rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ assert_raises_rpc_error(-3, msg, self.nodes[2].sendtoaddress, address=address, amount=1.0, fee_rate=invalid_value)
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
+ assert_raises_rpc_error(-3, msg, self.nodes[2].sendtoaddress, address=address, amount=10, fee_rate=invalid_value)
+ # Test fee_rate out of range (negative number).
assert_raises_rpc_error(-3, OUT_OF_RANGE, self.nodes[2].sendtoaddress, address=address, amount=1.0, fee_rate=-1)
+ # Test type error.
+ for invalid_value in [True, {"foo": "bar"}]:
+ assert_raises_rpc_error(-3, NOT_A_NUMBER_OR_STRING, self.nodes[2].sendtoaddress, address=address, amount=1.0, fee_rate=invalid_value)
self.log.info("Test sendtoaddress raises if an invalid conf_target or estimate_mode is passed")
for target, mode in product([-1, 0, 1009], ["economical", "conservative"]):
diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py
index 0d1b6c54ce..ff5070c1fa 100755
--- a/test/functional/wallet_bumpfee.py
+++ b/test/functional/wallet_bumpfee.py
@@ -110,13 +110,24 @@ class BumpFeeTest(BitcoinTestFramework):
assert_raises_rpc_error(-8, "Insufficient total fee 0.00000141", rbf_node.bumpfee, rbfid, {"fee_rate": INSUFFICIENT})
self.log.info("Test invalid fee rate settings")
- assert_raises_rpc_error(-8, "Insufficient total fee 0.00", rbf_node.bumpfee, rbfid, {"fee_rate": 0})
assert_raises_rpc_error(-4, "Specified or calculated fee 0.141 is too high (cannot be higher than -maxtxfee 0.10",
rbf_node.bumpfee, rbfid, {"fee_rate": TOO_HIGH})
+ # Test fee_rate with zero values.
+ msg = "Insufficient total fee 0.00"
+ for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:
+ assert_raises_rpc_error(-8, msg, rbf_node.bumpfee, rbfid, {"fee_rate": zero_value})
+ msg = "Invalid amount"
+ # Test fee_rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, {"fee_rate": invalid_value})
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
+ assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, {"fee_rate": invalid_value})
+ # Test fee_rate out of range (negative number).
assert_raises_rpc_error(-3, "Amount out of range", rbf_node.bumpfee, rbfid, {"fee_rate": -1})
+ # Test type error.
for value in [{"foo": "bar"}, True]:
assert_raises_rpc_error(-3, "Amount is not a number or string", rbf_node.bumpfee, rbfid, {"fee_rate": value})
- assert_raises_rpc_error(-3, "Invalid amount", rbf_node.bumpfee, rbfid, {"fee_rate": ""})
self.log.info("Test explicit fee rate raises RPC error if both fee_rate and conf_target are passed")
assert_raises_rpc_error(-8, "Cannot specify both conf_target and fee_rate. Please provide either a confirmation "
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index ed62ef0e9d..0a3dd56620 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -459,6 +459,77 @@ class ImportDescriptorsTest(BitcoinTestFramework):
assert_equal(tx_signed_2['complete'], True)
self.nodes[1].sendrawtransaction(tx_signed_2['hex'])
+ self.log.info("We can create and use a huge multisig under P2WSH")
+ self.nodes[1].createwallet(wallet_name='wmulti_priv_big', blank=True, descriptors=True)
+ wmulti_priv_big = self.nodes[1].get_wallet_rpc('wmulti_priv_big')
+ xkey = "tprv8ZgxMBicQKsPeZSeYx7VXDDTs3XrTcmZQpRLbAeSQFCQGgKwR4gKpcxHaKdoTNHniv4EPDJNdzA3KxRrrBHcAgth8fU5X4oCndkkxk39iAt/*"
+ xkey_int = "tprv8ZgxMBicQKsPeZSeYx7VXDDTs3XrTcmZQpRLbAeSQFCQGgKwR4gKpcxHaKdoTNHniv4EPDJNdzA3KxRrrBHcAgth8fU5X4oCndkkxk39iAt/1/*"
+ res = wmulti_priv_big.importdescriptors([
+ {
+ "desc": descsum_create(f"wsh(sortedmulti(20,{(xkey + ',') * 19}{xkey}))"),
+ "active": True,
+ "range": 1000,
+ "next_index": 0,
+ "timestamp": "now"
+ },
+ {
+ "desc": descsum_create(f"wsh(sortedmulti(20,{(xkey_int + ',') * 19}{xkey_int}))"),
+ "active": True,
+ "internal": True,
+ "range": 1000,
+ "next_index": 0,
+ "timestamp": "now"
+ }])
+ assert_equal(res[0]['success'], True)
+ assert_equal(res[1]['success'], True)
+
+ addr = wmulti_priv_big.getnewaddress()
+ w0.sendtoaddress(addr, 10)
+ self.nodes[0].generate(1)
+ self.sync_all()
+ # It is standard and would relay.
+ txid = wmulti_priv_big.sendtoaddress(w0.getnewaddress(), 9.999)
+ decoded = wmulti_priv_big.decoderawtransaction(wmulti_priv_big.gettransaction(txid)['hex'])
+ # 20 sigs + dummy + witness script
+ assert_equal(len(decoded['vin'][0]['txinwitness']), 22)
+
+
+ self.log.info("Under P2SH, multisig are standard with up to 15 "
+ "compressed keys")
+ self.nodes[1].createwallet(wallet_name='multi_priv_big_legacy',
+ blank=True, descriptors=True)
+ multi_priv_big = self.nodes[1].get_wallet_rpc('multi_priv_big_legacy')
+ res = multi_priv_big.importdescriptors([
+ {
+ "desc": descsum_create(f"sh(multi(15,{(xkey + ',') * 14}{xkey}))"),
+ "active": True,
+ "range": 1000,
+ "next_index": 0,
+ "timestamp": "now"
+ },
+ {
+ "desc": descsum_create(f"sh(multi(15,{(xkey_int + ',') * 14}{xkey_int}))"),
+ "active": True,
+ "internal": True,
+ "range": 1000,
+ "next_index": 0,
+ "timestamp": "now"
+ }])
+ assert_equal(res[0]['success'], True)
+ assert_equal(res[1]['success'], True)
+
+ addr = multi_priv_big.getnewaddress("", "legacy")
+ w0.sendtoaddress(addr, 10)
+ self.nodes[0].generate(6)
+ self.sync_all()
+ # It is standard and would relay.
+ txid = multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "",
+ True)
+ decoded = multi_priv_big.decoderawtransaction(
+ multi_priv_big.gettransaction(txid)['hex']
+ )
+
+
self.log.info("Combo descriptors cannot be active")
self.test_importdesc({"desc": descsum_create("combo(tpubDCJtdt5dgJpdhW4MtaVYDhG4T4tF6jcLR1PxL43q9pq1mxvXgMS9Mzw1HnXG15vxUGQJMMSqCQHMTy3F1eW5VkgVroWzchsPD5BUojrcWs8/*)"),
"active": True,
diff --git a/test/functional/wallet_send.py b/test/functional/wallet_send.py
index 53553dcd80..d24d1693af 100755
--- a/test/functional/wallet_send.py
+++ b/test/functional/wallet_send.py
@@ -33,12 +33,15 @@ class WalletSendTest(BitcoinTestFramework):
def test_send(self, from_wallet, to_wallet=None, amount=None, data=None,
arg_conf_target=None, arg_estimate_mode=None, arg_fee_rate=None,
conf_target=None, estimate_mode=None, fee_rate=None, add_to_wallet=None, psbt=None,
- inputs=None, add_inputs=None, change_address=None, change_position=None, change_type=None,
+ inputs=None, add_inputs=None, include_unsafe=None, change_address=None, change_position=None, change_type=None,
include_watching=None, locktime=None, lock_unspents=None, replaceable=None, subtract_fee_from_outputs=None,
expect_error=None):
assert (amount is None) != (data is None)
- from_balance_before = from_wallet.getbalance()
+ from_balance_before = from_wallet.getbalances()["mine"]["trusted"]
+ if include_unsafe:
+ from_balance_before += from_wallet.getbalances()["mine"]["untrusted_pending"]
+
if to_wallet is None:
assert amount is None
else:
@@ -71,6 +74,8 @@ class WalletSendTest(BitcoinTestFramework):
options["inputs"] = inputs
if add_inputs is not None:
options["add_inputs"] = add_inputs
+ if include_unsafe is not None:
+ options["include_unsafe"] = include_unsafe
if change_address is not None:
options["change_address"] = change_address
if change_position is not None:
@@ -133,6 +138,10 @@ class WalletSendTest(BitcoinTestFramework):
assert not "txid" in res
assert "psbt" in res
+ from_balance = from_wallet.getbalances()["mine"]["trusted"]
+ if include_unsafe:
+ from_balance += from_wallet.getbalances()["mine"]["untrusted_pending"]
+
if add_to_wallet and not include_watching:
# Ensure transaction exists in the wallet:
tx = from_wallet.gettransaction(res["txid"])
@@ -143,13 +152,13 @@ class WalletSendTest(BitcoinTestFramework):
assert tx
if amount:
if subtract_fee_from_outputs:
- assert_equal(from_balance_before - from_wallet.getbalance(), amount)
+ assert_equal(from_balance_before - from_balance, amount)
else:
- assert_greater_than(from_balance_before - from_wallet.getbalance(), amount)
+ assert_greater_than(from_balance_before - from_balance, amount)
else:
assert next((out for out in tx["vout"] if out["scriptPubKey"]["asm"] == "OP_RETURN 35"), None)
else:
- assert_equal(from_balance_before, from_wallet.getbalance())
+ assert_equal(from_balance_before, from_balance)
if to_wallet:
self.sync_mempools()
@@ -343,22 +352,41 @@ class WalletSendTest(BitcoinTestFramework):
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_conf_target=0.1, arg_estimate_mode=mode, expect_error=(-8, msg))
assert_raises_rpc_error(-8, msg, w0.send, {w1.getnewaddress(): 1}, 0.1, mode)
- for mode in ["economical", "conservative", "btc/kb", "sat/b"]:
- self.log.debug("{}".format(mode))
- for k, v in {"string": "true", "object": {"foo": "bar"}}.items():
+ for mode in ["economical", "conservative"]:
+ for k, v in {"string": "true", "bool": True, "object": {"foo": "bar"}}.items():
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
- expect_error=(-3, "Expected type number for conf_target, got {}".format(k)))
+ expect_error=(-3, f"Expected type number for conf_target, got {k}"))
- # Test setting explicit fee rate just below the minimum and at zero.
+ # Test setting explicit fee rate just below the minimum of 1 sat/vB.
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")
- self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0.99999999,
- expect_error=(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
- self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=0.99999999,
- expect_error=(-4, "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
- self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0,
- expect_error=(-4, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
- self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=0,
- expect_error=(-4, "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"))
+ msg = "Fee rate (0.999 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=0.999, expect_error=(-4, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=0.999, expect_error=(-4, msg))
+
+ self.log.info("Explicit fee rate raises if invalid fee_rate is passed")
+ # Test fee_rate with zero values.
+ msg = "Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)"
+ for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=zero_value, expect_error=(-4, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=zero_value, expect_error=(-4, msg))
+ msg = "Invalid amount"
+ # Test fee_rate values that don't pass fixed-point parsing checks.
+ for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=invalid_value, expect_error=(-3, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=invalid_value, expect_error=(-3, msg))
+ # Test fee_rate values that cannot be represented in sat/vB.
+ for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=invalid_value, expect_error=(-3, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=invalid_value, expect_error=(-3, msg))
+ # Test fee_rate out of range (negative number).
+ msg = "Amount out of range"
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=-1, expect_error=(-3, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=-1, expect_error=(-3, msg))
+ # Test type error.
+ msg = "Amount is not a number or string"
+ for invalid_value in [True, {"foo": "bar"}]:
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=invalid_value, expect_error=(-3, msg))
+ self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=invalid_value, expect_error=(-3, msg))
# TODO: Return hex if fee rate is below -maxmempool
# res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=0.1, estimate_mode="sat/b", add_to_wallet=False)
@@ -440,6 +468,14 @@ class WalletSendTest(BitcoinTestFramework):
self.log.info("Subtract fee from output")
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, subtract_fee_from_outputs=[0])
+ self.log.info("Include unsafe inputs")
+ self.nodes[1].createwallet(wallet_name="w5")
+ w5 = self.nodes[1].get_wallet_rpc("w5")
+ self.test_send(from_wallet=w0, to_wallet=w5, amount=2)
+ self.test_send(from_wallet=w5, to_wallet=w0, amount=1, expect_error=(-4, "Insufficient funds"))
+ res = self.test_send(from_wallet=w5, to_wallet=w0, amount=1, include_unsafe=True)
+ assert res["complete"]
+
if __name__ == '__main__':
WalletSendTest().main()
diff --git a/test/lint/commit-script-check.sh b/test/lint/commit-script-check.sh
index e66adfc3ce..9fca1129b6 100755
--- a/test/lint/commit-script-check.sh
+++ b/test/lint/commit-script-check.sh
@@ -12,7 +12,7 @@
# one. Any remaining diff signals an error.
export LC_ALL=C
-if test "x$1" = "x"; then
+if test -z $1; then
echo "Usage: $0 <commit>..."
exit 1
fi
@@ -24,7 +24,7 @@ for commit in $(git rev-list --reverse $1); do
if git rev-list -n 1 --pretty="%s" $commit | grep -q "^scripted-diff:"; then
git checkout --quiet $commit^ || exit
SCRIPT="$(git rev-list --format=%b -n1 $commit | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d')"
- if test "x$SCRIPT" = "x"; then
+ if test -z "$SCRIPT"; then
echo "Error: missing script for: $commit"
echo "Failed"
RET=1
diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh
index ad2333a808..354e14f361 100755
--- a/test/lint/lint-circular-dependencies.sh
+++ b/test/lint/lint-circular-dependencies.sh
@@ -14,6 +14,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"node/blockstorage -> validation -> node/blockstorage"
"index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex"
"index/base -> validation -> index/blockfilterindex -> index/base"
+ "index/coinstatsindex -> node/coinstats -> index/coinstatsindex"
"policy/fees -> txmempool -> policy/fees"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
diff --git a/test/lint/lint-filenames.sh b/test/lint/lint-filenames.sh
deleted file mode 100755
index 3f7491cd2b..0000000000
--- a/test/lint/lint-filenames.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2018-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.
-#
-# Make sure only lowercase alphanumerics (a-z0-9), underscores (_),
-# hyphens (-) and dots (.) are used in source code filenames.
-
-export LC_ALL=C
-
-EXIT_CODE=0
-OUTPUT=$(git ls-files --full-name -- "*.[cC][pP][pP]" "*.[hH]" "*.[pP][yY]" "*.[sS][hH]" | \
- grep -vE '^[a-z0-9_./-]+$' | \
- grep -vE '^src/(secp256k1/|univalue/|test/fuzz/FuzzedDataProvider.h)')
-
-if [[ ${OUTPUT} != "" ]]; then
- echo "Use only lowercase alphanumerics (a-z0-9), underscores (_), hyphens (-) and dots (.)"
- echo "in source code filenames:"
- echo
- echo "${OUTPUT}"
- EXIT_CODE=1
-fi
-exit ${EXIT_CODE}
diff --git a/test/lint/lint-files.py b/test/lint/lint-files.py
new file mode 100755
index 0000000000..400921e5f3
--- /dev/null
+++ b/test/lint/lint-files.py
@@ -0,0 +1,203 @@
+#!/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.
+
+"""
+This checks that all files in the repository have correct filenames and permissions
+"""
+
+import os
+import re
+import sys
+from subprocess import check_output
+from typing import Optional, NoReturn
+
+CMD_ALL_FILES = "git ls-files -z --full-name"
+CMD_SOURCE_FILES = 'git ls-files -z --full-name -- "*.[cC][pP][pP]" "*.[hH]" "*.[pP][yY]" "*.[sS][hH]"'
+CMD_SHEBANG_FILES = "git grep --full-name --line-number -I '^#!'"
+ALLOWED_FILENAME_REGEXP = "^[a-zA-Z0-9/_.@][a-zA-Z0-9/_.@-]*$"
+ALLOWED_SOURCE_FILENAME_REGEXP = "^[a-z0-9_./-]+$"
+ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP = (
+ "^src/(secp256k1/|univalue/|test/fuzz/FuzzedDataProvider.h)"
+)
+ALLOWED_PERMISSION_NON_EXECUTABLES = 644
+ALLOWED_PERMISSION_EXECUTABLES = 755
+ALLOWED_EXECUTABLE_SHEBANG = {
+ "py": [b"#!/usr/bin/env python3"],
+ "sh": [b"#!/usr/bin/env bash", b"#!/bin/sh"],
+}
+
+
+class FileMeta(object):
+ def __init__(self, file_path: str):
+ self.file_path = file_path
+
+ @property
+ def extension(self) -> Optional[str]:
+ """
+ Returns the file extension for a given filename string.
+ eg:
+ 'ci/lint_run_all.sh' -> 'sh'
+ 'ci/retry/retry' -> None
+ 'contrib/devtools/split-debug.sh.in' -> 'in'
+ """
+ return str(os.path.splitext(self.file_path)[1].strip(".") or None)
+
+ @property
+ def full_extension(self) -> Optional[str]:
+ """
+ Returns the full file extension for a given filename string.
+ eg:
+ 'ci/lint_run_all.sh' -> 'sh'
+ 'ci/retry/retry' -> None
+ 'contrib/devtools/split-debug.sh.in' -> 'sh.in'
+ """
+ filename_parts = self.file_path.split(os.extsep, 1)
+ try:
+ return filename_parts[1]
+ except IndexError:
+ return None
+
+ @property
+ def permissions(self) -> int:
+ """
+ Returns the octal file permission of the file
+ """
+ return int(oct(os.stat(self.file_path).st_mode)[-3:])
+
+
+def check_all_filenames() -> int:
+ """
+ Checks every file in the repository against an allowed regexp to make sure only lowercase or uppercase
+ alphanumerics (a-zA-Z0-9), underscores (_), hyphens (-), at (@) and dots (.) are used in repository filenames.
+ """
+ filenames = check_output(CMD_ALL_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
+ filename_regex = re.compile(ALLOWED_FILENAME_REGEXP)
+ failed_tests = 0
+ for filename in filenames:
+ if not filename_regex.match(filename):
+ print(
+ f"""File {repr(filename)} does not not match the allowed filename regexp ('{ALLOWED_FILENAME_REGEXP}')."""
+ )
+ failed_tests += 1
+ return failed_tests
+
+
+def check_source_filenames() -> int:
+ """
+ Checks only source files (*.cpp, *.h, *.py, *.sh) against a stricter allowed regexp to make sure only lowercase
+ alphanumerics (a-z0-9), underscores (_), hyphens (-) and dots (.) are used in source code filenames.
+
+ Additionally there is an exception regexp for directories or files which are excepted from matching this regexp.
+ """
+ filenames = check_output(CMD_SOURCE_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
+ filename_regex = re.compile(ALLOWED_SOURCE_FILENAME_REGEXP)
+ filename_exception_regex = re.compile(ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP)
+ failed_tests = 0
+ for filename in filenames:
+ if not filename_regex.match(filename) and not filename_exception_regex.match(filename):
+ print(
+ f"""File {repr(filename)} does not not match the allowed source filename regexp ('{ALLOWED_SOURCE_FILENAME_REGEXP}'), or the exception regexp ({ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP})."""
+ )
+ failed_tests += 1
+ return failed_tests
+
+
+def check_all_file_permissions() -> int:
+ """
+ Checks all files in the repository match an allowed executable or non-executable file permission octal.
+
+ Additionally checks that for executable files, the file contains a shebang line
+ """
+ filenames = check_output(CMD_ALL_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
+ failed_tests = 0
+ for filename in filenames:
+ file_meta = FileMeta(filename)
+ if file_meta.permissions == ALLOWED_PERMISSION_EXECUTABLES:
+ with open(filename, "rb") as f:
+ shebang = f.readline().rstrip(b"\n")
+
+ # For any file with executable permissions the first line must contain a shebang
+ if not shebang.startswith(b"#!"):
+ print(
+ f"""File "{filename}" has permission {ALLOWED_PERMISSION_EXECUTABLES} (executable) and is thus expected to contain a shebang '#!'. Add shebang or do "chmod {ALLOWED_PERMISSION_NON_EXECUTABLES} {filename}" to make it non-executable."""
+ )
+ failed_tests += 1
+
+ # For certain file extensions that have been defined, we also check that the shebang conforms to a specific
+ # allowable set of shebangs
+ if file_meta.extension in ALLOWED_EXECUTABLE_SHEBANG.keys():
+ if shebang not in ALLOWED_EXECUTABLE_SHEBANG[file_meta.extension]:
+ print(
+ f"""File "{filename}" is missing expected shebang """
+ + " or ".join(
+ [
+ x.decode("utf-8")
+ for x in ALLOWED_EXECUTABLE_SHEBANG[file_meta.extension]
+ ]
+ )
+ )
+ failed_tests += 1
+
+ elif file_meta.permissions == ALLOWED_PERMISSION_NON_EXECUTABLES:
+ continue
+ else:
+ print(
+ f"""File "{filename}" has unexpected permission {file_meta.permissions}. Do "chmod {ALLOWED_PERMISSION_NON_EXECUTABLES} {filename}" (if non-executable) or "chmod {ALLOWED_PERMISSION_EXECUTABLES} {filename}" (if executable)."""
+ )
+ failed_tests += 1
+
+ return failed_tests
+
+
+def check_shebang_file_permissions() -> int:
+ """
+ Checks every file that contains a shebang line to ensure it has an executable permission
+ """
+ filenames = check_output(CMD_SHEBANG_FILES, shell=True).decode("utf8").strip().split("\n")
+
+ # The git grep command we use returns files which contain a shebang on any line within the file
+ # so we need to filter the list to only files with the shebang on the first line
+ filenames = [filename.split(":1:")[0] for filename in filenames if ":1:" in filename]
+
+ failed_tests = 0
+ for filename in filenames:
+ file_meta = FileMeta(filename)
+ if file_meta.permissions != ALLOWED_PERMISSION_EXECUTABLES:
+ # These file types are typically expected to be sourced and not executed directly
+ if file_meta.full_extension in ["bash", "init", "openrc", "sh.in"]:
+ continue
+
+ # *.py files which don't contain an `if __name__ == '__main__'` are not expected to be executed directly
+ if file_meta.extension == "py":
+ with open(filename, "r", encoding="utf8") as f:
+ file_data = f.read()
+ if not re.search("""if __name__ == ['"]__main__['"]:""", file_data):
+ continue
+
+ print(
+ f"""File "{filename}" contains a shebang line, but has the file permission {file_meta.permissions} instead of the expected executable permission {ALLOWED_PERMISSION_EXECUTABLES}. Do "chmod {ALLOWED_PERMISSION_EXECUTABLES} {filename}" (or remove the shebang line)."""
+ )
+ failed_tests += 1
+ return failed_tests
+
+
+def main() -> NoReturn:
+ failed_tests = 0
+ failed_tests += check_all_filenames()
+ failed_tests += check_source_filenames()
+ failed_tests += check_all_file_permissions()
+ failed_tests += check_shebang_file_permissions()
+
+ if failed_tests:
+ print(
+ f"ERROR: There were {failed_tests} failed tests in the lint-files.py lint test. Please resolve the above errors."
+ )
+ sys.exit(1)
+ else:
+ sys.exit(0)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/test/lint/lint-files.sh b/test/lint/lint-files.sh
new file mode 100755
index 0000000000..1e115778bd
--- /dev/null
+++ b/test/lint/lint-files.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+export LC_ALL=C
+
+set -e
+cd "$(dirname $0)/../.."
+test/lint/lint-files.py
diff --git a/test/lint/lint-include-guards.sh b/test/lint/lint-include-guards.sh
index 5cfa41537f..c23b903bce 100755
--- a/test/lint/lint-include-guards.sh
+++ b/test/lint/lint-include-guards.sh
@@ -15,7 +15,7 @@ REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|crc32c/|secp256k1/
EXIT_CODE=0
for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}")
do
- HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr "[:lower:]" "[:upper:]")
+ HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr - _ | tr "[:lower:]" "[:upper:]")
HEADER_ID="${HEADER_ID_PREFIX}${HEADER_ID_BASE}${HEADER_ID_SUFFIX}"
if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID}" "${HEADER_FILE}") != 2 ]]; then
echo "${HEADER_FILE} seems to be missing the expected include guard:"
diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh
index e5657f7555..737d35a397 100755
--- a/test/lint/lint-locale-dependence.sh
+++ b/test/lint/lint-locale-dependence.sh
@@ -43,7 +43,7 @@ KNOWN_VIOLATIONS=(
"src/dbwrapper.cpp.*stoul"
"src/dbwrapper.cpp:.*vsnprintf"
"src/httprpc.cpp.*trim"
- "src/init.cpp:.*atoi"
+ "src/node/blockstorage.cpp:.*atoi"
"src/qt/rpcconsole.cpp:.*atoi"
"src/rest.cpp:.*strtol"
"src/test/dbwrapper_tests.cpp:.*snprintf"
diff --git a/test/lint/lint-shebang.sh b/test/lint/lint-shebang.sh
deleted file mode 100755
index 13ebdfd78a..0000000000
--- a/test/lint/lint-shebang.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-# Copyright (c) 2018-2020 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-# Assert expected shebang lines
-
-export LC_ALL=C
-EXIT_CODE=0
-for PYTHON_FILE in $(git ls-files -- "*.py"); do
- if [[ $(head -c 2 "${PYTHON_FILE}") == "#!" &&
- $(head -n 1 "${PYTHON_FILE}") != "#!/usr/bin/env python3" ]]; then
- echo "Missing shebang \"#!/usr/bin/env python3\" in ${PYTHON_FILE} (do not use python or python2)"
- EXIT_CODE=1
- fi
-done
-for SHELL_FILE in $(git ls-files -- "*.sh"); do
- if [[ $(head -n 1 "${SHELL_FILE}") != "#!/usr/bin/env bash" &&
- $(head -n 1 "${SHELL_FILE}") != "#!/bin/sh" ]]; then
- echo "Missing expected shebang \"#!/usr/bin/env bash\" or \"#!/bin/sh\" in ${SHELL_FILE}"
- EXIT_CODE=1
- fi
-done
-exit ${EXIT_CODE}
diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan
index 27885b094e..4f6f92bd3c 100644
--- a/test/sanitizer_suppressions/ubsan
+++ b/test/sanitizer_suppressions/ubsan
@@ -5,6 +5,8 @@
# names can be used.
# See https://github.com/google/sanitizers/issues/1364
signed-integer-overflow:txmempool.cpp
+# https://github.com/bitcoin/bitcoin/pull/21798#issuecomment-829180719
+signed-integer-overflow:policy/feerate.cpp
# -fsanitize=integer suppressions
# ===============================
@@ -60,7 +62,6 @@ implicit-integer-sign-change:key.cpp
implicit-integer-sign-change:noui.cpp
implicit-integer-sign-change:policy/fees.cpp
implicit-integer-sign-change:prevector.h
-implicit-integer-sign-change:protocol.cpp
implicit-integer-sign-change:script/bitcoinconsensus.cpp
implicit-integer-sign-change:script/interpreter.cpp
implicit-integer-sign-change:serialize.h
@@ -85,6 +86,7 @@ implicit-signed-integer-truncation:chain.h
implicit-signed-integer-truncation:crypto/
implicit-signed-integer-truncation:cuckoocache.h
implicit-signed-integer-truncation:leveldb/
+implicit-signed-integer-truncation:miner.cpp
implicit-signed-integer-truncation:net.cpp
implicit-signed-integer-truncation:net_processing.cpp
implicit-signed-integer-truncation:streams.h
@@ -96,6 +98,7 @@ implicit-unsigned-integer-truncation:crypto/
implicit-unsigned-integer-truncation:leveldb/
# std::variant warning fixed in https://github.com/gcc-mirror/gcc/commit/074436cf8cdd2a9ce75cadd36deb8301f00e55b9
implicit-unsigned-integer-truncation:std::__detail::__variant::_Variant_storage
+shift-base:nanobench.h
shift-base:*/include/c++/
shift-base:arith_uint256.cpp
shift-base:crypto/