aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/example_test.py8
-rwxr-xr-xtest/functional/keypool-topup.py75
-rwxr-xr-xtest/functional/resendwallettransactions.py31
-rwxr-xr-xtest/functional/sendheaders.py3
-rwxr-xr-xtest/functional/test_framework/test_framework.py7
-rwxr-xr-xtest/functional/test_runner.py2
-rwxr-xr-xtest/functional/wallet-hd.py10
7 files changed, 127 insertions, 9 deletions
diff --git a/test/functional/example_test.py b/test/functional/example_test.py
index 1ba5f756cd..7709524f23 100755
--- a/test/functional/example_test.py
+++ b/test/functional/example_test.py
@@ -58,6 +58,10 @@ class BaseNode(NodeConnCB):
message.block.calc_sha256()
self.block_receive_map[message.block.sha256] += 1
+ def on_inv(self, conn, message):
+ """Override the standard on_inv callback"""
+ pass
+
def custom_function():
"""Do some custom behaviour
@@ -198,10 +202,10 @@ class ExampleTest(BitcoinTestFramework):
self.log.info("Wait for node2 reach current tip. Test that it has propogated all the blocks to us")
+ getdata_request = msg_getdata()
for block in blocks:
- getdata_request = msg_getdata()
getdata_request.inv.append(CInv(2, block))
- node2.send_message(getdata_request)
+ node2.send_message(getdata_request)
# wait_until() will loop until a predicate condition is met. Use it to test properties of the
# NodeConnCB objects.
diff --git a/test/functional/keypool-topup.py b/test/functional/keypool-topup.py
new file mode 100755
index 0000000000..0e0c0ea74b
--- /dev/null
+++ b/test/functional/keypool-topup.py
@@ -0,0 +1,75 @@
+#!/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 HD Wallet keypool restore function.
+
+Two nodes. Node1 is under test. Node0 is providing transactions and generating blocks.
+
+- Start node1, shutdown and backup wallet.
+- Generate 110 keys (enough to drain the keypool). Store key 90 (in the initial keypool) and key 110 (beyond the initial keypool). Send funds to key 90 and key 110.
+- Stop node1, clear the datadir, move wallet file back into the datadir and restart node1.
+- connect node1 to node0. Verify that they sync and node1 receives its funds."""
+import shutil
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ connect_nodes_bi,
+ sync_blocks,
+)
+
+class KeypoolRestoreTest(BitcoinTestFramework):
+ def __init__(self):
+ super().__init__()
+ self.setup_clean_chain = True
+ self.num_nodes = 2
+ self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
+
+ def run_test(self):
+ self.tmpdir = self.options.tmpdir
+ self.nodes[0].generate(101)
+
+ self.log.info("Make backup of wallet")
+
+ self.stop_node(1)
+
+ shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", self.tmpdir + "/wallet.bak")
+ self.nodes[1] = self.start_node(1, self.tmpdir, self.extra_args[1])
+ connect_nodes_bi(self.nodes, 0, 1)
+
+ self.log.info("Generate keys for wallet")
+
+ for _ in range(90):
+ addr_oldpool = self.nodes[1].getnewaddress()
+ for _ in range(20):
+ addr_extpool = self.nodes[1].getnewaddress()
+
+ self.log.info("Send funds to wallet")
+
+ self.nodes[0].sendtoaddress(addr_oldpool, 10)
+ self.nodes[0].generate(1)
+ self.nodes[0].sendtoaddress(addr_extpool, 5)
+ self.nodes[0].generate(1)
+ sync_blocks(self.nodes)
+
+ self.log.info("Restart node with wallet backup")
+
+ self.stop_node(1)
+
+ shutil.copyfile(self.tmpdir + "/wallet.bak", self.tmpdir + "/node1/regtest/wallet.dat")
+
+ self.log.info("Verify keypool is restored and balance is correct")
+
+ self.nodes[1] = self.start_node(1, self.tmpdir, self.extra_args[1])
+ connect_nodes_bi(self.nodes, 0, 1)
+ self.sync_all()
+
+ assert_equal(self.nodes[1].getbalance(), 15)
+ 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'/111'")
+
+if __name__ == '__main__':
+ KeypoolRestoreTest().main()
diff --git a/test/functional/resendwallettransactions.py b/test/functional/resendwallettransactions.py
new file mode 100755
index 0000000000..5059aa106e
--- /dev/null
+++ b/test/functional/resendwallettransactions.py
@@ -0,0 +1,31 @@
+#!/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 resendwallettransactions RPC."""
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import assert_equal, assert_raises_jsonrpc
+
+class ResendWalletTransactionsTest(BitcoinTestFramework):
+
+ def __init__(self):
+ super().__init__()
+ self.extra_args = [['--walletbroadcast=false']]
+ self.num_nodes = 1
+
+ def run_test(self):
+ # Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled.
+ assert_raises_jsonrpc(-4, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast", self.nodes[0].resendwallettransactions)
+
+ # Should return an empty array if there aren't unconfirmed wallet transactions.
+ self.stop_node(0)
+ self.nodes[0] = self.start_node(0, self.options.tmpdir)
+ assert_equal(self.nodes[0].resendwallettransactions(), [])
+
+ # Should return an array with the unconfirmed wallet transaction.
+ txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
+ assert_equal(self.nodes[0].resendwallettransactions(), [txid])
+
+if __name__ == '__main__':
+ ResendWalletTransactionsTest().main()
diff --git a/test/functional/sendheaders.py b/test/functional/sendheaders.py
index 44c357c6db..e47e07fb86 100755
--- a/test/functional/sendheaders.py
+++ b/test/functional/sendheaders.py
@@ -121,9 +121,6 @@ class TestNode(NodeConnCB):
message.headers[-1].calc_sha256()
self.last_blockhash_announced = message.headers[-1].sha256
- def on_block(self, conn, message):
- self.last_message["block"].calc_sha256()
-
# Test whether the last announcement we received had the
# right header or the right inv
# inv and headers should be lists of block hashes
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index d8a8b56f92..7903bb0045 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -9,6 +9,7 @@ from enum import Enum
import logging
import optparse
import os
+import pdb
import shutil
import sys
import tempfile
@@ -119,6 +120,8 @@ class BitcoinTestFramework(object):
help="Write tested RPC commands into this directory")
parser.add_option("--configfile", dest="configfile",
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")
self.add_options(parser)
(self.options, self.args) = parser.parse_args()
@@ -156,6 +159,10 @@ class BitcoinTestFramework(object):
except KeyboardInterrupt as e:
self.log.warning("Exiting after keyboard interrupt")
+ if success == TestStatus.FAILED and self.options.pdbonfailure:
+ print("Testcase failed. Attaching python debugger. Enter ? for help")
+ pdb.set_trace()
+
if not self.options.noshutdown:
self.log.info("Stopping nodes")
if self.nodes:
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index dfd3b89895..93f180555d 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -79,6 +79,7 @@ BASE_SCRIPTS= [
'rawtransactions.py',
'reindex.py',
# vv Tests less than 30s vv
+ 'keypool-topup.py',
'zmq_test.py',
'mempool_resurrect_test.py',
'txn_doublespend.py --mineblock',
@@ -118,6 +119,7 @@ BASE_SCRIPTS= [
'bipdersig-p2p.py',
'bip65-cltv-p2p.py',
'uptime.py',
+ 'resendwallettransactions.py',
]
EXTENDED_SCRIPTS = [
diff --git a/test/functional/wallet-hd.py b/test/functional/wallet-hd.py
index dfd3dc83c5..821575ed19 100755
--- a/test/functional/wallet-hd.py
+++ b/test/functional/wallet-hd.py
@@ -9,7 +9,6 @@ from test_framework.util import (
assert_equal,
connect_nodes_bi,
)
-import os
import shutil
@@ -72,10 +71,12 @@ class WalletHDTest(BitcoinTestFramework):
self.log.info("Restore backup ...")
self.stop_node(1)
- os.remove(self.options.tmpdir + "/node1/regtest/wallet.dat")
+ # we need to delete the complete regtest directory
+ # otherwise node1 would auto-recover all funds in flag the keypool keys as used
+ shutil.rmtree(tmpdir + "/node1/regtest/blocks")
+ shutil.rmtree(tmpdir + "/node1/regtest/chainstate")
shutil.copyfile(tmpdir + "/hd.bak", tmpdir + "/node1/regtest/wallet.dat")
self.nodes[1] = self.start_node(1, self.options.tmpdir, self.extra_args[1])
- #connect_nodes_bi(self.nodes, 0, 1)
# Assert that derivation is deterministic
hd_add_2 = None
@@ -85,11 +86,12 @@ class WalletHDTest(BitcoinTestFramework):
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(_+1)+"'")
assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid)
assert_equal(hd_add, hd_add_2)
+ connect_nodes_bi(self.nodes, 0, 1)
+ self.sync_all()
# Needs rescan
self.stop_node(1)
self.nodes[1] = self.start_node(1, self.options.tmpdir, self.extra_args[1] + ['-rescan'])
- #connect_nodes_bi(self.nodes, 0, 1)
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
# send a tx and make sure its using the internal chain for the changeoutput