Skip to content

Commit

Permalink
Use logging framework in Dash specific tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock authored and PastaPastaPasta committed Mar 8, 2019
1 parent 0db2d15 commit 0e91ebc
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 78 deletions.
28 changes: 14 additions & 14 deletions qa/rpc-tests/addressindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def __init__(self):
def setup_network(self):
self.nodes = []
# Nodes 0/1 are "wallet" nodes
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-relaypriority=0"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-addressindex"]))
self.nodes.append(start_node(0, self.options.tmpdir, ["-relaypriority=0"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-addressindex"]))
# Nodes 2/3 are used for testing
self.nodes.append(start_node(2, self.options.tmpdir, ["-debug", "-addressindex", "-relaypriority=0"]))
self.nodes.append(start_node(3, self.options.tmpdir, ["-debug", "-addressindex"]))
self.nodes.append(start_node(2, self.options.tmpdir, ["-addressindex", "-relaypriority=0"]))
self.nodes.append(start_node(3, self.options.tmpdir, ["-addressindex"]))
connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[0], 2)
connect_nodes(self.nodes[0], 3)
Expand All @@ -36,7 +36,7 @@ def setup_network(self):
self.sync_all()

def run_test(self):
print("Mining blocks...")
self.log.info("Mining blocks...")
self.nodes[0].generate(105)
self.sync_all()

Expand All @@ -50,7 +50,7 @@ def run_test(self):
assert_equal(balance0["balance"], 0)

# Check p2pkh and p2sh address indexes
print("Testing p2pkh and p2sh address index...")
self.log.info("Testing p2pkh and p2sh address index...")

txid0 = self.nodes[0].sendtoaddress("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4", 10)
self.nodes[0].generate(1)
Expand Down Expand Up @@ -85,7 +85,7 @@ def run_test(self):
assert_equal(txidsb[2], txidb2)

# Check that limiting by height works
print("Testing querying txids by range of block heights..")
self.log.info("Testing querying txids by range of block heights..")
height_txids = self.nodes[1].getaddresstxids({
"addresses": ["93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB"],
"start": 105,
Expand All @@ -110,7 +110,7 @@ def run_test(self):
assert_equal(balance0["balance"], 45 * 100000000)

# Check that outputs with the same address will only return one txid
print("Testing for txid uniqueness...")
self.log.info("Testing for txid uniqueness...")
addressHash = binascii.unhexlify("FE30B718DCF0BF8A2A686BF1820C073F8B2C3B37")
scriptPubKey = CScript([OP_HASH160, addressHash, OP_EQUAL])
unspent = self.nodes[0].listunspent()
Expand All @@ -130,12 +130,12 @@ def run_test(self):
assert_equal(txidsmany[3], sent_txid)

# Check that balances are correct
print("Testing balances...")
self.log.info("Testing balances...")
balance0 = self.nodes[1].getaddressbalance("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB")
assert_equal(balance0["balance"], 45 * 100000000 + 21)

# Check that balances are correct after spending
print("Testing balances after spending...")
self.log.info("Testing balances after spending...")
privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
address2 = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
addressHash2 = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
Expand Down Expand Up @@ -188,13 +188,13 @@ def run_test(self):
assert_equal(len(deltas), 1)

# Check that unspent outputs can be queried
print("Testing utxos...")
self.log.info("Testing utxos...")
utxos = self.nodes[1].getaddressutxos({"addresses": [address2]})
assert_equal(len(utxos), 1)
assert_equal(utxos[0]["satoshis"], change_amount)

# Check that indexes will be updated with a reorg
print("Testing reorg...")
self.log.info("Testing reorg...")

best_hash = self.nodes[0].getbestblockhash()
self.nodes[0].invalidateblock(best_hash)
Expand Down Expand Up @@ -229,7 +229,7 @@ def run_test(self):
assert_equal(utxos3[2]["height"], 265)

# Check mempool indexing
print("Testing mempool indexing...")
self.log.info("Testing mempool indexing...")

privKey3 = "cRyrMvvqi1dmpiCmjmmATqjAwo6Wu7QTjKu1ABMYW5aFG4VXW99K"
address3 = "yWB15aAdpeKuSaQHFVJpBDPbNSLZJSnDLA"
Expand Down Expand Up @@ -327,7 +327,7 @@ def run_test(self):
mempool_deltas = self.nodes[2].getaddressmempool({"addresses": [address1]})
assert_equal(len(mempool_deltas), 2)

print("Passed\n")
self.log.info("Passed")


if __name__ == '__main__':
Expand Down
50 changes: 25 additions & 25 deletions qa/rpc-tests/dip3-deterministicmns.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setup_network(self):
self.is_network_split = False

def start_controller_node(self, extra_args=None):
print("starting controller node")
self.log.info("starting controller node")
if self.nodes is None:
self.nodes = [None]
args = self.extra_args
Expand All @@ -44,27 +44,27 @@ def start_controller_node(self, extra_args=None):
connect_nodes_bi(self.nodes, 0, i)

def stop_controller_node(self):
print("stopping controller node")
self.log.info("stopping controller node")
stop_node(self.nodes[0], 0)

def restart_controller_node(self):
self.stop_controller_node()
self.start_controller_node()

def run_test(self):
print("funding controller node")
self.log.info("funding controller node")
while self.nodes[0].getbalance() < (self.num_initial_mn + 3) * 1000:
self.nodes[0].generate(1) # generate enough for collaterals
print("controller node has {} dash".format(self.nodes[0].getbalance()))
self.log.info("controller node has {} dash".format(self.nodes[0].getbalance()))

# Make sure we're below block 135 (which activates dip3)
print("testing rejection of ProTx before dip3 activation")
self.log.info("testing rejection of ProTx before dip3 activation")
assert(self.nodes[0].getblockchaininfo()['blocks'] < 135)

mns = []

# prepare mn which should still be accepted later when dip3 activates
print("creating collateral for mn-before-dip3")
self.log.info("creating collateral for mn-before-dip3")
before_dip3_mn = self.prepare_mn(self.nodes[0], 1, 'mn-before-dip3')
self.create_mn_collateral(self.nodes[0], before_dip3_mn)
mns.append(before_dip3_mn)
Expand All @@ -73,19 +73,19 @@ def run_test(self):
while self.nodes[0].getblockcount() < 150:
self.nodes[0].generate(1)

print("mining final block for DIP3 activation")
self.log.info("mining final block for DIP3 activation")
self.nodes[0].generate(1)

# We have hundreds of blocks to sync here, give it more time
print("syncing blocks for all nodes")
self.log.info("syncing blocks for all nodes")
sync_blocks(self.nodes, timeout=120)

# DIP3 has activated here

self.register_mn(self.nodes[0], before_dip3_mn)
self.start_mn(before_dip3_mn)

print("registering MNs")
self.log.info("registering MNs")
for i in range(0, self.num_initial_mn):
mn = self.prepare_mn(self.nodes[0], i + 2, "mn-%d" % i)
mns.append(mn)
Expand All @@ -98,12 +98,12 @@ def run_test(self):
# let a few of the protx MNs refer to the existing collaterals
fund = (i % 2) == 0
if fund:
print("register_fund %s" % mn.alias)
self.log.info("register_fund %s" % mn.alias)
self.register_fund_mn(self.nodes[0], mn)
else:
print("create_collateral %s" % mn.alias)
self.log.info("create_collateral %s" % mn.alias)
self.create_mn_collateral(self.nodes[0], mn)
print("register %s" % mn.alias)
self.log.info("register %s" % mn.alias)
self.register_mn(self.nodes[0], mn)

self.nodes[0].generate(1)
Expand All @@ -114,10 +114,10 @@ def run_test(self):
self.sync_all()
self.assert_mnlists(mns)

print("testing instant send")
self.log.info("testing instant send")
self.test_instantsend(10, 3)

print("test that MNs disappear from the list when the ProTx collateral is spent")
self.log.info("test that MNs disappear from the list when the ProTx collateral is spent")
spend_mns_count = 3
mns_tmp = [] + mns
dummy_txins = []
Expand All @@ -129,30 +129,30 @@ def run_test(self):
mns_tmp.remove(mns[i])
self.assert_mnlists(mns_tmp)

print("test that reverting the blockchain on a single node results in the mnlist to be reverted as well")
self.log.info("test that reverting the blockchain on a single node results in the mnlist to be reverted as well")
for i in range(spend_mns_count):
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
mns_tmp.append(mns[spend_mns_count - 1 - i])
self.assert_mnlist(self.nodes[0], mns_tmp)

print("cause a reorg with a double spend and check that mnlists are still correct on all nodes")
self.log.info("cause a reorg with a double spend and check that mnlists are still correct on all nodes")
self.mine_double_spend(self.nodes[0], dummy_txins, self.nodes[0].getnewaddress(), use_mnmerkleroot_from_tip=True)
self.nodes[0].generate(spend_mns_count)
self.sync_all()
self.assert_mnlists(mns_tmp)

print("test mn payment enforcement with deterministic MNs")
self.log.info("test mn payment enforcement with deterministic MNs")
for i in range(20):
node = self.nodes[i % len(self.nodes)]
self.test_invalid_mn_payment(node)
node.generate(1)
self.sync_all()

print("testing ProUpServTx")
self.log.info("testing ProUpServTx")
for mn in mns:
self.test_protx_update_service(mn)

print("testing P2SH/multisig for payee addresses")
self.log.info("testing P2SH/multisig for payee addresses")
multisig = self.nodes[0].createmultisig(1, [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()])['address']
self.update_mn_payee(mns[0], multisig)
found_multisig_payee = False
Expand All @@ -171,7 +171,7 @@ def run_test(self):
found_multisig_payee = True
assert(found_multisig_payee)

print("testing reusing of collaterals for replaced MNs")
self.log.info("testing reusing of collaterals for replaced MNs")
for i in range(0, 5):
mn = mns[i]
# a few of these will actually refer to old ProRegTx internal collaterals,
Expand All @@ -186,15 +186,15 @@ def run_test(self):
self.nodes[0].generate(1)
self.sync_all()
self.assert_mnlists(mns)
print("restarting MN %s" % new_mn.alias)
self.log.info("restarting MN %s" % new_mn.alias)
self.stop_node(new_mn.idx)
self.start_mn(new_mn)
self.sync_all()

print("testing instant send with replaced MNs")
self.log.info("testing instant send with replaced MNs")
self.test_instantsend(10, 3, timeout=20)

print("testing simple PoSe")
self.log.info("testing simple PoSe")
self.assert_mnlists(mns)
self.nodes[0].spork('SPORK_17_QUORUM_DKG_ENABLED', 0)
self.wait_for_sporks()
Expand Down Expand Up @@ -408,8 +408,8 @@ def assert_mnlist(self, node, mns):
expected = []
for mn in mns:
expected.append('%s-%d' % (mn.collateral_txid, mn.collateral_vout))
print('mnlist: ' + str(node.masternode('list', 'status')))
print('expected: ' + str(expected))
self.log.error('mnlist: ' + str(node.masternode('list', 'status')))
self.log.error('expected: ' + str(expected))
raise AssertionError("mnlists does not match provided mns")

def wait_for_sporks(self, timeout=30):
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/fundrawtransaction-hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup_network(self, split=False):
self.sync_all()

def run_test(self):
print("Mining blocks...")
self.log.info("Mining blocks...")

min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
# This test is not meant to test fee estimation and we'd like
Expand Down
10 changes: 5 additions & 5 deletions qa/rpc-tests/multikeysporks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,39 @@ def setup_network(self):
# address(base58): yc5TGfcHYoLCrcbVy4umsiDjsYUn39vLui

self.nodes.append(start_node(0, self.options.tmpdir,
["-debug", "-sporkkey=931wyuRNVYvhg18Uu9bky5Qg1z4QbxaJ7fefNBzjBPiLRqcd33F",
["-sporkkey=931wyuRNVYvhg18Uu9bky5Qg1z4QbxaJ7fefNBzjBPiLRqcd33F",
"-sporkaddr=ygcG5S2pQz2U1UAaHvU6EznKZW7yapKMA7",
"-sporkaddr=yfLSXFfipnkgYioD6L8aUNyfRgEBuJv48h",
"-sporkaddr=yNsMZhEhYqv14TgdYb1NS2UmNZjE8FSJxa",
"-sporkaddr=ycbRQWbovrhQMTuxg9p4LAuW5SCMAKqPrn",
"-sporkaddr=yc5TGfcHYoLCrcbVy4umsiDjsYUn39vLui",
"-minsporkkeys=3"]))
self.nodes.append(start_node(1, self.options.tmpdir,
["-debug", "-sporkkey=91vbXGMSWKGHom62986XtL1q2mQDA12ngcuUNNe5NfMSj44j7g3",
["-sporkkey=91vbXGMSWKGHom62986XtL1q2mQDA12ngcuUNNe5NfMSj44j7g3",
"-sporkaddr=ygcG5S2pQz2U1UAaHvU6EznKZW7yapKMA7",
"-sporkaddr=yfLSXFfipnkgYioD6L8aUNyfRgEBuJv48h",
"-sporkaddr=yNsMZhEhYqv14TgdYb1NS2UmNZjE8FSJxa",
"-sporkaddr=ycbRQWbovrhQMTuxg9p4LAuW5SCMAKqPrn",
"-sporkaddr=yc5TGfcHYoLCrcbVy4umsiDjsYUn39vLui",
"-minsporkkeys=3"]))
self.nodes.append(start_node(2, self.options.tmpdir,
["-debug", "-sporkkey=92bxUjPT5AhgXuXJwfGGXqhomY2SdQ55MYjXyx9DZNxCABCSsRH",
["-sporkkey=92bxUjPT5AhgXuXJwfGGXqhomY2SdQ55MYjXyx9DZNxCABCSsRH",
"-sporkaddr=ygcG5S2pQz2U1UAaHvU6EznKZW7yapKMA7",
"-sporkaddr=yfLSXFfipnkgYioD6L8aUNyfRgEBuJv48h",
"-sporkaddr=yNsMZhEhYqv14TgdYb1NS2UmNZjE8FSJxa",
"-sporkaddr=ycbRQWbovrhQMTuxg9p4LAuW5SCMAKqPrn",
"-sporkaddr=yc5TGfcHYoLCrcbVy4umsiDjsYUn39vLui",
"-minsporkkeys=3"]))
self.nodes.append(start_node(3, self.options.tmpdir,
["-debug", "-sporkkey=934yPXiVGf4RCY2qTs2Bt5k3TEtAiAg12sMxCt8yVWbSU7p3fuD",
["-sporkkey=934yPXiVGf4RCY2qTs2Bt5k3TEtAiAg12sMxCt8yVWbSU7p3fuD",
"-sporkaddr=ygcG5S2pQz2U1UAaHvU6EznKZW7yapKMA7",
"-sporkaddr=yfLSXFfipnkgYioD6L8aUNyfRgEBuJv48h",
"-sporkaddr=yNsMZhEhYqv14TgdYb1NS2UmNZjE8FSJxa",
"-sporkaddr=ycbRQWbovrhQMTuxg9p4LAuW5SCMAKqPrn",
"-sporkaddr=yc5TGfcHYoLCrcbVy4umsiDjsYUn39vLui",
"-minsporkkeys=3"]))
self.nodes.append(start_node(4, self.options.tmpdir,
["-debug", "-sporkkey=92Cxwia363Wg2qGF1fE5z4GKi8u7r1nrWQXdtsj2ACZqaDPSihD",
["-sporkkey=92Cxwia363Wg2qGF1fE5z4GKi8u7r1nrWQXdtsj2ACZqaDPSihD",
"-sporkaddr=ygcG5S2pQz2U1UAaHvU6EznKZW7yapKMA7",
"-sporkaddr=yfLSXFfipnkgYioD6L8aUNyfRgEBuJv48h",
"-sporkaddr=yNsMZhEhYqv14TgdYb1NS2UmNZjE8FSJxa",
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/p2p-instantsend.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_test(self):
# start last node
self.nodes[self.isolated_idx] = start_node(self.isolated_idx,
self.options.tmpdir,
["-debug"] + self.extra_args)
self.extra_args)
# send doublespend transaction to isolated node
self.nodes[self.isolated_idx].sendrawtransaction(dblspnd_tx['hex'])
# generate block on isolated node with doublespend transaction
Expand Down
18 changes: 9 additions & 9 deletions qa/rpc-tests/spentindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def __init__(self):
def setup_network(self):
self.nodes = []
# Nodes 0/1 are "wallet" nodes
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-spentindex"]))
self.nodes.append(start_node(0, self.options.tmpdir))
self.nodes.append(start_node(1, self.options.tmpdir, ["-spentindex"]))
# Nodes 2/3 are used for testing
self.nodes.append(start_node(2, self.options.tmpdir, ["-debug", "-spentindex"]))
self.nodes.append(start_node(3, self.options.tmpdir, ["-debug", "-spentindex", "-txindex"]))
self.nodes.append(start_node(2, self.options.tmpdir, ["-spentindex"]))
self.nodes.append(start_node(3, self.options.tmpdir, ["-spentindex", "-txindex"]))
connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[0], 2)
connect_nodes(self.nodes[0], 3)
Expand All @@ -36,15 +36,15 @@ def setup_network(self):
self.sync_all()

def run_test(self):
print("Mining blocks...")
self.log.info("Mining blocks...")
self.nodes[0].generate(105)
self.sync_all()

chain_height = self.nodes[1].getblockcount()
assert_equal(chain_height, 105)

# Check that
print("Testing spent index...")
self.log.info("Testing spent index...")

privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
Expand All @@ -62,15 +62,15 @@ def run_test(self):
self.nodes[0].generate(1)
self.sync_all()

print("Testing getspentinfo method...")
self.log.info("Testing getspentinfo method...")

# Check that the spentinfo works standalone
info = self.nodes[1].getspentinfo({"txid": unspent[0]["txid"], "index": unspent[0]["vout"]})
assert_equal(info["txid"], txid)
assert_equal(info["index"], 0)
assert_equal(info["height"], 106)

print("Testing getrawtransaction method...")
self.log.info("Testing getrawtransaction method...")

# Check that verbose raw transaction includes spent info
txVerbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1)
Expand Down Expand Up @@ -112,7 +112,7 @@ def run_test(self):
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)

print("Passed\n")
self.log.info("Passed")


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 0e91ebc

Please sign in to comment.