aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/README.md6
-rw-r--r--test/functional/README.md18
-rwxr-xr-xtest/functional/create_cache.py1
-rwxr-xr-xtest/functional/deprecated_rpc.py23
-rwxr-xr-xtest/functional/feature_assumevalid.py (renamed from test/functional/assumevalid.py)0
-rwxr-xr-xtest/functional/feature_bip68_sequence.py (renamed from test/functional/bip68-sequence.py)17
-rwxr-xr-xtest/functional/feature_bip9_softforks.py (renamed from test/functional/bip9-softforks.py)2
-rwxr-xr-xtest/functional/feature_block.py (renamed from test/functional/p2p-fullblocktest.py)7
-rwxr-xr-xtest/functional/feature_cltv.py (renamed from test/functional/bip65-cltv-p2p.py)4
-rwxr-xr-xtest/functional/feature_config_args.py (renamed from test/functional/conf_args.py)0
-rwxr-xr-xtest/functional/feature_csv_activation.py (renamed from test/functional/bip68-112-113-p2p.py)4
-rwxr-xr-xtest/functional/feature_dbcrash.py (renamed from test/functional/dbcrash.py)2
-rwxr-xr-xtest/functional/feature_dersig.py (renamed from test/functional/bipdersig-p2p.py)2
-rwxr-xr-xtest/functional/feature_fee_estimation.py (renamed from test/functional/smartfees.py)163
-rwxr-xr-xtest/functional/feature_maxuploadtarget.py (renamed from test/functional/maxuploadtarget.py)0
-rwxr-xr-xtest/functional/feature_minchainwork.py (renamed from test/functional/minchainwork.py)0
-rwxr-xr-xtest/functional/feature_notifications.py (renamed from test/functional/notifications.py)0
-rwxr-xr-xtest/functional/feature_nulldummy.py (renamed from test/functional/nulldummy.py)10
-rwxr-xr-xtest/functional/feature_proxy.py (renamed from test/functional/proxy_test.py)0
-rwxr-xr-xtest/functional/feature_pruning.py (renamed from test/functional/pruning.py)0
-rwxr-xr-xtest/functional/feature_rbf.py (renamed from test/functional/replace-by-fee.py)2
-rwxr-xr-xtest/functional/feature_reindex.py (renamed from test/functional/reindex.py)0
-rwxr-xr-xtest/functional/feature_segwit.py (renamed from test/functional/segwit.py)177
-rwxr-xr-xtest/functional/feature_uacomment.py (renamed from test/functional/uacomment.py)2
-rwxr-xr-xtest/functional/feature_versionbits_warning.py112
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py (renamed from test/functional/bitcoin_cli.py)2
-rwxr-xr-xtest/functional/interface_http.py (renamed from test/functional/httpbasics.py)0
-rwxr-xr-xtest/functional/interface_rest.py (renamed from test/functional/rest.py)5
-rwxr-xr-xtest/functional/interface_zmq.py (renamed from test/functional/zmq_test.py)0
-rwxr-xr-xtest/functional/invalidtxrequest.py73
-rwxr-xr-xtest/functional/mempool_limit.py12
-rwxr-xr-xtest/functional/mempool_packages.py52
-rwxr-xr-xtest/functional/mempool_persist.py9
-rwxr-xr-xtest/functional/mempool_reorg.py2
-rwxr-xr-xtest/functional/mempool_resurrect.py (renamed from test/functional/mempool_resurrect_test.py)0
-rwxr-xr-xtest/functional/mempool_spend_coinbase.py (renamed from test/functional/mempool_spendcoinbase.py)0
-rwxr-xr-xtest/functional/mining_basic.py (renamed from test/functional/mining.py)0
-rwxr-xr-xtest/functional/mining_getblocktemplate_longpoll.py (renamed from test/functional/getblocktemplate_longpoll.py)0
-rwxr-xr-xtest/functional/mining_prioritisetransaction.py (renamed from test/functional/prioritise_transaction.py)23
-rwxr-xr-xtest/functional/node_network_limited.py57
-rwxr-xr-xtest/functional/p2p-versionbits-warning.py121
-rwxr-xr-xtest/functional/p2p_compactblocks.py (renamed from test/functional/p2p-compactblocks.py)2
-rwxr-xr-xtest/functional/p2p_disconnect_ban.py (renamed from test/functional/disconnect_ban.py)0
-rwxr-xr-xtest/functional/p2p_feefilter.py (renamed from test/functional/p2p-feefilter.py)0
-rwxr-xr-xtest/functional/p2p_fingerprint.py (renamed from test/functional/p2p-fingerprint.py)2
-rwxr-xr-xtest/functional/p2p_invalid_block.py (renamed from test/functional/invalidblockrequest.py)0
-rwxr-xr-xtest/functional/p2p_invalid_tx.py55
-rwxr-xr-xtest/functional/p2p_leak.py (renamed from test/functional/p2p-leaktests.py)0
-rwxr-xr-xtest/functional/p2p_mempool.py (renamed from test/functional/p2p-mempool.py)0
-rwxr-xr-xtest/functional/p2p_node_network_limited.py119
-rwxr-xr-xtest/functional/p2p_segwit.py (renamed from test/functional/p2p-segwit.py)16
-rwxr-xr-xtest/functional/p2p_sendheaders.py (renamed from test/functional/sendheaders.py)0
-rwxr-xr-xtest/functional/p2p_timeouts.py (renamed from test/functional/p2p-timeouts.py)0
-rwxr-xr-xtest/functional/p2p_unrequested_blocks.py (renamed from test/functional/p2p-acceptblock.py)0
-rwxr-xr-xtest/functional/rpc_bind.py (renamed from test/functional/rpcbind_test.py)0
-rwxr-xr-xtest/functional/rpc_blockchain.py (renamed from test/functional/blockchain.py)33
-rwxr-xr-xtest/functional/rpc_decodescript.py (renamed from test/functional/decodescript.py)0
-rwxr-xr-xtest/functional/rpc_deprecated.py30
-rwxr-xr-xtest/functional/rpc_fundrawtransaction.py (renamed from test/functional/fundrawtransaction.py)54
-rwxr-xr-xtest/functional/rpc_getchaintips.py (renamed from test/functional/getchaintips.py)0
-rwxr-xr-xtest/functional/rpc_invalidateblock.py (renamed from test/functional/invalidateblock.py)0
-rwxr-xr-xtest/functional/rpc_listtransactions.py (renamed from test/functional/listtransactions.py)11
-rwxr-xr-xtest/functional/rpc_named_arguments.py (renamed from test/functional/rpcnamedargs.py)0
-rwxr-xr-xtest/functional/rpc_net.py (renamed from test/functional/net.py)0
-rwxr-xr-xtest/functional/rpc_preciousblock.py (renamed from test/functional/preciousblock.py)0
-rwxr-xr-xtest/functional/rpc_rawtransaction.py (renamed from test/functional/rawtransactions.py)52
-rwxr-xr-xtest/functional/rpc_signmessage.py (renamed from test/functional/signmessages.py)1
-rwxr-xr-xtest/functional/rpc_signrawtransaction.py (renamed from test/functional/signrawtransactions.py)30
-rwxr-xr-xtest/functional/rpc_txoutproof.py (renamed from test/functional/merkle_blocks.py)6
-rwxr-xr-xtest/functional/rpc_uptime.py (renamed from test/functional/uptime.py)0
-rwxr-xr-xtest/functional/rpc_users.py (renamed from test/functional/multi_rpc.py)0
-rw-r--r--test/functional/test_framework/blocktools.py64
-rwxr-xr-x[-rw-r--r--]test/functional/test_framework/messages.py49
-rwxr-xr-xtest/functional/test_framework/mininode.py155
-rw-r--r--test/functional/test_framework/script.py6
-rwxr-xr-xtest/functional/test_framework/test_framework.py32
-rwxr-xr-xtest/functional/test_framework/test_node.py94
-rw-r--r--test/functional/test_framework/util.py18
-rwxr-xr-xtest/functional/test_runner.py197
-rwxr-xr-xtest/functional/wallet_abandonconflict.py (renamed from test/functional/abandonconflict.py)14
-rwxr-xr-xtest/functional/wallet_accounts.py (renamed from test/functional/wallet-accounts.py)2
-rwxr-xr-xtest/functional/wallet_address_types.py294
-rwxr-xr-xtest/functional/wallet_backup.py (renamed from test/functional/walletbackup.py)0
-rwxr-xr-xtest/functional/wallet_basic.py (renamed from test/functional/wallet.py)30
-rwxr-xr-xtest/functional/wallet_bumpfee.py (renamed from test/functional/bumpfee.py)30
-rwxr-xr-xtest/functional/wallet_disable.py (renamed from test/functional/disablewallet.py)0
-rwxr-xr-xtest/functional/wallet_dump.py (renamed from test/functional/wallet-dump.py)30
-rwxr-xr-xtest/functional/wallet_encryption.py (renamed from test/functional/wallet-encryption.py)19
-rwxr-xr-xtest/functional/wallet_fallbackfee.py28
-rwxr-xr-xtest/functional/wallet_hd.py (renamed from test/functional/wallet-hd.py)10
-rwxr-xr-xtest/functional/wallet_import_rescan.py (renamed from test/functional/import-rescan.py)4
-rwxr-xr-xtest/functional/wallet_importmulti.py (renamed from test/functional/importmulti.py)111
-rwxr-xr-xtest/functional/wallet_importprunedfunds.py (renamed from test/functional/importprunedfunds.py)14
-rwxr-xr-xtest/functional/wallet_keypool.py (renamed from test/functional/keypool.py)4
-rwxr-xr-xtest/functional/wallet_keypool_topup.py (renamed from test/functional/keypool-topup.py)2
-rwxr-xr-xtest/functional/wallet_listreceivedby.py (renamed from test/functional/receivedby.py)0
-rwxr-xr-xtest/functional/wallet_listsinceblock.py (renamed from test/functional/listsinceblock.py)6
-rwxr-xr-xtest/functional/wallet_multiwallet.py (renamed from test/functional/multiwallet.py)66
-rwxr-xr-xtest/functional/wallet_resendwallettransactions.py (renamed from test/functional/resendwallettransactions.py)0
-rwxr-xr-xtest/functional/wallet_txn_clone.py (renamed from test/functional/txn_clone.py)17
-rwxr-xr-xtest/functional/wallet_txn_doublespend.py (renamed from test/functional/txn_doublespend.py)2
-rwxr-xr-xtest/functional/wallet_zapwallettxes.py (renamed from test/functional/zapwallettxes.py)3
-rwxr-xr-xtest/util/bitcoin-util-test.py2
103 files changed, 1727 insertions, 895 deletions
diff --git a/test/README.md b/test/README.md
index 868eb667ae..b522c4469a 100644
--- a/test/README.md
+++ b/test/README.md
@@ -8,7 +8,7 @@ There are currently two sets of tests in this directory:
- [functional](/test/functional) which test the functionality of
bitcoind and bitcoin-qt by interacting with them through the RPC and P2P
interfaces.
-- [util](test/util) which tests the bitcoin utilities, currently only
+- [util](/test/util) which tests the bitcoin utilities, currently only
bitcoin-tx.
The util tests are run as part of `make check` target. The functional
@@ -33,13 +33,13 @@ The ZMQ functional test requires a python ZMQ library. To install it:
Individual tests can be run by directly calling the test script, eg:
```
-test/functional/replace-by-fee.py
+test/functional/feature_rbf.py
```
or can be run through the test_runner harness, eg:
```
-test/functional/test_runner.py replace-by-fee.py
+test/functional/test_runner.py feature_rbf.py
```
You can run any combination (incl. duplicates) of tests by calling:
diff --git a/test/functional/README.md b/test/functional/README.md
index 4d52751b05..662b4b44d5 100644
--- a/test/functional/README.md
+++ b/test/functional/README.md
@@ -27,6 +27,20 @@ don't have test cases for.
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
the subclass, then locally-defined helper methods, then the `run_test()` method.
+#### Naming guidelines
+
+- Name the test `<area>_test.py`, where area can be one of the following:
+ - `feature` for tests for full features that aren't wallet/mining/mempool, eg `feature_rbf.py`
+ - `interface` for tests for other interfaces (REST, ZMQ, etc), eg `interface_rest.py`
+ - `mempool` for tests for mempool behaviour, eg `mempool_reorg.py`
+ - `mining` for tests for mining features, eg `mining_prioritisetransaction.py`
+ - `p2p` for tests that explicitly test the p2p interface, eg `p2p_disconnect_ban.py`
+ - `rpc` for tests for individual RPC methods or features, eg `rpc_listtransactions.py`
+ - `wallet` for tests for wallet features, eg `wallet_keypool.py`
+- use an underscore to separate words
+ - exception: for tests for specific RPCs or command line options which don't include underscores, name the test after the exact RPC or argument name, eg `rpc_decodescript.py`, not `rpc_decode_script.py`
+- Don't use the redundant word `test` in the name, eg `interface_zmq.py`, not `interface_zmq_test.py`
+
#### General test-writing advice
- Set `self.num_nodes` to the minimum number of nodes necessary for the test.
@@ -73,7 +87,7 @@ start the networking thread. (Continue with the test logic in your existing
thread.)
- Can be used to write tests where specific P2P protocol behavior is tested.
-Examples tests are `p2p-accept-block.py`, `p2p-compactblocks.py`.
+Examples tests are `p2p_unrequested_blocks.py`, `p2p_compactblocks.py`.
#### Comptool
@@ -119,7 +133,7 @@ Each `TestInstance` consists of:
acceptance is tested against the given outcome.
- For examples of tests written in this framework, see
- `invalidblockrequest.py` and `p2p-fullblocktest.py`.
+ `p2p_invalid_block.py` and `feature_block.py`.
### test-framework modules
diff --git a/test/functional/create_cache.py b/test/functional/create_cache.py
index 4c79814a26..9665c50a92 100755
--- a/test/functional/create_cache.py
+++ b/test/functional/create_cache.py
@@ -16,6 +16,7 @@ class CreateCache(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 0
+ self.supports_cli = True
def setup_network(self):
pass
diff --git a/test/functional/deprecated_rpc.py b/test/functional/deprecated_rpc.py
deleted file mode 100755
index 19fd24edb9..0000000000
--- a/test/functional/deprecated_rpc.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2017 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 deprecation of RPC calls."""
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_raises_rpc_error
-
-class DeprecatedRpcTest(BitcoinTestFramework):
- def set_test_params(self):
- self.num_nodes = 2
- self.setup_clean_chain = True
- self.extra_args = [[], ["-deprecatedrpc=estimatefee"]]
-
- def run_test(self):
- self.log.info("estimatefee: Shows deprecated message")
- assert_raises_rpc_error(-32, 'estimatefee is deprecated', self.nodes[0].estimatefee, 1)
-
- self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
- self.nodes[1].estimatefee(1)
-
-if __name__ == '__main__':
- DeprecatedRpcTest().main()
diff --git a/test/functional/assumevalid.py b/test/functional/feature_assumevalid.py
index 5a09142412..5a09142412 100755
--- a/test/functional/assumevalid.py
+++ b/test/functional/feature_assumevalid.py
diff --git a/test/functional/bip68-sequence.py b/test/functional/feature_bip68_sequence.py
index 2acdd72aff..e5db9e18c7 100755
--- a/test/functional/bip68-sequence.py
+++ b/test/functional/feature_bip68_sequence.py
@@ -14,7 +14,7 @@ SEQUENCE_LOCKTIME_GRANULARITY = 9 # this is a bit-shift
SEQUENCE_LOCKTIME_MASK = 0x0000ffff
# RPC error for non-BIP68 final transactions
-NOT_FINAL_ERROR = "64: non-BIP68-final"
+NOT_FINAL_ERROR = "non-BIP68-final (code 64)"
class BIP68Test(BitcoinTestFramework):
def set_test_params(self):
@@ -70,7 +70,7 @@ class BIP68Test(BitcoinTestFramework):
tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)]
tx1.vout = [CTxOut(value, CScript([b'a']))]
- tx1_signed = self.nodes[0].signrawtransaction(ToHex(tx1))["hex"]
+ tx1_signed = self.nodes[0].signrawtransactionwithwallet(ToHex(tx1))["hex"]
tx1_id = self.nodes[0].sendrawtransaction(tx1_signed)
tx1_id = int(tx1_id, 16)
@@ -176,7 +176,7 @@ class BIP68Test(BitcoinTestFramework):
# Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output
tx_size = len(ToHex(tx))//2 + 120*num_inputs + 50
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), CScript([b'a'])))
- rawtx = self.nodes[0].signrawtransaction(ToHex(tx))["hex"]
+ rawtx = self.nodes[0].signrawtransactionwithwallet(ToHex(tx))["hex"]
if (using_sequence_locks and not should_pass):
# This transaction should be rejected
@@ -205,7 +205,7 @@ class BIP68Test(BitcoinTestFramework):
tx2.nVersion = 2
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
- tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2))["hex"]
+ tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
tx2 = FromHex(tx2, tx2_raw)
tx2.rehash()
@@ -278,7 +278,7 @@ class BIP68Test(BitcoinTestFramework):
utxos = self.nodes[0].listunspent()
tx5.vin.append(CTxIn(COutPoint(int(utxos[0]["txid"], 16), utxos[0]["vout"]), nSequence=1))
tx5.vout[0].nValue += int(utxos[0]["amount"]*COIN)
- raw_tx5 = self.nodes[0].signrawtransaction(ToHex(tx5))["hex"]
+ raw_tx5 = self.nodes[0].signrawtransactionwithwallet(ToHex(tx5))["hex"]
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, raw_tx5)
@@ -338,7 +338,7 @@ class BIP68Test(BitcoinTestFramework):
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
# sign tx2
- tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2))["hex"]
+ tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
tx2 = FromHex(tx2, tx2_raw)
tx2.rehash()
@@ -362,9 +362,10 @@ class BIP68Test(BitcoinTestFramework):
block.vtx.extend([tx1, tx2, tx3])
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
+ add_witness_commitment(block)
block.solve()
- self.nodes[0].submitblock(ToHex(block))
+ self.nodes[0].submitblock(bytes_to_hex_str(block.serialize(True)))
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
def activateCSV(self):
@@ -387,7 +388,7 @@ class BIP68Test(BitcoinTestFramework):
rawtxfund = self.nodes[1].fundrawtransaction(rawtx)['hex']
tx = FromHex(CTransaction(), rawtxfund)
tx.nVersion = 2
- tx_signed = self.nodes[1].signrawtransaction(ToHex(tx))["hex"]
+ tx_signed = self.nodes[1].signrawtransactionwithwallet(ToHex(tx))["hex"]
self.nodes[1].sendrawtransaction(tx_signed)
if __name__ == '__main__':
diff --git a/test/functional/bip9-softforks.py b/test/functional/feature_bip9_softforks.py
index ae92e9f07c..71d3d04002 100755
--- a/test/functional/bip9-softforks.py
+++ b/test/functional/feature_bip9_softforks.py
@@ -51,7 +51,7 @@ class BIP9SoftForksTest(ComparisonTestFramework):
return tx
def sign_transaction(self, node, tx):
- signresult = node.signrawtransaction(bytes_to_hex_str(tx.serialize()))
+ signresult = node.signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize()))
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(signresult['hex']))
tx.deserialize(f)
diff --git a/test/functional/p2p-fullblocktest.py b/test/functional/feature_block.py
index d08318a96b..fe9bbda14b 100755
--- a/test/functional/p2p-fullblocktest.py
+++ b/test/functional/feature_block.py
@@ -36,12 +36,15 @@ class CBrokenBlock(CBlock):
self.vtx = copy.deepcopy(base_block.vtx)
self.hashMerkleRoot = self.calc_merkle_root()
- def serialize(self):
+ def serialize(self, with_witness=False):
r = b""
r += super(CBlock, self).serialize()
r += struct.pack("<BQ", 255, len(self.vtx))
for tx in self.vtx:
- r += tx.serialize()
+ if with_witness:
+ r += tx.serialize_with_witness()
+ else:
+ r += tx.serialize_without_witness()
return r
def normal_serialize(self):
diff --git a/test/functional/bip65-cltv-p2p.py b/test/functional/feature_cltv.py
index f62ae31654..e9a8945e76 100755
--- a/test/functional/bip65-cltv-p2p.py
+++ b/test/functional/feature_cltv.py
@@ -41,7 +41,7 @@ def cltv_validate(node, tx, height):
tx.nLockTime = height
# Need to re-sign, since nSequence and nLockTime changed
- signed_result = node.signrawtransaction(ToHex(tx))
+ signed_result = node.signrawtransactionwithwallet(ToHex(tx))
new_tx = CTransaction()
new_tx.deserialize(BytesIO(hex_str_to_bytes(signed_result['hex'])))
@@ -54,7 +54,7 @@ def create_transaction(node, coinbase, to_address, amount):
inputs = [{ "txid" : from_txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = node.createrawtransaction(inputs, outputs)
- signresult = node.signrawtransaction(rawtx)
+ signresult = node.signrawtransactionwithwallet(rawtx)
tx = CTransaction()
tx.deserialize(BytesIO(hex_str_to_bytes(signresult['hex'])))
return tx
diff --git a/test/functional/conf_args.py b/test/functional/feature_config_args.py
index 61abba8082..61abba8082 100755
--- a/test/functional/conf_args.py
+++ b/test/functional/feature_config_args.py
diff --git a/test/functional/bip68-112-113-p2p.py b/test/functional/feature_csv_activation.py
index 30ceed3be7..8b5e5681e4 100755
--- a/test/functional/bip68-112-113-p2p.py
+++ b/test/functional/feature_csv_activation.py
@@ -95,7 +95,7 @@ class BIP68_112_113Test(ComparisonTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
- self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']]
+ self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4', '-addresstype=legacy']]
def run_test(self):
test = TestManager(self, self.options.tmpdir)
@@ -118,7 +118,7 @@ class BIP68_112_113Test(ComparisonTestFramework):
def sign_transaction(self, node, unsignedtx):
rawtx = ToHex(unsignedtx)
- signresult = node.signrawtransaction(rawtx)
+ signresult = node.signrawtransactionwithwallet(rawtx)
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(signresult['hex']))
tx.deserialize(f)
diff --git a/test/functional/dbcrash.py b/test/functional/feature_dbcrash.py
index 24b9765b4e..cef257cf9b 100755
--- a/test/functional/dbcrash.py
+++ b/test/functional/feature_dbcrash.py
@@ -206,7 +206,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
tx.vout.append(CTxOut(output_amount, hex_str_to_bytes(utxo['scriptPubKey'])))
# Sign and send the transaction to get into the mempool
- tx_signed_hex = node.signrawtransaction(ToHex(tx))['hex']
+ tx_signed_hex = node.signrawtransactionwithwallet(ToHex(tx))['hex']
node.sendrawtransaction(tx_signed_hex)
num_transactions += 1
diff --git a/test/functional/bipdersig-p2p.py b/test/functional/feature_dersig.py
index 3414571678..02dcc3e55d 100755
--- a/test/functional/bipdersig-p2p.py
+++ b/test/functional/feature_dersig.py
@@ -42,7 +42,7 @@ def create_transaction(node, coinbase, to_address, amount):
inputs = [{ "txid" : from_txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = node.createrawtransaction(inputs, outputs)
- signresult = node.signrawtransaction(rawtx)
+ signresult = node.signrawtransactionwithwallet(rawtx)
tx = CTransaction()
tx.deserialize(BytesIO(hex_str_to_bytes(signresult['hex'])))
return tx
diff --git a/test/functional/smartfees.py b/test/functional/feature_fee_estimation.py
index 68453e50f4..8a56d3eefa 100755
--- a/test/functional/smartfees.py
+++ b/test/functional/feature_fee_estimation.py
@@ -3,39 +3,47 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test fee estimation code."""
+from decimal import Decimal
+import random
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import *
-from test_framework.script import CScript, OP_1, OP_DROP, OP_2, OP_HASH160, OP_EQUAL, hash160, OP_TRUE
from test_framework.mininode import CTransaction, CTxIn, CTxOut, COutPoint, ToHex, COIN
+from test_framework.script import CScript, OP_1, OP_DROP, OP_2, OP_HASH160, OP_EQUAL, hash160, OP_TRUE
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_greater_than,
+ assert_greater_than_or_equal,
+ connect_nodes,
+ satoshi_round,
+ sync_blocks,
+ sync_mempools,
+)
# Construct 2 trivial P2SH's and the ScriptSigs that spend them
# So we can create many transactions without needing to spend
# time signing.
-redeem_script_1 = CScript([OP_1, OP_DROP])
-redeem_script_2 = CScript([OP_2, OP_DROP])
-P2SH_1 = CScript([OP_HASH160, hash160(redeem_script_1), OP_EQUAL])
-P2SH_2 = CScript([OP_HASH160, hash160(redeem_script_2), OP_EQUAL])
+REDEEM_SCRIPT_1 = CScript([OP_1, OP_DROP])
+REDEEM_SCRIPT_2 = CScript([OP_2, OP_DROP])
+P2SH_1 = CScript([OP_HASH160, hash160(REDEEM_SCRIPT_1), OP_EQUAL])
+P2SH_2 = CScript([OP_HASH160, hash160(REDEEM_SCRIPT_2), OP_EQUAL])
# Associated ScriptSig's to spend satisfy P2SH_1 and P2SH_2
-SCRIPT_SIG = [CScript([OP_TRUE, redeem_script_1]), CScript([OP_TRUE, redeem_script_2])]
-
-global log
+SCRIPT_SIG = [CScript([OP_TRUE, REDEEM_SCRIPT_1]), CScript([OP_TRUE, REDEEM_SCRIPT_2])]
def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee_increment):
- """
- Create and send a transaction with a random fee.
+ """Create and send a transaction with a random fee.
+
The transaction pays to a trivial P2SH script, and assumes that its inputs
are of the same form.
The function takes a list of confirmed outputs and unconfirmed outputs
and attempts to use the confirmed list first for its inputs.
It adds the newly created outputs to the unconfirmed list.
- Returns (raw transaction, fee)
- """
+ Returns (raw transaction, fee)."""
+
# It's best to exponentially distribute our random fees
# because the buckets are exponentially spaced.
# Exponentially distributed from 1-128 * fee_increment
- rand_fee = float(fee_increment)*(1.1892**random.randint(0,28))
+ rand_fee = float(fee_increment) * (1.1892 ** random.randint(0, 28))
# Total fee ranges from min_fee to min_fee + 127*fee_increment
fee = min_fee - fee_increment + satoshi_round(rand_fee)
tx = CTransaction()
@@ -50,95 +58,69 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
total_in += t["amount"]
tx.vin.append(CTxIn(COutPoint(int(t["txid"], 16), t["vout"]), b""))
if total_in <= amount + fee:
- raise RuntimeError("Insufficient funds: need %d, have %d"%(amount+fee, total_in))
- tx.vout.append(CTxOut(int((total_in - amount - fee)*COIN), P2SH_1))
- tx.vout.append(CTxOut(int(amount*COIN), P2SH_2))
+ raise RuntimeError("Insufficient funds: need %d, have %d" % (amount + fee, total_in))
+ tx.vout.append(CTxOut(int((total_in - amount - fee) * COIN), P2SH_1))
+ tx.vout.append(CTxOut(int(amount * COIN), P2SH_2))
# These transactions don't need to be signed, but we still have to insert
# the ScriptSig that will satisfy the ScriptPubKey.
for inp in tx.vin:
inp.scriptSig = SCRIPT_SIG[inp.prevout.n]
txid = from_node.sendrawtransaction(ToHex(tx), True)
- unconflist.append({ "txid" : txid, "vout" : 0 , "amount" : total_in - amount - fee})
- unconflist.append({ "txid" : txid, "vout" : 1 , "amount" : amount})
+ unconflist.append({"txid": txid, "vout": 0, "amount": total_in - amount - fee})
+ unconflist.append({"txid": txid, "vout": 1, "amount": amount})
return (ToHex(tx), fee)
-def split_inputs(from_node, txins, txouts, initial_split = False):
- """
- We need to generate a lot of inputs so we can generate a ton of transactions.
+def split_inputs(from_node, txins, txouts, initial_split=False):
+ """Generate a lot of inputs so we can generate a ton of transactions.
+
This function takes an input from txins, and creates and sends a transaction
which splits the value into 2 outputs which are appended to txouts.
Previously this was designed to be small inputs so they wouldn't have
- a high coin age when the notion of priority still existed.
- """
+ a high coin age when the notion of priority still existed."""
+
prevtxout = txins.pop()
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int(prevtxout["txid"], 16), prevtxout["vout"]), b""))
- half_change = satoshi_round(prevtxout["amount"]/2)
- rem_change = prevtxout["amount"] - half_change - Decimal("0.00001000")
- tx.vout.append(CTxOut(int(half_change*COIN), P2SH_1))
- tx.vout.append(CTxOut(int(rem_change*COIN), P2SH_2))
+ half_change = satoshi_round(prevtxout["amount"] / 2)
+ rem_change = prevtxout["amount"] - half_change - Decimal("0.00001000")
+ tx.vout.append(CTxOut(int(half_change * COIN), P2SH_1))
+ tx.vout.append(CTxOut(int(rem_change * COIN), P2SH_2))
# If this is the initial split we actually need to sign the transaction
# Otherwise we just need to insert the proper ScriptSig
- if (initial_split) :
- completetx = from_node.signrawtransaction(ToHex(tx))["hex"]
- else :
+ if (initial_split):
+ completetx = from_node.signrawtransactionwithwallet(ToHex(tx))["hex"]
+ else:
tx.vin[0].scriptSig = SCRIPT_SIG[prevtxout["vout"]]
completetx = ToHex(tx)
txid = from_node.sendrawtransaction(completetx, True)
- txouts.append({ "txid" : txid, "vout" : 0 , "amount" : half_change})
- txouts.append({ "txid" : txid, "vout" : 1 , "amount" : rem_change})
+ txouts.append({"txid": txid, "vout": 0, "amount": half_change})
+ txouts.append({"txid": txid, "vout": 1, "amount": rem_change})
-def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
- """
- This function calls estimatefee and verifies that the estimates
- meet certain invariants.
- """
- all_estimates = [ node.estimatefee(i) for i in range(1,26) ]
- if print_estimates:
- log.info([str(all_estimates[e-1]) for e in [1,2,3,6,15,25]])
- delta = 1.0e-6 # account for rounding error
- last_e = max(fees_seen)
- for e in [x for x in all_estimates if x >= 0]:
- # Estimates should be within the bounds of what transactions fees actually were:
- if float(e)+delta < min(fees_seen) or float(e)-delta > max(fees_seen):
+def check_estimates(node, fees_seen, max_invalid):
+ """Call estimatesmartfee and verify that the estimates meet certain invariants."""
+
+ delta = 1.0e-6 # account for rounding error
+ last_feerate = float(max(fees_seen))
+ all_smart_estimates = [node.estimatesmartfee(i) for i in range(1, 26)]
+ for i, e in enumerate(all_smart_estimates): # estimate is for i+1
+ feerate = float(e["feerate"])
+ assert_greater_than(feerate, 0)
+
+ if feerate + delta < min(fees_seen) or feerate - delta > max(fees_seen):
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
- %(float(e), min(fees_seen), max(fees_seen)))
- # Estimates should be monotonically decreasing
- if float(e)-delta > last_e:
+ % (feerate, min(fees_seen), max(fees_seen)))
+ if feerate - delta > last_feerate:
raise AssertionError("Estimated fee (%f) larger than last fee (%f) for lower number of confirms"
- %(float(e),float(last_e)))
- last_e = e
- valid_estimate = False
- invalid_estimates = 0
- for i,e in enumerate(all_estimates): # estimate is for i+1
- if e >= 0:
- valid_estimate = True
- if i >= 13: # for n>=14 estimatesmartfee(n/2) should be at least as high as estimatefee(n)
- assert(node.estimatesmartfee((i+1)//2)["feerate"] > float(e) - delta)
+ % (feerate, last_feerate))
+ last_feerate = feerate
+ if i == 0:
+ assert_equal(e["blocks"], 2)
else:
- invalid_estimates += 1
-
- # estimatesmartfee should still be valid
- approx_estimate = node.estimatesmartfee(i+1)["feerate"]
- answer_found = node.estimatesmartfee(i+1)["blocks"]
- assert(approx_estimate > 0)
- assert(answer_found > i+1)
-
- # Once we're at a high enough confirmation count that we can give an estimate
- # We should have estimates for all higher confirmation counts
- if valid_estimate:
- raise AssertionError("Invalid estimate appears at higher confirm count than valid estimate")
-
- # Check on the expected number of different confirmation counts
- # that we might not have valid estimates for
- if invalid_estimates > max_invalid:
- raise AssertionError("More than (%d) invalid estimates"%(max_invalid))
- return all_estimates
-
+ assert_greater_than_or_equal(i + 1, e["blocks"])
class EstimateFeeTest(BitcoinTestFramework):
def set_test_params(self):
@@ -151,7 +133,7 @@ class EstimateFeeTest(BitcoinTestFramework):
which we will use to generate our transactions.
"""
self.add_nodes(3, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
- ["-blockmaxsize=17000", "-maxorphantx=1000", "-deprecatedrpc=estimatefee"],
+ ["-blockmaxsize=17000", "-maxorphantx=1000"],
["-blockmaxsize=8000", "-maxorphantx=1000"]])
# Use node0 to mine blocks for input splitting
# Node1 mines small blocks but that are bigger than the expected transaction rate.
@@ -160,7 +142,6 @@ class EstimateFeeTest(BitcoinTestFramework):
# Node2 is a stingy miner, that
# produces too small blocks (room for only 55 or so transactions)
-
def transact_and_mine(self, numblocks, mining_node):
min_fee = Decimal("0.00001")
# We will now mine numblocks blocks generating on average 100 transactions between each block
@@ -169,14 +150,14 @@ class EstimateFeeTest(BitcoinTestFramework):
# resorting to tx's that depend on the mempool when those run out
for i in range(numblocks):
random.shuffle(self.confutxo)
- for j in range(random.randrange(100-50,100+50)):
- from_index = random.randint(1,2)
+ for j in range(random.randrange(100 - 50, 100 + 50)):
+ from_index = random.randint(1, 2)
(txhex, fee) = small_txpuzzle_randfee(self.nodes[from_index], self.confutxo,
self.memutxo, Decimal("0.005"), min_fee, min_fee)
tx_kbytes = (len(txhex) // 2) / 1000.0
- self.fees_per_kb.append(float(fee)/tx_kbytes)
+ self.fees_per_kb.append(float(fee) / tx_kbytes)
sync_mempools(self.nodes[0:3], wait=.1)
- mined = mining_node.getblock(mining_node.generate(1)[0],True)["tx"]
+ mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
sync_blocks(self.nodes[0:3], wait=.1)
# update which txouts are confirmed
newmem = []
@@ -191,10 +172,6 @@ class EstimateFeeTest(BitcoinTestFramework):
self.log.info("This test is time consuming, please be patient")
self.log.info("Splitting inputs so we can generate tx's")
- # Make log handler available to helper functions
- global log
- log = self.log
-
# Start node0
self.start_node(0)
self.txouts = []
@@ -210,13 +187,13 @@ class EstimateFeeTest(BitcoinTestFramework):
# Use txouts to monitor the available utxo, since these won't be tracked in wallet
reps = 0
while (reps < 5):
- #Double txouts to txouts2
- while (len(self.txouts)>0):
+ # Double txouts to txouts2
+ while (len(self.txouts) > 0):
split_inputs(self.nodes[0], self.txouts, self.txouts2)
while (len(self.nodes[0].getrawmempool()) > 0):
self.nodes[0].generate(1)
- #Double txouts2 to txouts
- while (len(self.txouts2)>0):
+ # Double txouts2 to txouts
+ while (len(self.txouts2) > 0):
split_inputs(self.nodes[0], self.txouts2, self.txouts)
while (len(self.nodes[0].getrawmempool()) > 0):
self.nodes[0].generate(1)
@@ -235,7 +212,7 @@ class EstimateFeeTest(BitcoinTestFramework):
self.fees_per_kb = []
self.memutxo = []
- self.confutxo = self.txouts # Start with the set of confirmed txouts after splitting
+ self.confutxo = self.txouts # Start with the set of confirmed txouts after splitting
self.log.info("Will output estimates for 1/2/3/6/15/25 blocks")
for i in range(2):
diff --git a/test/functional/maxuploadtarget.py b/test/functional/feature_maxuploadtarget.py
index 45336ee801..45336ee801 100755
--- a/test/functional/maxuploadtarget.py
+++ b/test/functional/feature_maxuploadtarget.py
diff --git a/test/functional/minchainwork.py b/test/functional/feature_minchainwork.py
index 90a3de0e0d..90a3de0e0d 100755
--- a/test/functional/minchainwork.py
+++ b/test/functional/feature_minchainwork.py
diff --git a/test/functional/notifications.py b/test/functional/feature_notifications.py
index 980bef5fc8..980bef5fc8 100755
--- a/test/functional/notifications.py
+++ b/test/functional/feature_notifications.py
diff --git a/test/functional/nulldummy.py b/test/functional/feature_nulldummy.py
index a94fe8204f..7db6a03b45 100755
--- a/test/functional/nulldummy.py
+++ b/test/functional/feature_nulldummy.py
@@ -21,7 +21,7 @@ from test_framework.script import CScript
from io import BytesIO
import time
-NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
+NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"
def trueDummy(tx):
scriptSig = CScript(tx.vin[0].scriptSig)
@@ -42,13 +42,13 @@ class NULLDUMMYTest(BitcoinTestFramework):
self.setup_clean_chain = True
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
# normal segwit activation here (and don't use the default always-on behaviour).
- self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness', '-vbparams=segwit:0:999999999999']]
+ self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness', '-vbparams=segwit:0:999999999999', '-addresstype=legacy', "-deprecatedrpc=addwitnessaddress"]]
def run_test(self):
self.address = self.nodes[0].getnewaddress()
- self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])
+ self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])['address']
self.wit_address = self.nodes[0].addwitnessaddress(self.address)
- self.wit_ms_address = self.nodes[0].addwitnessaddress(self.ms_address)
+ self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
network_thread_start()
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
@@ -102,7 +102,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
inputs = [{ "txid" : txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = node.createrawtransaction(inputs, outputs)
- signresult = node.signrawtransaction(rawtx)
+ signresult = node.signrawtransactionwithwallet(rawtx)
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(signresult['hex']))
tx.deserialize(f)
diff --git a/test/functional/proxy_test.py b/test/functional/feature_proxy.py
index 2eb1be47a5..2eb1be47a5 100755
--- a/test/functional/proxy_test.py
+++ b/test/functional/feature_proxy.py
diff --git a/test/functional/pruning.py b/test/functional/feature_pruning.py
index 49ad7f838c..49ad7f838c 100755
--- a/test/functional/pruning.py
+++ b/test/functional/feature_pruning.py
diff --git a/test/functional/replace-by-fee.py b/test/functional/feature_rbf.py
index 6b7ab0f43e..d6ab5ecc37 100755
--- a/test/functional/replace-by-fee.py
+++ b/test/functional/feature_rbf.py
@@ -42,7 +42,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
tx2.vout = [CTxOut(amount, scriptPubKey)]
tx2.rehash()
- signed_tx = node.signrawtransaction(txToHex(tx2))
+ signed_tx = node.signrawtransactionwithwallet(txToHex(tx2))
txid = node.sendrawtransaction(signed_tx['hex'], True)
diff --git a/test/functional/reindex.py b/test/functional/feature_reindex.py
index ac67e6e9ba..ac67e6e9ba 100755
--- a/test/functional/reindex.py
+++ b/test/functional/feature_reindex.py
diff --git a/test/functional/segwit.py b/test/functional/feature_segwit.py
index dbf4a86e38..fa1732c4c5 100755
--- a/test/functional/segwit.py
+++ b/test/functional/feature_segwit.py
@@ -4,10 +4,18 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the SegWit changeover logic."""
+from test_framework.address import (
+ key_to_p2sh_p2wpkh,
+ key_to_p2wpkh,
+ program_to_witness,
+ script_to_p2sh_p2wsh,
+ script_to_p2wsh,
+)
+from test_framework.blocktools import witness_script, send_to_witness
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import sha256, CTransaction, CTxIn, COutPoint, CTxOut, COIN, ToHex, FromHex
-from test_framework.address import script_to_p2sh, key_to_p2pkh, key_to_p2sh_p2wpkh, key_to_p2wpkh, script_to_p2sh_p2wsh, script_to_p2wsh, program_to_witness
+from test_framework.address import script_to_p2sh, key_to_p2pkh
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE
from io import BytesIO
@@ -16,71 +24,27 @@ NODE_2 = 2
WIT_V0 = 0
WIT_V1 = 1
-# Create a scriptPubKey corresponding to either a P2WPKH output for the
-# given pubkey, or a P2WSH output of a 1-of-1 multisig for the given
-# pubkey. Returns the hex encoding of the scriptPubKey.
-def witness_script(use_p2wsh, pubkey):
- if (use_p2wsh == False):
- # P2WPKH instead
- pubkeyhash = hash160(hex_str_to_bytes(pubkey))
- pkscript = CScript([OP_0, pubkeyhash])
- else:
- # 1-of-1 multisig
- witness_program = CScript([OP_1, hex_str_to_bytes(pubkey), OP_1, OP_CHECKMULTISIG])
- scripthash = sha256(witness_program)
- pkscript = CScript([OP_0, scripthash])
- return bytes_to_hex_str(pkscript)
-
-# Return a transaction (in hex) that spends the given utxo to a segwit output,
-# optionally wrapping the segwit output using P2SH.
-def create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount):
- if use_p2wsh:
- program = CScript([OP_1, hex_str_to_bytes(pubkey), OP_1, OP_CHECKMULTISIG])
- addr = script_to_p2sh_p2wsh(program) if encode_p2sh else script_to_p2wsh(program)
- else:
- addr = key_to_p2sh_p2wpkh(pubkey) if encode_p2sh else key_to_p2wpkh(pubkey)
- if not encode_p2sh:
- assert_equal(node.validateaddress(addr)['scriptPubKey'], witness_script(use_p2wsh, pubkey))
- return node.createrawtransaction([utxo], {addr: amount})
-
-# Create a transaction spending a given utxo to a segwit output corresponding
-# to the given pubkey: use_p2wsh determines whether to use P2WPKH or P2WSH;
-# encode_p2sh determines whether to wrap in P2SH.
-# sign=True will have the given node sign the transaction.
-# insert_redeem_script will be added to the scriptSig, if given.
-def send_to_witness(use_p2wsh, node, utxo, pubkey, encode_p2sh, amount, sign=True, insert_redeem_script=""):
- tx_to_witness = create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount)
- if (sign):
- signed = node.signrawtransaction(tx_to_witness)
- assert("errors" not in signed or len(["errors"]) == 0)
- return node.sendrawtransaction(signed["hex"])
- else:
- if (insert_redeem_script):
- tx = FromHex(CTransaction(), tx_to_witness)
- tx.vin[0].scriptSig += CScript([hex_str_to_bytes(insert_redeem_script)])
- tx_to_witness = ToHex(tx)
-
- return node.sendrawtransaction(tx_to_witness)
-
def getutxo(txid):
utxo = {}
utxo["vout"] = 0
utxo["txid"] = txid
return utxo
-def find_unspent(node, min_value):
- for utxo in node.listunspent():
- if utxo['amount'] >= min_value:
+def find_spendable_utxo(node, min_value):
+ for utxo in node.listunspent(query_options={'minimumAmount': min_value}):
+ if utxo['spendable']:
return utxo
+ raise AssertionError("Unspent output equal or higher than %s not found" % min_value)
+
class SegWitTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
- self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0", "-vbparams=segwit:0:999999999999"],
- ["-blockversion=4", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999"],
- ["-blockversion=536870915", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-vbparams=segwit:0:999999999999"]]
+ self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
+ ["-blockversion=4", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
+ ["-blockversion=536870915", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
def setup_network(self):
super().setup_network()
@@ -132,13 +96,12 @@ class SegWitTest(BitcoinTestFramework):
wit_ids = [] # wit_ids[NODE][VER] is an array of txids that spend to a witness version VER pkscript to an address for NODE via bare witness
for i in range(3):
newaddress = self.nodes[i].getnewaddress()
- self.pubkey.append(self.nodes[i].validateaddress(newaddress)["pubkey"])
- multiaddress = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]])
+ self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
- p2sh_addr = self.nodes[i].addwitnessaddress(newaddress, True)
+ p2sh_addr = self.nodes[i].addwitnessaddress(newaddress)
bip173_addr = self.nodes[i].addwitnessaddress(newaddress, False)
- p2sh_ms_addr = self.nodes[i].addwitnessaddress(multiaddress, True)
- bip173_ms_addr = self.nodes[i].addwitnessaddress(multiaddress, False)
+ p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
+ bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
assert_equal(p2sh_addr, key_to_p2sh_p2wpkh(self.pubkey[-1]))
assert_equal(bip173_addr, key_to_p2wpkh(self.pubkey[-1]))
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
@@ -152,8 +115,8 @@ class SegWitTest(BitcoinTestFramework):
for i in range(5):
for n in range(3):
for v in range(2):
- wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[n], False, Decimal("49.999")))
- p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))
+ wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], False, Decimal("49.999")))
+ p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))
self.nodes[0].generate(1) #block 163
sync_blocks(self.nodes)
@@ -248,7 +211,7 @@ class SegWitTest(BitcoinTestFramework):
# tx2 (segwit input, paying to a non-segwit output) ->
# tx3 (non-segwit input, paying to a non-segwit output).
# tx1 is allowed to appear in the block, but no others.
- txid1 = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996"))
+ txid1 = send_to_witness(1, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996"))
hex_tx = self.nodes[0].gettransaction(txid)['hex']
tx = FromHex(CTransaction(), hex_tx)
assert(tx.wit.is_null()) # This should not be a segwit input
@@ -258,7 +221,7 @@ class SegWitTest(BitcoinTestFramework):
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b''))
tx.vout.append(CTxOut(int(49.99*COIN), CScript([OP_TRUE])))
- tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex']
+ tx2_hex = self.nodes[0].signrawtransactionwithwallet(ToHex(tx))['hex']
txid2 = self.nodes[0].sendrawtransaction(tx2_hex)
tx = FromHex(CTransaction(), tx2_hex)
assert(not tx.wit.is_null())
@@ -311,8 +274,8 @@ class SegWitTest(BitcoinTestFramework):
uncompressed_spendable_address = ["mvozP4UwyGD2mGZU4D2eMvMLPB9WkMmMQu"]
self.nodes[0].importprivkey("cNC8eQ5dg3mFAVePDX4ddmPYpPbw41r9bm2jd1nLJT77e6RrzTRR")
compressed_spendable_address = ["mmWQubrDomqpgSYekvsU7HWEVjLFHAakLe"]
- assert ((self.nodes[0].validateaddress(uncompressed_spendable_address[0])['iscompressed'] == False))
- assert ((self.nodes[0].validateaddress(compressed_spendable_address[0])['iscompressed'] == True))
+ assert ((self.nodes[0].getaddressinfo(uncompressed_spendable_address[0])['iscompressed'] == False))
+ assert ((self.nodes[0].getaddressinfo(compressed_spendable_address[0])['iscompressed'] == True))
self.nodes[0].importpubkey(pubkeys[0])
compressed_solvable_address = [key_to_p2pkh(pubkeys[0])]
@@ -328,24 +291,24 @@ class SegWitTest(BitcoinTestFramework):
solvable_anytime = [] # These outputs should be solvable after importpubkey
unseen_anytime = [] # These outputs should never be seen
- uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], compressed_spendable_address[0]]))
- uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], uncompressed_spendable_address[0]]))
- compressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_spendable_address[0]]))
- uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], uncompressed_solvable_address[0]]))
- compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]]))
- compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], compressed_solvable_address[1]]))
+ uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], compressed_spendable_address[0]])['address'])
+ uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], uncompressed_spendable_address[0]])['address'])
+ compressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_spendable_address[0]])['address'])
+ uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], uncompressed_solvable_address[0]])['address'])
+ compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]])['address'])
+ compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], compressed_solvable_address[1]])['address'])
unknown_address = ["mtKKyoHabkk6e4ppT7NaM7THqPUt7AzPrT", "2NDP3jLWAFT8NDAiUa9qiE6oBt2awmMq7Dx"]
# Test multisig_without_privkey
# We have 2 public keys without private keys, use addmultisigaddress to add to wallet.
# Money sent to P2SH of multisig of this should only be seen after importaddress with the BASE58 P2SH address.
- multisig_without_privkey_address = self.nodes[0].addmultisigaddress(2, [pubkeys[3], pubkeys[4]])
+ multisig_without_privkey_address = self.nodes[0].addmultisigaddress(2, [pubkeys[3], pubkeys[4]])['address']
script = CScript([OP_2, hex_str_to_bytes(pubkeys[3]), hex_str_to_bytes(pubkeys[4]), OP_2, OP_CHECKMULTISIG])
solvable_after_importaddress.append(CScript([OP_HASH160, hash160(script), OP_EQUAL]))
for i in compressed_spendable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
# bare and p2sh multisig with compressed keys should always be spendable
@@ -356,11 +319,13 @@ class SegWitTest(BitcoinTestFramework):
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
# normal P2PKH and P2PK with compressed keys should always be spendable
spendable_anytime.extend([p2pkh, p2pk])
- # P2SH_P2PK, P2SH_P2PKH, and witness with compressed keys are spendable after direct importaddress
- spendable_after_importaddress.extend([p2wpkh, p2sh_p2wpkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
+ # P2SH_P2PK, P2SH_P2PKH with compressed keys are spendable after direct importaddress
+ spendable_after_importaddress.extend([p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
+ # P2WPKH and P2SH_P2WPKH with compressed keys should always be spendable
+ spendable_anytime.extend([p2wpkh, p2sh_p2wpkh])
for i in uncompressed_spendable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
# bare and p2sh multisig with uncompressed keys should always be spendable
@@ -373,24 +338,24 @@ class SegWitTest(BitcoinTestFramework):
spendable_anytime.extend([p2pkh, p2pk])
# P2SH_P2PK and P2SH_P2PKH are spendable after direct importaddress
spendable_after_importaddress.extend([p2sh_p2pk, p2sh_p2pkh])
- # witness with uncompressed keys are never seen
+ # Witness output types with uncompressed keys are never seen
unseen_anytime.extend([p2wpkh, p2sh_p2wpkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
for i in compressed_solvable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
# Multisig without private is not seen after addmultisigaddress, but seen after importaddress
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
solvable_after_importaddress.extend([bare, p2sh, p2wsh, p2sh_p2wsh])
else:
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
- # normal P2PKH and P2PK with compressed keys should always be seen
- solvable_anytime.extend([p2pkh, p2pk])
- # P2SH_P2PK, P2SH_P2PKH, and witness with compressed keys are seen after direct importaddress
- solvable_after_importaddress.extend([p2wpkh, p2sh_p2wpkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
+ # normal P2PKH, P2PK, P2WPKH and P2SH_P2WPKH with compressed keys should always be seen
+ solvable_anytime.extend([p2pkh, p2pk, p2wpkh, p2sh_p2wpkh])
+ # P2SH_P2PK, P2SH_P2PKH with compressed keys are seen after direct importaddress
+ solvable_after_importaddress.extend([p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
for i in uncompressed_solvable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
# Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
@@ -403,7 +368,7 @@ class SegWitTest(BitcoinTestFramework):
solvable_anytime.extend([p2pkh, p2pk])
# P2SH_P2PK, P2SH_P2PKH with uncompressed keys are seen after direct importaddress
solvable_after_importaddress.extend([p2sh_p2pk, p2sh_p2pkh])
- # witness with uncompressed keys are never seen
+ # Witness output types with uncompressed keys are never seen
unseen_anytime.extend([p2wpkh, p2sh_p2wpkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh])
op1 = CScript([OP_1])
@@ -430,7 +395,7 @@ class SegWitTest(BitcoinTestFramework):
importlist = []
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
bare = hex_str_to_bytes(v['hex'])
importlist.append(bytes_to_hex_str(bare))
@@ -496,17 +461,19 @@ class SegWitTest(BitcoinTestFramework):
spendable_after_addwitnessaddress = [] # These outputs should be seen after importaddress
solvable_after_addwitnessaddress=[] # These outputs should be seen after importaddress but not spendable
unseen_anytime = [] # These outputs should never be seen
+ solvable_anytime = [] # These outputs should be solvable after importpubkey
+ unseen_anytime = [] # These outputs should never be seen
- uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], compressed_spendable_address[0]]))
- uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], uncompressed_spendable_address[0]]))
- compressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_spendable_address[0]]))
- uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], uncompressed_solvable_address[0]]))
- compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]]))
+ uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], compressed_spendable_address[0]])['address'])
+ uncompressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [uncompressed_spendable_address[0], uncompressed_spendable_address[0]])['address'])
+ compressed_spendable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_spendable_address[0]])['address'])
+ uncompressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_solvable_address[0], uncompressed_solvable_address[0]])['address'])
+ compressed_solvable_address.append(self.nodes[0].addmultisigaddress(2, [compressed_spendable_address[0], compressed_solvable_address[0]])['address'])
premature_witaddress = []
for i in compressed_spendable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
# P2WSH and P2SH(P2WSH) multisig with compressed keys are spendable after addwitnessaddress
@@ -514,12 +481,11 @@ class SegWitTest(BitcoinTestFramework):
premature_witaddress.append(script_to_p2sh(p2wsh))
else:
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
- # P2WPKH, P2SH_P2WPKH are spendable after addwitnessaddress
- spendable_after_addwitnessaddress.extend([p2wpkh, p2sh_p2wpkh])
- premature_witaddress.append(script_to_p2sh(p2wpkh))
+ # P2WPKH, P2SH_P2WPKH are always spendable
+ spendable_anytime.extend([p2wpkh, p2sh_p2wpkh])
for i in uncompressed_spendable_address + uncompressed_solvable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
# P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
@@ -530,7 +496,7 @@ class SegWitTest(BitcoinTestFramework):
unseen_anytime.extend([p2wpkh, p2sh_p2wpkh])
for i in compressed_solvable_address:
- v = self.nodes[0].validateaddress(i)
+ v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
# P2WSH multisig without private key are seen after addwitnessaddress
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
@@ -538,10 +504,11 @@ class SegWitTest(BitcoinTestFramework):
premature_witaddress.append(script_to_p2sh(p2wsh))
else:
[p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh] = self.p2pkh_address_to_script(v)
- # P2SH_P2PK, P2SH_P2PKH with compressed keys are seen after addwitnessaddress
- solvable_after_addwitnessaddress.extend([p2wpkh, p2sh_p2wpkh])
- premature_witaddress.append(script_to_p2sh(p2wpkh))
+ # P2SH_P2PK, P2SH_P2PKH with compressed keys are always solvable
+ solvable_anytime.extend([p2wpkh, p2sh_p2wpkh])
+ self.mine_and_test_listunspent(spendable_anytime, 2)
+ self.mine_and_test_listunspent(solvable_anytime, 1)
self.mine_and_test_listunspent(spendable_after_addwitnessaddress + solvable_after_addwitnessaddress + unseen_anytime, 0)
# addwitnessaddress should refuse to return a witness address if an uncompressed key is used
@@ -552,14 +519,14 @@ class SegWitTest(BitcoinTestFramework):
assert_raises_rpc_error(-4, "Public key or redeemscript not known to wallet, or the key is uncompressed", self.nodes[0].addwitnessaddress, i)
# after importaddress it should pass addwitnessaddress
- v = self.nodes[0].validateaddress(compressed_solvable_address[1])
+ v = self.nodes[0].getaddressinfo(compressed_solvable_address[1])
self.nodes[0].importaddress(v['hex'],"",False,True)
for i in compressed_spendable_address + compressed_solvable_address + premature_witaddress:
witaddress = self.nodes[0].addwitnessaddress(i)
assert_equal(witaddress, self.nodes[0].addwitnessaddress(witaddress))
- spendable_txid.append(self.mine_and_test_listunspent(spendable_after_addwitnessaddress, 2))
- solvable_txid.append(self.mine_and_test_listunspent(solvable_after_addwitnessaddress, 1))
+ spendable_txid.append(self.mine_and_test_listunspent(spendable_after_addwitnessaddress + spendable_anytime, 2))
+ solvable_txid.append(self.mine_and_test_listunspent(solvable_after_addwitnessaddress + solvable_anytime, 1))
self.mine_and_test_listunspent(unseen_anytime, 0)
# Check that createrawtransaction/decoderawtransaction with non-v0 Bech32 works
@@ -592,7 +559,7 @@ class SegWitTest(BitcoinTestFramework):
self.nodes[1].importaddress(scriptPubKey, "", False)
rawtxfund = self.nodes[1].fundrawtransaction(transaction)['hex']
- rawtxfund = self.nodes[1].signrawtransaction(rawtxfund)["hex"]
+ rawtxfund = self.nodes[1].signrawtransactionwithwallet(rawtxfund)["hex"]
txid = self.nodes[1].sendrawtransaction(rawtxfund)
assert_equal(self.nodes[1].gettransaction(txid, True)["txid"], txid)
@@ -605,13 +572,13 @@ class SegWitTest(BitcoinTestFramework):
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)
def mine_and_test_listunspent(self, script_list, ismine):
- utxo = find_unspent(self.nodes[0], 50)
+ utxo = find_spendable_utxo(self.nodes[0], 50)
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int('0x'+utxo['txid'],0), utxo['vout'])))
for i in script_list:
tx.vout.append(CTxOut(10000000, i))
tx.rehash()
- signresults = self.nodes[0].signrawtransaction(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
+ signresults = self.nodes[0].signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
txid = self.nodes[0].sendrawtransaction(signresults, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -663,7 +630,7 @@ class SegWitTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(int('0x'+i,0), j)))
tx.vout.append(CTxOut(0, CScript()))
tx.rehash()
- signresults = self.nodes[0].signrawtransaction(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
+ signresults = self.nodes[0].signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
self.nodes[0].sendrawtransaction(signresults, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
diff --git a/test/functional/uacomment.py b/test/functional/feature_uacomment.py
index 0b2c64ab69..bc3791508a 100755
--- a/test/functional/uacomment.py
+++ b/test/functional/feature_uacomment.py
@@ -23,7 +23,7 @@ class UacommentTest(BitcoinTestFramework):
self.log.info("test -uacomment max length")
self.stop_node(0)
- expected = "Total length of network version string (286) exceeds maximum length (256). Reduce the number or size of uacomments."
+ expected = "exceeds maximum length (256). Reduce the number or size of uacomments."
self.assert_start_raises_init_error(0, ["-uacomment=" + 'a' * 256], expected)
self.log.info("test -uacomment unsafe characters")
diff --git a/test/functional/feature_versionbits_warning.py b/test/functional/feature_versionbits_warning.py
new file mode 100755
index 0000000000..2985569a8f
--- /dev/null
+++ b/test/functional/feature_versionbits_warning.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# Copyright (c) 2016-2017 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 version bits warning system.
+
+Generate chains with block versions that appear to be signalling unknown
+soft-forks, and test that warning alerts are generated.
+"""
+import os
+import re
+
+from test_framework.blocktools import create_block, create_coinbase
+from test_framework.messages import msg_block
+from test_framework.mininode import P2PInterface, network_thread_start, mininode_lock
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import wait_until
+
+VB_PERIOD = 144 # versionbits period length for regtest
+VB_THRESHOLD = 108 # versionbits activation threshold for regtest
+VB_TOP_BITS = 0x20000000
+VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
+VB_UNKNOWN_VERSION = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT)
+
+WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
+WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})".format(VB_UNKNOWN_BIT)
+VB_PATTERN = re.compile("Warning: unknown new rules activated.*versionbit")
+
+class VersionBitsWarningTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 1
+
+ def setup_network(self):
+ self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
+ # Open and close to create zero-length file
+ with open(self.alert_filename, 'w', encoding='utf8'):
+ pass
+ self.extra_args = [["-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
+ self.setup_nodes()
+
+ def send_blocks_with_version(self, peer, numblocks, version):
+ """Send numblocks blocks to peer with version set"""
+ tip = self.nodes[0].getbestblockhash()
+ height = self.nodes[0].getblockcount()
+ block_time = self.nodes[0].getblockheader(tip)["time"] + 1
+ tip = int(tip, 16)
+
+ for _ in range(numblocks):
+ block = create_block(tip, create_coinbase(height + 1), block_time)
+ block.nVersion = version
+ block.solve()
+ peer.send_message(msg_block(block))
+ block_time += 1
+ height += 1
+ tip = block.sha256
+ peer.sync_with_ping()
+
+ def versionbits_in_alert_file(self):
+ """Test that the versionbits warning has been written to the alert file."""
+ alert_text = open(self.alert_filename, 'r', encoding='utf8').read()
+ return VB_PATTERN.search(alert_text) is not None
+
+ def run_test(self):
+ # Handy alias
+ node = self.nodes[0]
+ node.add_p2p_connection(P2PInterface())
+ network_thread_start()
+ node.p2p.wait_for_verack()
+
+ # Mine one period worth of blocks
+ node.generate(VB_PERIOD)
+
+ self.log.info("Check that there is no warning if previous VB_BLOCKS have <VB_THRESHOLD blocks with unknown versionbits version.")
+ # Build one period of blocks with < VB_THRESHOLD blocks signaling some unknown bit
+ self.send_blocks_with_version(node.p2p, VB_THRESHOLD - 1, VB_UNKNOWN_VERSION)
+ node.generate(VB_PERIOD - VB_THRESHOLD + 1)
+
+ # Check that we're not getting any versionbit-related errors in get*info()
+ assert(not VB_PATTERN.match(node.getmininginfo()["warnings"]))
+ assert(not VB_PATTERN.match(node.getnetworkinfo()["warnings"]))
+
+ self.log.info("Check that there is a warning if >50 blocks in the last 100 were an unknown version")
+ # Build one period of blocks with VB_THRESHOLD blocks signaling some unknown bit
+ self.send_blocks_with_version(node.p2p, VB_THRESHOLD, VB_UNKNOWN_VERSION)
+ node.generate(VB_PERIOD - VB_THRESHOLD)
+
+ # Check that get*info() shows the 51/100 unknown block version error.
+ assert(WARN_UNKNOWN_RULES_MINED in node.getmininginfo()["warnings"])
+ assert(WARN_UNKNOWN_RULES_MINED in node.getnetworkinfo()["warnings"])
+
+ self.log.info("Check that there is a warning if previous VB_BLOCKS have >=VB_THRESHOLD blocks with unknown versionbits version.")
+ # Mine a period worth of expected blocks so the generic block-version warning
+ # is cleared. This will move the versionbit state to ACTIVE.
+ node.generate(VB_PERIOD)
+
+ # Stop-start the node. This is required because bitcoind will only warn once about unknown versions or unknown rules activating.
+ self.restart_node(0)
+
+ # Generating one block guarantees that we'll get out of IBD
+ node.generate(1)
+ wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=mininode_lock)
+ # Generating one more block will be enough to generate an error.
+ node.generate(1)
+ # Check that get*info() shows the versionbits unknown rules warning
+ assert(WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"])
+ assert(WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"])
+ # Check that the alert file shows the versionbits unknown rules warning
+ wait_until(lambda: self.versionbits_in_alert_file(), timeout=60)
+
+if __name__ == '__main__':
+ VersionBitsWarningTest().main()
diff --git a/test/functional/bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index d1cd3b3620..d8c80ab34f 100755
--- a/test/functional/bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -39,7 +39,7 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
self.log.info("Compare responses from `bitcoin-cli -getinfo` and the RPCs data is retrieved from.")
- cli_get_info = self.nodes[0].cli().send_cli('-getinfo')
+ cli_get_info = self.nodes[0].cli('-getinfo').send_cli()
wallet_info = self.nodes[0].getwalletinfo()
network_info = self.nodes[0].getnetworkinfo()
blockchain_info = self.nodes[0].getblockchaininfo()
diff --git a/test/functional/httpbasics.py b/test/functional/interface_http.py
index cd6d744545..cd6d744545 100755
--- a/test/functional/httpbasics.py
+++ b/test/functional/interface_http.py
diff --git a/test/functional/rest.py b/test/functional/interface_rest.py
index 9006e27cbe..8440f13a0d 100755
--- a/test/functional/rest.py
+++ b/test/functional/interface_rest.py
@@ -46,6 +46,7 @@ class RESTTest (BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
+ self.extra_args = [["-rest"]] * self.num_nodes
def setup_network(self, split=False):
super().setup_network()
@@ -295,8 +296,10 @@ class RESTTest (BitcoinTestFramework):
# check that there are our submitted transactions in the TX memory pool
json_string = http_get_call(url.hostname, url.port, '/rest/mempool/contents'+self.FORMAT_SEPARATOR+'json')
json_obj = json.loads(json_string)
- for tx in txs:
+ for i, tx in enumerate(txs):
assert_equal(tx in json_obj, True)
+ assert_equal(json_obj[tx]['spentby'], txs[i+1:i+2])
+ assert_equal(json_obj[tx]['depends'], txs[i-1:i])
# now mine the transactions
newblockhash = self.nodes[1].generate(1)
diff --git a/test/functional/zmq_test.py b/test/functional/interface_zmq.py
index 86ccea4394..86ccea4394 100755
--- a/test/functional/zmq_test.py
+++ b/test/functional/interface_zmq.py
diff --git a/test/functional/invalidtxrequest.py b/test/functional/invalidtxrequest.py
deleted file mode 100755
index 9c1100e070..0000000000
--- a/test/functional/invalidtxrequest.py
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2015-2017 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 node responses to invalid transactions.
-
-In this test we connect to one node over p2p, and test tx requests.
-"""
-
-from test_framework.test_framework import ComparisonTestFramework
-from test_framework.comptool import TestManager, TestInstance, RejectResult
-from test_framework.blocktools import *
-import time
-
-
-
-# Use the ComparisonTestFramework with 1 node: only use --testbinary.
-class InvalidTxRequestTest(ComparisonTestFramework):
-
- ''' Can either run this test as 1 node with expected answers, or two and compare them.
- Change the "outcome" variable from each TestInstance object to only do the comparison. '''
- def set_test_params(self):
- self.num_nodes = 1
- self.setup_clean_chain = True
-
- def run_test(self):
- test = TestManager(self, self.options.tmpdir)
- test.add_all_connections(self.nodes)
- self.tip = None
- self.block_time = None
- network_thread_start()
- test.run()
-
- def get_tests(self):
- if self.tip is None:
- self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0)
- self.block_time = int(time.time())+1
-
- '''
- Create a new block with an anyone-can-spend coinbase
- '''
- height = 1
- block = create_block(self.tip, create_coinbase(height), self.block_time)
- self.block_time += 1
- block.solve()
- # Save the coinbase for later
- self.block1 = block
- self.tip = block.sha256
- height += 1
- yield TestInstance([[block, True]])
-
- '''
- Now we need that block to mature so we can spend the coinbase.
- '''
- test = TestInstance(sync_every_block=False)
- for i in range(100):
- block = create_block(self.tip, create_coinbase(height), self.block_time)
- block.solve()
- self.tip = block.sha256
- self.block_time += 1
- test.blocks_and_transactions.append([block, True])
- height += 1
- yield test
-
- # b'\x64' is OP_NOTIF
- # Transaction will be rejected with code 16 (REJECT_INVALID)
- tx1 = create_transaction(self.block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
- yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]])
-
- # TODO: test further transactions...
-
-if __name__ == '__main__':
- InvalidTxRequestTest().main()
diff --git a/test/functional/mempool_limit.py b/test/functional/mempool_limit.py
index e7ce3820d2..5382fe439e 100755
--- a/test/functional/mempool_limit.py
+++ b/test/functional/mempool_limit.py
@@ -32,7 +32,7 @@ class MempoolLimitTest(BitcoinTestFramework):
self.nodes[0].settxfee(relayfee) # specifically fund this tx with low fee
txF = self.nodes[0].fundrawtransaction(tx)
self.nodes[0].settxfee(0) # return to automatic fee selection
- txFS = self.nodes[0].signrawtransaction(txF['hex'])
+ txFS = self.nodes[0].signrawtransactionwithwallet(txF['hex'])
txid = self.nodes[0].sendrawtransaction(txFS['hex'])
relayfee = self.nodes[0].getnetworkinfo()['relayfee']
@@ -50,5 +50,15 @@ class MempoolLimitTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
assert_greater_than(self.nodes[0].getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
+ self.log.info('Create a mempool tx that will not pass mempoolminfee')
+ us0 = utxos.pop()
+ inputs = [{ "txid" : us0["txid"], "vout" : us0["vout"]}]
+ outputs = {self.nodes[0].getnewaddress() : 0.0001}
+ tx = self.nodes[0].createrawtransaction(inputs, outputs)
+ # specifically fund this tx with a fee < mempoolminfee, >= than minrelaytxfee
+ txF = self.nodes[0].fundrawtransaction(tx, {'feeRate': relayfee})
+ txFS = self.nodes[0].signrawtransactionwithwallet(txF['hex'])
+ assert_raises_rpc_error(-26, "mempool min fee not met", self.nodes[0].sendrawtransaction, txFS['hex'])
+
if __name__ == '__main__':
MempoolLimitTest().main()
diff --git a/test/functional/mempool_packages.py b/test/functional/mempool_packages.py
index a3e872a8c6..8880db8002 100755
--- a/test/functional/mempool_packages.py
+++ b/test/functional/mempool_packages.py
@@ -25,7 +25,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
for i in range(num_outputs):
outputs[node.getnewaddress()] = send_value
rawtx = node.createrawtransaction(inputs, outputs)
- signedtx = node.signrawtransaction(rawtx)
+ signedtx = node.signrawtransactionwithwallet(rawtx)
txid = node.sendrawtransaction(signedtx['hex'])
fulltx = node.getrawtransaction(txid, 1)
assert(len(fulltx['vout']) == num_outputs) # make sure we didn't generate a change output
@@ -47,7 +47,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
value = sent_value
chain.append(txid)
- # Check mempool has MAX_ANCESTORS transactions in it, and descendant
+ # Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
# count and fees should look correct
mempool = self.nodes[0].getrawmempool(True)
assert_equal(len(mempool), MAX_ANCESTORS)
@@ -55,6 +55,10 @@ class MempoolPackagesTest(BitcoinTestFramework):
descendant_fees = 0
descendant_size = 0
+ ancestor_size = sum([mempool[tx]['size'] for tx in mempool])
+ ancestor_count = MAX_ANCESTORS
+ ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool])
+
descendants = []
ancestors = list(chain)
for x in reversed(chain):
@@ -71,14 +75,43 @@ class MempoolPackagesTest(BitcoinTestFramework):
assert_equal(mempool[x]['descendantsize'], descendant_size)
descendant_count += 1
+ # Check that ancestor calculations are correct
+ assert_equal(mempool[x]['ancestorcount'], ancestor_count)
+ assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN)
+ assert_equal(mempool[x]['ancestorsize'], ancestor_size)
+ ancestor_size -= mempool[x]['size']
+ ancestor_fees -= mempool[x]['fee']
+ ancestor_count -= 1
+
+ # Check that parent/child list is correct
+ assert_equal(mempool[x]['spentby'], descendants[-1:])
+ assert_equal(mempool[x]['depends'], ancestors[-2:-1])
+
# Check that getmempooldescendants is correct
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
+
+ # Check getmempooldescendants verbose output is correct
+ for descendant, dinfo in self.nodes[0].getmempooldescendants(x, True).items():
+ assert_equal(dinfo['depends'], [chain[chain.index(descendant)-1]])
+ if dinfo['descendantcount'] > 1:
+ assert_equal(dinfo['spentby'], [chain[chain.index(descendant)+1]])
+ else:
+ assert_equal(dinfo['spentby'], [])
descendants.append(x)
# Check that getmempoolancestors is correct
ancestors.remove(x)
assert_equal(sorted(ancestors), sorted(self.nodes[0].getmempoolancestors(x)))
+ # Check that getmempoolancestors verbose output is correct
+ for ancestor, ainfo in self.nodes[0].getmempoolancestors(x, True).items():
+ assert_equal(ainfo['spentby'], [chain[chain.index(ancestor)+1]])
+ if ainfo['ancestorcount'] > 1:
+ assert_equal(ainfo['depends'], [chain[chain.index(ancestor)-1]])
+ else:
+ assert_equal(ainfo['depends'], [])
+
+
# Check that getmempoolancestors/getmempooldescendants correctly handle verbose=true
v_ancestors = self.nodes[0].getmempoolancestors(chain[-1], True)
assert_equal(len(v_ancestors), len(chain)-1)
@@ -100,7 +133,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
for x in chain:
ancestor_fees += mempool[x]['fee']
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000)
-
+
# Undo the prioritisetransaction for later tests
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
@@ -149,6 +182,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
vout = utxo[1]['vout']
transaction_package = []
+ tx_children = []
# First create one parent tx with 10 children
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, vout, value, fee, 10)
parent_transaction = txid
@@ -159,11 +193,17 @@ class MempoolPackagesTest(BitcoinTestFramework):
for i in range(MAX_DESCENDANTS - 1):
utxo = transaction_package.pop(0)
(txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
+ if utxo['txid'] is parent_transaction:
+ tx_children.append(txid)
for j in range(10):
transaction_package.append({'txid': txid, 'vout': j, 'amount': sent_value})
mempool = self.nodes[0].getrawmempool(True)
assert_equal(mempool[parent_transaction]['descendantcount'], MAX_DESCENDANTS)
+ assert_equal(sorted(mempool[parent_transaction]['spentby']), sorted(tx_children))
+
+ for child in tx_children:
+ assert_equal(mempool[child]['depends'], [parent_transaction])
# Sending one more chained transaction will fail
utxo = transaction_package.pop(0)
@@ -205,7 +245,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
for i in range(2):
outputs[self.nodes[0].getnewaddress()] = send_value
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
- signedtx = self.nodes[0].signrawtransaction(rawtx)
+ signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
tx0_id = txid
value = send_value
@@ -229,10 +269,10 @@ class MempoolPackagesTest(BitcoinTestFramework):
inputs = [ {'txid' : tx1_id, 'vout': 0}, {'txid' : txid, 'vout': 0} ]
outputs = { self.nodes[0].getnewaddress() : send_value + value - 4*fee }
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
- signedtx = self.nodes[0].signrawtransaction(rawtx)
+ signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
sync_mempools(self.nodes)
-
+
# Now try to disconnect the tip on each node...
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py
index 31a96ec60e..17f0967219 100755
--- a/test/functional/mempool_persist.py
+++ b/test/functional/mempool_persist.py
@@ -66,16 +66,17 @@ class MempoolPersistTest(BitcoinTestFramework):
self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.")
self.stop_nodes()
+ self.start_node(1) # Give this one a head-start, so we can be "extra-sure" that it didn't load anything later
self.start_node(0)
- self.start_node(1)
self.start_node(2)
# Give bitcoind a second to reload the mempool
- time.sleep(1)
- wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
- wait_until(lambda: len(self.nodes[2].getrawmempool()) == 5)
+ wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5, timeout=1)
+ wait_until(lambda: len(self.nodes[2].getrawmempool()) == 5, timeout=1)
+ # The others have loaded their mempool. If node_1 loaded anything, we'd probably notice by now:
assert_equal(len(self.nodes[1].getrawmempool()), 0)
# Verify accounting of mempool transactions after restart is correct
+ self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
assert_equal(node2_balance, self.nodes[2].getbalance())
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
diff --git a/test/functional/mempool_reorg.py b/test/functional/mempool_reorg.py
index d6bb292a58..eabed5d633 100755
--- a/test/functional/mempool_reorg.py
+++ b/test/functional/mempool_reorg.py
@@ -48,7 +48,7 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
# Set the time lock
timelock_tx = timelock_tx.replace("ffffffff", "11111191", 1)
timelock_tx = timelock_tx[:-8] + hex(self.nodes[0].getblockcount() + 2)[2:] + "000000"
- timelock_tx = self.nodes[0].signrawtransaction(timelock_tx)["hex"]
+ timelock_tx = self.nodes[0].signrawtransactionwithwallet(timelock_tx)["hex"]
# This will raise an exception because the timelock transaction is too immature to spend
assert_raises_rpc_error(-26, "non-final", self.nodes[0].sendrawtransaction, timelock_tx)
diff --git a/test/functional/mempool_resurrect_test.py b/test/functional/mempool_resurrect.py
index 83e84da4bc..83e84da4bc 100755
--- a/test/functional/mempool_resurrect_test.py
+++ b/test/functional/mempool_resurrect.py
diff --git a/test/functional/mempool_spendcoinbase.py b/test/functional/mempool_spend_coinbase.py
index db0738c08a..db0738c08a 100755
--- a/test/functional/mempool_spendcoinbase.py
+++ b/test/functional/mempool_spend_coinbase.py
diff --git a/test/functional/mining.py b/test/functional/mining_basic.py
index 569bf71933..569bf71933 100755
--- a/test/functional/mining.py
+++ b/test/functional/mining_basic.py
diff --git a/test/functional/getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py
index 252ff4dbff..252ff4dbff 100755
--- a/test/functional/getblocktemplate_longpoll.py
+++ b/test/functional/mining_getblocktemplate_longpoll.py
diff --git a/test/functional/prioritise_transaction.py b/test/functional/mining_prioritisetransaction.py
index c10042ddb2..32e2b47fc9 100755
--- a/test/functional/prioritise_transaction.py
+++ b/test/functional/mining_prioritisetransaction.py
@@ -15,6 +15,25 @@ class PrioritiseTransactionTest(BitcoinTestFramework):
self.extra_args = [["-printpriority=1"], ["-printpriority=1"]]
def run_test(self):
+ # Test `prioritisetransaction` required parameters
+ assert_raises_rpc_error(-1, "prioritisetransaction", self.nodes[0].prioritisetransaction)
+ assert_raises_rpc_error(-1, "prioritisetransaction", self.nodes[0].prioritisetransaction, '')
+ assert_raises_rpc_error(-1, "prioritisetransaction", self.nodes[0].prioritisetransaction, '', 0)
+
+ # Test `prioritisetransaction` invalid extra parameters
+ assert_raises_rpc_error(-1, "prioritisetransaction", self.nodes[0].prioritisetransaction, '', 0, 0, 0)
+
+ # Test `prioritisetransaction` invalid `txid`
+ assert_raises_rpc_error(-1, "txid must be hexadecimal string", self.nodes[0].prioritisetransaction, txid='foo', fee_delta=0)
+
+ # Test `prioritisetransaction` invalid `dummy`
+ txid = '1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000'
+ assert_raises_rpc_error(-1, "JSON value is not a number as expected", self.nodes[0].prioritisetransaction, txid, 'foo', 0)
+ assert_raises_rpc_error(-8, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.", self.nodes[0].prioritisetransaction, txid, 1, 0)
+
+ # Test `prioritisetransaction` invalid `fee_delta`
+ assert_raises_rpc_error(-1, "JSON value is not an integer as expected", self.nodes[0].prioritisetransaction, txid=txid, fee_delta='foo')
+
self.txouts = gen_return_txouts()
self.relayfee = self.nodes[0].getnetworkinfo()['relayfee']
@@ -97,11 +116,11 @@ class PrioritiseTransactionTest(BitcoinTestFramework):
inputs.append({"txid" : utxo["txid"], "vout" : utxo["vout"]})
outputs[self.nodes[0].getnewaddress()] = utxo["amount"]
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
- tx_hex = self.nodes[0].signrawtransaction(raw_tx)["hex"]
+ tx_hex = self.nodes[0].signrawtransactionwithwallet(raw_tx)["hex"]
tx_id = self.nodes[0].decoderawtransaction(tx_hex)["txid"]
# This will raise an exception due to min relay fee not being met
- assert_raises_rpc_error(-26, "66: min relay fee not met", self.nodes[0].sendrawtransaction, tx_hex)
+ assert_raises_rpc_error(-26, "min relay fee not met (code 66)", self.nodes[0].sendrawtransaction, tx_hex)
assert(tx_id not in self.nodes[0].getrawmempool())
# This is a less than 1000-byte transaction, so just set the fee
diff --git a/test/functional/node_network_limited.py b/test/functional/node_network_limited.py
deleted file mode 100755
index 70415e0168..0000000000
--- a/test/functional/node_network_limited.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2017 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-"""Tests NODE_NETWORK_LIMITED.
-
-Tests that a node configured with -prune=550 signals NODE_NETWORK_LIMITED correctly
-and that it responds to getdata requests for blocks correctly:
- - send a block within 288 + 2 of the tip
- - disconnect peers who request blocks older than that."""
-from test_framework.messages import CInv, msg_getdata
-from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal
-
-class P2PIgnoreInv(P2PInterface):
- def on_inv(self, message):
- # The node will send us invs for other blocks. Ignore them.
- pass
-
- def send_getdata_for_block(self, blockhash):
- getdata_request = msg_getdata()
- getdata_request.inv.append(CInv(2, int(blockhash, 16)))
- self.send_message(getdata_request)
-
-class NodeNetworkLimitedTest(BitcoinTestFramework):
- def set_test_params(self):
- self.setup_clean_chain = True
- self.num_nodes = 1
- self.extra_args = [['-prune=550']]
-
- def run_test(self):
- node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
- NetworkThread().start()
- node.wait_for_verack()
-
- expected_services = NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED
-
- self.log.info("Check that node has signalled expected services.")
- assert_equal(node.nServices, expected_services)
-
- self.log.info("Check that the localservices is as expected.")
- assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
-
- self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
- blocks = self.nodes[0].generate(292)
-
- self.log.info("Make sure we can max retrive block at tip-288.")
- node.send_getdata_for_block(blocks[1]) # last block in valid range
- node.wait_for_block(int(blocks[1], 16), timeout=3)
-
- self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
- node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
- node.wait_for_disconnect(5)
-
-if __name__ == '__main__':
- NodeNetworkLimitedTest().main()
diff --git a/test/functional/p2p-versionbits-warning.py b/test/functional/p2p-versionbits-warning.py
deleted file mode 100755
index 0bfe94622f..0000000000
--- a/test/functional/p2p-versionbits-warning.py
+++ /dev/null
@@ -1,121 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2016-2017 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 version bits warning system.
-
-Generate chains with block versions that appear to be signalling unknown
-soft-forks, and test that warning alerts are generated.
-"""
-
-from test_framework.mininode import *
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import *
-import re
-from test_framework.blocktools import create_block, create_coinbase
-
-VB_PERIOD = 144 # versionbits period length for regtest
-VB_THRESHOLD = 108 # versionbits activation threshold for regtest
-VB_TOP_BITS = 0x20000000
-VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
-
-WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
-WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})".format(VB_UNKNOWN_BIT)
-VB_PATTERN = re.compile("^Warning.*versionbit")
-
-class TestNode(P2PInterface):
- def on_inv(self, message):
- pass
-
-class VersionBitsWarningTest(BitcoinTestFramework):
- def set_test_params(self):
- self.setup_clean_chain = True
- self.num_nodes = 1
-
- def setup_network(self):
- self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
- # Open and close to create zero-length file
- with open(self.alert_filename, 'w', encoding='utf8') as _:
- pass
- self.extra_args = [["-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
- self.setup_nodes()
-
- # Send numblocks blocks via peer with nVersionToUse set.
- def send_blocks_with_version(self, peer, numblocks, nVersionToUse):
- tip = self.nodes[0].getbestblockhash()
- height = self.nodes[0].getblockcount()
- block_time = self.nodes[0].getblockheader(tip)["time"]+1
- tip = int(tip, 16)
-
- for _ in range(numblocks):
- block = create_block(tip, create_coinbase(height+1), block_time)
- block.nVersion = nVersionToUse
- block.solve()
- peer.send_message(msg_block(block))
- block_time += 1
- height += 1
- tip = block.sha256
- peer.sync_with_ping()
-
- def test_versionbits_in_alert_file(self):
- with open(self.alert_filename, 'r', encoding='utf8') as f:
- alert_text = f.read()
- assert(VB_PATTERN.match(alert_text))
-
- def run_test(self):
- # Setup the p2p connection and start up the network thread.
- self.nodes[0].add_p2p_connection(TestNode())
-
- network_thread_start()
-
- # Test logic begins here
- self.nodes[0].p2p.wait_for_verack()
-
- # 1. Have the node mine one period worth of blocks
- self.nodes[0].generate(VB_PERIOD)
-
- # 2. Now build one period of blocks on the tip, with < VB_THRESHOLD
- # blocks signaling some unknown bit.
- nVersion = VB_TOP_BITS | (1<<VB_UNKNOWN_BIT)
- self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD-1, nVersion)
-
- # Fill rest of period with regular version blocks
- self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
- # Check that we're not getting any versionbit-related errors in
- # get*info()
- assert(not VB_PATTERN.match(self.nodes[0].getmininginfo()["warnings"]))
- assert(not VB_PATTERN.match(self.nodes[0].getnetworkinfo()["warnings"]))
-
- # 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
- # some unknown bit
- self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD, nVersion)
- self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD)
- # Might not get a versionbits-related alert yet, as we should
- # have gotten a different alert due to more than 51/100 blocks
- # being of unexpected version.
- # Check that get*info() shows some kind of error.
- assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getmininginfo()["warnings"])
- assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getnetworkinfo()["warnings"])
-
- # Mine a period worth of expected blocks so the generic block-version warning
- # is cleared, and restart the node. This should move the versionbit state
- # to ACTIVE.
- self.nodes[0].generate(VB_PERIOD)
- self.stop_nodes()
- # Empty out the alert file
- with open(self.alert_filename, 'w', encoding='utf8') as _:
- pass
- self.start_nodes()
-
- # Connecting one block should be enough to generate an error.
- self.nodes[0].generate(1)
- assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getmininginfo()["warnings"])
- assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getnetworkinfo()["warnings"])
- self.stop_nodes()
- self.test_versionbits_in_alert_file()
-
- # Test framework expects the node to still be running...
- self.start_nodes()
-
-if __name__ == '__main__':
- VersionBitsWarningTest().main()
diff --git a/test/functional/p2p-compactblocks.py b/test/functional/p2p_compactblocks.py
index e98ae31a89..d9f461a049 100755
--- a/test/functional/p2p-compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -95,7 +95,7 @@ class CompactBlocksTest(BitcoinTestFramework):
self.num_nodes = 2
# This test was written assuming SegWit is activated using BIP9 at height 432 (3x confirmation window).
# TODO: Rewrite this test to support SegWit being always active.
- self.extra_args = [["-vbparams=segwit:0:0"], ["-vbparams=segwit:0:999999999999", "-txindex"]]
+ self.extra_args = [["-vbparams=segwit:0:0"], ["-vbparams=segwit:0:999999999999", "-txindex", "-deprecatedrpc=addwitnessaddress"]]
self.utxos = []
def build_block_on_tip(self, node, segwit=False):
diff --git a/test/functional/disconnect_ban.py b/test/functional/p2p_disconnect_ban.py
index c6067befb2..c6067befb2 100755
--- a/test/functional/disconnect_ban.py
+++ b/test/functional/p2p_disconnect_ban.py
diff --git a/test/functional/p2p-feefilter.py b/test/functional/p2p_feefilter.py
index 47d9c55160..47d9c55160 100755
--- a/test/functional/p2p-feefilter.py
+++ b/test/functional/p2p_feefilter.py
diff --git a/test/functional/p2p-fingerprint.py b/test/functional/p2p_fingerprint.py
index 93ef73e25e..516ce8555b 100755
--- a/test/functional/p2p-fingerprint.py
+++ b/test/functional/p2p_fingerprint.py
@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test various fingerprinting protections.
-If an stale block more than a month old or its header are requested by a peer,
+If a stale block more than a month old or its header are requested by a peer,
the node should pretend that it does not have it to avoid fingerprinting.
"""
diff --git a/test/functional/invalidblockrequest.py b/test/functional/p2p_invalid_block.py
index edcade63c1..edcade63c1 100755
--- a/test/functional/invalidblockrequest.py
+++ b/test/functional/p2p_invalid_block.py
diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py
new file mode 100755
index 0000000000..64fada38e2
--- /dev/null
+++ b/test/functional/p2p_invalid_tx.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# Copyright (c) 2015-2017 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 node responses to invalid transactions.
+
+In this test we connect to one node over p2p, and test tx requests."""
+from test_framework.blocktools import create_block, create_coinbase, create_transaction
+from test_framework.messages import COIN
+from test_framework.mininode import network_thread_start, P2PDataStore
+from test_framework.test_framework import BitcoinTestFramework
+
+class InvalidTxRequestTest(BitcoinTestFramework):
+
+ def set_test_params(self):
+ self.num_nodes = 1
+ self.setup_clean_chain = True
+ self.extra_args = [["-whitelist=127.0.0.1"]]
+
+ def run_test(self):
+ # Add p2p connection to node0
+ node = self.nodes[0] # convenience reference to the node
+ node.add_p2p_connection(P2PDataStore())
+
+ network_thread_start()
+ node.p2p.wait_for_verack()
+
+ best_block = self.nodes[0].getbestblockhash()
+ tip = int(best_block, 16)
+ best_block_time = self.nodes[0].getblock(best_block)['time']
+ block_time = best_block_time + 1
+
+ self.log.info("Create a new block with an anyone-can-spend coinbase.")
+ height = 1
+ block = create_block(tip, create_coinbase(height), block_time)
+ block_time += 1
+ block.solve()
+ # Save the coinbase for later
+ block1 = block
+ tip = block.sha256
+ height += 1
+ node.p2p.send_blocks_and_test([block], node, success=True)
+
+ self.log.info("Mature the block.")
+ self.nodes[0].generate(100)
+
+ # b'\x64' is OP_NOTIF
+ # Transaction will be rejected with code 16 (REJECT_INVALID)
+ tx1 = create_transaction(block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
+ node.p2p.send_txs_and_test([tx1], node, success=False, reject_code=16, reject_reason=b'mandatory-script-verify-flag-failed (Invalid OP_IF construction)')
+
+ # TODO: test further transactions...
+
+if __name__ == '__main__':
+ InvalidTxRequestTest().main()
diff --git a/test/functional/p2p-leaktests.py b/test/functional/p2p_leak.py
index ce4e6e9144..ce4e6e9144 100755
--- a/test/functional/p2p-leaktests.py
+++ b/test/functional/p2p_leak.py
diff --git a/test/functional/p2p-mempool.py b/test/functional/p2p_mempool.py
index 485a8af3d0..485a8af3d0 100755
--- a/test/functional/p2p-mempool.py
+++ b/test/functional/p2p_mempool.py
diff --git a/test/functional/p2p_node_network_limited.py b/test/functional/p2p_node_network_limited.py
new file mode 100755
index 0000000000..81a41d6a97
--- /dev/null
+++ b/test/functional/p2p_node_network_limited.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Tests NODE_NETWORK_LIMITED.
+
+Tests that a node configured with -prune=550 signals NODE_NETWORK_LIMITED correctly
+and that it responds to getdata requests for blocks correctly:
+ - send a block within 288 + 2 of the tip
+ - disconnect peers who request blocks older than that."""
+from test_framework.messages import CInv, msg_getdata, msg_verack
+from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, P2PInterface, wait_until, mininode_lock, network_thread_start, network_thread_join
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import assert_equal, disconnect_nodes, connect_nodes_bi, sync_blocks
+
+class P2PIgnoreInv(P2PInterface):
+ firstAddrnServices = 0
+ def on_inv(self, message):
+ # The node will send us invs for other blocks. Ignore them.
+ pass
+ def on_addr(self, message):
+ self.firstAddrnServices = message.addrs[0].nServices
+ def wait_for_addr(self, timeout=5):
+ test_function = lambda: self.last_message.get("addr")
+ wait_until(test_function, timeout=timeout, lock=mininode_lock)
+ def send_getdata_for_block(self, blockhash):
+ getdata_request = msg_getdata()
+ getdata_request.inv.append(CInv(2, int(blockhash, 16)))
+ self.send_message(getdata_request)
+
+class NodeNetworkLimitedTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 3
+ self.extra_args = [['-prune=550', '-addrmantest'], [], []]
+
+ def disconnect_all(self):
+ disconnect_nodes(self.nodes[0], 1)
+ disconnect_nodes(self.nodes[1], 0)
+ disconnect_nodes(self.nodes[2], 1)
+ disconnect_nodes(self.nodes[2], 0)
+ disconnect_nodes(self.nodes[0], 2)
+ disconnect_nodes(self.nodes[1], 2)
+
+ def setup_network(self):
+ super(NodeNetworkLimitedTest, self).setup_network()
+ self.disconnect_all()
+
+ def run_test(self):
+ node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
+ network_thread_start()
+ node.wait_for_verack()
+
+ expected_services = NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED
+
+ self.log.info("Check that node has signalled expected services.")
+ assert_equal(node.nServices, expected_services)
+
+ self.log.info("Check that the localservices is as expected.")
+ assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
+
+ self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
+ connect_nodes_bi(self.nodes, 0, 1)
+ blocks = self.nodes[1].generate(292)
+ sync_blocks([self.nodes[0], self.nodes[1]])
+
+ self.log.info("Make sure we can max retrive block at tip-288.")
+ node.send_getdata_for_block(blocks[1]) # last block in valid range
+ node.wait_for_block(int(blocks[1], 16), timeout=3)
+
+ self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
+ node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
+ node.wait_for_disconnect(5)
+
+ self.log.info("Check local address relay, do a fresh connection.")
+ self.nodes[0].disconnect_p2ps()
+ network_thread_join()
+ node1 = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
+ network_thread_start()
+ node1.wait_for_verack()
+ node1.send_message(msg_verack())
+
+ node1.wait_for_addr()
+ #must relay address with NODE_NETWORK_LIMITED
+ assert_equal(node1.firstAddrnServices, 1036)
+
+ self.nodes[0].disconnect_p2ps()
+ node1.wait_for_disconnect()
+
+ # connect unsynced node 2 with pruned NODE_NETWORK_LIMITED peer
+ # because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible
+ connect_nodes_bi(self.nodes, 0, 2)
+ try:
+ sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
+ except:
+ pass
+ # node2 must remain at heigh 0
+ assert_equal(self.nodes[2].getblockheader(self.nodes[2].getbestblockhash())['height'], 0)
+
+ # now connect also to node 1 (non pruned)
+ connect_nodes_bi(self.nodes, 1, 2)
+
+ # sync must be possible
+ sync_blocks(self.nodes)
+
+ # disconnect all peers
+ self.disconnect_all()
+
+ # mine 10 blocks on node 0 (pruned node)
+ self.nodes[0].generate(10)
+
+ # connect node1 (non pruned) with node0 (pruned) and check if the can sync
+ connect_nodes_bi(self.nodes, 0, 1)
+
+ # sync must be possible, node 1 is no longer in IBD and should therefore connect to node 0 (NODE_NETWORK_LIMITED)
+ sync_blocks([self.nodes[0], self.nodes[1]])
+
+if __name__ == '__main__':
+ NodeNetworkLimitedTest().main()
diff --git a/test/functional/p2p-segwit.py b/test/functional/p2p_segwit.py
index 2487fdc239..20e4805df0 100755
--- a/test/functional/p2p-segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -25,7 +25,7 @@ MAX_SIGOP_COST = 80000
# Calculate the virtual size of a witness block:
# (base + witness/4)
def get_virtual_size(witness_block):
- base_size = len(witness_block.serialize())
+ base_size = len(witness_block.serialize(with_witness=False))
total_size = len(witness_block.serialize(with_witness=True))
# the "+3" is so we round up
vsize = int((3*base_size + total_size + 3)/4)
@@ -1396,18 +1396,20 @@ class SegWitTest(BitcoinTestFramework):
temp_utxos.pop(0)
- # Update self.utxos for later tests. Just spend everything in
- # temp_utxos to a corresponding entry in self.utxos
+ # Update self.utxos for later tests by creating two outputs
+ # that consolidate all the coins in temp_utxos.
+ output_value = sum(i.nValue for i in temp_utxos) // 2
+
tx = CTransaction()
index = 0
+ # Just spend to our usual anyone-can-spend output
+ tx.vout = [CTxOut(output_value, CScript([OP_TRUE]))] * 2
for i in temp_utxos:
- # Just spend to our usual anyone-can-spend output
- # Use SIGHASH_SINGLE|SIGHASH_ANYONECANPAY so we can build up
+ # Use SIGHASH_ALL|SIGHASH_ANYONECANPAY so we can build up
# the signatures as we go.
tx.vin.append(CTxIn(COutPoint(i.sha256, i.n), b""))
- tx.vout.append(CTxOut(i.nValue, CScript([OP_TRUE])))
tx.wit.vtxinwit.append(CTxInWitness())
- sign_P2PK_witness_input(witness_program, tx, index, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, i.nValue, key)
+ sign_P2PK_witness_input(witness_program, tx, index, SIGHASH_ALL|SIGHASH_ANYONECANPAY, i.nValue, key)
index += 1
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
diff --git a/test/functional/sendheaders.py b/test/functional/p2p_sendheaders.py
index 8869aeaaea..8869aeaaea 100755
--- a/test/functional/sendheaders.py
+++ b/test/functional/p2p_sendheaders.py
diff --git a/test/functional/p2p-timeouts.py b/test/functional/p2p_timeouts.py
index 6d21095cc6..6d21095cc6 100755
--- a/test/functional/p2p-timeouts.py
+++ b/test/functional/p2p_timeouts.py
diff --git a/test/functional/p2p-acceptblock.py b/test/functional/p2p_unrequested_blocks.py
index 672626f15b..672626f15b 100755
--- a/test/functional/p2p-acceptblock.py
+++ b/test/functional/p2p_unrequested_blocks.py
diff --git a/test/functional/rpcbind_test.py b/test/functional/rpc_bind.py
index 05433c7e24..05433c7e24 100755
--- a/test/functional/rpcbind_test.py
+++ b/test/functional/rpc_bind.py
diff --git a/test/functional/blockchain.py b/test/functional/rpc_blockchain.py
index 11acff4be1..a9e14d3e3c 100755
--- a/test/functional/blockchain.py
+++ b/test/functional/rpc_blockchain.py
@@ -100,6 +100,24 @@ class BlockchainTest(BitcoinTestFramework):
assert_greater_than(res['size_on_disk'], 0)
def _test_getchaintxstats(self):
+ self.log.info("Test getchaintxstats")
+
+ # Test `getchaintxstats` invalid extra parameters
+ assert_raises_rpc_error(-1, 'getchaintxstats', self.nodes[0].getchaintxstats, 0, '', 0)
+
+ # Test `getchaintxstats` invalid `nblocks`
+ assert_raises_rpc_error(-1, "JSON value is not an integer as expected", self.nodes[0].getchaintxstats, '')
+ assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, -1)
+ assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, self.nodes[0].getblockcount())
+
+ # Test `getchaintxstats` invalid `blockhash`
+ assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[0].getchaintxstats, blockhash=0)
+ assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getchaintxstats, blockhash='0')
+ blockhash = self.nodes[0].getblockhash(200)
+ self.nodes[0].invalidateblock(blockhash)
+ assert_raises_rpc_error(-8, "Block is not in main chain", self.nodes[0].getchaintxstats, blockhash=blockhash)
+ self.nodes[0].reconsiderblock(blockhash)
+
chaintxstats = self.nodes[0].getchaintxstats(1)
# 200 txs plus genesis tx
assert_equal(chaintxstats['txcount'], 201)
@@ -107,28 +125,30 @@ class BlockchainTest(BitcoinTestFramework):
# we have to round because of binary math
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1))
- b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1))
- b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200))
+ b1_hash = self.nodes[0].getblockhash(1)
+ b1 = self.nodes[0].getblock(b1_hash)
+ b200_hash = self.nodes[0].getblockhash(200)
+ b200 = self.nodes[0].getblock(b200_hash)
time_diff = b200['mediantime'] - b1['mediantime']
chaintxstats = self.nodes[0].getchaintxstats()
assert_equal(chaintxstats['time'], b200['time'])
assert_equal(chaintxstats['txcount'], 201)
+ assert_equal(chaintxstats['window_final_block_hash'], b200_hash)
assert_equal(chaintxstats['window_block_count'], 199)
assert_equal(chaintxstats['window_tx_count'], 199)
assert_equal(chaintxstats['window_interval'], time_diff)
assert_equal(round(chaintxstats['txrate'] * time_diff, 10), Decimal(199))
- chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash'])
+ chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1_hash)
assert_equal(chaintxstats['time'], b1['time'])
assert_equal(chaintxstats['txcount'], 2)
+ assert_equal(chaintxstats['window_final_block_hash'], b1_hash)
assert_equal(chaintxstats['window_block_count'], 0)
assert('window_tx_count' not in chaintxstats)
assert('window_interval' not in chaintxstats)
assert('txrate' not in chaintxstats)
- assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
-
def _test_gettxoutsetinfo(self):
node = self.nodes[0]
res = node.gettxoutsetinfo()
@@ -173,8 +193,7 @@ class BlockchainTest(BitcoinTestFramework):
def _test_getblockheader(self):
node = self.nodes[0]
- assert_raises_rpc_error(-5, "Block not found",
- node.getblockheader, "nonsense")
+ assert_raises_rpc_error(-5, "Block not found", node.getblockheader, "nonsense")
besthash = node.getbestblockhash()
secondbesthash = node.getblockhash(199)
diff --git a/test/functional/decodescript.py b/test/functional/rpc_decodescript.py
index 1ffc570437..1ffc570437 100755
--- a/test/functional/decodescript.py
+++ b/test/functional/rpc_decodescript.py
diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py
new file mode 100755
index 0000000000..b94b9d8fae
--- /dev/null
+++ b/test/functional/rpc_deprecated.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 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 deprecation of RPC calls."""
+from test_framework.test_framework import BitcoinTestFramework
+
+class DeprecatedRpcTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 2
+ self.setup_clean_chain = True
+ self.extra_args = [[], ["-deprecatedrpc=validateaddress"]]
+
+ def run_test(self):
+ # This test should be used to verify correct behaviour of deprecated
+ # RPC methods with and without the -deprecatedrpc flags. For example:
+ #
+ # self.log.info("Make sure that -deprecatedrpc=createmultisig allows it to take addresses")
+ # assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, [self.nodes[0].getnewaddress()])
+ # self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
+
+ self.log.info("Test validateaddress deprecation")
+ SOME_ADDRESS = "mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu" # This is just some random address to pass as a parameter to validateaddress
+ dep_validate_address = self.nodes[0].validateaddress(SOME_ADDRESS)
+ assert "ismine" not in dep_validate_address
+ not_dep_val = self.nodes[1].validateaddress(SOME_ADDRESS)
+ assert "ismine" in not_dep_val
+
+if __name__ == '__main__':
+ DeprecatedRpcTest().main()
diff --git a/test/functional/fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py
index 4739e73c39..5fb9a361d9 100755
--- a/test/functional/fundrawtransaction.py
+++ b/test/functional/rpc_fundrawtransaction.py
@@ -53,7 +53,7 @@ class RawTransactionsTest(BitcoinTestFramework):
assert_equal(rawmatch["changepos"], -1)
watchonly_address = self.nodes[0].getnewaddress()
- watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
+ watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
watchonly_amount = Decimal(200)
self.nodes[3].importpubkey(watchonly_pubkey, "", True)
watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount)
@@ -181,6 +181,9 @@ class RawTransactionsTest(BitcoinTestFramework):
assert_raises_rpc_error(-3, "Unexpected key foo", self.nodes[2].fundrawtransaction, rawtx, {'foo':'bar'})
+ # reserveChangeKey was deprecated and is now removed
+ assert_raises_rpc_error(-3, "Unexpected key reserveChangeKey", lambda: self.nodes[2].fundrawtransaction(hexstring=rawtx, options={'reserveChangeKey': True}))
+
############################################################
# test a fundrawtransaction with an invalid change address #
############################################################
@@ -212,6 +215,19 @@ class RawTransactionsTest(BitcoinTestFramework):
out = dec_tx['vout'][0]
assert_equal(change, out['scriptPubKey']['addresses'][0])
+ #########################################################
+ # test a fundrawtransaction with a provided change type #
+ #########################################################
+ utx = get_unspent(self.nodes[2].listunspent(), 5)
+
+ inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
+ outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
+ rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
+ assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[2].fundrawtransaction, rawtx, {'change_type': None})
+ assert_raises_rpc_error(-5, "Unknown change type", self.nodes[2].fundrawtransaction, rawtx, {'change_type': ''})
+ rawtx = self.nodes[2].fundrawtransaction(rawtx, {'change_type': 'bech32'})
+ dec_tx = self.nodes[2].decoderawtransaction(rawtx['hex'])
+ assert_equal('witness_v0_keyhash', dec_tx['vout'][rawtx['changepos']]['scriptPubKey']['type'])
#########################################################################
# test a fundrawtransaction with a VIN smaller than the required amount #
@@ -355,10 +371,10 @@ class RawTransactionsTest(BitcoinTestFramework):
addr1 = self.nodes[1].getnewaddress()
addr2 = self.nodes[1].getnewaddress()
- addr1Obj = self.nodes[1].validateaddress(addr1)
- addr2Obj = self.nodes[1].validateaddress(addr2)
+ addr1Obj = self.nodes[1].getaddressinfo(addr1)
+ addr2Obj = self.nodes[1].getaddressinfo(addr2)
- mSigObj = self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
+ mSigObj = self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
inputs = []
outputs = {mSigObj:1.1}
@@ -385,13 +401,13 @@ class RawTransactionsTest(BitcoinTestFramework):
addr4 = self.nodes[1].getnewaddress()
addr5 = self.nodes[1].getnewaddress()
- addr1Obj = self.nodes[1].validateaddress(addr1)
- addr2Obj = self.nodes[1].validateaddress(addr2)
- addr3Obj = self.nodes[1].validateaddress(addr3)
- addr4Obj = self.nodes[1].validateaddress(addr4)
- addr5Obj = self.nodes[1].validateaddress(addr5)
+ addr1Obj = self.nodes[1].getaddressinfo(addr1)
+ addr2Obj = self.nodes[1].getaddressinfo(addr2)
+ addr3Obj = self.nodes[1].getaddressinfo(addr3)
+ addr4Obj = self.nodes[1].getaddressinfo(addr4)
+ addr5Obj = self.nodes[1].getaddressinfo(addr5)
- mSigObj = self.nodes[1].addmultisigaddress(4, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey'], addr4Obj['pubkey'], addr5Obj['pubkey']])
+ mSigObj = self.nodes[1].addmultisigaddress(4, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey'], addr4Obj['pubkey'], addr5Obj['pubkey']])['address']
inputs = []
outputs = {mSigObj:1.1}
@@ -415,10 +431,10 @@ class RawTransactionsTest(BitcoinTestFramework):
addr1 = self.nodes[2].getnewaddress()
addr2 = self.nodes[2].getnewaddress()
- addr1Obj = self.nodes[2].validateaddress(addr1)
- addr2Obj = self.nodes[2].validateaddress(addr2)
+ addr1Obj = self.nodes[2].getaddressinfo(addr1)
+ addr2Obj = self.nodes[2].getaddressinfo(addr2)
- mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
+ mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
# send 1.2 BTC to msig addr
@@ -433,7 +449,7 @@ class RawTransactionsTest(BitcoinTestFramework):
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
fundedTx = self.nodes[2].fundrawtransaction(rawtx)
- signedTx = self.nodes[2].signrawtransaction(fundedTx['hex'])
+ signedTx = self.nodes[2].signrawtransactionwithwallet(fundedTx['hex'])
txId = self.nodes[2].sendrawtransaction(signedTx['hex'])
self.sync_all()
self.nodes[1].generate(1)
@@ -487,7 +503,7 @@ class RawTransactionsTest(BitcoinTestFramework):
#now we need to unlock
self.nodes[1].walletpassphrase("test", 600)
- signedTx = self.nodes[1].signrawtransaction(fundedTx['hex'])
+ signedTx = self.nodes[1].signrawtransactionwithwallet(fundedTx['hex'])
txId = self.nodes[1].sendrawtransaction(signedTx['hex'])
self.nodes[1].generate(1)
self.sync_all()
@@ -548,7 +564,7 @@ class RawTransactionsTest(BitcoinTestFramework):
outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04}
rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
fundedTx = self.nodes[1].fundrawtransaction(rawtx)
- fundedAndSignedTx = self.nodes[1].signrawtransaction(fundedTx['hex'])
+ fundedAndSignedTx = self.nodes[1].signrawtransactionwithwallet(fundedTx['hex'])
txId = self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex'])
self.sync_all()
self.nodes[0].generate(1)
@@ -606,9 +622,9 @@ class RawTransactionsTest(BitcoinTestFramework):
assert_greater_than(result["changepos"], -1)
assert_equal(result["fee"] + res_dec["vout"][result["changepos"]]["value"], watchonly_amount / 10)
- signedtx = self.nodes[3].signrawtransaction(result["hex"])
+ signedtx = self.nodes[3].signrawtransactionwithwallet(result["hex"])
assert(not signedtx["complete"])
- signedtx = self.nodes[0].signrawtransaction(signedtx["hex"])
+ signedtx = self.nodes[0].signrawtransactionwithwallet(signedtx["hex"])
assert(signedtx["complete"])
self.nodes[0].sendrawtransaction(signedtx["hex"])
self.nodes[0].generate(1)
@@ -663,7 +679,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee}),
self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee, "subtractFeeFromOutputs": [0]})]
- dec_tx = [self.nodes[3].decoderawtransaction(tx['hex']) for tx in result]
+ dec_tx = [self.nodes[3].decoderawtransaction(tx_['hex']) for tx_ in result]
output = [d['vout'][1 - r['changepos']]['value'] for d, r in zip(dec_tx, result)]
change = [d['vout'][r['changepos']]['value'] for d, r in zip(dec_tx, result)]
diff --git a/test/functional/getchaintips.py b/test/functional/rpc_getchaintips.py
index 277930bb1a..277930bb1a 100755
--- a/test/functional/getchaintips.py
+++ b/test/functional/rpc_getchaintips.py
diff --git a/test/functional/invalidateblock.py b/test/functional/rpc_invalidateblock.py
index b037c2431d..b037c2431d 100755
--- a/test/functional/invalidateblock.py
+++ b/test/functional/rpc_invalidateblock.py
diff --git a/test/functional/listtransactions.py b/test/functional/rpc_listtransactions.py
index cbed065928..0dd7372e6b 100755
--- a/test/functional/listtransactions.py
+++ b/test/functional/rpc_listtransactions.py
@@ -81,7 +81,8 @@ class ListTransactionsTest(BitcoinTestFramework):
{"category":"receive","amount":Decimal("0.44")},
{"txid":txid, "account" : "toself"} )
- multisig = self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
+ pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
+ multisig = self.nodes[1].createmultisig(1, [pubkey])
self.nodes[0].importaddress(multisig["redeemScript"], "watchonly", False, True)
txid = self.nodes[1].sendtoaddress(multisig["address"], 0.1)
self.nodes[1].generate(1)
@@ -130,7 +131,7 @@ class ListTransactionsTest(BitcoinTestFramework):
inputs = [{"txid":utxo_to_use["txid"], "vout":utxo_to_use["vout"]}]
outputs = {self.nodes[0].getnewaddress(): 0.999}
tx2 = self.nodes[1].createrawtransaction(inputs, outputs)
- tx2_signed = self.nodes[1].signrawtransaction(tx2)["hex"]
+ tx2_signed = self.nodes[1].signrawtransactionwithwallet(tx2)["hex"]
txid_2 = self.nodes[1].sendrawtransaction(tx2_signed)
# ...and check the result
@@ -147,7 +148,7 @@ class ListTransactionsTest(BitcoinTestFramework):
tx3_modified = txFromHex(tx3)
tx3_modified.vin[0].nSequence = 0
tx3 = bytes_to_hex_str(tx3_modified.serialize())
- tx3_signed = self.nodes[0].signrawtransaction(tx3)['hex']
+ tx3_signed = self.nodes[0].signrawtransactionwithwallet(tx3)['hex']
txid_3 = self.nodes[0].sendrawtransaction(tx3_signed)
assert(is_opt_in(self.nodes[0], txid_3))
@@ -161,7 +162,7 @@ class ListTransactionsTest(BitcoinTestFramework):
inputs = [{"txid": txid_3, "vout":utxo_to_use["vout"]}]
outputs = {self.nodes[0].getnewaddress(): 0.997}
tx4 = self.nodes[1].createrawtransaction(inputs, outputs)
- tx4_signed = self.nodes[1].signrawtransaction(tx4)["hex"]
+ tx4_signed = self.nodes[1].signrawtransactionwithwallet(tx4)["hex"]
txid_4 = self.nodes[1].sendrawtransaction(tx4_signed)
assert(not is_opt_in(self.nodes[1], txid_4))
@@ -173,7 +174,7 @@ class ListTransactionsTest(BitcoinTestFramework):
tx3_b = tx3_modified
tx3_b.vout[0].nValue -= int(Decimal("0.004") * COIN) # bump the fee
tx3_b = bytes_to_hex_str(tx3_b.serialize())
- tx3_b_signed = self.nodes[0].signrawtransaction(tx3_b)['hex']
+ tx3_b_signed = self.nodes[0].signrawtransactionwithwallet(tx3_b)['hex']
txid_3b = self.nodes[0].sendrawtransaction(tx3_b_signed, True)
assert(is_opt_in(self.nodes[0], txid_3b))
diff --git a/test/functional/rpcnamedargs.py b/test/functional/rpc_named_arguments.py
index 97bee39614..97bee39614 100755
--- a/test/functional/rpcnamedargs.py
+++ b/test/functional/rpc_named_arguments.py
diff --git a/test/functional/net.py b/test/functional/rpc_net.py
index 16e4f6adb4..16e4f6adb4 100755
--- a/test/functional/net.py
+++ b/test/functional/rpc_net.py
diff --git a/test/functional/preciousblock.py b/test/functional/rpc_preciousblock.py
index 960cd0ad12..960cd0ad12 100755
--- a/test/functional/preciousblock.py
+++ b/test/functional/rpc_preciousblock.py
diff --git a/test/functional/rawtransactions.py b/test/functional/rpc_rawtransaction.py
index 073ed394c1..e074f5bd74 100755
--- a/test/functional/rawtransactions.py
+++ b/test/functional/rpc_rawtransaction.py
@@ -6,7 +6,7 @@
Test the following RPCs:
- createrawtransaction
- - signrawtransaction
+ - signrawtransactionwithwallet
- sendrawtransaction
- decoderawtransaction
- getrawtransaction
@@ -39,6 +39,7 @@ class RawTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
+ self.extra_args = [["-addresstype=legacy"], ["-addresstype=legacy"], ["-addresstype=legacy"]]
def setup_network(self, split=False):
super().setup_network()
@@ -58,6 +59,10 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[0].generate(5)
self.sync_all()
+ # Test getrawtransaction on genesis block coinbase returns an error
+ block = self.nodes[0].getblock(self.nodes[0].getblockhash(0))
+ assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", self.nodes[0].getrawtransaction, block['merkleroot'])
+
# Test `createrawtransaction` required parameters
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction)
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [])
@@ -99,7 +104,7 @@ class RawTransactionsTest(BitcoinTestFramework):
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1}] #won't exists
outputs = { self.nodes[0].getnewaddress() : 4.998 }
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
- rawtx = self.nodes[2].signrawtransaction(rawtx)
+ rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx)
# This will raise an exception since there are missing inputs
assert_raises_rpc_error(-25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex'])
@@ -141,10 +146,15 @@ class RawTransactionsTest(BitcoinTestFramework):
addr1 = self.nodes[2].getnewaddress()
addr2 = self.nodes[2].getnewaddress()
- addr1Obj = self.nodes[2].validateaddress(addr1)
- addr2Obj = self.nodes[2].validateaddress(addr2)
+ addr1Obj = self.nodes[2].getaddressinfo(addr1)
+ addr2Obj = self.nodes[2].getaddressinfo(addr2)
+
+ # Tests for createmultisig and addmultisigaddress
+ assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, ["01020304"])
+ self.nodes[0].createmultisig(2, [addr1Obj['pubkey'], addr2Obj['pubkey']]) # createmultisig can only take public keys
+ assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 2, [addr1Obj['pubkey'], addr1]) # addmultisigaddress can take both pubkeys and addresses so long as they are in the wallet, which is tested here.
- mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
+ mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr1])['address']
#use balance deltas instead of absolute values
bal = self.nodes[2].getbalance()
@@ -163,11 +173,11 @@ class RawTransactionsTest(BitcoinTestFramework):
addr2 = self.nodes[2].getnewaddress()
addr3 = self.nodes[2].getnewaddress()
- addr1Obj = self.nodes[1].validateaddress(addr1)
- addr2Obj = self.nodes[2].validateaddress(addr2)
- addr3Obj = self.nodes[2].validateaddress(addr3)
+ addr1Obj = self.nodes[1].getaddressinfo(addr1)
+ addr2Obj = self.nodes[2].getaddressinfo(addr2)
+ addr3Obj = self.nodes[2].getaddressinfo(addr3)
- mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey']])
+ mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey']])['address']
txId = self.nodes[0].sendtoaddress(mSigObj, 2.2)
decTx = self.nodes[0].gettransaction(txId)
@@ -176,7 +186,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[0].generate(1)
self.sync_all()
- #THIS IS A INCOMPLETE FEATURE
+ #THIS IS AN INCOMPLETE FEATURE
#NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable
@@ -189,13 +199,13 @@ class RawTransactionsTest(BitcoinTestFramework):
break
bal = self.nodes[0].getbalance()
- inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex']}]
+ inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "amount" : vout['value']}]
outputs = { self.nodes[0].getnewaddress() : 2.19 }
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
- rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs)
+ rawTxPartialSigned = self.nodes[1].signrawtransactionwithwallet(rawTx, inputs)
assert_equal(rawTxPartialSigned['complete'], False) #node1 only has one key, can't comp. sign the tx
- rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs)
+ rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx, inputs)
assert_equal(rawTxSigned['complete'], True) #node2 can sign the tx compl., own two of three keys
self.nodes[2].sendrawtransaction(rawTxSigned['hex'])
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
@@ -209,12 +219,12 @@ class RawTransactionsTest(BitcoinTestFramework):
addr1 = self.nodes[1].getnewaddress()
addr2 = self.nodes[2].getnewaddress()
- addr1Obj = self.nodes[1].validateaddress(addr1)
- addr2Obj = self.nodes[2].validateaddress(addr2)
+ addr1Obj = self.nodes[1].getaddressinfo(addr1)
+ addr2Obj = self.nodes[2].getaddressinfo(addr2)
- self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
- mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
- mSigObjValid = self.nodes[2].validateaddress(mSigObj)
+ self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
+ mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
+ mSigObjValid = self.nodes[2].getaddressinfo(mSigObj)
txId = self.nodes[0].sendtoaddress(mSigObj, 2.2)
decTx = self.nodes[0].gettransaction(txId)
@@ -234,14 +244,14 @@ class RawTransactionsTest(BitcoinTestFramework):
break
bal = self.nodes[0].getbalance()
- inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "redeemScript" : mSigObjValid['hex']}]
+ inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "redeemScript" : mSigObjValid['hex'], "amount" : vout['value']}]
outputs = { self.nodes[0].getnewaddress() : 2.19 }
rawTx2 = self.nodes[2].createrawtransaction(inputs, outputs)
- rawTxPartialSigned1 = self.nodes[1].signrawtransaction(rawTx2, inputs)
+ rawTxPartialSigned1 = self.nodes[1].signrawtransactionwithwallet(rawTx2, inputs)
self.log.info(rawTxPartialSigned1)
assert_equal(rawTxPartialSigned['complete'], False) #node1 only has one key, can't comp. sign the tx
- rawTxPartialSigned2 = self.nodes[2].signrawtransaction(rawTx2, inputs)
+ rawTxPartialSigned2 = self.nodes[2].signrawtransactionwithwallet(rawTx2, inputs)
self.log.info(rawTxPartialSigned2)
assert_equal(rawTxPartialSigned2['complete'], False) #node2 only has one key, can't comp. sign the tx
rawTxComb = self.nodes[2].combinerawtransaction([rawTxPartialSigned1['hex'], rawTxPartialSigned2['hex']])
diff --git a/test/functional/signmessages.py b/test/functional/rpc_signmessage.py
index c1939b432b..5b6935ceea 100755
--- a/test/functional/signmessages.py
+++ b/test/functional/rpc_signmessage.py
@@ -11,6 +11,7 @@ class SignMessagesTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
+ self.extra_args = [["-addresstype=legacy"]]
def run_test(self):
message = 'This is just a test message'
diff --git a/test/functional/signrawtransactions.py b/test/functional/rpc_signrawtransaction.py
index dd0fa6c02c..18829ef4b8 100755
--- a/test/functional/signrawtransactions.py
+++ b/test/functional/rpc_signrawtransaction.py
@@ -2,7 +2,7 @@
# Copyright (c) 2015-2017 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 transaction signing using the signrawtransaction RPC."""
+"""Test transaction signing using the signrawtransaction* RPCs."""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
@@ -12,6 +12,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
+ self.extra_args = [["-deprecatedrpc=signrawtransaction"]]
def successful_signing_test(self):
"""Create and sign a valid raw transaction with one input.
@@ -33,15 +34,18 @@ class SignRawTransactionsTest(BitcoinTestFramework):
outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1}
rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
- rawTxSigned = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys)
+ rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, inputs)
# 1) The transaction has a complete set of signatures
- assert 'complete' in rawTxSigned
- assert_equal(rawTxSigned['complete'], True)
+ assert rawTxSigned['complete']
# 2) No script verification error occurred
assert 'errors' not in rawTxSigned
+ # Perform the same test on signrawtransaction
+ rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys)
+ assert_equal(rawTxSigned, rawTxSigned2)
+
def script_verification_error_test(self):
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.
@@ -84,11 +88,10 @@ class SignRawTransactionsTest(BitcoinTestFramework):
# Make sure decoderawtransaction throws if there is extra data
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, rawTx + "00")
- rawTxSigned = self.nodes[0].signrawtransaction(rawTx, scripts, privKeys)
+ rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, scripts)
# 3) The transaction has no complete set of signatures
- assert 'complete' in rawTxSigned
- assert_equal(rawTxSigned['complete'], False)
+ assert not rawTxSigned['complete']
# 4) Two script verification errors occurred
assert 'errors' in rawTxSigned
@@ -109,14 +112,17 @@ class SignRawTransactionsTest(BitcoinTestFramework):
assert_equal(rawTxSigned['errors'][1]['vout'], inputs[2]['vout'])
assert not rawTxSigned['errors'][0]['witness']
+ # Perform same test with signrawtransaction
+ rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, scripts, privKeys)
+ assert_equal(rawTxSigned, rawTxSigned2)
+
# Now test signing failure for transaction with input witnesses
p2wpkh_raw_tx = "01000000000102fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000494830450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac000247304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee0121025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee635711000000"
- rawTxSigned = self.nodes[0].signrawtransaction(p2wpkh_raw_tx)
+ rawTxSigned = self.nodes[0].signrawtransactionwithwallet(p2wpkh_raw_tx)
# 7) The transaction has no complete set of signatures
- assert 'complete' in rawTxSigned
- assert_equal(rawTxSigned['complete'], False)
+ assert not rawTxSigned['complete']
# 8) Two script verification errors occurred
assert 'errors' in rawTxSigned
@@ -134,6 +140,10 @@ class SignRawTransactionsTest(BitcoinTestFramework):
assert_equal(rawTxSigned['errors'][1]['witness'], ["304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01", "025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357"])
assert not rawTxSigned['errors'][0]['witness']
+ # Perform same test with signrawtransaction
+ rawTxSigned2 = self.nodes[0].signrawtransaction(p2wpkh_raw_tx)
+ assert_equal(rawTxSigned, rawTxSigned2)
+
def run_test(self):
self.successful_signing_test()
self.script_verification_error_test()
diff --git a/test/functional/merkle_blocks.py b/test/functional/rpc_txoutproof.py
index 50e0371fdf..c52a7397dc 100755
--- a/test/functional/merkle_blocks.py
+++ b/test/functional/rpc_txoutproof.py
@@ -34,9 +34,9 @@ class MerkleBlockTest(BitcoinTestFramework):
node0utxos = self.nodes[0].listunspent(1)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
- txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
+ txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransactionwithwallet(tx1)["hex"])
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
- txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"])
+ txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransactionwithwallet(tx2)["hex"])
# This will raise an exception because the transaction is not yet in a block
assert_raises_rpc_error(-5, "Transaction not yet in block", self.nodes[0].gettxoutproof, [txid1])
@@ -55,7 +55,7 @@ class MerkleBlockTest(BitcoinTestFramework):
txin_spent = self.nodes[1].listunspent(1).pop()
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 49.98})
- txid3 = self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
+ txid3 = self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransactionwithwallet(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()
diff --git a/test/functional/uptime.py b/test/functional/rpc_uptime.py
index 78236b2393..78236b2393 100755
--- a/test/functional/uptime.py
+++ b/test/functional/rpc_uptime.py
diff --git a/test/functional/multi_rpc.py b/test/functional/rpc_users.py
index 01f68344ae..01f68344ae 100755
--- a/test/functional/multi_rpc.py
+++ b/test/functional/rpc_users.py
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index 93af0037e9..43982cd09a 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -4,8 +4,24 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for manipulating blocks and transactions."""
+from .address import (
+ key_to_p2sh_p2wpkh,
+ key_to_p2wpkh,
+ script_to_p2sh_p2wsh,
+ script_to_p2wsh,
+)
from .mininode import *
-from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN
+from .script import (
+ CScript,
+ OP_0,
+ OP_1,
+ OP_CHECKMULTISIG,
+ OP_CHECKSIG,
+ OP_RETURN,
+ OP_TRUE,
+ hash160,
+)
+from .util import assert_equal
# Create a block (with regtest difficulty)
def create_block(hashprev, coinbase, nTime=None):
@@ -108,3 +124,49 @@ def get_legacy_sigopcount_tx(tx, fAccurate=True):
# scriptSig might be of type bytes, so convert to CScript for the moment
count += CScript(j.scriptSig).GetSigOpCount(fAccurate)
return count
+
+# Create a scriptPubKey corresponding to either a P2WPKH output for the
+# given pubkey, or a P2WSH output of a 1-of-1 multisig for the given
+# pubkey. Returns the hex encoding of the scriptPubKey.
+def witness_script(use_p2wsh, pubkey):
+ if (use_p2wsh == False):
+ # P2WPKH instead
+ pubkeyhash = hash160(hex_str_to_bytes(pubkey))
+ pkscript = CScript([OP_0, pubkeyhash])
+ else:
+ # 1-of-1 multisig
+ witness_program = CScript([OP_1, hex_str_to_bytes(pubkey), OP_1, OP_CHECKMULTISIG])
+ scripthash = sha256(witness_program)
+ pkscript = CScript([OP_0, scripthash])
+ return bytes_to_hex_str(pkscript)
+
+# Return a transaction (in hex) that spends the given utxo to a segwit output,
+# optionally wrapping the segwit output using P2SH.
+def create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount):
+ if use_p2wsh:
+ program = CScript([OP_1, hex_str_to_bytes(pubkey), OP_1, OP_CHECKMULTISIG])
+ addr = script_to_p2sh_p2wsh(program) if encode_p2sh else script_to_p2wsh(program)
+ else:
+ addr = key_to_p2sh_p2wpkh(pubkey) if encode_p2sh else key_to_p2wpkh(pubkey)
+ if not encode_p2sh:
+ assert_equal(node.getaddressinfo(addr)['scriptPubKey'], witness_script(use_p2wsh, pubkey))
+ return node.createrawtransaction([utxo], {addr: amount})
+
+# Create a transaction spending a given utxo to a segwit output corresponding
+# to the given pubkey: use_p2wsh determines whether to use P2WPKH or P2WSH;
+# encode_p2sh determines whether to wrap in P2SH.
+# sign=True will have the given node sign the transaction.
+# insert_redeem_script will be added to the scriptSig, if given.
+def send_to_witness(use_p2wsh, node, utxo, pubkey, encode_p2sh, amount, sign=True, insert_redeem_script=""):
+ tx_to_witness = create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount)
+ if (sign):
+ signed = node.signrawtransactionwithwallet(tx_to_witness)
+ assert("errors" not in signed or len(["errors"]) == 0)
+ return node.sendrawtransaction(signed["hex"])
+ else:
+ if (insert_redeem_script):
+ tx = FromHex(CTransaction(), tx_to_witness)
+ tx.vin[0].scriptSig += CScript([hex_str_to_bytes(insert_redeem_script)])
+ tx_to_witness = ToHex(tx)
+
+ return node.sendrawtransaction(tx_to_witness)
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py
index d8032e4430..e032be1337 100644..100755
--- a/test/functional/test_framework/messages.py
+++ b/test/functional/test_framework/messages.py
@@ -44,6 +44,11 @@ NODE_UNSUPPORTED_SERVICE_BIT_5 = (1 << 5)
NODE_UNSUPPORTED_SERVICE_BIT_7 = (1 << 7)
NODE_NETWORK_LIMITED = (1 << 10)
+MSG_TX = 1
+MSG_BLOCK = 2
+MSG_WITNESS_FLAG = 1 << 30
+MSG_TYPE_MASK = 0xffffffff >> 2
+
# Serialization/deserialization tools
def sha256(s):
return hashlib.new('sha256', s).digest()
@@ -181,19 +186,24 @@ def ToHex(obj):
class CAddress():
def __init__(self):
+ self.time = 0
self.nServices = 1
self.pchReserved = b"\x00" * 10 + b"\xff" * 2
self.ip = "0.0.0.0"
self.port = 0
- def deserialize(self, f):
+ def deserialize(self, f, with_time=True):
+ if with_time:
+ self.time = struct.unpack("<i", f.read(4))[0]
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.pchReserved = f.read(12)
self.ip = socket.inet_ntoa(f.read(4))
self.port = struct.unpack(">H", f.read(2))[0]
- def serialize(self):
+ def serialize(self, with_time=True):
r = b""
+ if with_time:
+ r += struct.pack("<i", self.time)
r += struct.pack("<Q", self.nServices)
r += self.pchReserved
r += socket.inet_aton(self.ip)
@@ -204,8 +214,6 @@ class CAddress():
return "CAddress(nServices=%i ip=%s port=%i)" % (self.nServices,
self.ip, self.port)
-MSG_WITNESS_FLAG = 1<<30
-
class CInv():
typemap = {
0: "Error",
@@ -453,10 +461,10 @@ class CTransaction():
r += struct.pack("<I", self.nLockTime)
return r
- # Regular serialization is without witness -- must explicitly
- # call serialize_with_witness to include witness data.
+ # Regular serialization is with witness -- must explicitly
+ # call serialize_without_witness to exclude witness data.
def serialize(self):
- return self.serialize_without_witness()
+ return self.serialize_with_witness()
# Recalculate the txid (transaction hash without witness)
def rehash(self):
@@ -472,7 +480,7 @@ class CTransaction():
if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(self.serialize_without_witness()))
- self.hash = encode(hash256(self.serialize())[::-1], 'hex_codec').decode('ascii')
+ self.hash = encode(hash256(self.serialize_without_witness())[::-1], 'hex_codec').decode('ascii')
def is_valid(self):
self.calc_sha256()
@@ -569,7 +577,7 @@ class CBlock(CBlockHeader):
if with_witness:
r += ser_vector(self.vtx, "serialize_with_witness")
else:
- r += ser_vector(self.vtx)
+ r += ser_vector(self.vtx, "serialize_without_witness")
return r
# Calculate the merkle root given a vector of transaction hashes
@@ -636,7 +644,7 @@ class PrefilledTransaction():
self.tx = CTransaction()
self.tx.deserialize(f)
- def serialize(self, with_witness=False):
+ def serialize(self, with_witness=True):
r = b""
r += ser_compact_size(self.index)
if with_witness:
@@ -645,6 +653,9 @@ class PrefilledTransaction():
r += self.tx.serialize_without_witness()
return r
+ def serialize_without_witness(self):
+ return self.serialize(with_witness=False)
+
def serialize_with_witness(self):
return self.serialize(with_witness=True)
@@ -684,7 +695,7 @@ class P2PHeaderAndShortIDs():
if with_witness:
r += ser_vector(self.prefilled_txn, "serialize_with_witness")
else:
- r += ser_vector(self.prefilled_txn)
+ r += ser_vector(self.prefilled_txn, "serialize_without_witness")
return r
def __repr__(self):
@@ -815,13 +826,13 @@ class BlockTransactions():
self.blockhash = deser_uint256(f)
self.transactions = deser_vector(f, CTransaction)
- def serialize(self, with_witness=False):
+ def serialize(self, with_witness=True):
r = b""
r += ser_uint256(self.blockhash)
if with_witness:
r += ser_vector(self.transactions, "serialize_with_witness")
else:
- r += ser_vector(self.transactions)
+ r += ser_vector(self.transactions, "serialize_without_witness")
return r
def __repr__(self):
@@ -850,11 +861,11 @@ class msg_version():
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.nTime = struct.unpack("<q", f.read(8))[0]
self.addrTo = CAddress()
- self.addrTo.deserialize(f)
+ self.addrTo.deserialize(f, False)
if self.nVersion >= 106:
self.addrFrom = CAddress()
- self.addrFrom.deserialize(f)
+ self.addrFrom.deserialize(f, False)
self.nNonce = struct.unpack("<Q", f.read(8))[0]
self.strSubVer = deser_string(f)
else:
@@ -882,8 +893,8 @@ class msg_version():
r += struct.pack("<i", self.nVersion)
r += struct.pack("<Q", self.nServices)
r += struct.pack("<q", self.nTime)
- r += self.addrTo.serialize()
- r += self.addrFrom.serialize()
+ r += self.addrTo.serialize(False)
+ r += self.addrFrom.serialize(False)
r += struct.pack("<Q", self.nNonce)
r += ser_string(self.strSubVer)
r += struct.pack("<i", self.nStartingHeight)
@@ -1021,7 +1032,7 @@ class msg_block():
self.block.deserialize(f)
def serialize(self):
- return self.block.serialize()
+ return self.block.serialize(with_witness=False)
def __repr__(self):
return "msg_block(block=%s)" % (repr(self.block))
@@ -1292,7 +1303,7 @@ class msg_blocktxn():
def serialize(self):
r = b""
- r += self.block_transactions.serialize()
+ r += self.block_transactions.serialize(with_witness=False)
return r
def __repr__(self):
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index fe14591139..99d0abc3f9 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -6,11 +6,13 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Bitcoin P2P network half-a-node.
-This python code was modified from ArtForz' public domain half-a-node, as
+This python code was modified from ArtForz' public domain half-a-node, as
found in the mini-node branch of http://github.com/jgarzik/pynode.
P2PConnection: A low-level connection object to a node's P2P interface
-P2PInterface: A high-level interface object for communicating to a node over P2P"""
+P2PInterface: A high-level interface object for communicating to a node over P2P
+P2PDataStore: A p2p interface class that keeps a store of transactions and blocks
+ and can respond correctly to getdata and getheaders messages"""
import asyncore
from collections import defaultdict
from io import BytesIO
@@ -86,7 +88,7 @@ class P2PConnection(asyncore.dispatcher):
self.network = net
self.disconnect = False
- logger.info('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport))
+ logger.debug('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport))
try:
self.connect((dstaddr, dstport))
@@ -356,10 +358,22 @@ class P2PInterface(P2PConnection):
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_getdata(self, timeout=60):
+ """Waits for a getdata message.
+
+ Receiving any getdata message will satisfy the predicate. the last_message["getdata"]
+ value must be explicitly cleared before calling this method, or this will return
+ immediately with success. TODO: change this method to take a hash value and only
+ return true if the correct block/tx has been requested."""
test_function = lambda: self.last_message.get("getdata")
wait_until(test_function, timeout=timeout, lock=mininode_lock)
def wait_for_getheaders(self, timeout=60):
+ """Waits for a getheaders message.
+
+ Receiving any getheaders message will satisfy the predicate. the last_message["getheaders"]
+ value must be explicitly cleared before calling this method, or this will return
+ immediately with success. TODO: change this method to take a hash value and only
+ return true if the correct block header has been requested."""
test_function = lambda: self.last_message.get("getheaders")
wait_until(test_function, timeout=timeout, lock=mininode_lock)
@@ -440,3 +454,138 @@ def network_thread_join(timeout=10):
for thread in network_threads:
thread.join(timeout)
assert not thread.is_alive()
+
+class P2PDataStore(P2PInterface):
+ """A P2P data store class.
+
+ Keeps a block and transaction store and responds correctly to getdata and getheaders requests."""
+
+ def __init__(self):
+ super().__init__()
+ self.reject_code_received = None
+ self.reject_reason_received = None
+ # store of blocks. key is block hash, value is a CBlock object
+ self.block_store = {}
+ self.last_block_hash = ''
+ # store of txs. key is txid, value is a CTransaction object
+ self.tx_store = {}
+ self.getdata_requests = []
+
+ def on_getdata(self, message):
+ """Check for the tx/block in our stores and if found, reply with an inv message."""
+ for inv in message.inv:
+ self.getdata_requests.append(inv.hash)
+ if (inv.type & MSG_TYPE_MASK) == MSG_TX and inv.hash in self.tx_store.keys():
+ self.send_message(msg_tx(self.tx_store[inv.hash]))
+ elif (inv.type & MSG_TYPE_MASK) == MSG_BLOCK and inv.hash in self.block_store.keys():
+ self.send_message(msg_block(self.block_store[inv.hash]))
+ else:
+ logger.debug('getdata message type {} received.'.format(hex(inv.type)))
+
+ def on_getheaders(self, message):
+ """Search back through our block store for the locator, and reply with a headers message if found."""
+
+ locator, hash_stop = message.locator, message.hashstop
+
+ # Assume that the most recent block added is the tip
+ if not self.block_store:
+ return
+
+ headers_list = [self.block_store[self.last_block_hash]]
+ maxheaders = 2000
+ while headers_list[-1].sha256 not in locator.vHave:
+ # Walk back through the block store, adding headers to headers_list
+ # as we go.
+ prev_block_hash = headers_list[-1].hashPrevBlock
+ if prev_block_hash in self.block_store:
+ prev_block_header = self.block_store[prev_block_hash]
+ headers_list.append(prev_block_header)
+ if prev_block_header.sha256 == hash_stop:
+ # if this is the hashstop header, stop here
+ break
+ else:
+ logger.debug('block hash {} not found in block store'.format(hex(prev_block_hash)))
+ break
+
+ # Truncate the list if there are too many headers
+ headers_list = headers_list[:-maxheaders - 1:-1]
+ response = msg_headers(headers_list)
+
+ if response is not None:
+ self.send_message(response)
+
+ def on_reject(self, message):
+ """Store reject reason and code for testing."""
+ self.reject_code_received = message.code
+ self.reject_reason_received = message.reason
+
+ def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
+ """Send blocks to test node and test whether the tip advances.
+
+ - add all blocks to our block_store
+ - send a headers message for the final block
+ - the on_getheaders handler will ensure that any getheaders are responded to
+ - if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will
+ ensure that any getdata messages are responded to
+ - if success is True: assert that the node's tip advances to the most recent block
+ - if success is False: assert that the node's tip doesn't advance
+ - if reject_code and reject_reason are set: assert that the correct reject message is received"""
+
+ with mininode_lock:
+ self.reject_code_received = None
+ self.reject_reason_received = None
+
+ for block in blocks:
+ self.block_store[block.sha256] = block
+ self.last_block_hash = block.sha256
+
+ self.send_message(msg_headers([blocks[-1]]))
+
+ if request_block:
+ wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
+
+ if success:
+ wait_until(lambda: rpc.getbestblockhash() == blocks[-1].hash, timeout=timeout)
+ else:
+ assert rpc.getbestblockhash() != blocks[-1].hash
+
+ if reject_code is not None:
+ wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock)
+ if reject_reason is not None:
+ wait_until(lambda: self.reject_reason_received == reject_reason, lock=mininode_lock)
+
+ def send_txs_and_test(self, txs, rpc, success=True, reject_code=None, reject_reason=None):
+ """Send txs to test node and test whether they're accepted to the mempool.
+
+ - add all txs to our tx_store
+ - send tx messages for all txs
+ - if success is True: assert that the tx is accepted to the mempool
+ - if success is False: assert that the tx is not accepted to the mempool
+ - if reject_code and reject_reason are set: assert that the correct reject message is received."""
+
+ with mininode_lock:
+ self.reject_code_received = None
+ self.reject_reason_received = None
+
+ for tx in txs:
+ self.tx_store[tx.sha256] = tx
+
+ for tx in txs:
+ self.send_message(msg_tx(tx))
+
+ self.sync_with_ping()
+
+ raw_mempool = rpc.getrawmempool()
+ if success:
+ # Check that all txs are now in the mempool
+ for tx in txs:
+ assert tx.hash in raw_mempool, "{} not found in mempool".format(tx.hash)
+ else:
+ # Check that none of the txs are now in the mempool
+ for tx in txs:
+ assert tx.hash not in raw_mempool, "{} tx found in mempool".format(tx.hash)
+
+ if reject_code is not None:
+ wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock)
+ if reject_reason is not None:
+ wait_until(lambda: self.reject_reason_received == reject_reason, lock=mininode_lock)
diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py
index 8429f34c41..6fe0b445da 100644
--- a/test/functional/test_framework/script.py
+++ b/test/functional/test_framework/script.py
@@ -526,11 +526,9 @@ class CScript(bytes):
yield CScriptOp(opcode)
def __repr__(self):
- # For Python3 compatibility add b before strings so testcases don't
- # need to change
def _repr(o):
if isinstance(o, bytes):
- return b"x('%s')" % hexlify(o).decode('ascii')
+ return "x('%s')" % hexlify(o).decode('ascii')
else:
return repr(o)
@@ -641,7 +639,7 @@ def SignatureHash(script, txTo, inIdx, hashtype):
txtmp.vin = []
txtmp.vin.append(tmp)
- s = txtmp.serialize()
+ s = txtmp.serialize_without_witness()
s += struct.pack(b"<I", hashtype)
hash = hash256(s)
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index e42f3e60c2..ecb91b315e 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -62,6 +62,7 @@ class BitcoinTestFramework():
self.setup_clean_chain = False
self.nodes = []
self.mocktime = 0
+ self.supports_cli = False
self.set_test_params()
assert hasattr(self, "num_nodes"), "Test must set self.num_nodes in set_test_params()"
@@ -91,12 +92,16 @@ class BitcoinTestFramework():
help="Location of the test framework config file")
parser.add_option("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
help="Attach a python debugger if test fails")
+ parser.add_option("--usecli", dest="usecli", default=False, action="store_true",
+ help="use bitcoin-cli instead of RPC for all commands")
self.add_options(parser)
(self.options, self.args) = parser.parse_args()
PortSeed.n = self.options.port_seed
- os.environ['PATH'] = self.options.srcdir + ":" + self.options.srcdir + "/qt:" + os.environ['PATH']
+ os.environ['PATH'] = self.options.srcdir + os.pathsep + \
+ self.options.srcdir + os.path.sep + "qt" + os.pathsep + \
+ os.environ['PATH']
check_json_precision()
@@ -113,6 +118,8 @@ class BitcoinTestFramework():
success = TestStatus.FAILED
try:
+ if self.options.usecli and not self.supports_cli:
+ raise SkipTest("--usecli specified but test does not support using CLI")
self.setup_chain()
self.setup_network()
self.run_test()
@@ -143,10 +150,11 @@ class BitcoinTestFramework():
self.log.info("Note: bitcoinds were not stopped and may still be running")
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:
- self.log.info("Cleaning up")
- shutil.rmtree(self.options.tmpdir)
+ self.log.info("Cleaning up {} on exit".format(self.options.tmpdir))
+ cleanup_tree_on_exit = True
else:
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir)
+ cleanup_tree_on_exit = False
if success == TestStatus.PASSED:
self.log.info("Tests successful")
@@ -159,6 +167,8 @@ class BitcoinTestFramework():
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
exit_code = TEST_EXIT_FAILED
logging.shutdown()
+ if cleanup_tree_on_exit:
+ shutil.rmtree(self.options.tmpdir)
sys.exit(exit_code)
# Methods to override in subclass test scripts.
@@ -213,20 +223,20 @@ class BitcoinTestFramework():
assert_equal(len(extra_args), num_nodes)
assert_equal(len(binary), num_nodes)
for i in range(num_nodes):
- self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir))
+ self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, use_cli=self.options.usecli))
- def start_node(self, i, extra_args=None, stderr=None):
+ def start_node(self, i, *args, **kwargs):
"""Start a bitcoind"""
node = self.nodes[i]
- node.start(extra_args, stderr)
+ node.start(*args, **kwargs)
node.wait_for_rpc_connection()
if self.options.coveragedir is not None:
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
- def start_nodes(self, extra_args=None):
+ def start_nodes(self, extra_args=None, *args, **kwargs):
"""Start multiple bitcoinds"""
if extra_args is None:
@@ -234,7 +244,7 @@ class BitcoinTestFramework():
assert_equal(len(extra_args), self.num_nodes)
try:
for i, node in enumerate(self.nodes):
- node.start(extra_args[i])
+ node.start(extra_args[i], *args, **kwargs)
for node in self.nodes:
node.wait_for_rpc_connection()
except:
@@ -266,10 +276,10 @@ class BitcoinTestFramework():
self.stop_node(i)
self.start_node(i, extra_args)
- def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None):
+ def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None, *args, **kwargs):
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
try:
- self.start_node(i, extra_args, stderr=log_stderr)
+ self.start_node(i, extra_args, stderr=log_stderr, *args, **kwargs)
self.stop_node(i)
except Exception as e:
assert 'bitcoind exited' in str(e) # node must have shutdown
@@ -382,7 +392,7 @@ class BitcoinTestFramework():
# Create cache directories, run bitcoinds:
for i in range(MAX_NODES):
datadir = initialize_datadir(self.options.cachedir, i)
- args = [os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"]
+ args = [os.getenv("BITCOIND", "bitcoind"), "-datadir=" + datadir]
if i > 0:
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index a9248c764e..93a052f785 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -10,6 +10,7 @@ import http.client
import json
import logging
import os
+import re
import subprocess
import time
@@ -22,6 +23,9 @@ from .util import (
p2p_port,
)
+# For Python 3.4 compatibility
+JSONDecodeError = getattr(json, "JSONDecodeError", ValueError)
+
BITCOIND_PROC_WAIT_TIMEOUT = 60
class TestNode():
@@ -38,7 +42,7 @@ class TestNode():
To make things easier for the test writer, any unrecognised messages will
be dispatched to the RPC connection."""
- def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mocktime, coverage_dir):
+ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mocktime, coverage_dir, use_cli=False):
self.index = i
self.datadir = os.path.join(dirname, "node" + str(i))
self.rpchost = rpchost
@@ -53,11 +57,14 @@ class TestNode():
self.binary = binary
self.stderr = stderr
self.coverage_dir = coverage_dir
- # Most callers will just need to add extra args to the standard list below. For those callers that need more flexibity, they can just set the args property directly.
+ # Most callers will just need to add extra args to the standard list below.
+ # For those callers that need more flexibity, they can just set the args property directly.
+ # Note that common args are set in the config file (see initialize_datadir)
self.extra_args = extra_args
- self.args = [self.binary, "-datadir=" + self.datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(mocktime), "-uacomment=testnode%d" % i]
+ self.args = [self.binary, "-datadir=" + self.datadir, "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(mocktime), "-uacomment=testnode%d" % i]
self.cli = TestNodeCLI(os.getenv("BITCOINCLI", "bitcoin-cli"), self.datadir)
+ self.use_cli = use_cli
self.running = False
self.process = None
@@ -69,17 +76,20 @@ class TestNode():
self.p2ps = []
def __getattr__(self, name):
- """Dispatches any unrecognised messages to the RPC connection."""
- assert self.rpc_connected and self.rpc is not None, "Error: no RPC connection"
- return getattr(self.rpc, name)
+ """Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
+ if self.use_cli:
+ return getattr(self.cli, name)
+ else:
+ assert self.rpc_connected and self.rpc is not None, "Error: no RPC connection"
+ return getattr(self.rpc, name)
- def start(self, extra_args=None, stderr=None):
+ def start(self, extra_args=None, stderr=None, *args, **kwargs):
"""Start the node."""
if extra_args is None:
extra_args = self.extra_args
if stderr is None:
stderr = self.stderr
- self.process = subprocess.Popen(self.args + extra_args, stderr=stderr)
+ self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
self.running = True
self.log.debug("bitcoind started, waiting for RPC to come up")
@@ -110,10 +120,13 @@ class TestNode():
raise AssertionError("Unable to connect to bitcoind")
def get_wallet_rpc(self, wallet_name):
- assert self.rpc_connected
- assert self.rpc
- wallet_path = "wallet/%s" % wallet_name
- return self.rpc / wallet_path
+ if self.use_cli:
+ return self.cli("-rpcwallet={}".format(wallet_name))
+ else:
+ assert self.rpc_connected
+ assert self.rpc
+ wallet_path = "wallet/%s" % wallet_name
+ return self.rpc / wallet_path
def stop_node(self):
"""Stop the node."""
@@ -187,41 +200,70 @@ class TestNode():
p.peer_disconnect()
del self.p2ps[:]
+class TestNodeCLIAttr:
+ def __init__(self, cli, command):
+ self.cli = cli
+ self.command = command
+
+ def __call__(self, *args, **kwargs):
+ return self.cli.send_cli(self.command, *args, **kwargs)
+
+ def get_request(self, *args, **kwargs):
+ return lambda: self(*args, **kwargs)
class TestNodeCLI():
"""Interface to bitcoin-cli for an individual node"""
def __init__(self, binary, datadir):
- self.args = []
+ self.options = []
self.binary = binary
self.datadir = datadir
self.input = None
+ self.log = logging.getLogger('TestFramework.bitcoincli')
- def __call__(self, *args, input=None):
- # TestNodeCLI is callable with bitcoin-cli command-line args
- self.args = [str(arg) for arg in args]
- self.input = input
- return self
+ def __call__(self, *options, input=None):
+ # TestNodeCLI is callable with bitcoin-cli command-line options
+ cli = TestNodeCLI(self.binary, self.datadir)
+ cli.options = [str(o) for o in options]
+ cli.input = input
+ return cli
def __getattr__(self, command):
- def dispatcher(*args, **kwargs):
- return self.send_cli(command, *args, **kwargs)
- return dispatcher
-
- def send_cli(self, command, *args, **kwargs):
+ return TestNodeCLIAttr(self, command)
+
+ def batch(self, requests):
+ results = []
+ for request in requests:
+ try:
+ results.append(dict(result=request()))
+ except JSONRPCException as e:
+ results.append(dict(error=e))
+ return results
+
+ def send_cli(self, command=None, *args, **kwargs):
"""Run bitcoin-cli command. Deserializes returned string as python object."""
pos_args = [str(arg) for arg in args]
named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()]
assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call"
- p_args = [self.binary, "-datadir=" + self.datadir] + self.args
+ p_args = [self.binary, "-datadir=" + self.datadir] + self.options
if named_args:
p_args += ["-named"]
- p_args += [command] + pos_args + named_args
+ if command is not None:
+ p_args += [command]
+ p_args += pos_args + named_args
+ self.log.debug("Running bitcoin-cli command: %s" % command)
process = subprocess.Popen(p_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
cli_stdout, cli_stderr = process.communicate(input=self.input)
returncode = process.poll()
if returncode:
+ match = re.match(r'error code: ([-0-9]+)\nerror message:\n(.*)', cli_stderr)
+ if match:
+ code, message = match.groups()
+ raise JSONRPCException(dict(code=int(code), message=message))
# Ignore cli_stdout, raise with cli_stderr
raise subprocess.CalledProcessError(returncode, self.binary, output=cli_stderr)
- return json.loads(cli_stdout, parse_float=decimal.Decimal)
+ try:
+ return json.loads(cli_stdout, parse_float=decimal.Decimal)
+ except JSONDecodeError:
+ return cli_stdout.rstrip("\n")
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 664dc6d0af..e9e7bbd8e4 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -26,7 +26,7 @@ logger = logging.getLogger("TestFramework.utils")
def assert_fee_amount(fee, tx_size, fee_per_kB):
"""Assert the fee was in range"""
- target_fee = tx_size * fee_per_kB / 1000
+ target_fee = round(tx_size * fee_per_kB / 1000, 8)
if fee < target_fee:
raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee)))
# allow the wallet's estimation to be at most 2 bytes off
@@ -291,6 +291,9 @@ def initialize_datadir(dirname, n):
f.write("regtest=1\n")
f.write("port=" + str(p2p_port(n)) + "\n")
f.write("rpcport=" + str(rpc_port(n)) + "\n")
+ f.write("server=1\n")
+ f.write("keypool=1\n")
+ f.write("discover=0\n")
f.write("listenonion=0\n")
return datadir
@@ -390,7 +393,7 @@ def sync_chain(rpc_connections, *, wait=1, timeout=60):
timeout -= wait
raise AssertionError("Chain sync failed: Best block hashes don't match")
-def sync_mempools(rpc_connections, *, wait=1, timeout=60):
+def sync_mempools(rpc_connections, *, wait=1, timeout=60, flush_scheduler=True):
"""
Wait until everybody has the same transactions in their memory
pools
@@ -402,6 +405,9 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60):
if set(rpc_connections[i].getrawmempool()) == pool:
num_match = num_match + 1
if num_match == len(rpc_connections):
+ if flush_scheduler:
+ for r in rpc_connections:
+ r.syncwithvalidationinterfacequeue()
return
time.sleep(wait)
timeout -= wait
@@ -469,7 +475,7 @@ def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants):
outputs[to_node.getnewaddress()] = float(amount)
rawtx = from_node.createrawtransaction(inputs, outputs)
- signresult = from_node.signrawtransaction(rawtx)
+ signresult = from_node.signrawtransactionwithwallet(rawtx)
txid = from_node.sendrawtransaction(signresult["hex"], True)
return (txid, signresult["hex"], fee)
@@ -496,7 +502,7 @@ def create_confirmed_utxos(fee, node, count):
outputs[addr1] = satoshi_round(send_value / 2)
outputs[addr2] = satoshi_round(send_value / 2)
raw_tx = node.createrawtransaction(inputs, outputs)
- signed_tx = node.signrawtransaction(raw_tx)["hex"]
+ signed_tx = node.signrawtransactionwithwallet(raw_tx)["hex"]
node.sendrawtransaction(signed_tx)
while (node.getmempoolinfo()['size'] > 0):
@@ -530,7 +536,7 @@ def create_tx(node, coinbase, to_address, amount):
inputs = [{"txid": coinbase, "vout": 0}]
outputs = {to_address: amount}
rawtx = node.createrawtransaction(inputs, outputs)
- signresult = node.signrawtransaction(rawtx)
+ signresult = node.signrawtransactionwithwallet(rawtx)
assert_equal(signresult["complete"], True)
return signresult["hex"]
@@ -549,7 +555,7 @@ def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
newtx = rawtx[0:92]
newtx = newtx + txouts
newtx = newtx + rawtx[94:]
- signresult = node.signrawtransaction(newtx, None, None, "NONE")
+ signresult = node.signrawtransactionwithwallet(newtx, None, "NONE")
txid = node.sendrawtransaction(signresult["hex"], True)
txids.append(txid)
return txids
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 428a18be86..082191098e 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -55,81 +55,85 @@ TEST_EXIT_SKIPPED = 77
BASE_SCRIPTS= [
# Scripts that are run by the travis build process.
# Longest test should go first, to favor running tests in parallel
- 'wallet-hd.py',
- 'walletbackup.py',
+ 'wallet_hd.py',
+ 'wallet_backup.py',
# vv Tests less than 5m vv
- 'p2p-fullblocktest.py',
- 'fundrawtransaction.py',
- 'p2p-compactblocks.py',
- 'segwit.py',
+ 'feature_block.py',
+ 'rpc_fundrawtransaction.py',
+ 'p2p_compactblocks.py',
+ 'feature_segwit.py',
# vv Tests less than 2m vv
- 'wallet.py',
- 'wallet-accounts.py',
- 'p2p-segwit.py',
- 'wallet-dump.py',
- 'listtransactions.py',
+ 'wallet_basic.py',
+ 'wallet_accounts.py',
+ 'p2p_segwit.py',
+ 'wallet_dump.py',
+ 'rpc_listtransactions.py',
# vv Tests less than 60s vv
- 'sendheaders.py',
- 'zapwallettxes.py',
- 'importmulti.py',
+ 'p2p_sendheaders.py',
+ 'wallet_zapwallettxes.py',
+ 'wallet_importmulti.py',
'mempool_limit.py',
- 'merkle_blocks.py',
- 'receivedby.py',
- 'abandonconflict.py',
- 'bip68-112-113-p2p.py',
- 'rawtransactions.py',
- 'reindex.py',
+ 'rpc_txoutproof.py',
+ 'wallet_listreceivedby.py',
+ 'wallet_abandonconflict.py',
+ 'feature_csv_activation.py',
+ 'rpc_rawtransaction.py',
+ 'wallet_address_types.py',
+ 'feature_reindex.py',
# vv Tests less than 30s vv
- 'keypool-topup.py',
- 'zmq_test.py',
- 'bitcoin_cli.py',
- 'mempool_resurrect_test.py',
- 'txn_doublespend.py --mineblock',
- 'txn_clone.py',
- 'getchaintips.py',
- 'rest.py',
- 'mempool_spendcoinbase.py',
+ 'wallet_keypool_topup.py',
+ 'interface_zmq.py',
+ 'interface_bitcoin_cli.py',
+ 'mempool_resurrect.py',
+ 'wallet_txn_doublespend.py --mineblock',
+ 'wallet_txn_clone.py',
+ 'wallet_txn_clone.py --segwit',
+ 'rpc_getchaintips.py',
+ 'interface_rest.py',
+ 'mempool_spend_coinbase.py',
'mempool_reorg.py',
'mempool_persist.py',
- 'multiwallet.py',
- 'httpbasics.py',
- 'multi_rpc.py',
- 'proxy_test.py',
- 'signrawtransactions.py',
- 'disconnect_ban.py',
- 'decodescript.py',
- 'blockchain.py',
- 'deprecated_rpc.py',
- 'disablewallet.py',
- 'net.py',
- 'keypool.py',
- 'p2p-mempool.py',
- 'prioritise_transaction.py',
- 'invalidblockrequest.py',
- 'invalidtxrequest.py',
- 'p2p-versionbits-warning.py',
- 'preciousblock.py',
- 'importprunedfunds.py',
- 'signmessages.py',
- 'nulldummy.py',
- 'import-rescan.py',
- 'mining.py',
- 'bumpfee.py',
- 'rpcnamedargs.py',
- 'listsinceblock.py',
- 'p2p-leaktests.py',
- 'wallet-encryption.py',
- 'bipdersig-p2p.py',
- 'bip65-cltv-p2p.py',
- 'uptime.py',
- 'resendwallettransactions.py',
- 'minchainwork.py',
- 'p2p-fingerprint.py',
- 'uacomment.py',
- 'p2p-acceptblock.py',
+ 'wallet_multiwallet.py',
+ 'wallet_multiwallet.py --usecli',
+ 'interface_http.py',
+ 'rpc_users.py',
+ 'feature_proxy.py',
+ 'rpc_signrawtransaction.py',
+ 'p2p_disconnect_ban.py',
+ 'rpc_decodescript.py',
+ 'rpc_blockchain.py',
+ 'rpc_deprecated.py',
+ 'wallet_disable.py',
+ 'rpc_net.py',
+ 'wallet_keypool.py',
+ 'p2p_mempool.py',
+ 'mining_prioritisetransaction.py',
+ 'p2p_invalid_block.py',
+ 'p2p_invalid_tx.py',
+ 'feature_versionbits_warning.py',
+ 'rpc_preciousblock.py',
+ 'wallet_importprunedfunds.py',
+ 'rpc_signmessage.py',
+ 'feature_nulldummy.py',
+ 'wallet_import_rescan.py',
+ 'mining_basic.py',
+ 'wallet_bumpfee.py',
+ 'rpc_named_arguments.py',
+ 'wallet_listsinceblock.py',
+ 'p2p_leak.py',
+ 'wallet_encryption.py',
+ 'feature_dersig.py',
+ 'feature_cltv.py',
+ 'rpc_uptime.py',
+ 'wallet_resendwallettransactions.py',
+ 'wallet_fallbackfee.py',
+ 'feature_minchainwork.py',
+ 'p2p_fingerprint.py',
+ 'feature_uacomment.py',
+ 'p2p_unrequested_blocks.py',
'feature_logging.py',
- 'node_network_limited.py',
- 'conf_args.py',
+ 'p2p_node_network_limited.py',
+ 'feature_config_args.py',
# Don't append tests at the end to avoid merge conflicts
# Put them in a random line within the section that fits their approximate run-time
]
@@ -137,29 +141,29 @@ BASE_SCRIPTS= [
EXTENDED_SCRIPTS = [
# These tests are not run by the travis build process.
# Longest test should go first, to favor running tests in parallel
- 'pruning.py',
+ 'feature_pruning.py',
# vv Tests less than 20m vv
- 'smartfees.py',
+ 'feature_fee_estimation.py',
# vv Tests less than 5m vv
- 'maxuploadtarget.py',
+ 'feature_maxuploadtarget.py',
'mempool_packages.py',
- 'dbcrash.py',
+ 'feature_dbcrash.py',
# vv Tests less than 2m vv
- 'bip68-sequence.py',
- 'getblocktemplate_longpoll.py',
- 'p2p-timeouts.py',
+ 'feature_bip68_sequence.py',
+ 'mining_getblocktemplate_longpoll.py',
+ 'p2p_timeouts.py',
# vv Tests less than 60s vv
- 'bip9-softforks.py',
- 'p2p-feefilter.py',
- 'rpcbind_test.py',
+ 'feature_bip9_softforks.py',
+ 'p2p_feefilter.py',
+ 'rpc_bind.py',
# vv Tests less than 30s vv
- 'assumevalid.py',
+ 'feature_assumevalid.py',
'example_test.py',
- 'txn_doublespend.py',
- 'txn_clone.py --mineblock',
- 'notifications.py',
- 'invalidateblock.py',
- 'replace-by-fee.py',
+ 'wallet_txn_doublespend.py',
+ 'wallet_txn_clone.py --mineblock',
+ 'feature_notifications.py',
+ 'rpc_invalidateblock.py',
+ 'feature_rbf.py',
]
# Place EXTENDED_SCRIPTS first since it has the 3 longest running tests
@@ -265,10 +269,11 @@ def main():
if args.help:
# Print help for test_runner.py, then print help of the first script (with args removed) and exit.
parser.print_help()
- subprocess.check_call([(config["environment"]["SRCDIR"] + '/test/functional/' + test_list[0].split()[0])] + ['-h'])
+ subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'functional', test_list[0].split()[0]), '-h'])
sys.exit(0)
check_script_list(config["environment"]["SRCDIR"])
+ check_script_prefixes()
if not args.keepcache:
shutil.rmtree("%s/test/cache" % config["environment"]["BUILDDIR"], ignore_errors=True)
@@ -308,10 +313,10 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
if len(test_list) > 1 and jobs > 1:
# Populate cache
try:
- subprocess.check_output([tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir])
- except Exception as e:
- print(e.output)
- raise e
+ subprocess.check_output([sys.executable, tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir])
+ except subprocess.CalledProcessError as e:
+ sys.stdout.buffer.write(e.output)
+ raise
#Run Tests
job_queue = TestHandler(jobs, tests_dir, tmpdir, test_list, flags)
@@ -338,7 +343,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
print('\n============')
print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0]))
print('============\n')
- combined_logs, _ = subprocess.Popen([os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
+ combined_logs, _ = subprocess.Popen([sys.executable, os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
print("\n".join(deque(combined_logs.splitlines(), combined_logs_len)))
print_results(test_results, max_len_name, (int(time.time() - time0)))
@@ -408,7 +413,7 @@ class TestHandler:
tmpdir_arg = ["--tmpdir={}".format(testdir)]
self.jobs.append((t,
time.time(),
- subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
+ subprocess.Popen([sys.executable, self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
universal_newlines=True,
stdout=log_stdout,
stderr=log_stderr),
@@ -467,6 +472,18 @@ class TestResult():
return self.status != "Failed"
+def check_script_prefixes():
+ """Check that test scripts start with one of the allowed name prefixes."""
+
+ good_prefixes_re = re.compile("(example|feature|interface|mempool|mining|p2p|rpc|wallet)_")
+ bad_script_names = [script for script in ALL_SCRIPTS if good_prefixes_re.match(script) is None]
+
+ if bad_script_names:
+ print("%sERROR:%s %d tests not meeting naming conventions:" % (BOLD[1], BOLD[0], len(bad_script_names)))
+ print(" %s" % ("\n ".join(sorted(bad_script_names))))
+ raise AssertionError("Some tests are not following naming convention!")
+
+
def check_script_list(src_dir):
"""Check scripts directory.
diff --git a/test/functional/abandonconflict.py b/test/functional/wallet_abandonconflict.py
index 14964438af..7e0635d80f 100755
--- a/test/functional/abandonconflict.py
+++ b/test/functional/wallet_abandonconflict.py
@@ -8,11 +8,12 @@
descendants as abandoned which allows their inputs to be respent. It can be
used to replace "stuck" or evicted transactions. It only works on transactions
which are not included in a block and are not currently in the mempool. It has
- no effect on transactions which are already conflicted or abandoned.
+ no effect on transactions which are already abandoned.
"""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
+
class AbandonConflictTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
@@ -28,6 +29,11 @@ class AbandonConflictTest(BitcoinTestFramework):
sync_mempools(self.nodes)
self.nodes[1].generate(1)
+ # Can not abandon non-wallet transaction
+ assert_raises_rpc_error(-5, 'Invalid or non-wallet transaction id', lambda: self.nodes[0].abandontransaction(txid='ff' * 32))
+ # Can not abandon confirmed transaction
+ assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA))
+
sync_blocks(self.nodes)
newbalance = self.nodes[0].getbalance()
assert(balance - newbalance < Decimal("0.001")) #no more than fees lost
@@ -49,7 +55,7 @@ class AbandonConflictTest(BitcoinTestFramework):
outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998")
outputs[self.nodes[1].getnewaddress()] = Decimal("5")
- signed = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
+ signed = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
txAB1 = self.nodes[0].sendrawtransaction(signed["hex"])
# Identify the 14.99998btc output
@@ -61,7 +67,7 @@ class AbandonConflictTest(BitcoinTestFramework):
inputs.append({"txid":txC, "vout":nC})
outputs = {}
outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996")
- signed2 = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs))
+ signed2 = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"])
# In mempool txs from self should increase balance from change
@@ -132,7 +138,7 @@ class AbandonConflictTest(BitcoinTestFramework):
outputs = {}
outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999")
tx = self.nodes[0].createrawtransaction(inputs, outputs)
- signed = self.nodes[0].signrawtransaction(tx)
+ signed = self.nodes[0].signrawtransactionwithwallet(tx)
self.nodes[1].sendrawtransaction(signed["hex"])
self.nodes[1].generate(1)
diff --git a/test/functional/wallet-accounts.py b/test/functional/wallet_accounts.py
index 287436877f..ecd1cfc82b 100755
--- a/test/functional/wallet-accounts.py
+++ b/test/functional/wallet_accounts.py
@@ -126,7 +126,7 @@ class WalletAccountsTest(BitcoinTestFramework):
addresses = []
for x in range(10):
addresses.append(node.getnewaddress())
- multisig_address = node.addmultisigaddress(5, addresses, account.name)
+ multisig_address = node.addmultisigaddress(5, addresses, account.name)['address']
account.add_address(multisig_address)
account.verify(node)
node.sendfrom("", multisig_address, 50)
diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py
new file mode 100755
index 0000000000..5d2428e6ef
--- /dev/null
+++ b/test/functional/wallet_address_types.py
@@ -0,0 +1,294 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 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 that the wallet can send and receive using all combinations of address types.
+
+There are 5 nodes-under-test:
+ - node0 uses legacy addresses
+ - node1 uses p2sh/segwit addresses
+ - node2 uses p2sh/segwit addresses and bech32 addresses for change
+ - node3 uses bech32 addresses
+ - node4 uses a p2sh/segwit addresses for change
+
+node5 exists to generate new blocks.
+
+## Multisig address test
+
+Test that adding a multisig address with:
+ - an uncompressed pubkey always gives a legacy address
+ - only compressed pubkeys gives the an `-addresstype` address
+
+## Sending to address types test
+
+A series of tests, iterating over node0-node4. In each iteration of the test, one node sends:
+ - 10/101th of its balance to itself (using getrawchangeaddress for single key addresses)
+ - 20/101th to the next node
+ - 30/101th to the node after that
+ - 40/101th to the remaining node
+ - 1/101th remains as fee+change
+
+Iterate over each node for single key addresses, and then over each node for
+multisig addresses.
+
+Repeat test, but with explicit address_type parameters passed to getnewaddress
+and getrawchangeaddress:
+ - node0 and node3 send to p2sh.
+ - node1 sends to bech32.
+ - node2 sends to legacy.
+
+As every node sends coins after receiving, this also
+verifies that spending coins sent to all these address types works.
+
+## Change type test
+
+Test that the nodes generate the correct change address type:
+ - node0 always uses a legacy change address.
+ - node1 uses a bech32 addresses for change if any destination address is bech32.
+ - node2 always uses a bech32 address for change
+ - node3 always uses a bech32 address for change
+ - node4 always uses p2sh/segwit output for change.
+"""
+
+from decimal import Decimal
+import itertools
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_greater_than,
+ assert_raises_rpc_error,
+ connect_nodes_bi,
+ sync_blocks,
+ sync_mempools,
+)
+
+class AddressTypeTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 6
+ self.extra_args = [
+ ["-addresstype=legacy"],
+ ["-addresstype=p2sh-segwit"],
+ ["-addresstype=p2sh-segwit", "-changetype=bech32"],
+ ["-addresstype=bech32"],
+ ["-changetype=p2sh-segwit"],
+ []
+ ]
+
+ def setup_network(self):
+ self.setup_nodes()
+
+ # Fully mesh-connect nodes for faster mempool sync
+ for i, j in itertools.product(range(self.num_nodes), repeat=2):
+ if i > j:
+ connect_nodes_bi(self.nodes, i, j)
+ self.sync_all()
+
+ def get_balances(self, confirmed=True):
+ """Return a list of confirmed or unconfirmed balances."""
+ if confirmed:
+ return [self.nodes[i].getbalance() for i in range(4)]
+ else:
+ return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
+
+ def test_address(self, node, address, multisig, typ):
+ """Run sanity checks on an address."""
+ info = self.nodes[node].getaddressinfo(address)
+ assert(self.nodes[node].validateaddress(address)['isvalid'])
+ if not multisig and typ == 'legacy':
+ # P2PKH
+ assert(not info['isscript'])
+ assert(not info['iswitness'])
+ assert('pubkey' in info)
+ elif not multisig and typ == 'p2sh-segwit':
+ # P2SH-P2WPKH
+ assert(info['isscript'])
+ assert(not info['iswitness'])
+ assert_equal(info['script'], 'witness_v0_keyhash')
+ assert('pubkey' in info)
+ elif not multisig and typ == 'bech32':
+ # P2WPKH
+ assert(not info['isscript'])
+ assert(info['iswitness'])
+ assert_equal(info['witness_version'], 0)
+ assert_equal(len(info['witness_program']), 40)
+ assert('pubkey' in info)
+ elif typ == 'legacy':
+ # P2SH-multisig
+ assert(info['isscript'])
+ assert_equal(info['script'], 'multisig')
+ assert(not info['iswitness'])
+ assert('pubkeys' in info)
+ elif typ == 'p2sh-segwit':
+ # P2SH-P2WSH-multisig
+ assert(info['isscript'])
+ assert_equal(info['script'], 'witness_v0_scripthash')
+ assert(not info['iswitness'])
+ assert(info['embedded']['isscript'])
+ assert_equal(info['embedded']['script'], 'multisig')
+ assert(info['embedded']['iswitness'])
+ assert_equal(info['embedded']['witness_version'], 0)
+ assert_equal(len(info['embedded']['witness_program']), 64)
+ assert('pubkeys' in info['embedded'])
+ elif typ == 'bech32':
+ # P2WSH-multisig
+ assert(info['isscript'])
+ assert_equal(info['script'], 'multisig')
+ assert(info['iswitness'])
+ assert_equal(info['witness_version'], 0)
+ assert_equal(len(info['witness_program']), 64)
+ assert('pubkeys' in info)
+ else:
+ # Unknown type
+ assert(False)
+
+ def test_change_output_type(self, node_sender, destinations, expected_type):
+ txid = self.nodes[node_sender].sendmany(fromaccount="", amounts=dict.fromkeys(destinations, 0.001))
+ raw_tx = self.nodes[node_sender].getrawtransaction(txid)
+ tx = self.nodes[node_sender].decoderawtransaction(raw_tx)
+
+ # Make sure the transaction has change:
+ assert_equal(len(tx["vout"]), len(destinations) + 1)
+
+ # Make sure the destinations are included, and remove them:
+ output_addresses = [vout['scriptPubKey']['addresses'][0] for vout in tx["vout"]]
+ change_addresses = [d for d in output_addresses if d not in destinations]
+ assert_equal(len(change_addresses), 1)
+
+ self.log.debug("Check if change address " + change_addresses[0] + " is " + expected_type)
+ self.test_address(node_sender, change_addresses[0], multisig=False, typ=expected_type)
+
+ def run_test(self):
+ # Mine 101 blocks on node5 to bring nodes out of IBD and make sure that
+ # no coinbases are maturing for the nodes-under-test during the test
+ self.nodes[5].generate(101)
+ sync_blocks(self.nodes)
+
+ uncompressed_1 = "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee"
+ uncompressed_2 = "047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77"
+ compressed_1 = "0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"
+ compressed_2 = "037211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073"
+
+ # addmultisigaddress with at least 1 uncompressed key should return a legacy address.
+ for node in range(4):
+ self.test_address(node, self.nodes[node].addmultisigaddress(2, [uncompressed_1, uncompressed_2])['address'], True, 'legacy')
+ self.test_address(node, self.nodes[node].addmultisigaddress(2, [compressed_1, uncompressed_2])['address'], True, 'legacy')
+ self.test_address(node, self.nodes[node].addmultisigaddress(2, [uncompressed_1, compressed_2])['address'], True, 'legacy')
+ # addmultisigaddress with all compressed keys should return the appropriate address type (even when the keys are not ours).
+ self.test_address(0, self.nodes[0].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'legacy')
+ self.test_address(1, self.nodes[1].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'p2sh-segwit')
+ self.test_address(2, self.nodes[2].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'p2sh-segwit')
+ self.test_address(3, self.nodes[3].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'bech32')
+
+ for explicit_type, multisig, from_node in itertools.product([False, True], [False, True], range(4)):
+ address_type = None
+ if explicit_type and not multisig:
+ if from_node == 1:
+ address_type = 'bech32'
+ elif from_node == 0 or from_node == 3:
+ address_type = 'p2sh-segwit'
+ else:
+ address_type = 'legacy'
+ self.log.info("Sending from node {} ({}) with{} multisig using {}".format(from_node, self.extra_args[from_node], "" if multisig else "out", "default" if address_type is None else address_type))
+ old_balances = self.get_balances()
+ self.log.debug("Old balances are {}".format(old_balances))
+ to_send = (old_balances[from_node] / 101).quantize(Decimal("0.00000001"))
+ sends = {}
+
+ self.log.debug("Prepare sends")
+ for n, to_node in enumerate(range(from_node, from_node + 4)):
+ to_node %= 4
+ change = False
+ if not multisig:
+ if from_node == to_node:
+ # When sending non-multisig to self, use getrawchangeaddress
+ address = self.nodes[to_node].getrawchangeaddress(address_type=address_type)
+ change = True
+ else:
+ address = self.nodes[to_node].getnewaddress(address_type=address_type)
+ else:
+ addr1 = self.nodes[to_node].getnewaddress()
+ addr2 = self.nodes[to_node].getnewaddress()
+ address = self.nodes[to_node].addmultisigaddress(2, [addr1, addr2])['address']
+
+ # Do some sanity checking on the created address
+ if address_type is not None:
+ typ = address_type
+ elif to_node == 0:
+ typ = 'legacy'
+ elif to_node == 1 or (to_node == 2 and not change):
+ typ = 'p2sh-segwit'
+ else:
+ typ = 'bech32'
+ self.test_address(to_node, address, multisig, typ)
+
+ # Output entry
+ sends[address] = to_send * 10 * (1 + n)
+
+ self.log.debug("Sending: {}".format(sends))
+ self.nodes[from_node].sendmany("", sends)
+ sync_mempools(self.nodes)
+
+ unconf_balances = self.get_balances(False)
+ self.log.debug("Check unconfirmed balances: {}".format(unconf_balances))
+ assert_equal(unconf_balances[from_node], 0)
+ for n, to_node in enumerate(range(from_node + 1, from_node + 4)):
+ to_node %= 4
+ assert_equal(unconf_balances[to_node], to_send * 10 * (2 + n))
+
+ # node5 collects fee and block subsidy to keep accounting simple
+ self.nodes[5].generate(1)
+ sync_blocks(self.nodes)
+
+ new_balances = self.get_balances()
+ self.log.debug("Check new balances: {}".format(new_balances))
+ # We don't know what fee was set, so we can only check bounds on the balance of the sending node
+ assert_greater_than(new_balances[from_node], to_send * 10)
+ assert_greater_than(to_send * 11, new_balances[from_node])
+ for n, to_node in enumerate(range(from_node + 1, from_node + 4)):
+ to_node %= 4
+ assert_equal(new_balances[to_node], old_balances[to_node] + to_send * 10 * (2 + n))
+
+ # Get one p2sh/segwit address from node2 and two bech32 addresses from node3:
+ to_address_p2sh = self.nodes[2].getnewaddress()
+ to_address_bech32_1 = self.nodes[3].getnewaddress()
+ to_address_bech32_2 = self.nodes[3].getnewaddress()
+
+ # Fund node 4:
+ self.nodes[5].sendtoaddress(self.nodes[4].getnewaddress(), Decimal("1"))
+ self.nodes[5].generate(1)
+ sync_blocks(self.nodes)
+ assert_equal(self.nodes[4].getbalance(), 1)
+
+ self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output")
+ self.test_change_output_type(0, [to_address_bech32_1], 'legacy')
+
+ self.log.info("Nodes with addresstype=p2sh-segwit only use a P2WPKH change output if any destination address is bech32:")
+ self.test_change_output_type(1, [to_address_p2sh], 'p2sh-segwit')
+ self.test_change_output_type(1, [to_address_bech32_1], 'bech32')
+ self.test_change_output_type(1, [to_address_p2sh, to_address_bech32_1], 'bech32')
+ self.test_change_output_type(1, [to_address_bech32_1, to_address_bech32_2], 'bech32')
+
+ self.log.info("Nodes with change_type=bech32 always use a P2WPKH change output:")
+ self.test_change_output_type(2, [to_address_bech32_1], 'bech32')
+ self.test_change_output_type(2, [to_address_p2sh], 'bech32')
+
+ self.log.info("Nodes with addresstype=bech32 always use a P2WPKH change output (unless changetype is set otherwise):")
+ self.test_change_output_type(3, [to_address_bech32_1], 'bech32')
+ self.test_change_output_type(3, [to_address_p2sh], 'bech32')
+
+ self.log.info('getrawchangeaddress defaults to addresstype if -changetype is not set and argument is absent')
+ self.test_address(3, self.nodes[3].getrawchangeaddress(), multisig=False, typ='bech32')
+
+ self.log.info('getrawchangeaddress fails with invalid changetype argument')
+ assert_raises_rpc_error(-5, "Unknown address type 'bech23'", self.nodes[3].getrawchangeaddress, 'bech23')
+
+ self.log.info("Nodes with changetype=p2sh-segwit never use a P2WPKH change output")
+ self.test_change_output_type(4, [to_address_bech32_1], 'p2sh-segwit')
+ self.test_address(4, self.nodes[4].getrawchangeaddress(), multisig=False, typ='p2sh-segwit')
+ self.log.info("Except for getrawchangeaddress if specified:")
+ self.test_address(4, self.nodes[4].getrawchangeaddress(), multisig=False, typ='p2sh-segwit')
+ self.test_address(4, self.nodes[4].getrawchangeaddress('bech32'), multisig=False, typ='bech32')
+
+if __name__ == '__main__':
+ AddressTypeTest().main()
diff --git a/test/functional/walletbackup.py b/test/functional/wallet_backup.py
index b4be7debb5..b4be7debb5 100755
--- a/test/functional/walletbackup.py
+++ b/test/functional/wallet_backup.py
diff --git a/test/functional/wallet.py b/test/functional/wallet_basic.py
index 8cd059c618..f686cb6ea5 100755
--- a/test/functional/wallet.py
+++ b/test/functional/wallet_basic.py
@@ -27,6 +27,9 @@ class WalletTest(BitcoinTestFramework):
assert_fee_amount(fee, tx_size, fee_per_byte * 1000)
return curr_balance
+ def get_vsize(self, txn):
+ return self.nodes[0].decoderawtransaction(txn)['vsize']
+
def run_test(self):
# Check that there's no UTXO on none of the nodes
assert_equal(len(self.nodes[0].listunspent()), 0)
@@ -63,7 +66,7 @@ class WalletTest(BitcoinTestFramework):
assert_equal(txout['value'], 50)
txout = self.nodes[0].gettxout(txid=confirmed_txid, n=confirmed_index, include_mempool=True)
assert_equal(txout['value'], 50)
-
+
# Send 21 BTC from 0 to 2 using sendtoaddress call.
# Locked memory should use at least 32 bytes to sign each transaction
self.log.info("test getmemoryinfo")
@@ -137,7 +140,7 @@ class WalletTest(BitcoinTestFramework):
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
- txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))
+ txns_to_send.append(self.nodes[0].signrawtransactionwithwallet(raw_tx))
# Have node 1 (miner) send the transactions
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True)
@@ -162,7 +165,7 @@ class WalletTest(BitcoinTestFramework):
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]])
- node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
assert_equal(self.nodes[0].getbalance(), Decimal('10'))
# Send 10 BTC with subtract fee from amount
@@ -171,14 +174,14 @@ class WalletTest(BitcoinTestFramework):
self.sync_all([self.nodes[0:3]])
node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal)
- node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
# Sendmany 10 BTC
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [])
self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]])
node_0_bal += Decimal('10')
- node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
assert_equal(self.nodes[0].getbalance(), node_0_bal)
# Sendmany 10 BTC with subtract fee from amount
@@ -187,7 +190,7 @@ class WalletTest(BitcoinTestFramework):
self.sync_all([self.nodes[0:3]])
node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal)
- node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
# Test ResendWalletTransactions:
# Create a couple of transactions, then start up a fourth
@@ -222,7 +225,7 @@ class WalletTest(BitcoinTestFramework):
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
- signedRawTx = self.nodes[1].signrawtransaction(rawTx)
+ signedRawTx = self.nodes[1].signrawtransactionwithwallet(rawTx)
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex'])
zeroValueTxid= decRawTx['txid']
self.nodes[1].sendrawtransaction(signedRawTx['hex'])
@@ -314,7 +317,7 @@ class WalletTest(BitcoinTestFramework):
self.nodes[1].importaddress(address_to_import)
# 3. Validate that the imported address is watch-only on node1
- assert(self.nodes[1].validateaddress(address_to_import)["iswatchonly"])
+ assert(self.nodes[1].getaddressinfo(address_to_import)["iswatchonly"])
# 4. Check that the unspents after import are not spendable
assert_array_result(self.nodes[1].listunspent(),
@@ -397,7 +400,7 @@ class WalletTest(BitcoinTestFramework):
node0_balance = self.nodes[0].getbalance()
# Split into two chains
rawtx = self.nodes[0].createrawtransaction([{"txid":singletxid, "vout":0}], {chain_addrs[0]:node0_balance/2-Decimal('0.01'), chain_addrs[1]:node0_balance/2-Decimal('0.01')})
- signedtx = self.nodes[0].signrawtransaction(rawtx)
+ signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"])
self.nodes[0].generate(1)
@@ -439,5 +442,14 @@ class WalletTest(BitcoinTestFramework):
# Verify nothing new in wallet
assert_equal(total_txs, len(self.nodes[0].listtransactions("*",99999)))
+ # Test getaddressinfo. Note that these addresses are taken from disablewallet.py
+ assert_raises_rpc_error(-5, "Invalid address", self.nodes[0].getaddressinfo, "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy")
+ address_info = self.nodes[0].getaddressinfo("mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ")
+ assert_equal(address_info['address'], "mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ")
+ assert_equal(address_info["scriptPubKey"], "76a9144e3854046c7bd1594ac904e4793b6a45b36dea0988ac")
+ assert not address_info["ismine"]
+ assert not address_info["iswatchonly"]
+ assert not address_info["isscript"]
+
if __name__ == '__main__':
WalletTest().main()
diff --git a/test/functional/bumpfee.py b/test/functional/wallet_bumpfee.py
index ffd5ac197b..3e496248fd 100755
--- a/test/functional/bumpfee.py
+++ b/test/functional/wallet_bumpfee.py
@@ -14,7 +14,7 @@ added in the future, they should try to follow the same convention and not
make assumptions about execution order.
"""
-from segwit import send_to_witness
+from test_framework.blocktools import send_to_witness
from test_framework.test_framework import BitcoinTestFramework
from test_framework import blocktools
from test_framework.mininode import CTransaction
@@ -33,7 +33,7 @@ class BumpFeeTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
- self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]
+ self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-deprecatedrpc=addwitnessaddress", "-walletrbf={}".format(i)]
for i in range(self.num_nodes)]
def run_test(self):
@@ -104,7 +104,7 @@ def test_segwit_bumpfee_succeeds(rbf_node, dest_address):
# which spends it, and make sure bumpfee can be called on it.
segwit_in = next(u for u in rbf_node.listunspent() if u["amount"] == Decimal("0.001"))
- segwit_out = rbf_node.validateaddress(rbf_node.getnewaddress())
+ segwit_out = rbf_node.getaddressinfo(rbf_node.getnewaddress())
rbf_node.addwitnessaddress(segwit_out["address"])
segwitid = send_to_witness(
use_p2wsh=False,
@@ -121,7 +121,7 @@ def test_segwit_bumpfee_succeeds(rbf_node, dest_address):
"sequence": BIP125_SEQUENCE_NUMBER
}], {dest_address: Decimal("0.0005"),
rbf_node.getrawchangeaddress(): Decimal("0.0003")})
- rbfsigned = rbf_node.signrawtransaction(rbfraw)
+ rbfsigned = rbf_node.signrawtransactionwithwallet(rbfraw)
rbfid = rbf_node.sendrawtransaction(rbfsigned["hex"])
assert rbfid in rbf_node.getrawmempool()
@@ -150,8 +150,8 @@ def test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address):
} for utxo in utxos]
output_val = sum(utxo["amount"] for utxo in utxos) - Decimal("0.001")
rawtx = rbf_node.createrawtransaction(inputs, {dest_address: output_val})
- signedtx = rbf_node.signrawtransaction(rawtx)
- signedtx = peer_node.signrawtransaction(signedtx["hex"])
+ signedtx = rbf_node.signrawtransactionwithwallet(rawtx)
+ signedtx = peer_node.signrawtransactionwithwallet(signedtx["hex"])
rbfid = rbf_node.sendrawtransaction(signedtx["hex"])
assert_raises_rpc_error(-4, "Transaction contains inputs that don't belong to this wallet",
rbf_node.bumpfee, rbfid)
@@ -162,7 +162,7 @@ def test_bumpfee_with_descendant_fails(rbf_node, rbf_node_address, dest_address)
# parent is send-to-self, so we don't have to check which output is change when creating the child tx
parent_id = spend_one_input(rbf_node, rbf_node_address)
tx = rbf_node.createrawtransaction([{"txid": parent_id, "vout": 0}], {dest_address: 0.00020000})
- tx = rbf_node.signrawtransaction(tx)
+ tx = rbf_node.signrawtransactionwithwallet(tx)
rbf_node.sendrawtransaction(tx["hex"])
assert_raises_rpc_error(-8, "Transaction has descendants in the wallet", rbf_node.bumpfee, parent_id)
@@ -194,7 +194,7 @@ def test_settxfee(rbf_node, dest_address):
requested_feerate = Decimal("0.00025000")
rbf_node.settxfee(requested_feerate)
bumped_tx = rbf_node.bumpfee(rbfid)
- actual_feerate = bumped_tx["fee"] * 1000 / rbf_node.getrawtransaction(bumped_tx["txid"], True)["size"]
+ actual_feerate = bumped_tx["fee"] * 1000 / rbf_node.getrawtransaction(bumped_tx["txid"], True)["vsize"]
# Assert that the difference between the requested feerate and the actual
# feerate of the bumped transaction is small.
assert_greater_than(Decimal("0.00001000"), abs(requested_feerate - actual_feerate))
@@ -231,13 +231,16 @@ def test_unconfirmed_not_spendable(rbf_node, rbf_node_address):
assert_equal([t for t in rbf_node.listunspent(minconf=0, include_unsafe=False) if t["txid"] == bumpid], [])
# submit a block with the rbf tx to clear the bump tx out of the mempool,
- # then call abandon to make sure the wallet doesn't attempt to resubmit the
- # bump tx, then invalidate the block so the rbf tx will be put back in the
- # mempool. this makes it possible to check whether the rbf tx outputs are
+ # then invalidate the block so the rbf tx will be put back in the mempool.
+ # This makes it possible to check whether the rbf tx outputs are
# spendable before the rbf tx is confirmed.
block = submit_block_with_tx(rbf_node, rbftx)
- rbf_node.abandontransaction(bumpid)
+ # Can not abandon conflicted tx
+ assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: rbf_node.abandontransaction(txid=bumpid))
rbf_node.invalidateblock(block.hash)
+ # Call abandon to make sure the wallet doesn't attempt to resubmit
+ # the bump tx and hope the wallet does not rebroadcast before we call.
+ rbf_node.abandontransaction(bumpid)
assert bumpid not in rbf_node.getrawmempool()
assert rbfid in rbf_node.getrawmempool()
@@ -274,7 +277,7 @@ def spend_one_input(node, dest_address):
rawtx = node.createrawtransaction(
[tx_input], {dest_address: Decimal("0.00050000"),
node.getrawchangeaddress(): Decimal("0.00049000")})
- signedtx = node.signrawtransaction(rawtx)
+ signedtx = node.signrawtransactionwithwallet(rawtx)
txid = node.sendrawtransaction(signedtx["hex"])
return txid
@@ -290,6 +293,7 @@ def submit_block_with_tx(node, tx):
block.vtx.append(ctx)
block.rehash()
block.hashMerkleRoot = block.calc_merkle_root()
+ blocktools.add_witness_commitment(block)
block.solve()
node.submitblock(bytes_to_hex_str(block.serialize(True)))
return block
diff --git a/test/functional/disablewallet.py b/test/functional/wallet_disable.py
index b0627d88ac..b0627d88ac 100755
--- a/test/functional/disablewallet.py
+++ b/test/functional/wallet_disable.py
diff --git a/test/functional/wallet-dump.py b/test/functional/wallet_dump.py
index fa51a2e9d7..59eae78cbd 100755
--- a/test/functional/wallet-dump.py
+++ b/test/functional/wallet_dump.py
@@ -20,6 +20,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
found_script_addr = 0
found_addr_chg = 0
found_addr_rsv = 0
+ witness_addr_ret = None
hd_master_addr_ret = None
for line in inputfile:
# only read non comment lines
@@ -47,7 +48,14 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
# count key types
for addrObj in addrs:
- if addrObj['address'] == addr and addrObj['hdkeypath'] == keypath and keytype == "label=":
+ if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
+ # a labeled entry in the wallet should contain both a native address
+ # and the p2sh-p2wpkh address that was added at wallet setup
+ if len(addr.split(",")) == 2:
+ addr_list = addr.split(",")
+ # the entry should be of the first key in the wallet
+ assert_equal(addrs[0]['address'], addr_list[0])
+ witness_addr_ret = addr_list[1]
found_addr += 1
break
elif keytype == "change=1":
@@ -63,13 +71,13 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
found_script_addr += 1
break
- return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
+ return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret, witness_addr_ret
class WalletDumpTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
- self.extra_args = [["-keypool=90"]]
+ self.extra_args = [["-keypool=90", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
def setup_network(self, split=False):
# Use 1 minute timeout because the initial getnewaddress RPC can take
@@ -83,30 +91,33 @@ class WalletDumpTest(BitcoinTestFramework):
tmpdir = self.options.tmpdir
# generate 20 addresses to compare against the dump
+ # but since we add a p2sh-p2wpkh address for the first pubkey in the
+ # wallet, we will expect 21 addresses in the dump
test_addr_count = 20
addrs = []
for i in range(0,test_addr_count):
addr = self.nodes[0].getnewaddress()
- vaddr= self.nodes[0].validateaddress(addr) #required to get hd keypath
+ vaddr= self.nodes[0].getaddressinfo(addr) #required to get hd keypath
addrs.append(vaddr)
# Should be a no-op:
self.nodes[0].keypoolrefill()
# Test scripts dump by adding a P2SH witness and a 1-of-1 multisig address
witness_addr = self.nodes[0].addwitnessaddress(addrs[0]["address"], True)
- multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])
+ multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])["address"]
script_addrs = [witness_addr, multisig_addr]
# dump unencrypted wallet
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
- found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
+ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc, witness_addr_ret = \
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, script_addrs, None)
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
assert_equal(found_script_addr, 2) # all scripts must be in the dump
assert_equal(found_addr_chg, 50) # 50 blocks where mined
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
+ assert_equal(witness_addr_ret, witness_addr) # p2sh-p2wsh address added to the first key
#encrypt wallet, restart, unlock and dump
self.nodes[0].node_encrypt_wallet('test')
@@ -116,12 +127,13 @@ class WalletDumpTest(BitcoinTestFramework):
self.nodes[0].keypoolrefill()
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump")
- found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
+ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _, witness_addr_ret = \
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, script_addrs, hd_master_addr_unenc)
assert_equal(found_addr, test_addr_count)
assert_equal(found_script_addr, 2)
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 90*2)
+ assert_equal(witness_addr_ret, witness_addr)
# Overwriting should fail
assert_raises_rpc_error(-8, "already exists", self.nodes[0].dumpwallet, tmpdir + "/node0/wallet.unencrypted.dump")
@@ -131,13 +143,13 @@ class WalletDumpTest(BitcoinTestFramework):
self.start_node(0, ['-wallet=w2'])
# Make sure the address is not IsMine before import
- result = self.nodes[0].validateaddress(multisig_addr)
+ result = self.nodes[0].getaddressinfo(multisig_addr)
assert(result['ismine'] == False)
self.nodes[0].importwallet(os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
# Now check IsMine is true
- result = self.nodes[0].validateaddress(multisig_addr)
+ result = self.nodes[0].getaddressinfo(multisig_addr)
assert(result['ismine'] == True)
if __name__ == '__main__':
diff --git a/test/functional/wallet-encryption.py b/test/functional/wallet_encryption.py
index 452e8ec291..3c927ee484 100755
--- a/test/functional/wallet-encryption.py
+++ b/test/functional/wallet_encryption.py
@@ -10,6 +10,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
+ assert_greater_than,
+ assert_greater_than_or_equal,
)
class WalletEncryptionTest(BitcoinTestFramework):
@@ -56,6 +58,23 @@ class WalletEncryptionTest(BitcoinTestFramework):
assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase, 10)
self.nodes[0].walletpassphrase(passphrase2, 10)
assert_equal(privkey, self.nodes[0].dumpprivkey(address))
+ self.nodes[0].walletlock()
+
+ # Test timeout bounds
+ assert_raises_rpc_error(-8, "Timeout cannot be negative.", self.nodes[0].walletpassphrase, passphrase2, -10)
+ # Check the timeout
+ # Check a time less than the limit
+ expected_time = int(time.time()) + (1 << 30) - 600
+ self.nodes[0].walletpassphrase(passphrase2, (1 << 30) - 600)
+ actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
+ assert_greater_than_or_equal(actual_time, expected_time)
+ assert_greater_than(expected_time + 5, actual_time) # 5 second buffer
+ # Check a time greater than the limit
+ expected_time = int(time.time()) + (1 << 30) - 1
+ self.nodes[0].walletpassphrase(passphrase2, (1 << 33))
+ actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
+ assert_greater_than_or_equal(actual_time, expected_time)
+ assert_greater_than(expected_time + 5, actual_time) # 5 second buffer
if __name__ == '__main__':
WalletEncryptionTest().main()
diff --git a/test/functional/wallet_fallbackfee.py b/test/functional/wallet_fallbackfee.py
new file mode 100755
index 0000000000..e9cd052344
--- /dev/null
+++ b/test/functional/wallet_fallbackfee.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 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 wallet replace-by-fee capabilities in conjunction with the fallbackfee."""
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import *
+
+class WalletRBFTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 1
+ self.setup_clean_chain = True
+
+ def run_test(self):
+ self.nodes[0].generate(101)
+
+ # sending a transaction without fee estimations must be possible by default on regtest
+ self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
+
+ # test sending a tx with disabled fallback fee (must fail)
+ self.restart_node(0, extra_args=["-fallbackfee=0"])
+ assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
+ assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].fundrawtransaction(self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})))
+ assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendfrom("", self.nodes[0].getnewaddress(), 1))
+ assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[0].sendmany("", {self.nodes[0].getnewaddress(): 1}))
+
+if __name__ == '__main__':
+ WalletRBFTest().main()
diff --git a/test/functional/wallet-hd.py b/test/functional/wallet_hd.py
index 9f0e9acb47..91f77dd5ba 100755
--- a/test/functional/wallet-hd.py
+++ b/test/functional/wallet_hd.py
@@ -33,7 +33,7 @@ class WalletHDTest(BitcoinTestFramework):
# create an internal key
change_addr = self.nodes[1].getrawchangeaddress()
- change_addrV= self.nodes[1].validateaddress(change_addr)
+ change_addrV= self.nodes[1].getaddressinfo(change_addr)
assert_equal(change_addrV["hdkeypath"], "m/0'/1'/0'") #first internal child key
# Import a non-HD private key in the HD wallet
@@ -51,7 +51,7 @@ class WalletHDTest(BitcoinTestFramework):
num_hd_adds = 300
for i in range(num_hd_adds):
hd_add = self.nodes[1].getnewaddress()
- hd_info = self.nodes[1].validateaddress(hd_add)
+ hd_info = self.nodes[1].getaddressinfo(hd_add)
assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'")
assert_equal(hd_info["hdmasterkeyid"], masterkeyid)
self.nodes[0].sendtoaddress(hd_add, 1)
@@ -61,7 +61,7 @@ class WalletHDTest(BitcoinTestFramework):
# create an internal key (again)
change_addr = self.nodes[1].getrawchangeaddress()
- change_addrV= self.nodes[1].validateaddress(change_addr)
+ change_addrV= self.nodes[1].getaddressinfo(change_addr)
assert_equal(change_addrV["hdkeypath"], "m/0'/1'/1'") #second internal child key
self.sync_all()
@@ -80,7 +80,7 @@ class WalletHDTest(BitcoinTestFramework):
hd_add_2 = None
for _ in range(num_hd_adds):
hd_add_2 = self.nodes[1].getnewaddress()
- hd_info_2 = self.nodes[1].validateaddress(hd_add_2)
+ hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2)
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(_)+"'")
assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid)
assert_equal(hd_add, hd_add_2)
@@ -114,7 +114,7 @@ class WalletHDTest(BitcoinTestFramework):
keypath = ""
for out in outs:
if out['value'] != 1:
- keypath = self.nodes[1].validateaddress(out['scriptPubKey']['addresses'][0])['hdkeypath']
+ keypath = self.nodes[1].getaddressinfo(out['scriptPubKey']['addresses'][0])['hdkeypath']
assert_equal(keypath[0:7], "m/0'/1'")
diff --git a/test/functional/import-rescan.py b/test/functional/wallet_import_rescan.py
index 7d5fbb8d65..3288ce4b60 100755
--- a/test/functional/import-rescan.py
+++ b/test/functional/wallet_import_rescan.py
@@ -119,7 +119,7 @@ class ImportRescanTest(BitcoinTestFramework):
self.num_nodes = 2 + len(IMPORT_NODES)
def setup_network(self):
- extra_args = [[] for _ in range(self.num_nodes)]
+ extra_args = [["-addresstype=legacy"] for _ in range(self.num_nodes)]
for i, import_node in enumerate(IMPORT_NODES, 2):
if import_node.prune:
extra_args[i] += ["-prune=1"]
@@ -134,7 +134,7 @@ class ImportRescanTest(BitcoinTestFramework):
# each possible type of wallet import RPC.
for i, variant in enumerate(IMPORT_VARIANTS):
variant.label = "label {} {}".format(i, variant)
- variant.address = self.nodes[1].validateaddress(self.nodes[1].getnewaddress(variant.label))
+ variant.address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress(variant.label))
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
variant.initial_amount = 10 - (i + 1) / 4.0
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
diff --git a/test/functional/importmulti.py b/test/functional/wallet_importmulti.py
index 35cb5b6768..56ebc2622a 100755
--- a/test/functional/importmulti.py
+++ b/test/functional/wallet_importmulti.py
@@ -9,6 +9,7 @@ from test_framework.util import *
class ImportMultiTest (BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
+ self.extra_args = [["-addresstype=legacy"], ["-addresstype=legacy"]]
self.setup_clean_chain = True
def setup_network(self):
@@ -20,7 +21,7 @@ class ImportMultiTest (BitcoinTestFramework):
self.nodes[1].generate(1)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
- node0_address1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ node0_address1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
#Check only one address
assert_equal(node0_address1['ismine'], True)
@@ -29,7 +30,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(self.nodes[1].getblockcount(),1)
#Address Test - before import
- address_info = self.nodes[1].validateaddress(node0_address1['address'])
+ address_info = self.nodes[1].getaddressinfo(node0_address1['address'])
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False)
@@ -38,7 +39,7 @@ class ImportMultiTest (BitcoinTestFramework):
# Bitcoin Address
self.log.info("Should import an address")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -46,7 +47,7 @@ class ImportMultiTest (BitcoinTestFramework):
"timestamp": "now",
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], timestamp)
@@ -66,21 +67,21 @@ class ImportMultiTest (BitcoinTestFramework):
# ScriptPubKey + internal
self.log.info("Should import a scriptPubKey with internal flag")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
"internal": True
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], timestamp)
# ScriptPubKey + !internal
self.log.info("Should not import a scriptPubKey without internal flag")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -88,7 +89,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -8)
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
@@ -96,7 +97,7 @@ class ImportMultiTest (BitcoinTestFramework):
# Address + Public key + !Internal
self.log.info("Should import an address with public key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -105,7 +106,7 @@ class ImportMultiTest (BitcoinTestFramework):
"pubkeys": [ address['pubkey'] ]
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], timestamp)
@@ -113,7 +114,7 @@ class ImportMultiTest (BitcoinTestFramework):
# ScriptPubKey + Public key + internal
self.log.info("Should import a scriptPubKey with internal and with public key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
request = [{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -122,14 +123,14 @@ class ImportMultiTest (BitcoinTestFramework):
}]
result = self.nodes[1].importmulti(request)
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], timestamp)
# ScriptPubKey + Public key + !internal
self.log.info("Should not import a scriptPubKey without internal and with public key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
request = [{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -139,14 +140,14 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -8)
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
# Address + Private key + !watchonly
self.log.info("Should import an address with private key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -155,7 +156,7 @@ class ImportMultiTest (BitcoinTestFramework):
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], True)
assert_equal(address_assert['timestamp'], timestamp)
@@ -174,7 +175,7 @@ class ImportMultiTest (BitcoinTestFramework):
# Address + Private key + watchonly
self.log.info("Should not import an address with private key and with watchonly")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -186,14 +187,14 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -8)
assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
# ScriptPubKey + Private key + internal
self.log.info("Should import a scriptPubKey with internal and with private key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -201,14 +202,14 @@ class ImportMultiTest (BitcoinTestFramework):
"internal": True
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], True)
assert_equal(address_assert['timestamp'], timestamp)
# ScriptPubKey + Private key + !internal
self.log.info("Should not import a scriptPubKey without internal and with private key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -217,17 +218,17 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -8)
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
# P2SH address
- sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
+ sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
self.nodes[1].generate(100)
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
self.nodes[1].generate(1)
@@ -241,7 +242,7 @@ class ImportMultiTest (BitcoinTestFramework):
"timestamp": "now",
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
+ address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
assert_equal(address_assert['isscript'], True)
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['timestamp'], timestamp)
@@ -251,10 +252,10 @@ class ImportMultiTest (BitcoinTestFramework):
# P2SH + Redeem script
- sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
+ sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
self.nodes[1].generate(100)
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
self.nodes[1].generate(1)
@@ -269,7 +270,7 @@ class ImportMultiTest (BitcoinTestFramework):
"redeemscript": multi_sig_script['redeemScript']
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
+ address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
assert_equal(address_assert['timestamp'], timestamp)
p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]
@@ -278,10 +279,10 @@ class ImportMultiTest (BitcoinTestFramework):
# P2SH + Redeem script + Private Keys + !Watchonly
- sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
+ sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
self.nodes[1].generate(100)
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
self.nodes[1].generate(1)
@@ -297,7 +298,7 @@ class ImportMultiTest (BitcoinTestFramework):
"keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
+ address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
assert_equal(address_assert['timestamp'], timestamp)
p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]
@@ -305,10 +306,10 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(p2shunspent['solvable'], True)
# P2SH + Redeem script + Private Keys + Watchonly
- sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
+ sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
self.nodes[1].generate(100)
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
self.nodes[1].generate(1)
@@ -331,8 +332,8 @@ class ImportMultiTest (BitcoinTestFramework):
# Address + Public key + !Internal + Wrong pubkey
self.log.info("Should not import an address with a wrong public key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ address2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -343,7 +344,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -5)
assert_equal(result[0]['error']['message'], 'Consistency check failed')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
@@ -351,8 +352,8 @@ class ImportMultiTest (BitcoinTestFramework):
# ScriptPubKey + Public key + internal + Wrong pubkey
self.log.info("Should not import a scriptPubKey with internal and with a wrong public key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ address2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
request = [{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -363,7 +364,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -5)
assert_equal(result[0]['error']['message'], 'Consistency check failed')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
@@ -371,8 +372,8 @@ class ImportMultiTest (BitcoinTestFramework):
# Address + Private key + !watchonly + Wrong private key
self.log.info("Should not import an address with a wrong private key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ address2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": {
"address": address['address']
@@ -383,7 +384,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -5)
assert_equal(result[0]['error']['message'], 'Consistency check failed')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
@@ -391,8 +392,8 @@ class ImportMultiTest (BitcoinTestFramework):
# ScriptPubKey + Private key + internal + Wrong private key
self.log.info("Should not import a scriptPubKey with internal and with a wrong private key")
- address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
- address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
+ address = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
+ address2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
result = self.nodes[1].importmulti([{
"scriptPubKey": address['scriptPubKey'],
"timestamp": "now",
@@ -402,7 +403,7 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -5)
assert_equal(result[0]['error']['message'], 'Consistency check failed')
- address_assert = self.nodes[1].validateaddress(address['address'])
+ address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], False)
assert_equal(address_assert['ismine'], False)
assert_equal('timestamp' in address_assert, False)
@@ -418,7 +419,7 @@ class ImportMultiTest (BitcoinTestFramework):
"timestamp": "now",
}])
assert_equal(result[0]['success'], True)
- address_assert = self.nodes[1].validateaddress(watchonly_address)
+ address_assert = self.nodes[1].getaddressinfo(watchonly_address)
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], timestamp)
@@ -428,7 +429,7 @@ class ImportMultiTest (BitcoinTestFramework):
# restart nodes to check for proper serialization/deserialization of watch only address
self.stop_nodes()
self.start_nodes()
- address_assert = self.nodes[1].validateaddress(watchonly_address)
+ address_assert = self.nodes[1].getaddressinfo(watchonly_address)
assert_equal(address_assert['iswatchonly'], True)
assert_equal(address_assert['ismine'], False)
assert_equal(address_assert['timestamp'], watchonly_timestamp)
diff --git a/test/functional/importprunedfunds.py b/test/functional/wallet_importprunedfunds.py
index 6b2919b5ae..4d349db23f 100755
--- a/test/functional/importprunedfunds.py
+++ b/test/functional/wallet_importprunedfunds.py
@@ -26,7 +26,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
#Check only one address
- address_info = self.nodes[0].validateaddress(address1)
+ address_info = self.nodes[0].getaddressinfo(address1)
assert_equal(address_info['ismine'], True)
self.sync_all()
@@ -35,15 +35,15 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
assert_equal(self.nodes[1].getblockcount(),101)
#Address Test - before import
- address_info = self.nodes[1].validateaddress(address1)
+ address_info = self.nodes[1].getaddressinfo(address1)
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False)
- address_info = self.nodes[1].validateaddress(address2)
+ address_info = self.nodes[1].getaddressinfo(address2)
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False)
- address_info = self.nodes[1].validateaddress(address3)
+ address_info = self.nodes[1].getaddressinfo(address3)
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False)
@@ -86,13 +86,13 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
assert_equal(balance3, Decimal('0.075'))
#Addresses Test - after import
- address_info = self.nodes[1].validateaddress(address1)
+ address_info = self.nodes[1].getaddressinfo(address1)
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], False)
- address_info = self.nodes[1].validateaddress(address2)
+ address_info = self.nodes[1].getaddressinfo(address2)
assert_equal(address_info['iswatchonly'], True)
assert_equal(address_info['ismine'], False)
- address_info = self.nodes[1].validateaddress(address3)
+ address_info = self.nodes[1].getaddressinfo(address3)
assert_equal(address_info['iswatchonly'], False)
assert_equal(address_info['ismine'], True)
diff --git a/test/functional/keypool.py b/test/functional/wallet_keypool.py
index 45a5eed8ec..9825e4d894 100755
--- a/test/functional/keypool.py
+++ b/test/functional/wallet_keypool.py
@@ -14,7 +14,7 @@ class KeyPoolTest(BitcoinTestFramework):
def run_test(self):
nodes = self.nodes
addr_before_encrypting = nodes[0].getnewaddress()
- addr_before_encrypting_data = nodes[0].validateaddress(addr_before_encrypting)
+ addr_before_encrypting_data = nodes[0].getaddressinfo(addr_before_encrypting)
wallet_info_old = nodes[0].getwalletinfo()
assert(addr_before_encrypting_data['hdmasterkeyid'] == wallet_info_old['hdmasterkeyid'])
@@ -24,7 +24,7 @@ class KeyPoolTest(BitcoinTestFramework):
self.start_node(0)
# Keep creating keys
addr = nodes[0].getnewaddress()
- addr_data = nodes[0].validateaddress(addr)
+ addr_data = nodes[0].getaddressinfo(addr)
wallet_info = nodes[0].getwalletinfo()
assert(addr_before_encrypting_data['hdmasterkeyid'] != wallet_info['hdmasterkeyid'])
assert(addr_data['hdmasterkeyid'] == wallet_info['hdmasterkeyid'])
diff --git a/test/functional/keypool-topup.py b/test/functional/wallet_keypool_topup.py
index e7af3c3987..e7b76dfaf2 100755
--- a/test/functional/keypool-topup.py
+++ b/test/functional/wallet_keypool_topup.py
@@ -68,7 +68,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
assert_equal(self.nodes[1].listtransactions()[0]['category'], "receive")
# Check that we have marked all keys up to the used keypool key as used
- assert_equal(self.nodes[1].validateaddress(self.nodes[1].getnewaddress())['hdkeypath'], "m/0'/0'/110'")
+ assert_equal(self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['hdkeypath'], "m/0'/0'/110'")
if __name__ == '__main__':
KeypoolRestoreTest().main()
diff --git a/test/functional/receivedby.py b/test/functional/wallet_listreceivedby.py
index 1f2b3c8aa7..1f2b3c8aa7 100755
--- a/test/functional/receivedby.py
+++ b/test/functional/wallet_listreceivedby.py
diff --git a/test/functional/listsinceblock.py b/test/functional/wallet_listsinceblock.py
index 67e7744bf8..25e2716661 100755
--- a/test/functional/listsinceblock.py
+++ b/test/functional/wallet_listsinceblock.py
@@ -158,7 +158,7 @@ class ListSinceBlockTest (BitcoinTestFramework):
'vout': utxo['vout'],
}]
txid1 = self.nodes[1].sendrawtransaction(
- self.nodes[1].signrawtransaction(
+ self.nodes[1].signrawtransactionwithwallet(
self.nodes[1].createrawtransaction(utxoDicts, recipientDict))['hex'])
# send from nodes[2] using utxo to nodes[3]
@@ -167,7 +167,7 @@ class ListSinceBlockTest (BitcoinTestFramework):
self.nodes[2].getnewaddress(): change,
}
self.nodes[2].sendrawtransaction(
- self.nodes[2].signrawtransaction(
+ self.nodes[2].signrawtransactionwithwallet(
self.nodes[2].createrawtransaction(utxoDicts, recipientDict2))['hex'])
# generate on both sides
@@ -232,7 +232,7 @@ class ListSinceBlockTest (BitcoinTestFramework):
'txid': utxo['txid'],
'vout': utxo['vout'],
}]
- signedtxres = self.nodes[2].signrawtransaction(
+ signedtxres = self.nodes[2].signrawtransactionwithwallet(
self.nodes[2].createrawtransaction(utxoDicts, recipientDict))
assert signedtxres['complete']
diff --git a/test/functional/multiwallet.py b/test/functional/wallet_multiwallet.py
index d0c40e5446..b07e451667 100755
--- a/test/functional/multiwallet.py
+++ b/test/functional/wallet_multiwallet.py
@@ -15,63 +15,75 @@ from test_framework.util import assert_equal, assert_raises_rpc_error
class MultiWalletTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
- self.num_nodes = 1
- self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3', '-wallet=w']]
+ self.num_nodes = 2
+ self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3', '-wallet=w'], []]
+ self.supports_cli = True
def run_test(self):
- assert_equal(set(self.nodes[0].listwallets()), {"w1", "w2", "w3", "w"})
+ node = self.nodes[0]
- self.stop_node(0)
+ data_dir = lambda *p: os.path.join(node.datadir, 'regtest', *p)
+ wallet_dir = lambda *p: data_dir('wallets', *p)
+ wallet = lambda name: node.get_wallet_rpc(name)
+
+ assert_equal(set(node.listwallets()), {"w1", "w2", "w3", "w"})
+
+ self.stop_nodes()
+
+ self.assert_start_raises_init_error(0, ['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist')
+ self.assert_start_raises_init_error(0, ['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir())
+ self.assert_start_raises_init_error(0, ['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir())
# should not initialize if there are duplicate wallets
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
# should not initialize if wallet file is a directory
- wallet_dir = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'wallets')
- os.mkdir(os.path.join(wallet_dir, 'w11'))
+ os.mkdir(wallet_dir('w11'))
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
# should not initialize if one wallet is a copy of another
- shutil.copyfile(os.path.join(wallet_dir, 'w2'), os.path.join(wallet_dir, 'w22'))
+ shutil.copyfile(wallet_dir('w2'), wallet_dir('w22'))
self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')
# should not initialize if wallet file is a symlink
- os.symlink(os.path.join(wallet_dir, 'w1'), os.path.join(wallet_dir, 'w12'))
+ os.symlink(wallet_dir('w1'), wallet_dir('w12'))
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
# should not initialize if the specified walletdir does not exist
self.assert_start_raises_init_error(0, ['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
# should not initialize if the specified walletdir is not a directory
- not_a_dir = os.path.join(wallet_dir, 'notadir')
+ not_a_dir = wallet_dir('notadir')
open(not_a_dir, 'a').close()
- self.assert_start_raises_init_error(0, ['-walletdir='+not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
+ self.assert_start_raises_init_error(0, ['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
# if wallets/ doesn't exist, datadir should be the default wallet dir
- wallet_dir2 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')
- os.rename(wallet_dir, wallet_dir2)
+ wallet_dir2 = data_dir('walletdir')
+ os.rename(wallet_dir(), wallet_dir2)
self.start_node(0, ['-wallet=w4', '-wallet=w5'])
- assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
- w5 = self.nodes[0].get_wallet_rpc("w5")
+ assert_equal(set(node.listwallets()), {"w4", "w5"})
+ w5 = wallet("w5")
w5.generate(1)
- self.stop_node(0)
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
- os.rename(wallet_dir2, wallet_dir)
- self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + os.path.join(self.options.tmpdir, 'node0', 'regtest')])
- assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
- w5 = self.nodes[0].get_wallet_rpc("w5")
+ os.rename(wallet_dir2, wallet_dir())
+ self.restart_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + data_dir()])
+ assert_equal(set(node.listwallets()), {"w4", "w5"})
+ w5 = wallet("w5")
w5_info = w5.getwalletinfo()
assert_equal(w5_info['immature_balance'], 50)
- self.stop_node(0)
+ competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
+ os.mkdir(competing_wallet_dir)
+ self.restart_node(0, ['-walletdir='+competing_wallet_dir])
+ self.assert_start_raises_init_error(1, ['-walletdir='+competing_wallet_dir], 'Error initializing wallet database environment')
- self.start_node(0, self.extra_args[0])
+ self.restart_node(0, self.extra_args[0])
- w1 = self.nodes[0].get_wallet_rpc("w1")
- w2 = self.nodes[0].get_wallet_rpc("w2")
- w3 = self.nodes[0].get_wallet_rpc("w3")
- w4 = self.nodes[0].get_wallet_rpc("w")
- wallet_bad = self.nodes[0].get_wallet_rpc("bad")
+ w1 = wallet("w1")
+ w2 = wallet("w2")
+ w3 = wallet("w3")
+ w4 = wallet("w")
+ wallet_bad = wallet("bad")
w1.generate(1)
@@ -79,7 +91,7 @@ class MultiWalletTest(BitcoinTestFramework):
assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", wallet_bad.getwalletinfo)
# accessing wallet RPC without using wallet endpoint fails
- assert_raises_rpc_error(-19, "Wallet file not specified", self.nodes[0].getwalletinfo)
+ assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
# check w1 wallet balance
w1_info = w1.getwalletinfo()
diff --git a/test/functional/resendwallettransactions.py b/test/functional/wallet_resendwallettransactions.py
index d959bb4c38..d959bb4c38 100755
--- a/test/functional/resendwallettransactions.py
+++ b/test/functional/wallet_resendwallettransactions.py
diff --git a/test/functional/txn_clone.py b/test/functional/wallet_txn_clone.py
index c50f86341f..d742ec4618 100755
--- a/test/functional/txn_clone.py
+++ b/test/functional/wallet_txn_clone.py
@@ -14,6 +14,8 @@ class TxnMallTest(BitcoinTestFramework):
def add_options(self, parser):
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
help="Test double-spend of 1-confirmed transaction")
+ parser.add_option("--segwit", dest="segwit", default=False, action="store_true",
+ help="Test behaviour with SegWit txn (which should fail")
def setup_network(self):
# Start with split network:
@@ -22,6 +24,11 @@ class TxnMallTest(BitcoinTestFramework):
disconnect_nodes(self.nodes[2], 1)
def run_test(self):
+ if self.options.segwit:
+ output_type="p2sh-segwit"
+ else:
+ output_type="legacy"
+
# All nodes should start with 1,250 BTC:
starting_balance = 1250
for i in range(4):
@@ -31,11 +38,11 @@ class TxnMallTest(BitcoinTestFramework):
# Assign coins to foo and bar accounts:
self.nodes[0].settxfee(.001)
- node0_address_foo = self.nodes[0].getnewaddress("foo")
+ node0_address_foo = self.nodes[0].getnewaddress("foo", output_type)
fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219)
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)
- node0_address_bar = self.nodes[0].getnewaddress("bar")
+ node0_address_bar = self.nodes[0].getnewaddress("bar", output_type)
fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29)
fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid)
@@ -71,7 +78,7 @@ class TxnMallTest(BitcoinTestFramework):
# Use a different signature hash type to sign. This creates an equivalent but malleated clone.
# Don't send the clone anywhere yet
- tx1_clone = self.nodes[0].signrawtransaction(clone_raw, None, None, "ALL|ANYONECANPAY")
+ tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_raw, None, "ALL|ANYONECANPAY")
assert_equal(tx1_clone["complete"], True)
# Have node0 mine a block, if requested:
@@ -106,6 +113,10 @@ class TxnMallTest(BitcoinTestFramework):
# Send clone and its parent to miner
self.nodes[2].sendrawtransaction(fund_foo_tx["hex"])
txid1_clone = self.nodes[2].sendrawtransaction(tx1_clone["hex"])
+ if self.options.segwit:
+ assert_equal(txid1, txid1_clone)
+ return
+
# ... mine a block...
self.nodes[2].generate(1)
diff --git a/test/functional/txn_doublespend.py b/test/functional/wallet_txn_doublespend.py
index 01129f3817..f16756eeaa 100755
--- a/test/functional/txn_doublespend.py
+++ b/test/functional/wallet_txn_doublespend.py
@@ -58,7 +58,7 @@ class TxnMallTest(BitcoinTestFramework):
outputs[node1_address] = 1240
outputs[change_address] = 1248 - 1240 + doublespend_fee
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
- doublespend = self.nodes[0].signrawtransaction(rawtx)
+ doublespend = self.nodes[0].signrawtransactionwithwallet(rawtx)
assert_equal(doublespend["complete"], True)
# Create two spends using 1 50 BTC coin each
diff --git a/test/functional/zapwallettxes.py b/test/functional/wallet_zapwallettxes.py
index 0471f2afb3..87f44b2737 100755
--- a/test/functional/zapwallettxes.py
+++ b/test/functional/wallet_zapwallettxes.py
@@ -10,7 +10,7 @@
transactions are still available.
- restart node 0 with zapwallettxes and persistmempool, and verify that both
the confirmed and the unconfirmed transactions are still available.
-- restart node 0 with just zapwallettxed and verify that the confirmed
+- restart node 0 with just zapwallettxes and verify that the confirmed
transactions are still available, but that the unconfirmed transaction has
been zapped.
"""
@@ -59,6 +59,7 @@ class ZapWalletTXesTest (BitcoinTestFramework):
self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
+ self.nodes[0].syncwithvalidationinterfacequeue() # Flush mempool to wallet
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
diff --git a/test/util/bitcoin-util-test.py b/test/util/bitcoin-util-test.py
index 64e826ad0b..30bd13d0dc 100755
--- a/test/util/bitcoin-util-test.py
+++ b/test/util/bitcoin-util-test.py
@@ -44,7 +44,7 @@ def main():
# Add the format/level to the logger
logging.basicConfig(format=formatter, level=level)
- bctester(os.path.join(env_conf["SRCDIR"], "test/util/data"), "bitcoin-util-test.json", env_conf)
+ bctester(os.path.join(env_conf["SRCDIR"], "test", "util", "data"), "bitcoin-util-test.json", env_conf)
def bctester(testDir, input_basename, buildenv):
""" Loads and parses the input file, runs all tests and reports results"""