Skip to content

Commit 719ae92

Browse files
committed
Update lockunspent tests for lock persistence
1 parent f13fc16 commit 719ae92

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/functional/wallet_basic.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,49 @@ def run_test(self):
121121
# Exercise locking of unspent outputs
122122
unspent_0 = self.nodes[2].listunspent()[0]
123123
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
124+
# Trying to unlock an output which isn't locked should error
124125
assert_raises_rpc_error(-8, "Invalid parameter, expected locked output", self.nodes[2].lockunspent, True, [unspent_0])
126+
127+
# Locking an already-locked output should error
125128
self.nodes[2].lockunspent(False, [unspent_0])
126129
assert_raises_rpc_error(-8, "Invalid parameter, output already locked", self.nodes[2].lockunspent, False, [unspent_0])
130+
131+
# Restarting the node should clear the lock
132+
self.restart_node(2)
133+
self.nodes[2].lockunspent(False, [unspent_0])
134+
135+
# Unloading and reloating the wallet should clear the lock
136+
assert_equal(self.nodes[0].listwallets(), [self.default_wallet_name])
137+
self.nodes[2].unloadwallet(self.default_wallet_name)
138+
self.nodes[2].loadwallet(self.default_wallet_name)
139+
assert_equal(len(self.nodes[2].listlockunspent()), 0)
140+
141+
# Locking non-persistently, then re-locking persistently, is allowed
142+
self.nodes[2].lockunspent(False, [unspent_0])
143+
self.nodes[2].lockunspent(False, [unspent_0], True)
144+
145+
# Restarting the node with the lock written to the wallet should keep the lock
146+
self.restart_node(2)
147+
assert_raises_rpc_error(-8, "Invalid parameter, output already locked", self.nodes[2].lockunspent, False, [unspent_0])
148+
149+
# Unloading and reloading the wallet with a persistent lock should keep the lock
150+
self.nodes[2].unloadwallet(self.default_wallet_name)
151+
self.nodes[2].loadwallet(self.default_wallet_name)
152+
assert_raises_rpc_error(-8, "Invalid parameter, output already locked", self.nodes[2].lockunspent, False, [unspent_0])
153+
154+
# Locked outputs should not be used, even if they are the only available funds
127155
assert_raises_rpc_error(-6, "Insufficient funds", self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
128156
assert_equal([unspent_0], self.nodes[2].listlockunspent())
157+
158+
# Unlocking should remove the persistent lock
129159
self.nodes[2].lockunspent(True, [unspent_0])
160+
self.restart_node(2)
130161
assert_equal(len(self.nodes[2].listlockunspent()), 0)
162+
163+
# Reconnect node 2 after restarts
164+
self.connect_nodes(1, 2)
165+
self.connect_nodes(0, 2)
166+
131167
assert_raises_rpc_error(-8, "txid must be of length 64 (not 34, for '0000000000000000000000000000000000')",
132168
self.nodes[2].lockunspent, False,
133169
[{"txid": "0000000000000000000000000000000000", "vout": 0}])

0 commit comments

Comments
 (0)