Skip to content

Commit

Permalink
test: Add salvage test for wallet tool
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Sep 28, 2021
1 parent a9d0cec commit 8d600d6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/functional/tool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import hashlib
import os
import random
import stat
import subprocess
import textwrap
Expand Down Expand Up @@ -34,7 +35,10 @@ def bitcoin_wallet_process(self, *args):
if self.options.descriptors and 'create' in args:
default_args.append('-descriptors')

return subprocess.Popen([binary] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
process_args = default_args + list(args)
self.log.debug('Running wallet tool with args "{}"'.format('" "'.join(process_args)))

return subprocess.Popen([binary] + process_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)

def assert_raises_tool_error(self, error, *args):
p = self.bitcoin_wallet_process(*args)
Expand Down Expand Up @@ -309,12 +313,27 @@ def test_getwalletinfo_on_different_wallet(self):
def test_salvage(self):
# TODO: Check salvage actually salvages and doesn't break things. https://github.com/bitcoin/bitcoin/issues/7463
self.log.info('Check salvage')
self.start_node(0)
self.start_node(0, ['-nowallet'])
self.nodes[0].createwallet("salvage")
address_gen_rand = random.Random(123)

def gna():
return self.nodes[0].getnewaddress(address_type=address_gen_rand.choice(['legacy', 'p2sh-segwit', 'bech32']))

for _ in range(101):
# Generate to fresh address each time
self.nodes[0].generatetoaddress(1, gna())
self.nodes[0].sendmany(amounts={gna(): 0.05 for _ in range(50)})
self.nodes[0].sendmany(amounts={gna(): 0.05 for _ in range(50)})
balances_before = self.nodes[0].getbalances()
self.stop_node(0)

self.assert_tool_output('', '-wallet=salvage', 'salvage')

self.start_node(0, ['-nowallet', '-wallet=salvage'])
assert_equal(balances_before, self.nodes[0].getbalances())
self.stop_node(0)

def test_dump_createfromdump(self):
self.start_node(0)
self.nodes[0].createwallet("todump")
Expand Down

0 comments on commit 8d600d6

Please sign in to comment.