diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index fbaede37ab256..08ead2eb9b27c 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -36,7 +36,7 @@ 'fundrawtransaction.py', 'fundrawtransaction-hd.py', 'p2p-autoinstantsend.py', - 'autoix-mempool.py', + 'autois-mempool.py', # vv Tests less than 2m vv 'p2p-instantsend.py', 'wallet.py', diff --git a/qa/rpc-tests/autois-mempool.py b/qa/rpc-tests/autois-mempool.py new file mode 100755 index 0000000000000..7a63cd0ec8480 --- /dev/null +++ b/qa/rpc-tests/autois-mempool.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# Copyright (c) 2018 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.mininode import * +from test_framework.test_framework import DashTestFramework +from test_framework.util import * +from time import * + +''' +autois-mempool.py + +Checks if automatic InstantSend locks stop working when transaction mempool +is full (more than 0.1 part from max value). + +''' + +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 AutoISMempoolTest(DashTestFramework): + def __init__(self): + super().__init__(8, 5, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE, '-limitdescendantsize=10'], fast_dip3_enforcement=True) + # set sender, receiver + self.receiver_idx = 1 + self.sender_idx = 2 + + def get_mempool_usage(self, node): + info = node.getmempoolinfo() + return info['usage'] + + def fill_mempool(self): + # send lots of txes to yourself just to fill the mempool + counter = 0 + sync_period = 10 + dummy_address = self.nodes[0].getnewaddress() + while self.get_mempool_usage(self.nodes[self.sender_idx]) < MAX_MEMPOOL_SIZE * MB_SIZE * AUTO_IX_MEM_THRESHOLD: + self.nodes[0].sendtoaddress(dummy_address, 1.0) + counter += 1 + if counter % sync_period == 0: + # sync nodes + self.sync_all() + self.sync_all() + + def run_test(self): + # make sure masternodes are synced + sync_masternodes(self.nodes) + + self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0) + self.wait_for_sporks_same() + self.mine_quorum() + + self.log.info("Test old InstantSend") + self.test_auto(); + + self.nodes[0].spork("SPORK_20_INSTANTSEND_LLMQ_BASED", 0) + self.wait_for_sporks_same() + + self.log.info("Test new InstantSend") + self.test_auto(True); + + def test_auto(self, new_is = False): + self.activate_autois_bip9(self.nodes[0]) + self.set_autois_spork_state(self.nodes[0], True) + + # check pre-conditions for autoIS + assert(self.get_autois_bip9_status(self.nodes[0]) == 'active') + assert(self.get_autois_spork_state(self.nodes[0])) + + # create 3 inputs for txes on sender node and give them enough confirmations + sender = self.nodes[self.sender_idx] + receiver = self.nodes[self.receiver_idx] + sender_address = sender.getnewaddress() + for i in range(0, 4): + self.nodes[0].sendtoaddress(sender_address, 2.0) + for i in range(0, 2): + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + self.nodes[0].generate(1) + self.sync_all() + + # autoIS is working + assert(self.send_simple_tx(sender, receiver)) + + # fill mempool with transactions + self.set_autois_spork_state(self.nodes[0], False) + self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800) + self.wait_for_sporks_same() + self.fill_mempool() + self.set_autois_spork_state(self.nodes[0], True) + self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0) + self.wait_for_sporks_same() + + # autoIS is not working now + assert(not self.send_simple_tx(sender, receiver)) + # regular IS is still working for old IS but not for new one + assert(not self.send_regular_instantsend(sender, receiver, False) if new_is else self.send_regular_instantsend(sender, receiver)) + + # generate one block to clean up mempool and retry auto and regular IS + # generate 2 more blocks to have enough confirmations for IS + self.nodes[0].generate(3) + self.sync_all() + assert(self.send_simple_tx(sender, receiver)) + assert(self.send_regular_instantsend(sender, receiver, not new_is)) + + +if __name__ == '__main__': + AutoISMempoolTest().main() diff --git a/qa/rpc-tests/autoix-mempool.py b/qa/rpc-tests/autoix-mempool.py deleted file mode 100755 index 5bd9ed023f4b5..0000000000000 --- a/qa/rpc-tests/autoix-mempool.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2018 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. - -from test_framework.mininode import * -from test_framework.test_framework import DashTestFramework -from test_framework.util import * -from time import * - -''' -autoix-mempool.py - -Checks if automatic InstantSend locks stop working when transaction mempool -is full (more than 0.1 part from max value). - -''' - -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__(8, 5, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE, '-limitdescendantsize=10'], fast_dip3_enforcement=True) - # set sender, receiver - self.receiver_idx = 1 - self.sender_idx = 2 - - def get_autoix_bip9_status(self): - info = self.nodes[0].getblockchaininfo() - # we reuse the dip3 deployment - return info['bip9_softforks']['dip0003']['status'] - - def activate_autoix_bip9(self): - # sync nodes periodically - # if we sync them too often, activation takes too many time - # if we sync them too rarely, nodes failed to update its state and - # bip9 status is not updated - # so, in this code nodes are synced once per 20 blocks - counter = 0 - sync_period = 10 - - while self.get_autoix_bip9_status() == 'defined': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - while self.get_autoix_bip9_status() == 'started': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - while self.get_autoix_bip9_status() == 'locked_in': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - # sync nodes - self.sync_all() - - assert(self.get_autoix_bip9_status() == 'active') - - def get_autoix_spork_state(self): - info = self.nodes[0].spork('active') - return info['SPORK_16_INSTANTSEND_AUTOLOCKS'] - - def set_autoix_spork_state(self, state): - # Increment mocktime as otherwise nodes will not update sporks - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - - if state: - value = 0 - else: - value = 4070908800 - self.nodes[0].spork('SPORK_16_INSTANTSEND_AUTOLOCKS', value) - - # sends regular IX with high fee and may inputs (not-simple transaction) - def send_regular_IX(self, sender, receiver): - receiver_addr = receiver.getnewaddress() - txid = sender.instantsendtoaddress(receiver_addr, 1.0) - return self.wait_for_instantlock(txid, sender) - - # sends simple trx, it should become IX if autolocks are allowed - def send_simple_tx(self, sender, receiver): - raw_tx = self.create_raw_trx(sender, receiver, 1.0, 1, 4) - txid = self.nodes[0].sendrawtransaction(raw_tx['hex']) - self.sync_all() - return self.wait_for_instantlock(txid, sender) - - def get_mempool_usage(self, node): - info = node.getmempoolinfo() - return info['usage'] - - def fill_mempool(self): - # send lots of txes to yourself just to fill the mempool - counter = 0 - sync_period = 10 - dummy_address = self.nodes[0].getnewaddress() - while self.get_mempool_usage(self.nodes[self.sender_idx]) < MAX_MEMPOOL_SIZE * MB_SIZE * AUTO_IX_MEM_THRESHOLD: - self.nodes[0].sendtoaddress(dummy_address, 1.0) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - self.sync_all() - - def run_test(self): - # make sure masternodes are synced - sync_masternodes(self.nodes) - - self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0) - self.wait_for_sporks_same() - self.mine_quorum() - - self.log.info("Test old InstantSend") - self.test_auto(); - - self.nodes[0].spork("SPORK_20_INSTANTSEND_LLMQ_BASED", 0) - self.wait_for_sporks_same() - - self.log.info("Test new InstantSend") - self.test_auto(True); - - def test_auto(self, new_is = False): - self.activate_autoix_bip9() - self.set_autoix_spork_state(True) - - # check pre-conditions for autoIX - assert(self.get_autoix_bip9_status() == 'active') - assert(self.get_autoix_spork_state()) - - # create 3 inputs for txes on sender node and give them 6 confirmations - sender = self.nodes[self.sender_idx] - receiver = self.nodes[self.receiver_idx] - sender_address = sender.getnewaddress() - for i in range(0, 4): - self.nodes[0].sendtoaddress(sender_address, 2.0) - for i in range(0, 6): - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - self.sync_all() - - # autoIX is working - assert(self.send_simple_tx(sender, receiver)) - - # fill mempool with transactions - self.set_autoix_spork_state(False) - self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800) - self.wait_for_sporks_same() - self.fill_mempool() - self.set_autoix_spork_state(True) - self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0) - self.wait_for_sporks_same() - - # autoIX is not working now - assert(not self.send_simple_tx(sender, receiver)) - # regular IX is still working for old IS but not for new one - assert(not self.send_regular_IX(sender, receiver) if new_is else self.send_regular_IX(sender, receiver)) - - # generate one block to clean up mempool and retry auto and regular IX - # generate 2 more blocks to have enough confirmations for IX - self.nodes[0].generate(3) - self.sync_all() - assert(self.send_simple_tx(sender, receiver)) - assert(self.send_regular_IX(sender, receiver)) - - -if __name__ == '__main__': - AutoIXMempoolTest().main() diff --git a/qa/rpc-tests/p2p-autoinstantsend.py b/qa/rpc-tests/p2p-autoinstantsend.py index fb2910a313dd8..4af1e7640f9da 100755 --- a/qa/rpc-tests/p2p-autoinstantsend.py +++ b/qa/rpc-tests/p2p-autoinstantsend.py @@ -28,90 +28,6 @@ def __init__(self): self.receiver_idx = 1 self.sender_idx = 2 - def get_autoix_bip9_status(self): - info = self.nodes[0].getblockchaininfo() - # we reuse the dip3 deployment - return info['bip9_softforks']['dip0003']['status'] - - def activate_autoix_bip9(self): - # sync nodes periodically - # if we sync them too often, activation takes too many time - # if we sync them too rarely, nodes failed to update its state and - # bip9 status is not updated - # so, in this code nodes are synced once per 20 blocks - counter = 0 - sync_period = 10 - - while self.get_autoix_bip9_status() == 'defined': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - while self.get_autoix_bip9_status() == 'started': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - while self.get_autoix_bip9_status() == 'locked_in': - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - self.nodes[0].generate(1) - counter += 1 - if counter % sync_period == 0: - # sync nodes - self.sync_all() - - # sync nodes - self.sync_all() - - assert(self.get_autoix_bip9_status() == 'active') - - def get_autoix_spork_state(self): - info = self.nodes[0].spork('active') - return info['SPORK_16_INSTANTSEND_AUTOLOCKS'] - - def set_autoix_spork_state(self, state): - set_mocktime(get_mocktime() + 1) - set_node_times(self.nodes, get_mocktime()) - if state: - value = 0 - else: - value = 4070908800 - self.nodes[0].spork('SPORK_16_INSTANTSEND_AUTOLOCKS', value) - - # sends regular IX with high fee and may inputs (not-simple transaction) - def send_regular_IX(self, check_fee = True): - receiver_addr = self.nodes[self.receiver_idx].getnewaddress() - txid = self.nodes[0].instantsendtoaddress(receiver_addr, 1.0) - if (check_fee): - MIN_FEE = satoshi_round(-0.0001) - fee = self.nodes[0].gettransaction(txid)['fee'] - expected_fee = MIN_FEE * len(self.nodes[0].getrawtransaction(txid, True)['vin']) - assert_equal(fee, expected_fee) - return self.wait_for_instantlock(txid, self.nodes[0]) - - # sends simple trx, it should become IX if autolocks are allowed - def send_simple_tx(self): - raw_tx = self.create_raw_trx(self.nodes[0], self.nodes[self.receiver_idx], 1.0, 1, 4) - txid = self.nodes[0].sendrawtransaction(raw_tx['hex']) - self.sync_all() - return self.wait_for_instantlock(txid, self.nodes[0]) - - # sends complex trx, it should never become IX - def send_complex_tx(self): - raw_tx = self.create_raw_trx(self.nodes[0], self.nodes[self.receiver_idx], 1.0, 5, 100) - txid = self.nodes[0].sendrawtransaction(raw_tx['hex']) - self.sync_all() - return self.wait_for_instantlock(txid, self.nodes[0]) - def run_test(self): # make sure masternodes are synced sync_masternodes(self.nodes) @@ -130,38 +46,50 @@ def run_test(self): self.test_auto(True); def test_auto(self, new_is = False): - # feed the sender with some balance - sender_addr = self.nodes[self.sender_idx].getnewaddress() - self.nodes[0].sendtoaddress(sender_addr, 1) + sender = self.nodes[self.sender_idx] + receiver = self.nodes[self.receiver_idx] + # feed the sender with some balance, make sure there are enough inputs + recipients = {} + for i in range(0, 30): + recipients[sender.getnewaddress()] = 1 + # use a single transaction to not overload Travis with InstantSend + self.nodes[0].sendmany("", recipients) + # make sender funds mature for InstantSend for i in range(0, 2): set_mocktime(get_mocktime() + 1) set_node_times(self.nodes, get_mocktime()) self.nodes[0].generate(1) - - assert(not self.get_autoix_spork_state()) + self.sync_all() + + assert(not self.get_autois_spork_state(self.nodes[0])) - assert(self.send_regular_IX(not new_is)) - assert(self.send_simple_tx() if new_is else not self.send_simple_tx()) - assert(self.send_complex_tx() if new_is else not self.send_complex_tx()) + assert(self.send_regular_instantsend(sender, receiver, not new_is)) + assert(self.send_simple_tx(sender, receiver) if new_is else not self.send_simple_tx(sender, receiver)) + assert(self.send_complex_tx(sender, receiver) if new_is else not self.send_complex_tx(sender, receiver)) - self.activate_autoix_bip9() - self.set_autoix_spork_state(True) + self.activate_autois_bip9(self.nodes[0]) + self.set_autois_spork_state(self.nodes[0], True) - assert(self.get_autoix_bip9_status() == 'active') - assert(self.get_autoix_spork_state()) + assert(self.get_autois_bip9_status(self.nodes[0]) == 'active') + assert(self.get_autois_spork_state(self.nodes[0])) - assert(self.send_regular_IX(not new_is)) - assert(self.send_simple_tx()) - assert(self.send_complex_tx() if new_is else not self.send_complex_tx()) + assert(self.send_regular_instantsend(sender, receiver, not new_is)) + assert(self.send_simple_tx(sender, receiver)) + assert(self.send_complex_tx(sender, receiver) if new_is else not self.send_complex_tx(sender, receiver)) - self.set_autoix_spork_state(False) - assert(not self.get_autoix_spork_state()) + self.set_autois_spork_state(self.nodes[0], False) + assert(not self.get_autois_spork_state(self.nodes[0])) - assert(self.send_regular_IX(not new_is)) - assert(self.send_simple_tx() if new_is else not self.send_simple_tx()) - assert(self.send_complex_tx() if new_is else not self.send_complex_tx()) + assert(self.send_regular_instantsend(sender, receiver, not new_is)) + assert(self.send_simple_tx(sender, receiver) if new_is else not self.send_simple_tx(sender, receiver)) + assert(self.send_complex_tx(sender, receiver) if new_is else not self.send_complex_tx(sender, receiver)) + # mine all mempool txes + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + self.nodes[0].generate(1) + self.sync_all() if __name__ == '__main__': AutoInstantSendTest().main() diff --git a/qa/rpc-tests/p2p-instantsend.py b/qa/rpc-tests/p2p-instantsend.py index 89841d0c04cc4..5e1ed9cfb9eb4 100755 --- a/qa/rpc-tests/p2p-instantsend.py +++ b/qa/rpc-tests/p2p-instantsend.py @@ -34,9 +34,12 @@ def run_test(self): self.log.info("Test new InstantSend") self.test_doublespend() - def test_doublespend(self): + def test_doublespend(self, new_is = False): + sender = self.nodes[self.sender_idx] + receiver = self.nodes[self.receiver_idx] + isolated = self.nodes[self.isolated_idx] # feed the sender with some balance - sender_addr = self.nodes[self.sender_idx].getnewaddress() + sender_addr = sender.getnewaddress() self.nodes[0].sendtoaddress(sender_addr, 1) # make sender funds mature for InstantSend for i in range(0, 2): @@ -46,35 +49,22 @@ def test_doublespend(self): self.sync_all() # create doublepending transaction, but don't relay it - dblspnd_tx = self.create_raw_trx(self.nodes[self.sender_idx], - self.nodes[self.isolated_idx], - 0.5, 1, 100) + dblspnd_tx = self.create_raw_tx(sender, isolated, 0.5, 1, 100) # stop one node to isolate it from network - self.nodes[self.isolated_idx].setnetworkactive(False) + isolated.setnetworkactive(False) # instantsend to receiver - receiver_addr = self.nodes[self.receiver_idx].getnewaddress() - is_id = self.nodes[self.sender_idx].instantsendtoaddress(receiver_addr, 0.9) - # wait for instantsend locks - start = time() - locked = False - while True: - is_trx = self.nodes[self.sender_idx].gettransaction(is_id) - if is_trx['instantlock']: - locked = True - break - if time() > start + 10: - break - sleep(0.1) - assert(locked) + receiver_addr = receiver.getnewaddress() + is_id = sender.instantsendtoaddress(receiver_addr, 0.9) + self.wait_for_instantlock(is_id, sender) # send doublespend transaction to isolated node - self.nodes[self.isolated_idx].sendrawtransaction(dblspnd_tx['hex']) + isolated.sendrawtransaction(dblspnd_tx['hex']) # generate block on isolated node with doublespend transaction set_mocktime(get_mocktime() + 1) set_node_times(self.nodes, get_mocktime()) - self.nodes[self.isolated_idx].generate(1) - wrong_block = self.nodes[self.isolated_idx].getbestblockhash() + isolated.generate(1) + wrong_block = isolated.getbestblockhash() # connect isolated block to network - self.nodes[self.isolated_idx].setnetworkactive(True) + isolated.setnetworkactive(True) for i in range(0, self.isolated_idx): connect_nodes(self.nodes[i], self.isolated_idx) # check doublespend block is rejected by other nodes diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 7c6b9b65e11f6..c48a3571bc403 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -15,6 +15,7 @@ from time import time, sleep from .util import ( + assert_equal, initialize_chain, start_node, start_nodes, @@ -400,7 +401,67 @@ def setup_network(self): for status in mn_info.values(): assert (status == 'ENABLED') - def create_raw_trx(self, node_from, node_to, amount, min_inputs, max_inputs): + def get_autois_bip9_status(self, node): + info = node.getblockchaininfo() + # we reuse the dip3 deployment + return info['bip9_softforks']['dip0003']['status'] + + def activate_autois_bip9(self, node): + # sync nodes periodically + # if we sync them too often, activation takes too many time + # if we sync them too rarely, nodes failed to update its state and + # bip9 status is not updated + # so, in this code nodes are synced once per 20 blocks + counter = 0 + sync_period = 10 + + while self.get_autois_bip9_status(node) == 'defined': + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + node.generate(1) + counter += 1 + if counter % sync_period == 0: + # sync nodes + self.sync_all() + + while self.get_autois_bip9_status(node) == 'started': + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + node.generate(1) + counter += 1 + if counter % sync_period == 0: + # sync nodes + self.sync_all() + + while self.get_autois_bip9_status(node) == 'locked_in': + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + node.generate(1) + counter += 1 + if counter % sync_period == 0: + # sync nodes + self.sync_all() + + # sync nodes + self.sync_all() + + assert(self.get_autois_bip9_status(node) == 'active') + + def get_autois_spork_state(self, node): + info = node.spork('active') + return info['SPORK_16_INSTANTSEND_AUTOLOCKS'] + + def set_autois_spork_state(self, node, state): + # Increment mocktime as otherwise nodes will not update sporks + set_mocktime(get_mocktime() + 1) + set_node_times(self.nodes, get_mocktime()) + if state: + value = 0 + else: + value = 4070908800 + node.spork('SPORK_16_INSTANTSEND_AUTOLOCKS', value) + + def create_raw_tx(self, node_from, node_to, amount, min_inputs, max_inputs): assert (min_inputs <= max_inputs) # fill inputs inputs = [] @@ -431,8 +492,9 @@ def create_raw_trx(self, node_from, node_to, amount, min_inputs, max_inputs): inputs[-1] = input last_amount = float(tx['amount']) - assert (len(inputs) > 0) - assert (in_amount > amount) + assert (len(inputs) >= min_inputs) + assert (len(inputs) <= max_inputs) + assert (in_amount >= amount) # fill outputs receiver_address = node_to.getnewaddress() change_address = node_from.getnewaddress() @@ -443,18 +505,43 @@ def create_raw_trx(self, node_from, node_to, amount, min_inputs, max_inputs): rawtx = node_from.createrawtransaction(inputs, outputs) return node_from.signrawtransaction(rawtx) + # sends regular instantsend with high fee + def send_regular_instantsend(self, sender, receiver, check_fee = True): + receiver_addr = receiver.getnewaddress() + txid = sender.instantsendtoaddress(receiver_addr, 1.0) + if (check_fee): + MIN_FEE = satoshi_round(-0.0001) + fee = sender.gettransaction(txid)['fee'] + expected_fee = MIN_FEE * len(sender.getrawtransaction(txid, True)['vin']) + assert_equal(fee, expected_fee) + return self.wait_for_instantlock(txid, sender) + + # sends simple tx, it should become locked if autolocks are allowed + def send_simple_tx(self, sender, receiver): + raw_tx = self.create_raw_tx(sender, receiver, 1.0, 1, 4) + txid = self.nodes[0].sendrawtransaction(raw_tx['hex']) + self.sync_all() + return self.wait_for_instantlock(txid, sender) + + # sends complex tx, it should never become locked for old instentsend + def send_complex_tx(self, sender, receiver): + raw_tx = self.create_raw_tx(sender, receiver, 1.0, 5, 100) + txid = sender.sendrawtransaction(raw_tx['hex']) + self.sync_all() + return self.wait_for_instantlock(txid, sender) + def wait_for_instantlock(self, txid, node): # wait for instantsend locks start = time() locked = False while True: - is_trx = node.gettransaction(txid) - if is_trx['instantlock']: + is_tx = node.getrawtransaction(txid, True) + if is_tx['instantlock']: locked = True break if time() > start + 10: break - sleep(0.1) + sleep(0.5) return locked def wait_for_sporks_same(self, timeout=30):