From 82745dd076eedb005702a4c4dd5abf530858cffa Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 31 Dec 2018 08:12:36 +0100 Subject: [PATCH] Use DIP3 MNs in auto-IX tests (#2588) * Speed up autoix-mempool tests by making the max mempool smaller With this less TXs have to be created to fill up the mempool. * Change DashTestFramework to use DIP3 MNs * Don't assert disabled bip9 in p2p-autoinstantsend.py --- qa/rpc-tests/autoix-mempool.py | 5 +- qa/rpc-tests/p2p-autoinstantsend.py | 5 +- qa/rpc-tests/test_framework/test_framework.py | 111 ++++++++++-------- 3 files changed, 62 insertions(+), 59 deletions(-) diff --git a/qa/rpc-tests/autoix-mempool.py b/qa/rpc-tests/autoix-mempool.py index 9266a06b51014..80673b98c791d 100755 --- a/qa/rpc-tests/autoix-mempool.py +++ b/qa/rpc-tests/autoix-mempool.py @@ -16,14 +16,14 @@ ''' -MAX_MEMPOOL_SIZE = 5 # max node mempool in MBs +MAX_MEMPOOL_SIZE = 1 # max node mempool in MBs MB_SIZE = 1000000 # C++ code use this coefficient to calc MB in mempool AUTO_IX_MEM_THRESHOLD = 0.1 class AutoIXMempoolTest(DashTestFramework): def __init__(self): - super().__init__(13, 10, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE]) + super().__init__(13, 10, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE, '-limitdescendantsize=10']) # set sender, receiver self.receiver_idx = self.num_nodes - 2 self.sender_idx = self.num_nodes - 3 @@ -118,7 +118,6 @@ def fill_mempool(self): def run_test(self): # make sure masternodes are synced sync_masternodes(self.nodes) - self.enforce_masternode_payments() # required for bip9 activation self.activate_autoix_bip9() self.set_autoix_spork_state(True) diff --git a/qa/rpc-tests/p2p-autoinstantsend.py b/qa/rpc-tests/p2p-autoinstantsend.py index 3177515141a2e..a6d2d09b8451d 100755 --- a/qa/rpc-tests/p2p-autoinstantsend.py +++ b/qa/rpc-tests/p2p-autoinstantsend.py @@ -15,8 +15,7 @@ Checks that simple transactions automatically become InstantSend locked, complex transactions don't become IS-locked and this functionality is -activated only if it is BIP9-activated and SPORK_16_INSTANTSEND_AUTOLOCKS is -active. +activated only if SPORK_16_INSTANTSEND_AUTOLOCKS is active. Also checks that this functionality doesn't influence regular InstantSend transactions with high fee. @@ -125,8 +124,6 @@ def run_test(self): set_node_times(self.nodes, get_mocktime()) self.nodes[0].generate(1) - self.enforce_masternode_payments() # required for bip9 activation - assert(self.get_autoix_bip9_status() == 'defined') assert(not self.get_autoix_spork_state()) assert(self.send_regular_IX()) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index c209550fcac99..fbff894288764 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -35,8 +35,8 @@ set_mocktime, set_node_times, p2p_port, - satoshi_round -) + satoshi_round, + wait_to_sync) from .authproxy import JSONRPCException @@ -207,11 +207,15 @@ def main(self): class MasternodeInfo: - def __init__(self, key, blsKey, collateral_id, collateral_out): - self.key = key - self.blsKey = blsKey - self.collateral_id = collateral_id - self.collateral_out = collateral_out + def __init__(self, proTxHash, ownerAddr, votingAddr, pubKeyOperator, keyOperator, collateral_address, collateral_txid, collateral_vout): + self.proTxHash = proTxHash + self.ownerAddr = ownerAddr + self.votingAddr = votingAddr + self.pubKeyOperator = pubKeyOperator + self.keyOperator = keyOperator + self.collateral_address = collateral_address + self.collateral_txid = collateral_txid + self.collateral_vout = collateral_vout class DashTestFramework(BitcoinTestFramework): @@ -228,71 +232,80 @@ def __init__(self, num_nodes, masterodes_count, extra_args): def create_simple_node(self): idx = len(self.nodes) args = self.extra_args - self.nodes.append(start_node(idx, self.options.tmpdir, - args)) + self.nodes.append(start_node(idx, self.options.tmpdir, args)) for i in range(0, idx): connect_nodes(self.nodes[i], idx) - def get_mnconf_file(self): - return os.path.join(self.options.tmpdir, "node0/regtest/masternode.conf") - def prepare_masternodes(self): for idx in range(0, self.mn_count): - key = self.nodes[0].masternode("genkey") - blsKey = self.nodes[0].bls('generate')['secret'] + bls = self.nodes[0].bls('generate') address = self.nodes[0].getnewaddress() txid = self.nodes[0].sendtoaddress(address, MASTERNODE_COLLATERAL) - txrow = self.nodes[0].getrawtransaction(txid, True) + + txraw = self.nodes[0].getrawtransaction(txid, True) collateral_vout = 0 - for vout_idx in range(0, len(txrow["vout"])): - vout = txrow["vout"][vout_idx] + for vout_idx in range(0, len(txraw["vout"])): + vout = txraw["vout"][vout_idx] if vout["value"] == MASTERNODE_COLLATERAL: collateral_vout = vout_idx - self.nodes[0].lockunspent(False, - [{"txid": txid, "vout": collateral_vout}]) - self.mninfo.append(MasternodeInfo(key, blsKey, txid, collateral_vout)) + self.nodes[0].lockunspent(False, [{'txid': txid, 'vout': collateral_vout}]) - def write_mn_config(self): - conf = self.get_mnconf_file() - f = open(conf, 'a') - for idx in range(0, self.mn_count): - f.write("mn%d 127.0.0.1:%d %s %s %d\n" % (idx + 1, p2p_port(idx + 1), - self.mninfo[idx].key, - self.mninfo[idx].collateral_id, - self.mninfo[idx].collateral_out)) - f.close() + # send to same address to reserve some funds for fees + self.nodes[0].sendtoaddress(address, 0.001) + + ownerAddr = self.nodes[0].getnewaddress() + votingAddr = self.nodes[0].getnewaddress() + rewardsAddr = self.nodes[0].getnewaddress() + + port = p2p_port(len(self.nodes) + idx) + if (idx % 2) == 0: + self.nodes[0].lockunspent(True, [{'txid': txid, 'vout': collateral_vout}]) + proTxHash = self.nodes[0].protx('register_fund', address, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address) + else: + self.nodes[0].generate(1) + proTxHash = self.nodes[0].protx('register', txid, collateral_vout, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address) + self.nodes[0].generate(1) + + self.mninfo.append(MasternodeInfo(proTxHash, ownerAddr, votingAddr, bls['public'], bls['secret'], address, txid, collateral_vout)) + self.sync_all() - def create_masternodes(self): + def start_masternodes(self): + start_idx = len(self.nodes) for idx in range(0, self.mn_count): - args = ['-externalip=127.0.0.1', '-masternode=1', - '-masternodeprivkey=%s' % self.mninfo[idx].key, - '-masternodeblsprivkey=%s' % self.mninfo[idx].blsKey] + self.extra_args - self.nodes.append(start_node(idx + 1, self.options.tmpdir, args)) + args = ['-masternode=1', + '-masternodeblsprivkey=%s' % self.mninfo[idx].keyOperator] + self.extra_args + node = start_node(idx + start_idx, self.options.tmpdir, args) + self.mninfo[idx].node = node + self.nodes.append(node) for i in range(0, idx + 1): - connect_nodes(self.nodes[i], idx + 1) + connect_nodes(self.nodes[idx + start_idx], i) + wait_to_sync(node, True) + sync_masternodes(self.nodes, True) def setup_network(self): self.nodes = [] # create faucet node for collateral and transactions - args = self.extra_args + args = ["-sporkkey=cP4EKFyJsHT39LDqgdcB43Y3YXjNyjb5Fuas1GQSeAtjnZWmZEQK"] + self.extra_args self.nodes.append(start_node(0, self.options.tmpdir, args)) required_balance = MASTERNODE_COLLATERAL * self.mn_count + 1 while self.nodes[0].getbalance() < required_balance: set_mocktime(get_mocktime() + 1) set_node_times(self.nodes, get_mocktime()) self.nodes[0].generate(1) - # create masternodes - self.prepare_masternodes() - self.write_mn_config() - stop_node(self.nodes[0], 0) - args = ["-sporkkey=cP4EKFyJsHT39LDqgdcB43Y3YXjNyjb5Fuas1GQSeAtjnZWmZEQK"] + \ - self.extra_args - self.nodes[0] = start_node(0, self.options.tmpdir, - args) - self.create_masternodes() # create connected simple nodes for i in range(0, self.num_nodes - self.mn_count - 1): self.create_simple_node() + sync_masternodes(self.nodes, True) + + # activate DIP3 + while self.nodes[0].getblockcount() < 500: + self.nodes[0].generate(10) + self.sync_all() + + # create masternodes + self.prepare_masternodes() + self.start_masternodes() + set_mocktime(get_mocktime() + 1) set_node_times(self.nodes, get_mocktime()) self.nodes[0].generate(1) @@ -300,18 +313,12 @@ def setup_network(self): self.sync_all() set_mocktime(get_mocktime() + 1) set_node_times(self.nodes, get_mocktime()) - sync_masternodes(self.nodes, True) - for i in range(1, self.mn_count + 1): - res = self.nodes[0].masternode("start-alias", "mn%d" % i) - assert (res["result"] == 'successful') + mn_info = self.nodes[0].masternodelist("status") assert (len(mn_info) == self.mn_count) for status in mn_info.values(): assert (status == 'ENABLED') - def enforce_masternode_payments(self): - self.nodes[0].spork('SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT', 0) - def create_raw_trx(self, node_from, node_to, amount, min_inputs, max_inputs): assert (min_inputs <= max_inputs) # fill inputs