aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/merkle_blocks.py25
-rwxr-xr-xtest/functional/replace-by-fee.py2
-rwxr-xr-xtest/functional/test_runner.py8
-rwxr-xr-xtest/functional/wallet-encryption.py66
-rwxr-xr-xtest/functional/zmq_test.py65
5 files changed, 124 insertions, 42 deletions
diff --git a/test/functional/merkle_blocks.py b/test/functional/merkle_blocks.py
index 06af72ef10..bcc65c8408 100755
--- a/test/functional/merkle_blocks.py
+++ b/test/functional/merkle_blocks.py
@@ -39,7 +39,8 @@ class MerkleBlockTest(BitcoinTestFramework):
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(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"])
- assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1])
+ # This will raise an exception because the transaction is not yet in a block
+ assert_raises_jsonrpc(-5, "Transaction not yet in block", self.nodes[0].gettxoutproof, [txid1])
self.nodes[0].generate(1)
blockhash = self.nodes[0].getblockhash(chain_height + 1)
@@ -56,7 +57,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})
- self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
+ txid3 = self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()
@@ -64,17 +65,21 @@ class MerkleBlockTest(BitcoinTestFramework):
txid_unspent = txid1 if txin_spent["txid"] != txid1 else txid2
# We can't find the block from a fully-spent tx
- assert_raises(JSONRPCException, self.nodes[2].gettxoutproof, [txid_spent])
- # ...but we can if we specify the block
+ assert_raises_jsonrpc(-5, "Transaction not yet in block", self.nodes[2].gettxoutproof, [txid_spent])
+ # We can get the proof if we specify the block
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid_spent], blockhash)), [txid_spent])
- # ...or if the first tx is not fully-spent
+ # We can't get the proof if we specify a non-existent block
+ assert_raises_jsonrpc(-5, "Block not found", self.nodes[2].gettxoutproof, [txid_spent], "00000000000000000000000000000000")
+ # We can get the proof if the transaction is unspent
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid_unspent])), [txid_unspent])
- try:
- assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2])), txlist)
- except JSONRPCException:
- assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid2, txid1])), txlist)
- # ...or if we have a -txindex
+ # We can get the proof if we provide a list of transactions and one of them is unspent. The ordering of the list should not matter.
+ assert_equal(sorted(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2]))), sorted(txlist))
+ assert_equal(sorted(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid2, txid1]))), sorted(txlist))
+ # We can always get a proof if we have a -txindex
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[3].gettxoutproof([txid_spent])), [txid_spent])
+ # We can't get a proof if we specify transactions from different blocks
+ assert_raises_jsonrpc(-5, "Not all transactions found in specified or retrieved block", self.nodes[2].gettxoutproof, [txid1, txid3])
+
if __name__ == '__main__':
MerkleBlockTest().main()
diff --git a/test/functional/replace-by-fee.py b/test/functional/replace-by-fee.py
index ca7b623ca3..d6bf3ea59f 100755
--- a/test/functional/replace-by-fee.py
+++ b/test/functional/replace-by-fee.py
@@ -521,7 +521,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
def test_rpc(self):
us0 = self.nodes[0].listunspent()[0]
- ins = [us0];
+ ins = [us0]
outs = {self.nodes[0].getnewaddress() : Decimal(1.0000000)}
rawtx0 = self.nodes[0].createrawtransaction(ins, outs, 0, True)
rawtx1 = self.nodes[0].createrawtransaction(ins, outs, 0, False)
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 4702f2d773..0dca318af8 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -20,6 +20,7 @@ import datetime
import os
import time
import shutil
+import signal
import sys
import subprocess
import tempfile
@@ -78,7 +79,7 @@ BASE_SCRIPTS= [
'rawtransactions.py',
'reindex.py',
# vv Tests less than 30s vv
- "zmq_test.py",
+ 'zmq_test.py',
'mempool_resurrect_test.py',
'txn_doublespend.py --mineblock',
'txn_clone.py',
@@ -111,6 +112,7 @@ BASE_SCRIPTS= [
'rpcnamedargs.py',
'listsinceblock.py',
'p2p-leaktests.py',
+ 'wallet-encryption.py',
]
EXTENDED_SCRIPTS = [
@@ -389,6 +391,10 @@ class TestHandler:
time.sleep(.5)
for j in self.jobs:
(name, time0, proc, log_out, log_err) = j
+ if os.getenv('TRAVIS') == 'true' and int(time.time() - time0) > 20 * 60:
+ # In travis, timeout individual tests after 20 minutes (to stop tests hanging and not
+ # providing useful output.
+ proc.send_signal(signal.SIGINT)
if proc.poll() is not None:
log_out.seek(0), log_err.seek(0)
[stdout, stderr] = [l.read().decode('utf-8') for l in (log_out, log_err)]
diff --git a/test/functional/wallet-encryption.py b/test/functional/wallet-encryption.py
new file mode 100755
index 0000000000..33872e3c94
--- /dev/null
+++ b/test/functional/wallet-encryption.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+# Copyright (c) 2016 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 encryption"""
+
+import time
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_raises_jsonrpc,
+ bitcoind_processes,
+ BITCOIND_PROC_WAIT_TIMEOUT,
+)
+
+class WalletEncryptionTest(BitcoinTestFramework):
+
+ def __init__(self):
+ super().__init__()
+ self.setup_clean_chain = True
+ self.num_nodes = 1
+
+ def run_test(self):
+ passphrase = "WalletPassphrase"
+ passphrase2 = "SecondWalletPassphrase"
+
+ # Make sure the wallet isn't encrypted first
+ address = self.nodes[0].getnewaddress()
+ privkey = self.nodes[0].dumpprivkey(address)
+ assert_equal(privkey[:1], "c")
+ assert_equal(len(privkey), 52)
+
+ # Encrypt the wallet
+ self.nodes[0].encryptwallet(passphrase)
+ bitcoind_processes[0].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
+ self.nodes[0] = self.start_node(0, self.options.tmpdir)
+
+ # Test that the wallet is encrypted
+ assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
+
+ # Check that walletpassphrase works
+ self.nodes[0].walletpassphrase(passphrase, 2)
+ assert_equal(privkey, self.nodes[0].dumpprivkey(address))
+
+ # Check that the timeout is right
+ time.sleep(2)
+ assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
+
+ # Test wrong passphrase
+ assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase + "wrong", 10)
+
+ # Test walletlock
+ self.nodes[0].walletpassphrase(passphrase, 84600)
+ assert_equal(privkey, self.nodes[0].dumpprivkey(address))
+ self.nodes[0].walletlock()
+ assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
+
+ # Test passphrase changes
+ self.nodes[0].walletpassphrasechange(passphrase, passphrase2)
+ assert_raises_jsonrpc(-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))
+
+if __name__ == '__main__':
+ WalletEncryptionTest().main()
diff --git a/test/functional/zmq_test.py b/test/functional/zmq_test.py
index ce39cfefdc..26c946d215 100755
--- a/test/functional/zmq_test.py
+++ b/test/functional/zmq_test.py
@@ -8,15 +8,15 @@ import os
import struct
from test_framework.test_framework import BitcoinTestFramework, SkipTest
-from test_framework.util import *
+from test_framework.util import (assert_equal,
+ bytes_to_hex_str,
+ )
class ZMQTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
- self.num_nodes = 4
-
- port = 28332
+ self.num_nodes = 2
def setup_nodes(self):
# Try to import python3-zmq. Skip this test if the import fails.
@@ -28,7 +28,7 @@ class ZMQTest (BitcoinTestFramework):
# Check that bitcoin has been built with ZMQ enabled
config = configparser.ConfigParser()
if not self.options.configfile:
- self.options.configfile = os.path.dirname(__file__) + "/config.ini"
+ self.options.configfile = os.path.dirname(__file__) + "/../config.ini"
config.read_file(open(self.options.configfile))
if not config["components"].getboolean("ENABLE_ZMQ"):
@@ -36,59 +36,66 @@ class ZMQTest (BitcoinTestFramework):
self.zmqContext = zmq.Context()
self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
+ self.zmqSubSocket.set(zmq.RCVTIMEO, 60000)
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock")
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx")
- self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % self.port)
- self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[
- ['-zmqpubhashtx=tcp://127.0.0.1:'+str(self.port), '-zmqpubhashblock=tcp://127.0.0.1:'+str(self.port)],
- [],
- [],
- []
- ])
+ ip_address = "tcp://127.0.0.1:28332"
+ self.zmqSubSocket.connect(ip_address)
+ extra_args = [['-zmqpubhashtx=%s' % ip_address, '-zmqpubhashblock=%s' % ip_address], []]
+ self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
def run_test(self):
- self.sync_all()
+ try:
+ self._zmq_test()
+ finally:
+ # Destroy the zmq context
+ self.log.debug("Destroying zmq context")
+ self.zmqContext.destroy(linger=None)
+ def _zmq_test(self):
genhashes = self.nodes[0].generate(1)
self.sync_all()
- self.log.info("listen...")
+ self.log.info("Wait for tx")
msg = self.zmqSubSocket.recv_multipart()
topic = msg[0]
assert_equal(topic, b"hashtx")
body = msg[1]
msgSequence = struct.unpack('<I', msg[-1])[-1]
- assert_equal(msgSequence, 0) #must be sequence 0 on hashtx
+ assert_equal(msgSequence, 0) # must be sequence 0 on hashtx
+ self.log.info("Wait for block")
msg = self.zmqSubSocket.recv_multipart()
topic = msg[0]
body = msg[1]
msgSequence = struct.unpack('<I', msg[-1])[-1]
- assert_equal(msgSequence, 0) #must be sequence 0 on hashblock
+ assert_equal(msgSequence, 0) # must be sequence 0 on hashblock
blkhash = bytes_to_hex_str(body)
- assert_equal(genhashes[0], blkhash) #blockhash from generate must be equal to the hash received over zmq
+ assert_equal(genhashes[0], blkhash) # blockhash from generate must be equal to the hash received over zmq
+ self.log.info("Generate 10 blocks (and 10 coinbase txes)")
n = 10
genhashes = self.nodes[1].generate(n)
self.sync_all()
zmqHashes = []
blockcount = 0
- for x in range(0,n*2):
+ for x in range(n * 2):
msg = self.zmqSubSocket.recv_multipart()
topic = msg[0]
body = msg[1]
if topic == b"hashblock":
zmqHashes.append(bytes_to_hex_str(body))
msgSequence = struct.unpack('<I', msg[-1])[-1]
- assert_equal(msgSequence, blockcount+1)
+ assert_equal(msgSequence, blockcount + 1)
blockcount += 1
- for x in range(0,n):
- assert_equal(genhashes[x], zmqHashes[x]) #blockhash from generate must be equal to the hash received over zmq
+ for x in range(n):
+ assert_equal(genhashes[x], zmqHashes[x]) # blockhash from generate must be equal to the hash received over zmq
- #test tx from a second node
+ self.log.info("Wait for tx from second node")
+ # test tx from a second node
hashRPC = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1.0)
self.sync_all()
@@ -96,14 +103,12 @@ class ZMQTest (BitcoinTestFramework):
msg = self.zmqSubSocket.recv_multipart()
topic = msg[0]
body = msg[1]
- hashZMQ = ""
- if topic == b"hashtx":
- hashZMQ = bytes_to_hex_str(body)
- msgSequence = struct.unpack('<I', msg[-1])[-1]
- assert_equal(msgSequence, blockcount+1)
-
- assert_equal(hashRPC, hashZMQ) #blockhash from generate must be equal to the hash received over zmq
+ assert_equal(topic, b"hashtx")
+ hashZMQ = bytes_to_hex_str(body)
+ msgSequence = struct.unpack('<I', msg[-1])[-1]
+ assert_equal(msgSequence, blockcount + 1)
+ assert_equal(hashRPC, hashZMQ) # txid from sendtoaddress must be equal to the hash received over zmq
if __name__ == '__main__':
- ZMQTest ().main ()
+ ZMQTest().main()