Skip to content

Commit d964b5b

Browse files
committed
Merge pull request bitcoin#7229
fa33d97 [walletdb] Add missing LOCK() in Recover() for dummyWallet (MarcoFalke) fa14d99 [qa] check if wallet or blochchain maintenance changes the balance (MarcoFalke) fa0765d [qa] Cleanup wallet.py test (MarcoFalke)
2 parents de9e5ea + fa33d97 commit d964b5b

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

qa/rpc-tests/wallet.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
#
7-
# Exercise the wallet. Ported from wallet.sh.
8-
# Does the following:
9-
# a) creates 3 nodes, with an empty chain (no blocks).
10-
# b) node0 mines a block
11-
# c) node1 mines 101 blocks, so now nodes 0 and 1 have 50btc, node2 has none.
12-
# d) node0 sends 21 btc to node2, in two transactions (11 btc, then 10 btc).
13-
# e) node0 mines a block, collects the fee on the second transaction
14-
# f) node1 mines 100 blocks, to mature node0's just-mined block
15-
# g) check that node0 has 100-21, node2 has 21
16-
# h) node0 should now have 2 unspent outputs; send these to node2 via raw tx broadcast by node1
17-
# i) have node1 mine a block
18-
# j) check balances - node0 should have 0, node2 should have 100
19-
# k) test ResendWalletTransactions - create transactions, startup fourth node, make sure it syncs
20-
#
216

227
from test_framework.test_framework import BitcoinTestFramework
238
from test_framework.util import *
@@ -190,7 +175,7 @@ def run_test (self):
190175
for uTx in unspentTxs:
191176
if uTx['txid'] == zeroValueTxid:
192177
found = True
193-
assert_equal(uTx['amount'], Decimal('0.00000000'));
178+
assert_equal(uTx['amount'], Decimal('0'))
194179
assert(found)
195180

196181
#do some -walletbroadcast tests
@@ -202,21 +187,22 @@ def run_test (self):
202187
connect_nodes_bi(self.nodes,0,2)
203188
self.sync_all()
204189

205-
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
190+
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
206191
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
207192
self.nodes[1].generate(1) #mine a block, tx should not be in there
208193
self.sync_all()
209-
assert_equal(self.nodes[2].getbalance(), node_2_bal); #should not be changed because tx was not broadcasted
194+
assert_equal(self.nodes[2].getbalance(), node_2_bal) #should not be changed because tx was not broadcasted
210195

211196
#now broadcast from another node, mine a block, sync, and check the balance
212197
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
213198
self.nodes[1].generate(1)
214199
self.sync_all()
200+
node_2_bal += 2
215201
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
216-
assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('2')); #should not be
202+
assert_equal(self.nodes[2].getbalance(), node_2_bal)
217203

218204
#create another tx
219-
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
205+
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
220206

221207
#restart the nodes with -walletbroadcast=1
222208
stop_nodes(self.nodes)
@@ -229,23 +215,24 @@ def run_test (self):
229215

230216
self.nodes[0].generate(1)
231217
sync_blocks(self.nodes)
218+
node_2_bal += 2
232219

233220
#tx should be added to balance because after restarting the nodes tx should be broadcastet
234-
assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('4')); #should not be
221+
assert_equal(self.nodes[2].getbalance(), node_2_bal)
235222

236223
#send a tx with value in a string (PR#6380 +)
237224
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
238225
txObj = self.nodes[0].gettransaction(txId)
239-
assert_equal(txObj['amount'], Decimal('-2.00000000'))
226+
assert_equal(txObj['amount'], Decimal('-2'))
240227

241228
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
242229
txObj = self.nodes[0].gettransaction(txId)
243-
assert_equal(txObj['amount'], Decimal('-0.00010000'))
230+
assert_equal(txObj['amount'], Decimal('-0.0001'))
244231

245232
#check if JSON parser can handle scientific notation in strings
246233
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
247234
txObj = self.nodes[0].gettransaction(txId)
248-
assert_equal(txObj['amount'], Decimal('-0.00010000'))
235+
assert_equal(txObj['amount'], Decimal('-0.0001'))
249236

250237
#this should fail
251238
errorString = ""
@@ -254,15 +241,38 @@ def run_test (self):
254241
except JSONRPCException,e:
255242
errorString = e.error['message']
256243

257-
assert_equal("Invalid amount" in errorString, True);
244+
assert_equal("Invalid amount" in errorString, True)
258245

259246
errorString = ""
260247
try:
261248
self.nodes[0].generate("2") #use a string to as block amount parameter must fail because it's not interpreted as amount
262249
except JSONRPCException,e:
263250
errorString = e.error['message']
264251

265-
assert_equal("not an integer" in errorString, True);
252+
assert_equal("not an integer" in errorString, True)
253+
254+
#check if wallet or blochchain maintenance changes the balance
255+
self.sync_all()
256+
self.nodes[0].generate(1)
257+
self.sync_all()
258+
balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
259+
260+
maintenance = [
261+
'-rescan',
262+
'-reindex',
263+
'-zapwallettxes=1',
264+
'-zapwallettxes=2',
265+
'-salvagewallet',
266+
]
267+
for m in maintenance:
268+
stop_nodes(self.nodes)
269+
wait_bitcoinds()
270+
self.nodes = start_nodes(3, self.options.tmpdir, [[m]] * 3)
271+
connect_nodes_bi(self.nodes,0,1)
272+
connect_nodes_bi(self.nodes,1,2)
273+
connect_nodes_bi(self.nodes,0,2)
274+
self.sync_all()
275+
assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])
266276

267277

268278
if __name__ == '__main__':

src/wallet/walletdb.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,13 @@ bool CWalletDB::Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKe
966966
CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
967967
CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
968968
string strType, strErr;
969-
bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
969+
bool fReadOK;
970+
{
971+
// Required in LoadKeyMetadata():
972+
LOCK(dummyWallet.cs_wallet);
973+
fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
970974
wss, strType, strErr);
975+
}
971976
if (!IsKeyType(strType))
972977
continue;
973978
if (!fReadOK)

0 commit comments

Comments
 (0)