Browse Source

Fix tests to run if mainnet is concurrent.

Add option to query unconfirmed in utxoset.
master
AdamISZ 8 years ago
parent
commit
ed445fe84c
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 4
      jmbase/test/test_commands.py
  2. 8
      jmclient/jmclient/blockchaininterface.py
  3. 6
      jmclient/test/test_client_protocol.py
  4. 3
      jmclient/test/test_configure.py
  5. 7
      jmclient/test/test_wallets.py
  6. 8
      jmdaemon/test/test_daemon_protocol.py

4
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()")

8
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}

6
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)

3
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"

7
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']])

8
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)

Loading…
Cancel
Save