From ed445fe84cd7faaa42db4156d8c63a7374485644 Mon Sep 17 00:00:00 2001 From: AdamISZ Date: Thu, 7 Sep 2017 00:52:33 +0200 Subject: [PATCH] Fix tests to run if mainnet is concurrent. Add option to query unconfirmed in utxoset. --- jmbase/test/test_commands.py | 4 ++-- jmclient/jmclient/blockchaininterface.py | 8 ++++---- jmclient/test/test_client_protocol.py | 6 +++--- jmclient/test/test_configure.py | 3 ++- jmclient/test/test_wallets.py | 7 ++----- jmdaemon/test/test_daemon_protocol.py | 8 ++++---- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/jmbase/test/test_commands.py b/jmbase/test/test_commands.py index 010b1e5..db23972 100644 --- a/jmbase/test/test_commands.py +++ b/jmbase/test/test_commands.py @@ -232,13 +232,13 @@ class TrialTestJMProto(unittest.TestCase): def setUp(self): print("setUp()") - self.port = reactor.listenTCP(27184, JMTestServerProtocolFactory()) + self.port = reactor.listenTCP(28184, JMTestServerProtocolFactory()) self.addCleanup(self.port.stopListening) def cb(client): self.client = client self.addCleanup(self.client.transport.loseConnection) creator = protocol.ClientCreator(reactor, JMTestClientProtocol) - creator.connectTCP("localhost", 27184).addCallback(cb) + creator.connectTCP("localhost", 28184).addCallback(cb) def test_waiter(self): print("test_main()") diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 8c263bc..4672517 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -778,12 +778,12 @@ class BitcoinCoreInterface(BlockchainInterface): return False return True - def query_utxo_set(self, txout, includeconf=False): + def query_utxo_set(self, txout, includeconf=False, includeunconf=False): if not isinstance(txout, list): txout = [txout] result = [] for txo in txout: - ret = self.rpc('gettxout', [txo[:64], int(txo[65:]), False]) + ret = self.rpc('gettxout', [txo[:64], int(txo[65:]), includeunconf]) if ret is None: result.append(None) else: @@ -910,8 +910,8 @@ class RegtestBitcoinCoreInterface(BitcoinCoreInterface): #pragma: no cover # in the wallet res = [] for address in addresses: - self.rpc('importaddress', [address, 'watchonly']) + #self.rpc('importaddress', [address, 'watchonly']) res.append({'address': address, 'balance': int(round(Decimal(1e8) * Decimal(self.rpc( - 'getreceivedbyaddress', [address]))))}) + 'getreceivedbyaddress', [address, 0]))))}) return {'data': res} diff --git a/jmclient/test/test_client_protocol.py b/jmclient/test/test_client_protocol.py index 748e0a2..f0e8f17 100644 --- a/jmclient/test/test_client_protocol.py +++ b/jmclient/test/test_client_protocol.py @@ -216,7 +216,7 @@ class TrialTestJMClientProto(unittest.TestCase): params = [[False, False], [True, False], [False, True], [-1, False]] load_program_config() jm_single().maker_timeout_sec = 1 - self.port = reactor.listenTCP(27184, JMTestServerProtocolFactory()) + self.port = reactor.listenTCP(28184, JMTestServerProtocolFactory()) self.addCleanup(self.port.stopListening) def cb(client): self.client = client @@ -231,13 +231,13 @@ class TrialTestJMClientProto(unittest.TestCase): takers[i].testflag = True if i != 0: clientfactories.append(JMClientProtocolFactory(takers[i])) - clientconn = reactor.connectTCP("localhost", 27184, + clientconn = reactor.connectTCP("localhost", 28184, clientfactories[i]) self.addCleanup(clientconn.disconnect) else: clientfactories.append(DummyClientProtocolFactory(takers[i])) clientfactory = clientfactories[0] - clientconn = reactor.connectTCP("localhost", 27184, + clientconn = reactor.connectTCP("localhost", 28184, clientfactories[0]) self.addCleanup(clientconn.disconnect) diff --git a/jmclient/test/test_configure.py b/jmclient/test/test_configure.py index bb437aa..02749ae 100644 --- a/jmclient/test/test_configure.py +++ b/jmclient/test/test_configure.py @@ -29,7 +29,8 @@ def test_load_config(): #actually mainnet, but tests cannot; for now catch the connection error with pytest.raises(JsonRpcConnectionError) as e_info: load_program_config(config_path=ncp, bs="regtest") - assert str(e_info.value) == "JSON-RPC connection failed. Err:error(111, 'Connection refused')" + assert str(e_info.value) in ["authentication for JSON-RPC failed", + "JSON-RPC connection failed. Err:error(111, 'Connection refused')"] os.remove("dummydirforconfig/joinmarket.cfg") os.removedirs("dummydirforconfig") jm_single().config_location = "joinmarket.cfg" diff --git a/jmclient/test/test_wallets.py b/jmclient/test/test_wallets.py index b898e67..0cf11b3 100644 --- a/jmclient/test/test_wallets.py +++ b/jmclient/test/test_wallets.py @@ -6,7 +6,6 @@ import sys import os import time import binascii -import pexpect import random import subprocess import datetime @@ -55,14 +54,12 @@ def test_query_utxo_set(setup_wallets): ["wallet4utxo.json", "4utxo", [2, 3]]) sync_wallet(wallet) txid = do_tx(wallet, 90000000) - time.sleep(3) txid2 = do_tx(wallet, 20000000) - time.sleep(3) print("Got txs: ", txid, txid2) - res1 = jm_single().bc_interface.query_utxo_set(txid + ":0") + res1 = jm_single().bc_interface.query_utxo_set(txid + ":0", includeunconf=True) res2 = jm_single().bc_interface.query_utxo_set( [txid + ":0", txid2 + ":1"], - includeconf=True) + includeconf=True, includeunconf=True) assert len(res1) == 1 assert len(res2) == 2 assert all([x in res1[0] for x in ['script', 'address', 'value']]) diff --git a/jmdaemon/test/test_daemon_protocol.py b/jmdaemon/test/test_daemon_protocol.py index dd1eea4..08b4e1c 100644 --- a/jmdaemon/test/test_daemon_protocol.py +++ b/jmdaemon/test/test_daemon_protocol.py @@ -295,9 +295,9 @@ class TrialTestJMDaemonProto(unittest.TestCase): def setUp(self): load_program_config() jm_single().maker_timeout_sec = 1 - self.port = reactor.listenTCP(27184, JMDaemonTestServerProtocolFactory()) + self.port = reactor.listenTCP(28184, JMDaemonTestServerProtocolFactory()) self.addCleanup(self.port.stopListening) - clientconn = reactor.connectTCP("localhost", 27184, + clientconn = reactor.connectTCP("localhost", 28184, JMTestClientProtocolFactory()) self.addCleanup(clientconn.disconnect) @@ -315,9 +315,9 @@ class TestJMDaemonProtoInit(unittest.TestCase): end_early = True load_program_config() jm_single().maker_timeout_sec = 1 - self.port = reactor.listenTCP(27184, JMDaemonTest2ServerProtocolFactory()) + self.port = reactor.listenTCP(28184, JMDaemonTest2ServerProtocolFactory()) self.addCleanup(self.port.stopListening) - clientconn = reactor.connectTCP("localhost", 27184, + clientconn = reactor.connectTCP("localhost", 28184, JMTestClientProtocolFactory()) self.addCleanup(clientconn.disconnect)