Browse Source

extra features for test running (ygrunner)

master
Adam Gibson 9 years ago
parent
commit
990e5d02f2
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 12
      conftest.py
  2. 44
      jmclient/jmclient/blockchaininterface.py
  3. 5
      jmclient/jmclient/client_protocol.py
  4. 4
      scripts/sample-schedule-for-testnet
  5. 6
      test/regtest_joinmarket.cfg
  6. 5
      test/ygrunner.py

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

44
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):

5
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

4
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
1, 110000000, 3, INTERNAL, 0.8, 0
0, 20000000, 2, mnsquzxrHXpFsZeL42qwbKdCP2y1esN3qw, 0, 0

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

5
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()
jm_single().bc_interface.tick_forward_chain_interval = 10
jm_single().bc_interface.simulate_blocks()
Loading…
Cancel
Save