@@ -121,13 +121,49 @@ def run_test(self):
121
121
# Exercise locking of unspent outputs
122
122
unspent_0 = self .nodes [2 ].listunspent ()[0 ]
123
123
unspent_0 = {"txid" : unspent_0 ["txid" ], "vout" : unspent_0 ["vout" ]}
124
+ # Trying to unlock an output which isn't locked should error
124
125
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
125
128
self .nodes [2 ].lockunspent (False , [unspent_0 ])
126
129
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
127
155
assert_raises_rpc_error (- 6 , "Insufficient funds" , self .nodes [2 ].sendtoaddress , self .nodes [2 ].getnewaddress (), 20 )
128
156
assert_equal ([unspent_0 ], self .nodes [2 ].listlockunspent ())
157
+
158
+ # Unlocking should remove the persistent lock
129
159
self .nodes [2 ].lockunspent (True , [unspent_0 ])
160
+ self .restart_node (2 )
130
161
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
+
131
167
assert_raises_rpc_error (- 8 , "txid must be of length 64 (not 34, for '0000000000000000000000000000000000')" ,
132
168
self .nodes [2 ].lockunspent , False ,
133
169
[{"txid" : "0000000000000000000000000000000000" , "vout" : 0 }])
0 commit comments