diff --git a/tests/test_closing.py b/tests/test_closing.py index 822889d43..da229f265 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -24,7 +24,7 @@ def test_closing(node_factory, bitcoind): billboard = only_one(l2.rpc.listpeers(l1.info['id'])['peers'][0]['channels'])['status'] assert billboard == ['CHANNELD_NORMAL:Funding transaction locked.'] - bitcoind.rpc.generate(5) + bitcoind.generate_block(5) # Only wait for the channels to activate with DEVELOPER=1, # otherwise it's going to take too long because of the missing @@ -62,7 +62,7 @@ def test_closing(node_factory, bitcoind): billboard = only_one(l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'])['status'] assert billboard == ['CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi'] - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) l1.daemon.wait_for_log(r'Owning output .* txid %s' % closetxid) l2.daemon.wait_for_log(r'Owning output .* txid %s' % closetxid) @@ -77,7 +77,7 @@ def test_closing(node_factory, bitcoind): 'ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel' ]) - bitcoind.rpc.generate(9) + bitcoind.generate_block(9) wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'])['status'] == [ 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi', 'ONCHAIN:Tracking mutual close transaction', @@ -85,7 +85,7 @@ def test_closing(node_factory, bitcoind): ]) # Make sure both have forgotten about it - bitcoind.rpc.generate(90) + bitcoind.generate_block(90) wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 0) wait_for(lambda: len(l2.rpc.listchannels()['channels']) == 0) @@ -110,7 +110,7 @@ def test_closing_while_disconnected(node_factory, bitcoind): l1.daemon.wait_for_log('sendrawtx exit 0') l2.daemon.wait_for_log('sendrawtx exit 0') - bitcoind.rpc.generate(101) + bitcoind.generate_block(101) wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 0) wait_for(lambda: len(l2.rpc.listchannels()['channels']) == 0) @@ -535,7 +535,7 @@ def test_onchaind_replay(node_factory, bitcoind): } l1.rpc.sendpay([routestep], rhash) l1.daemon.wait_for_log('sendrawtx exit 0') - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) # Wait for nodes to notice the failure, this seach needle is after the # DB commit so we're sure the tx entries in onchaindtxs have been added @@ -548,7 +548,7 @@ def test_onchaind_replay(node_factory, bitcoind): # Generate some blocks so we restart the onchaind from DB (we rescan # last_height - 100) - bitcoind.rpc.generate(100) + bitcoind.generate_block(100) sync_blockheight(bitcoind, [l1, l2]) # l1 should still have a running onchaind @@ -563,7 +563,7 @@ def test_onchaind_replay(node_factory, bitcoind): # l1 should still notice that the funding was spent and that we should react to it l1.daemon.wait_for_log("Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET") sync_blockheight(bitcoind, [l1]) - bitcoind.rpc.generate(10) + bitcoind.generate_block(10) sync_blockheight(bitcoind, [l1]) diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 1c21fe84d..0b21dd391 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -29,7 +29,7 @@ def test_gossip_pruning(node_factory, bitcoind): scid1 = l1.fund_channel(l2, 10**6) scid2 = l2.fund_channel(l3, 10**6) - bitcoind.rpc.generate(6) + bitcoind.generate_block(6) # Channels should be activated locally wait_for(lambda: [c['active'] for c in l1.rpc.listchannels()['channels']] == [True] * 4) @@ -78,7 +78,7 @@ def test_gossip_disable_channels(node_factory, bitcoind): l1.rpc.connect(l2.info['id'], 'localhost', l2.port) scid = l1.fund_channel(l2, 10**6) - bitcoind.rpc.generate(5) + bitcoind.generate_block(5) def count_active(node): chans = node.rpc.listchannels()['channels'] @@ -358,7 +358,7 @@ def test_gossip_weirdalias(node_factory, bitcoind): l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l2.daemon.wait_for_log('openingd-{} chan #1: Handed peer, entering loop'.format(l1.info['id'])) l2.fund_channel(l1, 10**6) - bitcoind.rpc.generate(6) + bitcoind.generate_block(6) # They should gossip together. l1.daemon.wait_for_log('Received node_announcement for node {}' @@ -390,9 +390,9 @@ def test_gossip_persistence(node_factory, bitcoind): l2.fund_channel(l3, 10**6) # Make channels public, except for l3 -> l4, which is kept local-only for now - bitcoind.rpc.generate(5) + bitcoind.generate_block(5) l3.fund_channel(l4, 10**6) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) def count_active(node): chans = node.rpc.listchannels()['channels'] @@ -418,7 +418,7 @@ def test_gossip_persistence(node_factory, bitcoind): # channel from their network view l1.rpc.dev_fail(l2.info['id']) time.sleep(1) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) wait_for(lambda: count_active(l1) == 2) wait_for(lambda: count_active(l2) == 2) diff --git a/tests/test_misc.py b/tests/test_misc.py index 97a41c10b..02b64fded 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -158,7 +158,7 @@ def test_ping(node_factory): @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 for --dev-broadcast-interval") -def test_htlc_sig_persistence(node_factory, executor): +def test_htlc_sig_persistence(node_factory, bitcoind, executor): """Interrupt a payment between two peers, then fail and recover funds using the HTLC sig. """ # Feerates identical so we don't get gratuitous commit to update them @@ -184,7 +184,7 @@ def test_htlc_sig_persistence(node_factory, executor): # Make sure it broadcasts to chain. l2.wait_for_channel_onchain(l1.info['id']) l2.stop() - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) l1.start() assert l1.daemon.is_in_log(r'Loaded 1 HTLC signatures from DB') @@ -192,10 +192,10 @@ def test_htlc_sig_persistence(node_factory, executor): r'Peer permanent failure in CHANNELD_NORMAL: Funding transaction spent', r'Propose handling THEIR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TO_US' ]) - l1.bitcoin.rpc.generate(5) + bitcoind.generate_block(5) l1.daemon.wait_for_log("Broadcasting OUR_HTLC_TIMEOUT_TO_US") time.sleep(3) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) l1.daemon.wait_for_logs([ r'Owning output . (\d+) .SEGWIT. txid', ]) @@ -388,7 +388,7 @@ def test_withdraw(node_factory, bitcoind): # lightningd uses P2SH-P2WPKH waddr = l2.rpc.newaddr('bech32')['address'] l1.rpc.withdraw(waddr, 2 * amount) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) # Make sure l2 received the withdrawal. wait_for(lambda: len(l2.rpc.listfunds()['outputs']) == 1) @@ -408,7 +408,7 @@ def test_withdraw(node_factory, bitcoind): with pytest.raises(RpcError): l1.rpc.withdraw('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxxxxxx', 2 * amount) l1.rpc.withdraw(waddr, 2 * amount) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) # Now make sure additional two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 6 @@ -422,7 +422,7 @@ def test_withdraw(node_factory, bitcoind): with pytest.raises(RpcError): l1.rpc.withdraw('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qxxxxxx', 2 * amount) l1.rpc.withdraw(waddr, 2 * amount) - l1.bitcoin.rpc.generate(1) + bitcoind.generate_block(1) # Now make sure additional two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 8 @@ -457,7 +457,7 @@ def test_withdraw(node_factory, bitcoind): # Test withdrawal to self. l1.rpc.withdraw(l1.rpc.newaddr('bech32')['address'], 'all') - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 1 l1.rpc.withdraw(waddr, 'all') @@ -476,7 +476,7 @@ def test_addfunds_from_block(node_factory, bitcoind): addr = l1.rpc.newaddr()['address'] bitcoind.rpc.sendtoaddress(addr, 0.1) - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) @@ -490,7 +490,7 @@ def test_addfunds_from_block(node_factory, bitcoind): # Send all our money to a P2WPKH address this time. addr = l1.rpc.newaddr("bech32")['address'] l1.rpc.withdraw(addr, "all") - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) time.sleep(1) # The address we detect must match what was paid to. @@ -700,10 +700,10 @@ def test_blockchaintrack(node_factory, bitcoind): height = bitcoind.rpc.getblockcount() # At height 111 we receive an incoming payment - hashes = bitcoind.rpc.generate(9) + hashes = bitcoind.generate_block(9) bitcoind.rpc.sendtoaddress(addr, 1) time.sleep(1) # mempool is still unpredictable - bitcoind.rpc.generate(1) + bitcoind.generate_block(1) l1.daemon.wait_for_log(r'Owning') outputs = l1.rpc.listfunds()['outputs'] @@ -711,14 +711,14 @@ def test_blockchaintrack(node_factory, bitcoind): ###################################################################### # Second failure scenario: perform a 20 block reorg - bitcoind.rpc.generate(10) + bitcoind.generate_block(10) l1.daemon.wait_for_log('Adding block {}: '.format(height + 20)) # Now reorg out with a longer fork of 21 blocks bitcoind.rpc.invalidateblock(hashes[0]) bitcoind.wait_for_log(r'InvalidChainFound: invalid block=.* height={}' .format(height + 1)) - hashes = bitcoind.rpc.generate(30) + hashes = bitcoind.generate_block(30) time.sleep(1) bitcoind.rpc.getblockcount() @@ -756,7 +756,7 @@ def test_rescan(node_factory, bitcoind): # the current height l1.daemon.opts['rescan'] = -500000 l1.stop() - bitcoind.rpc.generate(4) + bitcoind.generate_block(4) l1.start() l1.daemon.wait_for_log(r'Adding block 105') assert not l1.daemon.is_in_log(r'Adding block 102') diff --git a/tests/test_pay.py b/tests/test_pay.py index e80b367a5..15a545df4 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -179,7 +179,7 @@ def test_pay_optional_args(node_factory): @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") -def test_payment_success_persistence(node_factory, executor): +def test_payment_success_persistence(node_factory, bitcoind, executor): # Start two nodes and open a channel.. die during payment. # Feerates identical so we don't get gratuitous commit to update them l1 = node_factory.get_node(disconnect=['+WIRE_COMMITMENT_SIGNED'], @@ -216,7 +216,7 @@ def test_payment_success_persistence(node_factory, executor): assert len(invoices) == 1 and invoices[0]['status'] == 'paid' # FIXME: We should re-add pre-announced routes on startup! - l1.bitcoin.rpc.generate(5) + bitcoind.generate_block(5) l1.wait_channel_active(chanid) # A duplicate should succeed immediately (nop) and return correct preimage. diff --git a/tests/utils.py b/tests/utils.py index 93e5161e3..bfce2cc55 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -291,7 +291,7 @@ class BitcoinD(TailableProc): def generate_block(self, numblocks=1): # As of 0.16, generate() is removed; use generatetoaddress. - self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress()) + return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress()) class LightningD(TailableProc):