Repository: bitcoin/bitcoin
File: test/functional/wallet_importdescriptors.py (Python)

Code before:
                              success=True,
                              wallet=w_multipath)

        self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/10/0/*)"),
                              "active": True,
                              "range": 10,
                              "timestamp": timestamp},
                              success=True,
                              wallet=w_multisplit)
        self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/20/0/*)"),
                              "active": True,
                              "range": 10,
                              "internal": True,
                              "timestamp": timestamp},
                              success=True,
                              wallet=w_multisplit)
        for _ in range(0, 10):
            assert_equal(w_multipath.getnewaddress(address_type="bech32"), w_multisplit.getnewaddress(address_type="bech32"))
            assert_equal(w_multipath.getrawchangeaddress(address_type="bech32"), w_multisplit.getrawchangeaddress(address_type="bech32"))
        assert_equal(sorted(w_multipath.listdescriptors()["descriptors"], key=lambda x: x["desc"]), sorted(w_multisplit.listdescriptors()["descriptors"], key=lambda x: x["desc"]))

        self.log.info("Test older() safety")

        for flag in [0, SEQUENCE_LOCKTIME_TYPE_FLAG]:
            self.log.debug("Importing a safe value always works")
            height_delta = 65535 + (1 << 22 if flag is SEQUENCE_LOCKTIME_TYPE_FLAG else 0)
            self.test_importdesc(
                {
                    'desc': descsum_create(f"wsh(and_v(v:pk([12345678/0h/0h]{xpub}/*),older({height_delta})))"),
                    'active': True,
                    'range': [0, 2],
                    'timestamp': 'now'
                },
                success=True
            )

            self.log.debug("Importing an unsafe value is prevented by default")
            height_delta = height_delta + 1
            desc = descsum_create(f"wsh(and_v(v:pk([12345678/0h/0h]{xpub}/*),older({height_delta})))")
            self.test_importdesc(
                {
                    'desc': desc,
                    'active': True,
                    'range': [0, 2],
                    'timestamp': 'now'
                },
                success=False,
                error_code=-5,
                error_message=f"older({height_delta}{' - 1<<22' if flag is SEQUENCE_LOCKTIME_TYPE_FLAG else ''}) > 65535 is unsafe"
            )


Review comment (suggestion):
nit
```suggestion
            height_delta = 65535 + (flag if flag is SEQUENCE_LOCKTIME_TYPE_FLAG else 0)
```

Code after:
                              "active": True,
                              "range": 10,
                              "timestamp": timestamp,
                              "internal": True},
                              success=False,
                              error_code=-5,
                              error_message="Cannot have multipath descriptor while also specifying \'internal\'",
                              wallet=w_multipath)

        self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/<10;20>/0/*)"),
                              "active": True,
                              "range": 10,
                              "timestamp": timestamp},
                              success=True,
                              wallet=w_multipath)

        self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/10/0/*)"),
                              "active": True,
                              "range": 10,
                              "timestamp": timestamp},
                              success=True,
                              wallet=w_multisplit)
        self.test_importdesc({"desc": descsum_create(f"wpkh({xpriv}/20/0/*)"),
                              "active": True,
                              "range": 10,
                              "internal": True,
                              "timestamp": timestamp},
                              success=True,
                              wallet=w_multisplit)
        for _ in range(0, 10):
            assert_equal(w_multipath.getnewaddress(address_type="bech32"), w_multisplit.getnewaddress(address_type="bech32"))
            assert_equal(w_multipath.getrawchangeaddress(address_type="bech32"), w_multisplit.getrawchangeaddress(address_type="bech32"))
        assert_equal(sorted(w_multipath.listdescriptors()["descriptors"], key=lambda x: x["desc"]), sorted(w_multisplit.listdescriptors()["descriptors"], key=lambda x: x["desc"]))

        self.log.info("Test older() safety")

        for flag in [0, SEQUENCE_LOCKTIME_TYPE_FLAG]:
            self.log.debug("Importing a safe value always works")
            safe_value = (65535 | flag)
            self.test_importdesc(
                {
                    'desc': descsum_create(f"wsh(and_v(v:pk([12345678/0h/0h]{xpub}/*),older({safe_value})))"),
                    'active': True,
                    'range': [0, 2],
                    'timestamp': 'now'
                },
                success=True
            )

            self.log.debug("Importing an unsafe value results in a warning")
            unsafe_value = safe_value + 1