wallet_timelock.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2022-present The Bitcoin Core developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  from test_framework.test_framework import BitcoinTestFramework
   7  from test_framework.util import assert_equal
   8  
   9  
  10  class WalletLocktimeTest(BitcoinTestFramework):
  11      def set_test_params(self):
  12          self.num_nodes = 1
  13  
  14      def skip_test_if_missing_module(self):
  15          self.skip_if_no_wallet()
  16  
  17      def run_test(self):
  18          node = self.nodes[0]
  19  
  20          mtp_tip = node.getblockheader(node.getbestblockhash())["mediantime"]
  21  
  22          self.log.info("Get new address with label")
  23          label = "timelock⌛🔓"
  24          address = node.getnewaddress(label=label)
  25  
  26          self.log.info("Send to new address with locktime")
  27          node.send(
  28              outputs={address: 5},
  29              locktime=mtp_tip - 1,
  30          )
  31          self.generate(node, 1)
  32  
  33          self.log.info("Check that clock cannot change finality of confirmed txs")
  34          amount_before_ad = node.getreceivedbyaddress(address)
  35          amount_before_lb = node.getreceivedbylabel(label)
  36          list_before_ad = node.listreceivedbyaddress(address_filter=address)
  37          list_before_lb = node.listreceivedbylabel(include_empty=False)
  38          balance_before = node.getbalances()["mine"]["trusted"]
  39          coin_before = node.listunspent(maxconf=1)
  40          node.setmocktime(mtp_tip - 1)
  41          assert_equal(node.getreceivedbyaddress(address), amount_before_ad)
  42          assert_equal(node.getreceivedbylabel(label), amount_before_lb)
  43          assert_equal(node.listreceivedbyaddress(address_filter=address), list_before_ad)
  44          assert_equal(node.listreceivedbylabel(include_empty=False), list_before_lb)
  45          assert_equal(node.getbalances()["mine"]["trusted"], balance_before)
  46          assert_equal(node.listunspent(maxconf=1), coin_before)
  47  
  48  
  49  if __name__ == "__main__":
  50      WalletLocktimeTest(__file__).main()
  51