diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 57b83490b..35522dbc2 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -2521,6 +2521,32 @@ class LightningDTests(BaseLightningDTests): l2.daemon.wait_for_logs(['sendrawtx exit 0', ' to CLOSINGD_COMPLETE']) assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 1 + def test_bech32_funding(self): + # Don't get any funds from previous runs. + l1 = self.node_factory.get_node(random_hsm=True) + l2 = self.node_factory.get_node(random_hsm=True) + + # connect + l1.rpc.connect(l2.info['id'], 'localhost', l2.info['port']) + + # fund a bech32 address and then open a channel with it + res = l1.openchannel(l2, 20000, addrtype='bech32') + address = res['address'] + assert address[0:4] == "bcrt" + + # probably overly paranoid checking + wallettxid = res['wallettxid'] + + wallettx = l1.bitcoin.rpc.getrawtransaction(wallettxid, True) + fundingtx = l1.bitcoin.rpc.decoderawtransaction(res['fundingtx']['tx']) + + def is_p2wpkh(output): + return output['type'] == 'witness_v0_keyhash' and \ + address == output['addresses'][0] + + assert any(is_p2wpkh(output['scriptPubKey']) for output in wallettx['vout']) + assert fundingtx['vin'][0]['txid'] == res['wallettxid'] + def test_withdraw(self): amount = 1000000 # Don't get any funds from previous runs. diff --git a/tests/utils.py b/tests/utils.py index 7b9c437c0..f8b7db817 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -327,15 +327,20 @@ class LightningNode(object): else: return wait_connected() - def openchannel(self, remote_node, capacity): - addr = self.rpc.newaddr()['address'] - txid = self.bitcoin.rpc.sendtoaddress(addr, capacity / 10**6) - self.bitcoin.generate_block(1) - self.daemon.wait_for_log('Owning output .* txid {}'.format(txid)) - self.rpc.fundchannel(remote_node.info['id'], capacity) + def openchannel(self, remote_node, capacity, addrtype="p2sh-segwit"): + addr, wallettxid = self.fundwallet(capacity, addrtype) + fundingtx = self.rpc.fundchannel(remote_node.info['id'], capacity) self.daemon.wait_for_log('sendrawtx exit 0, gave') self.bitcoin.generate_block(6) self.daemon.wait_for_log('to CHANNELD_NORMAL|STATE_NORMAL') + return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': fundingtx} + + def fundwallet(self, sats, addrtype="p2sh-segwit"): + addr = self.rpc.newaddr(addrtype)['address'] + txid = self.bitcoin.rpc.sendtoaddress(addr, sats / 10**6) + self.bitcoin.generate_block(1) + self.daemon.wait_for_log('Owning output .* txid {}'.format(txid)) + return addr, txid def getactivechannels(self): return [c for c in self.rpc.listchannels()['channels'] if c['active']]