(node_factory, bitcoind, executor, chainparams, old_hsmsecret)
| 3649 | |
| 3650 | @pytest.mark.parametrize("old_hsmsecret", [False, True]) |
| 3651 | def test_option_upfront_shutdown_script(node_factory, bitcoind, executor, chainparams, old_hsmsecret): |
| 3652 | l1 = node_factory.get_node(start=False, allow_warning=True, old_hsmsecret=old_hsmsecret) |
| 3653 | # Insist on upfront script we're not going to match. |
| 3654 | # '0014' + l1.rpc.call('dev-listaddrs', [10])['addresses'][-1]['bech32_redeemscript'] |
| 3655 | l1.daemon.env["DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"] = "00143d43d226bcc27019ade52d7a3dc52a7ac1be28b8" |
| 3656 | l1.start() |
| 3657 | |
| 3658 | l2 = node_factory.get_node(allow_warning=True, old_hsmsecret=old_hsmsecret) |
| 3659 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3660 | l1.fundchannel(l2, 1000000, False) |
| 3661 | |
| 3662 | # This will block, as l1 will send a warning but l2 will retry. |
| 3663 | fut = executor.submit(l1.rpc.close, l2.info['id']) |
| 3664 | |
| 3665 | # l2 will send a warning when it dislikes shutdown script. |
| 3666 | l1.daemon.wait_for_log(r'WARNING.*scriptpubkey .* is not as agreed upfront \(00143d43d226bcc27019ade52d7a3dc52a7ac1be28b8\)') |
| 3667 | |
| 3668 | # Close from l2's side and clear channel. |
| 3669 | l2.rpc.close(l1.info['id'], unilateraltimeout=1) |
| 3670 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 3671 | fut.result(TIMEOUT) |
| 3672 | wait_for(lambda: [c['state'] for c in l1.rpc.listpeerchannels()['channels']] == ['ONCHAIN']) |
| 3673 | wait_for(lambda: [c['state'] for c in l2.rpc.listpeerchannels()['channels']] == ['ONCHAIN']) |
| 3674 | |
| 3675 | # Works when l2 closes channel, too. |
| 3676 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3677 | l1.fundchannel(l2, 1000000, False) |
| 3678 | |
| 3679 | fut = executor.submit(l2.rpc.close, l1.info['id']) |
| 3680 | |
| 3681 | # l2 will send warning unilaterally when it dislikes shutdown script. |
| 3682 | l1.daemon.wait_for_log(r'WARNING.*scriptpubkey .* is not as agreed upfront \(00143d43d226bcc27019ade52d7a3dc52a7ac1be28b8\)') |
| 3683 | |
| 3684 | l2.rpc.close(l1.info['id'], unilateraltimeout=1) |
| 3685 | fut.result(TIMEOUT) |
| 3686 | |
| 3687 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 3688 | wait_for(lambda: [c['state'] for c in l1.rpc.listpeerchannels()['channels']] == ['ONCHAIN', 'ONCHAIN']) |
| 3689 | wait_for(lambda: [c['state'] for c in l2.rpc.listpeerchannels()['channels']] == ['ONCHAIN', 'ONCHAIN']) |
| 3690 | |
| 3691 | # Figure out what address it will try to use. |
| 3692 | # With BIP86 mnemonic format (old_hsmsecret=False), addresses use bip86_max_index |
| 3693 | # With old hsmsecret (old_hsmsecret=True), use bip32_max_index |
| 3694 | if old_hsmsecret: |
| 3695 | keyidx = int(l1.db_query("SELECT intval FROM vars WHERE name='bip32_max_index';")[0]['intval']) |
| 3696 | else: |
| 3697 | keyidx = int(l1.db_query("SELECT intval FROM vars WHERE name='bip86_max_index';")[0]['intval']) |
| 3698 | |
| 3699 | # Expect 1 for change address, plus 1 for the funding address of the actual |
| 3700 | # funding tx. |
| 3701 | # dev-listaddrs now handles both BIP32 and BIP86 wallets automatically |
| 3702 | addr = l1.rpc.call('dev-listaddrs', [keyidx + 2])['addresses'][-1] |
| 3703 | # the above used to be keyidx + 3, but that was when `fundchannel` |
| 3704 | # used the `txprepare`-`txdiscard`-`txprepare` trick, which skipped |
| 3705 | # one address in the discarded tx. |
| 3706 | # Now we use PSBTs, which means we never discard and skip an address. |
| 3707 | |
| 3708 | # Now, if we specify upfront and it's OK, all good. |
nothing calls this directly
no test coverage detected