mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
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:
parent
0e59e091e7
commit
3d27bbb47d
@ -2521,6 +2521,32 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
l2.daemon.wait_for_logs(['sendrawtx exit 0', ' to CLOSINGD_COMPLETE'])
|
l2.daemon.wait_for_logs(['sendrawtx exit 0', ' to CLOSINGD_COMPLETE'])
|
||||||
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 1
|
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):
|
def test_withdraw(self):
|
||||||
amount = 1000000
|
amount = 1000000
|
||||||
# Don't get any funds from previous runs.
|
# Don't get any funds from previous runs.
|
||||||
|
@ -327,15 +327,20 @@ class LightningNode(object):
|
|||||||
else:
|
else:
|
||||||
return wait_connected()
|
return wait_connected()
|
||||||
|
|
||||||
def openchannel(self, remote_node, capacity):
|
def openchannel(self, remote_node, capacity, addrtype="p2sh-segwit"):
|
||||||
addr = self.rpc.newaddr()['address']
|
addr, wallettxid = self.fundwallet(capacity, addrtype)
|
||||||
txid = self.bitcoin.rpc.sendtoaddress(addr, capacity / 10**6)
|
fundingtx = self.rpc.fundchannel(remote_node.info['id'], capacity)
|
||||||
self.bitcoin.generate_block(1)
|
|
||||||
self.daemon.wait_for_log('Owning output .* txid {}'.format(txid))
|
|
||||||
self.rpc.fundchannel(remote_node.info['id'], capacity)
|
|
||||||
self.daemon.wait_for_log('sendrawtx exit 0, gave')
|
self.daemon.wait_for_log('sendrawtx exit 0, gave')
|
||||||
self.bitcoin.generate_block(6)
|
self.bitcoin.generate_block(6)
|
||||||
self.daemon.wait_for_log('to CHANNELD_NORMAL|STATE_NORMAL')
|
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):
|
def getactivechannels(self):
|
||||||
return [c for c in self.rpc.listchannels()['channels'] if c['active']]
|
return [c for c in self.rpc.listchannels()['channels'] if c['active']]
|
||||||
|
Loading…
Reference in New Issue
Block a user