test: test_bech32_funding

1. Test wallet funding to a bech32 p2wpkh address
2. Test channel opening with this address

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2018-01-24 10:37:23 -08:00 committed by Rusty Russell
parent 0e59e091e7
commit 3d27bbb47d
2 changed files with 37 additions and 6 deletions

View File

@ -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.

View File

@ -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']]