diff --git a/conftest.py b/conftest.py index abfa846..0162367 100644 --- a/conftest.py +++ b/conftest.py @@ -89,7 +89,11 @@ def setup(request): #start up regtest blockchain btc_proc = subprocess.call([bitcoin_path + "bitcoind", "-regtest", "-daemon", "-conf=" + bitcoin_conf]) - time.sleep(3) - #generate blocks - local_command([bitcoin_path + "bitcoin-cli", "-regtest", "-rpcuser=" + bitcoin_rpcusername, - "-rpcpassword=" + bitcoin_rpcpassword, "generate", "101"]) + time.sleep(1) + #generate blocks; segwit activates around block 500-600 + for i in range(2): + local_command([bitcoin_path + "bitcoin-cli", "-regtest", + "-rpcuser=" + bitcoin_rpcusername, + "-rpcpassword=" + bitcoin_rpcpassword, "generate", "301"]) + time.sleep(1) + diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 8b246ce..7f75b88 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -1296,6 +1296,25 @@ class BitcoinCoreInterface(BlockchainInterface): return estimate +class TickChainThread(threading.Thread): + + def __init__(self, bcinterface, forever=False): + threading.Thread.__init__(self, name='TickChainThread') + self.bcinterface = bcinterface + self.forever = forever + def run(self): + if self.bcinterface.tick_forward_chain_interval < 0: + log.debug('not ticking forward chain') + return + if self.forever: + while True: + if self.bcinterface.shutdown_signal: + return + time.sleep(self.bcinterface.tick_forward_chain_interval) + self.bcinterface.tick_forward_chain(1) + time.sleep(self.bcinterface.tick_forward_chain_interval) + self.bcinterface.tick_forward_chain(1) + # class for regtest chain access # running on local daemon. Only # to be instantiated after network is up @@ -1305,8 +1324,10 @@ class RegtestBitcoinCoreInterface(BitcoinCoreInterface): #pragma: no cover def __init__(self, jsonRpc): super(RegtestBitcoinCoreInterface, self).__init__(jsonRpc, 'regtest') self.pushtx_failure_prob = 0 - self.tick_forward_chain_interval = 2 + self.tick_forward_chain_interval = -1 self.absurd_fees = False + self.simulating = False + self.shutdown_signal = False def estimate_fee_per_kb(self, N): if not self.absurd_fees: @@ -1316,6 +1337,10 @@ class RegtestBitcoinCoreInterface(BitcoinCoreInterface): #pragma: no cover return jm_single().config.getint("POLICY", "absurd_fee_per_kb") + 100 + def simulate_blocks(self): + TickChainThread(self, forever=True).start() + self.simulating = True + def pushtx(self, txhex): if self.pushtx_failure_prob != 0 and random.random() <\ self.pushtx_failure_prob: @@ -1324,21 +1349,8 @@ class RegtestBitcoinCoreInterface(BitcoinCoreInterface): #pragma: no cover return True ret = super(RegtestBitcoinCoreInterface, self).pushtx(txhex) - - class TickChainThread(threading.Thread): - - def __init__(self, bcinterface): - threading.Thread.__init__(self, name='TickChainThread') - self.bcinterface = bcinterface - - def run(self): - if self.bcinterface.tick_forward_chain_interval < 0: - log.debug('not ticking forward chain') - return - time.sleep(self.bcinterface.tick_forward_chain_interval) - self.bcinterface.tick_forward_chain(1) - - TickChainThread(self).start() + if not self.simulating: + TickChainThread(self).start() return ret def tick_forward_chain(self, n): diff --git a/jmclient/jmclient/client_protocol.py b/jmclient/jmclient/client_protocol.py index 9000688..072a78f 100644 --- a/jmclient/jmclient/client_protocol.py +++ b/jmclient/jmclient/client_protocol.py @@ -26,7 +26,8 @@ import os import sys import pprint from jmclient import (Taker, Wallet, jm_single, get_irc_mchannels, - load_program_config, get_log, get_p2sh_vbyte) + load_program_config, get_log, get_p2sh_vbyte, + RegtestBitcoinCoreInterface) from jmbase import _byteify import btc @@ -475,3 +476,5 @@ def start_reactor(host, port, factory, ish=True, daemon=False, rs=True): #pragma reactor.connectTCP(host, port, factory) if rs: reactor.run(installSignalHandlers=ish) + if isinstance(jm_single().bc_interface, RegtestBitcoinCoreInterface): + jm_single().bc_interface.shutdown_signal = True diff --git a/scripts/sample-schedule-for-testnet b/scripts/sample-schedule-for-testnet index 6ce39ea..e056ddc 100644 --- a/scripts/sample-schedule-for-testnet +++ b/scripts/sample-schedule-for-testnet @@ -23,5 +23,5 @@ # is changed to the txid. This is particularly useful for the `--restart` feature # of tumbler. Then changes to 1 when tx is confirmed. #========================== -1, 110000000, 3, INTERNAL, 0, 0 -0, 20000000, 2, mnsquzxrHXpFsZeL42qwbKdCP2y1esN3qw, 0, 0 \ No newline at end of file +1, 110000000, 3, INTERNAL, 0.8, 0 +0, 20000000, 2, mnsquzxrHXpFsZeL42qwbKdCP2y1esN3qw, 0, 0 diff --git a/test/regtest_joinmarket.cfg b/test/regtest_joinmarket.cfg index 3d85e8c..b7b3b62 100644 --- a/test/regtest_joinmarket.cfg +++ b/test/regtest_joinmarket.cfg @@ -41,3 +41,9 @@ taker_utxo_retries = 3 taker_utxo_age = 1 taker_utxo_amtpercent = 20 accept_commitment_broadcasts = 1 +#some settings useful for testing scenarios +#laxity for repeated tests; tests on actual +#commitments/maker limit/utxo sourcing logic should obviously reset +taker_utxo_retries = 250 +minimum_makers = 1 +listunspent_args = [0] diff --git a/test/ygrunner.py b/test/ygrunner.py index aead85c..894486c 100644 --- a/test/ygrunner.py +++ b/test/ygrunner.py @@ -25,7 +25,7 @@ from jmclient import (YieldGeneratorBasic, ygmain, load_program_config, "num_ygs, wallet_structures, mean_amt", [ # 1sp 3yg, 2 mixdepths, sweep from depth1 - (2, [[1, 3, 0, 0, 0]] * 3, 2), + (3, [[1, 3, 0, 0, 0]] * 4, 2), ]) def test_start_ygs(setup_ygrunner, num_ygs, wallet_structures, mean_amt): """Set up some wallets, for the ygs and 1 sp. @@ -63,4 +63,5 @@ def test_start_ygs(setup_ygrunner, num_ygs, wallet_structures, mean_amt): @pytest.fixture(scope="module") def setup_ygrunner(): load_program_config() - \ No newline at end of file + jm_single().bc_interface.tick_forward_chain_interval = 10 + jm_single().bc_interface.simulate_blocks() \ No newline at end of file