In 1cd57c67b10a771d2eb1c2324b241533c0b1f287 "test: Add a test for anchor outputs in the wallet"
There is a bit of duplication in all 3 tests. Maybe can remove this test altogether and put some of its functionality in the below test.
diff --git a/test/functional/wallet_anchor.py b/test/functional/wallet_anchor.py
index 1d1435145a..e6872deba0 100755
--- a/test/functional/wallet_anchor.py
+++ b/test/functional/wallet_anchor.py
@@ -79,40 +79,22 @@ class WalletAnchorTest(BitcoinTestFramework):
assert_equal(wallet.listunspent(), [])
wallet.gettransaction(anchor_spend_txid)
- def test_import_anchors(self):
- self.log.info("Test that descriptors for anchor outputs can only be imported to watchonly wallets")
- self.nodes[0].createwallet(wallet_name="import_anchor_privkeys", blank=True)
- wallet = self.nodes[0].get_wallet_rpc("import_anchor_privkeys")
- import_res = wallet.importdescriptors([
- {"desc": descsum_create(f"addr({ANCHOR_ADDRESS})"), "timestamp": "now"},
- {"desc": descsum_create(f"raw({PAY_TO_ANCHOR.hex()})"), "timestamp": "now"}
- ])
- assert_equal(import_res[0]["success"], False)
- assert_equal(import_res[1]["success"], False)
-
- self.nodes[0].createwallet(wallet_name="import_anchor", disable_private_keys=True)
- wallet = self.nodes[0].get_wallet_rpc("import_anchor")
- import_res = wallet.importdescriptors([
- {"desc": descsum_create(f"addr({ANCHOR_ADDRESS})"), "timestamp": "now"},
- {"desc": descsum_create(f"raw({PAY_TO_ANCHOR.hex()})"), "timestamp": "now"}
- ])
- assert_equal(import_res[0]["success"], True)
- assert_equal(import_res[1]["success"], True)
-
def test_cannot_sign_anchors(self):
self.log.info("Test that the wallet cannot spend anchor outputs")
- self.nodes[0].createwallet(wallet_name="anchor_spend", disable_private_keys=True)
- wallet = self.nodes[0].get_wallet_rpc("anchor_spend")
- import_res = wallet.importdescriptors([
- {"desc": descsum_create(f"addr({ANCHOR_ADDRESS})"), "timestamp": "now"},
- {"desc": descsum_create(f"raw({PAY_TO_ANCHOR.hex()})"), "timestamp": "now"}
- ])
- assert_equal(import_res[0]["success"], True)
- assert_equal(import_res[1]["success"], True)
+ for disable_private_keys in [False, True]:
+ self.nodes[0].createwallet(wallet_name=f"anchor_spend_{disable_private_keys}", disable_private_keys=disable_private_keys)
+ wallet = self.nodes[0].get_wallet_rpc(f"anchor_spend_{disable_private_keys}")
+ import_res = wallet.importdescriptors([
+ {"desc": descsum_create(f"addr({ANCHOR_ADDRESS})"), "timestamp": "now"},
+ {"desc": descsum_create(f"raw({PAY_TO_ANCHOR.hex()})"), "timestamp": "now"}
+ ])
+ assert_equal(import_res[0]["success"], disable_private_keys)
+ assert_equal(import_res[1]["success"], disable_private_keys)
anchor_txid = self.default_wallet.sendtoaddress(ANCHOR_ADDRESS, 1)
self.generate(self.nodes[0], 1)
+ wallet = self.nodes[0].get_wallet_rpc(f"anchor_spend_True")
utxos = wallet.listunspent()
assert_equal(len(utxos), 1)
assert_equal(utxos[0]["txid"], anchor_txid)
@@ -126,7 +108,6 @@ class WalletAnchorTest(BitcoinTestFramework):
def run_test(self):
self.default_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
self.test_0_value_anchor_listunspent()
- self.test_import_anchors()
self.test_cannot_sign_anchors()
if __name__ == '__main__':