v29.4-roots.2 · Commit 4: [PATCH 04/21] wallet: harden database and signing behavior
test/functional/wallet_signer.py
Before: test/functional/wallet_signer.py · After: test/functional/wallet_signer.py
File metadata
index fe1c7953c23ffa9139444ed993e6cf652865b3fb..8c8ed10a6173dcc0fb2738929a449e6fbfe10515 100755
Download original patch · Release notes
Diff rows 1–53 of 53. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/wallet_signer.py
CHANGED
|
@@ -26,6 +26,10 @@ class WalletSignerTest(BitcoinTestFramework):
|
|
| 26 |
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'signer.py')
|
| 27 |
return sys.executable + " " + path
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def mock_invalid_signer_path(self):
|
| 30 |
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'invalid_signer.py')
|
| 31 |
return sys.executable + " " + path
|
|
@@ -55,6 +59,7 @@ class WalletSignerTest(BitcoinTestFramework):
|
|
| 55 |
|
| 56 |
def run_test(self):
|
| 57 |
self.test_valid_signer()
|
|
|
|
| 58 |
self.restart_node(1, [f"-signer={self.mock_invalid_signer_path()}", "-keypool=10"])
|
| 59 |
self.test_invalid_signer()
|
| 60 |
self.restart_node(1, [f"-signer={self.mock_multi_signers_path()}", "-keypool=10"])
|
|
@@ -242,6 +247,28 @@ class WalletSignerTest(BitcoinTestFramework):
|
|
| 242 |
# )
|
| 243 |
# self.clear_mock_result(self.nodes[4])
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
def test_invalid_signer(self):
|
| 246 |
self.log.debug(f"-signer={self.mock_invalid_signer_path()}")
|
| 247 |
self.log.info('Test invalid external signer')
|
|
@@ -251,7 +278,7 @@ class WalletSignerTest(BitcoinTestFramework):
|
|
| 251 |
self.log.debug(f"-signer={self.mock_multi_signers_path()}")
|
| 252 |
self.log.info('Test multiple external signers')
|
| 253 |
|
| 254 |
-
assert_raises_rpc_error(-1, "GetExternalSigner: More than one external signer found", self.nodes[1].createwallet, wallet_name='multi_hww', disable_private_keys=True, descriptors=True, external_signer=True)
|
| 255 |
|
| 256 |
if __name__ == '__main__':
|
| 257 |
WalletSignerTest(__file__).main()
|
|
|
|
| 26 |
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'signer.py')
|
| 27 |
return sys.executable + " " + path
|
| 28 |
|
| 29 |
+
def mock_no_connected_signer_path(self):
|
| 30 |
+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'no_signer.py')
|
| 31 |
+
return sys.executable + " " + path
|
| 32 |
+
|
| 33 |
def mock_invalid_signer_path(self):
|
| 34 |
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'invalid_signer.py')
|
| 35 |
return sys.executable + " " + path
|
|
|
|
| 59 |
|
| 60 |
def run_test(self):
|
| 61 |
self.test_valid_signer()
|
| 62 |
+
self.test_disconnected_signer()
|
| 63 |
self.restart_node(1, [f"-signer={self.mock_invalid_signer_path()}", "-keypool=10"])
|
| 64 |
self.test_invalid_signer()
|
| 65 |
self.restart_node(1, [f"-signer={self.mock_multi_signers_path()}", "-keypool=10"])
|
|
|
|
| 247 |
# )
|
| 248 |
# self.clear_mock_result(self.nodes[4])
|
| 249 |
|
| 250 |
+
def test_disconnected_signer(self):
|
| 251 |
+
self.log.info('Test disconnected external signer')
|
| 252 |
+
|
| 253 |
+
# First create a wallet with the signer connected
|
| 254 |
+
self.nodes[1].createwallet(wallet_name='hww_disconnect', disable_private_keys=True, external_signer=True)
|
| 255 |
+
hww = self.nodes[1].get_wallet_rpc('hww_disconnect')
|
| 256 |
+
assert_equal(hww.getwalletinfo()["external_signer"], True)
|
| 257 |
+
|
| 258 |
+
# Fund wallet
|
| 259 |
+
self.nodes[0].sendtoaddress(hww.getnewaddress(address_type="bech32m"), 1)
|
| 260 |
+
self.generate(self.nodes[0], 1)
|
| 261 |
+
|
| 262 |
+
# Restart node with no signer connected
|
| 263 |
+
self.log.debug(f"-signer={self.mock_no_connected_signer_path()}")
|
| 264 |
+
self.restart_node(1, [f"-signer={self.mock_no_connected_signer_path()}", "-keypool=10"])
|
| 265 |
+
self.nodes[1].loadwallet('hww_disconnect')
|
| 266 |
+
hww = self.nodes[1].get_wallet_rpc('hww_disconnect')
|
| 267 |
+
|
| 268 |
+
# Try to spend
|
| 269 |
+
dest = hww.getrawchangeaddress()
|
| 270 |
+
assert_raises_rpc_error(-25, "External signer not found", hww.send, outputs=[{dest:0.5}])
|
| 271 |
+
|
| 272 |
def test_invalid_signer(self):
|
| 273 |
self.log.debug(f"-signer={self.mock_invalid_signer_path()}")
|
| 274 |
self.log.info('Test invalid external signer')
|
|
|
|
| 278 |
self.log.debug(f"-signer={self.mock_multi_signers_path()}")
|
| 279 |
self.log.info('Test multiple external signers')
|
| 280 |
|
| 281 |
+
assert_raises_rpc_error(-1, "More than one external signer found", self.nodes[1].createwallet, wallet_name='multi_hww', disable_private_keys=True, descriptors=True, external_signer=True)
|
| 282 |
|
| 283 |
if __name__ == '__main__':
|
| 284 |
WalletSignerTest(__file__).main()
|