pytest: test new commitment_revocation hook values

This commit is contained in:
Michael Schmoock 2021-09-03 16:30:09 +02:00 committed by Rusty Russell
parent 37a7dab549
commit f6709a7a90
2 changed files with 8 additions and 3 deletions

View file

@ -6,9 +6,9 @@ plugin = Plugin()
@plugin.hook('commitment_revocation') @plugin.hook('commitment_revocation')
def on_commitment_revocation(commitment_txid, penalty_tx, plugin, **kwargs): def on_commitment_revocation(commitment_txid, penalty_tx, channel_id, commitnum, plugin, **kwargs):
with open('watchtower.csv', 'a') as f: with open('watchtower.csv', 'a') as f:
f.write("{}, {}\n".format(commitment_txid, penalty_tx)) f.write("{}, {}, {}, {}\n".format(commitment_txid, penalty_tx, channel_id, commitnum))
plugin.run() plugin.run()

View file

@ -1797,6 +1797,7 @@ def test_watchtower(node_factory, bitcoind, directory, chainparams):
2, 2,
opts=[{'may_fail': True, 'allow_broken_log': True}, {'plugin': p}] opts=[{'may_fail': True, 'allow_broken_log': True}, {'plugin': p}]
) )
channel_id = l1.rpc.listpeers()['peers'][0]['channels'][0]['channel_id']
# Force a new commitment # Force a new commitment
l1.rpc.pay(l2.rpc.invoice(25000000, 'lbl1', 'desc1')['bolt11']) l1.rpc.pay(l2.rpc.invoice(25000000, 'lbl1', 'desc1')['bolt11'])
@ -1821,8 +1822,12 @@ def test_watchtower(node_factory, bitcoind, directory, chainparams):
) )
cheat_tx = bitcoind.rpc.decoderawtransaction(tx) cheat_tx = bitcoind.rpc.decoderawtransaction(tx)
lastcommitnum = 0
for l in open(wt_file, 'r'): for l in open(wt_file, 'r'):
txid, penalty = l.strip().split(', ') txid, penalty, channel_id_hook, commitnum = l.strip().split(', ')
assert lastcommitnum == int(commitnum)
assert channel_id_hook == channel_id
lastcommitnum += 1
if txid == cheat_tx['txid']: if txid == cheat_tx['txid']:
# This one should succeed, since it is a response to the cheat_tx # This one should succeed, since it is a response to the cheat_tx
bitcoind.rpc.sendrawtransaction(penalty) bitcoind.rpc.sendrawtransaction(penalty)