Skip to content

Commit

Permalink
pytest: test withdrawal transactions' nLockTime
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior authored and ZmnSCPxj committed Feb 3, 2020
1 parent a589daa commit d2638c9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !")

0 comments on commit d2638c9

Please sign in to comment.