wallet_timelock.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2022 The Limenka 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 LimenkaTestFramework
   7  from test_framework.util import assert_equal
   8  
   9  
  10  class WalletLocktimeTest(LimenkaTestFramework):
  11      def add_options(self, parser):
  12          self.add_wallet_options(parser)
  13  
  14      def set_test_params(self):
  15          self.num_nodes = 1
  16  
  17      def skip_test_if_missing_module(self):
  18          self.skip_if_no_wallet()
  19  
  20      def run_test(self):
  21          node = self.nodes[0]
  22  
  23          mtp_tip = node.getblockheader(node.getbestblockhash())["mediantime"]
  24  
  25          self.log.info("Get new address with label")
  26          label = "timelock⌛🔓"
  27          address = node.getnewaddress(label=label)
  28  
  29          self.log.info("Send to new address with locktime")
  30          node.send(
  31              outputs={address: 5},
  32              locktime=mtp_tip - 1,
  33          )
  34          self.generate(node, 1)
  35  
  36          self.log.info("Check that clock cannot change finality of confirmed txs")
  37          amount_before_ad = node.getreceivedbyaddress(address)
  38          amount_before_lb = node.getreceivedbylabel(label)
  39          list_before_ad = node.listreceivedbyaddress(address_filter=address)
  40          list_before_lb = node.listreceivedbylabel(include_empty=False)
  41          balance_before = node.getbalances()["mine"]["trusted"]
  42          coin_before = node.listunspent(maxconf=1)
  43          node.setmocktime(mtp_tip - 1)
  44          assert_equal(node.getreceivedbyaddress(address), amount_before_ad)
  45          assert_equal(node.getreceivedbylabel(label), amount_before_lb)
  46          assert_equal(node.listreceivedbyaddress(address_filter=address), list_before_ad)
  47          assert_equal(node.listreceivedbylabel(include_empty=False), list_before_lb)
  48          assert_equal(node.getbalances()["mine"]["trusted"], balance_before)
  49          assert_equal(node.listunspent(maxconf=1), coin_before)
  50  
  51  
  52  if __name__ == "__main__":
  53      WalletLocktimeTest(__file__).main()
  54