From d2638c99afbbe3f18e58389c9301c0cdc10e6629 Mon Sep 17 00:00:00 2001 From: darosior Date: Thu, 30 Jan 2020 13:20:35 +0100 Subject: [PATCH] pytest: test withdrawal transactions' nLockTime --- tests/test_wallet.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 0be04ed89..8a9e11dd8 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -698,3 +698,44 @@ def test_fundchannel_listtransaction(node_factory, bitcoind): tx = [t for t in txs if t['hash'] == txid][0] assert tx['blockheight'] == 0 + + +def test_withdraw_nlocktime(node_factory): + """ + Test that we don't set the nLockTime to 0 for withdrawal transactions. + """ + l1 = node_factory.get_node(1) + l1.fundwallet(10**4) + + addr = l1.rpc.newaddr()["bech32"] + tx = l1.rpc.withdraw(addr, 10**3)["tx"] + nlocktime = node_factory.bitcoind.rpc.decoderawtransaction(tx)["locktime"] + tip = node_factory.bitcoind.rpc.getblockcount() + + assert nlocktime > 0 and nlocktime <= tip + + +@flaky +@unittest.skipIf(VALGRIND, "A big loop is used to check fuzz.") +def test_withdraw_nlocktime_fuzz(node_factory, bitcoind): + """ + Test that we eventually fuzz nLockTime for withdrawal transactions. + Marked flaky "just in case" as we fuzz from 0 to 100 with a 10% + probability. + """ + l1 = node_factory.get_node(1) + l1.fundwallet(10**8) + + for i in range(100): + addr = l1.rpc.newaddr()["bech32"] + withdraw = l1.rpc.withdraw(addr, 10**3) + bitcoind.generate_block(1) + l1.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'. + format(withdraw["txid"])) + decoded = bitcoind.rpc.decoderawtransaction(withdraw["tx"]) + tip = node_factory.bitcoind.rpc.getblockcount() + assert decoded["locktime"] > 0 + if decoded["locktime"] < tip: + return + else: + raise Exception("No transaction with fuzzed nLockTime !")