mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
[qa] util: Rework sync_*()
* Only allow named args in sync_*() * Make sync_* fails more verbose * Add timeout to sync_chain()
This commit is contained in:
parent
fac1141600
commit
fa97ccb06d
@ -225,9 +225,9 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||||||
self.memutxo, Decimal("0.005"), min_fee, min_fee)
|
self.memutxo, Decimal("0.005"), min_fee, min_fee)
|
||||||
tx_kbytes = (len(txhex) // 2) / 1000.0
|
tx_kbytes = (len(txhex) // 2) / 1000.0
|
||||||
self.fees_per_kb.append(float(fee)/tx_kbytes)
|
self.fees_per_kb.append(float(fee)/tx_kbytes)
|
||||||
sync_mempools(self.nodes[0:3],.1)
|
sync_mempools(self.nodes[0:3], wait=.1)
|
||||||
mined = mining_node.getblock(mining_node.generate(1)[0],True)["tx"]
|
mined = mining_node.getblock(mining_node.generate(1)[0],True)["tx"]
|
||||||
sync_blocks(self.nodes[0:3],.1)
|
sync_blocks(self.nodes[0:3], wait=.1)
|
||||||
# update which txouts are confirmed
|
# update which txouts are confirmed
|
||||||
newmem = []
|
newmem = []
|
||||||
for utx in self.memutxo:
|
for utx in self.memutxo:
|
||||||
@ -259,7 +259,7 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||||||
while len(self.nodes[1].getrawmempool()) > 0:
|
while len(self.nodes[1].getrawmempool()) > 0:
|
||||||
self.nodes[1].generate(1)
|
self.nodes[1].generate(1)
|
||||||
|
|
||||||
sync_blocks(self.nodes[0:3],.1)
|
sync_blocks(self.nodes[0:3], wait=.1)
|
||||||
print("Final estimates after emptying mempools")
|
print("Final estimates after emptying mempools")
|
||||||
check_estimates(self.nodes[1], self.fees_per_kb, 2)
|
check_estimates(self.nodes[1], self.fees_per_kb, 2)
|
||||||
|
|
||||||
|
@ -121,33 +121,35 @@ def hex_str_to_bytes(hex_str):
|
|||||||
def str_to_b64str(string):
|
def str_to_b64str(string):
|
||||||
return b64encode(string.encode('utf-8')).decode('ascii')
|
return b64encode(string.encode('utf-8')).decode('ascii')
|
||||||
|
|
||||||
def sync_blocks(rpc_connections, wait=1, timeout=60):
|
def sync_blocks(rpc_connections, *, wait=1, timeout=60):
|
||||||
"""
|
"""
|
||||||
Wait until everybody has the same tip
|
Wait until everybody has the same tip
|
||||||
"""
|
"""
|
||||||
maxheight = 0
|
maxheight = 0
|
||||||
while timeout > 0:
|
while timeout > 0:
|
||||||
tips = [ x.waitforblockheight(maxheight, int(wait * 1000)) for x in rpc_connections ]
|
tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
|
||||||
heights = [ x["height"] for x in tips ]
|
heights = [t["height"] for t in tips]
|
||||||
if tips == [ tips[0] ]*len(tips):
|
if tips == [tips[0]] * len(tips):
|
||||||
return True
|
return
|
||||||
if heights == [ heights[0] ]*len(heights): #heights are the same but hashes are not
|
if heights == [heights[0]] * len(heights):
|
||||||
raise AssertionError("Block sync failed")
|
raise AssertionError("Block sync failed: (Hashes don't match)")
|
||||||
timeout -= wait
|
timeout -= wait
|
||||||
maxheight = max(heights)
|
maxheight = max(heights)
|
||||||
raise AssertionError("Block sync failed")
|
raise AssertionError("Block sync failed with heights: {}".format(heights))
|
||||||
|
|
||||||
def sync_chain(rpc_connections, wait=1):
|
def sync_chain(rpc_connections, *, wait=1, timeout=60):
|
||||||
"""
|
"""
|
||||||
Wait until everybody has the same best block
|
Wait until everybody has the same best block
|
||||||
"""
|
"""
|
||||||
while True:
|
while timeout > 0:
|
||||||
counts = [ x.getbestblockhash() for x in rpc_connections ]
|
best_hash = [x.getbestblockhash() for x in rpc_connections]
|
||||||
if counts == [ counts[0] ]*len(counts):
|
if best_hash == [best_hash[0]]*len(best_hash):
|
||||||
break
|
return
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
timeout -= wait
|
||||||
|
raise AssertionError("Chain sync failed: Best block hashes don't match")
|
||||||
|
|
||||||
def sync_mempools(rpc_connections, wait=1, timeout=60):
|
def sync_mempools(rpc_connections, *, wait=1, timeout=60):
|
||||||
"""
|
"""
|
||||||
Wait until everybody has the same transactions in their memory
|
Wait until everybody has the same transactions in their memory
|
||||||
pools
|
pools
|
||||||
@ -159,7 +161,7 @@ def sync_mempools(rpc_connections, wait=1, timeout=60):
|
|||||||
if set(rpc_connections[i].getrawmempool()) == pool:
|
if set(rpc_connections[i].getrawmempool()) == pool:
|
||||||
num_match = num_match+1
|
num_match = num_match+1
|
||||||
if num_match == len(rpc_connections):
|
if num_match == len(rpc_connections):
|
||||||
return True
|
return
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
timeout -= wait
|
timeout -= wait
|
||||||
raise AssertionError("Mempool sync failed")
|
raise AssertionError("Mempool sync failed")
|
||||||
|
Loading…
Reference in New Issue
Block a user