mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
test, refactor: add default_wallet_name and wallet_data_filename variables
No changes in behavior
This commit is contained in:
parent
ec9b4492eb
commit
ed3acda33b
@ -30,7 +30,7 @@ class FilelockTest(BitcoinTestFramework):
|
||||
wallet_dir = os.path.join(datadir, 'wallets')
|
||||
self.log.info("Check that we can't start a second bitcoind instance using the same wallet")
|
||||
expected_msg = "Error: Error initializing wallet database environment"
|
||||
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=', '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
|
||||
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=' + self.default_wallet_name, '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
|
||||
|
||||
if __name__ == '__main__':
|
||||
FilelockTest().main()
|
||||
|
@ -95,7 +95,7 @@ class TestBitcoinCli(BitcoinTestFramework):
|
||||
assert_equal(self.nodes[0].cli.getwalletinfo(), wallet_info)
|
||||
|
||||
# Setup to test -getinfo, -generate, and -rpcwallet= with multiple wallets.
|
||||
wallets = ['', 'Encrypted', 'secret']
|
||||
wallets = [self.default_wallet_name, 'Encrypted', 'secret']
|
||||
amounts = [BALANCE + Decimal('9.999928'), Decimal(9), Decimal(31)]
|
||||
self.nodes[0].createwallet(wallet_name=wallets[1])
|
||||
self.nodes[0].createwallet(wallet_name=wallets[2])
|
||||
|
@ -29,7 +29,7 @@ class DeprecatedRpcTest(BitcoinTestFramework):
|
||||
self.nodes[0].generate(101)
|
||||
self.nodes[0].createwallet(wallet_name='nopriv', disable_private_keys=True)
|
||||
noprivs0 = self.nodes[0].get_wallet_rpc('nopriv')
|
||||
w0 = self.nodes[0].get_wallet_rpc('')
|
||||
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||
self.nodes[1].createwallet(wallet_name='nopriv', disable_private_keys=True)
|
||||
noprivs1 = self.nodes[1].get_wallet_rpc('nopriv')
|
||||
|
||||
|
@ -102,6 +102,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
|
||||
self.supports_cli = True
|
||||
self.bind_to_localhost_only = True
|
||||
self.default_wallet_name = ""
|
||||
self.wallet_data_filename = "wallet.dat"
|
||||
self.set_test_params()
|
||||
self.parse_args()
|
||||
if self.options.timeout_factor == 0 :
|
||||
|
@ -213,7 +213,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||
self.assert_tool_output('', '-wallet=salvage', 'salvage')
|
||||
|
||||
def run_test(self):
|
||||
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')
|
||||
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
|
||||
self.test_invalid_tool_commands_and_args()
|
||||
# Warning: The following tests are order-dependent.
|
||||
self.test_tool_wallet_info()
|
||||
|
@ -107,9 +107,9 @@ class WalletBackupTest(BitcoinTestFramework):
|
||||
self.stop_node(2)
|
||||
|
||||
def erase_three(self):
|
||||
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Generating initial blockchain")
|
||||
@ -171,9 +171,9 @@ class WalletBackupTest(BitcoinTestFramework):
|
||||
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
|
||||
|
||||
# Restore wallets from backup
|
||||
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
|
||||
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
|
||||
|
||||
self.log.info("Re-starting nodes")
|
||||
self.start_three()
|
||||
@ -209,9 +209,9 @@ class WalletBackupTest(BitcoinTestFramework):
|
||||
|
||||
# Backup to source wallet file must fail
|
||||
sourcePaths = [
|
||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', 'wallet.dat'),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name),
|
||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
|
||||
|
||||
for sourcePath in sourcePaths:
|
||||
|
@ -215,10 +215,10 @@ class WalletTest(BitcoinTestFramework):
|
||||
# dynamically loading the wallet.
|
||||
before = self.nodes[1].getbalances()['mine']['untrusted_pending']
|
||||
dst = self.nodes[1].getnewaddress()
|
||||
self.nodes[1].unloadwallet('')
|
||||
self.nodes[1].unloadwallet(self.default_wallet_name)
|
||||
self.nodes[0].sendtoaddress(dst, 0.1)
|
||||
self.sync_all()
|
||||
self.nodes[1].loadwallet('')
|
||||
self.nodes[1].loadwallet(self.default_wallet_name)
|
||||
after = self.nodes[1].getbalances()['mine']['untrusted_pending']
|
||||
assert_equal(before + Decimal('0.1'), after)
|
||||
|
||||
|
@ -24,7 +24,7 @@ class WalletDescriptorTest(BitcoinTestFramework):
|
||||
# Make a descriptor wallet
|
||||
self.log.info("Making a descriptor wallet")
|
||||
self.nodes[0].createwallet(wallet_name="desc1", descriptors=True)
|
||||
self.nodes[0].unloadwallet("")
|
||||
self.nodes[0].unloadwallet(self.default_wallet_name)
|
||||
|
||||
# A descriptor wallet should have 100 addresses * 3 types = 300 keys
|
||||
self.log.info("Checking wallet info")
|
||||
|
@ -84,7 +84,7 @@ class WalletHDTest(BitcoinTestFramework):
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
|
||||
shutil.copyfile(
|
||||
os.path.join(self.nodes[1].datadir, "hd.bak"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, 'wallets', "wallet.dat"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
|
||||
)
|
||||
self.start_node(1)
|
||||
|
||||
@ -112,7 +112,7 @@ class WalletHDTest(BitcoinTestFramework):
|
||||
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
|
||||
shutil.copyfile(
|
||||
os.path.join(self.nodes[1].datadir, "hd.bak"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"),
|
||||
os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename),
|
||||
)
|
||||
self.start_node(1, extra_args=self.extra_args[1])
|
||||
connect_nodes(self.nodes[0], 1)
|
||||
|
@ -820,7 +820,7 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||
|
||||
# Cannot import those pubkeys to keypool of wallet with privkeys
|
||||
self.log.info("Pubkeys cannot be added to the keypool of a wallet with private keys")
|
||||
wrpc = self.nodes[1].get_wallet_rpc("")
|
||||
wrpc = self.nodes[1].get_wallet_rpc(self.default_wallet_name)
|
||||
assert wrpc.getwalletinfo()['private_keys_enabled']
|
||||
result = wrpc.importmulti(
|
||||
[{
|
||||
|
@ -143,7 +143,7 @@ class KeyPoolTest(BitcoinTestFramework):
|
||||
w2 = nodes[0].get_wallet_rpc('w2')
|
||||
|
||||
# refer to initial wallet as w1
|
||||
w1 = nodes[0].get_wallet_rpc('')
|
||||
w1 = nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||
|
||||
# import private key and fund it
|
||||
address = addr.pop()
|
||||
|
@ -30,7 +30,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def run_test(self):
|
||||
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat")
|
||||
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename)
|
||||
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
|
||||
self.nodes[0].generate(101)
|
||||
|
||||
|
@ -62,14 +62,14 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
def wallet_file(name):
|
||||
if os.path.isdir(wallet_dir(name)):
|
||||
return wallet_dir(name, "wallet.dat")
|
||||
return wallet_dir(name, self.wallet_data_filename)
|
||||
return wallet_dir(name)
|
||||
|
||||
assert_equal(self.nodes[0].listwalletdir(), { 'wallets': [{ 'name': '' }] })
|
||||
assert_equal(self.nodes[0].listwalletdir(), { 'wallets': [{ 'name': self.default_wallet_name }] })
|
||||
|
||||
# check wallet.dat is created
|
||||
self.stop_nodes()
|
||||
assert_equal(os.path.isfile(wallet_dir('wallet.dat')), True)
|
||||
assert_equal(os.path.isfile(wallet_dir(self.default_wallet_name, self.wallet_data_filename)), True)
|
||||
|
||||
# create symlink to verify wallet directory path can be referenced
|
||||
# through symlink
|
||||
@ -78,13 +78,13 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
# rename wallet.dat to make sure plain wallet file paths (as opposed to
|
||||
# directory paths) can be loaded
|
||||
os.rename(wallet_dir("wallet.dat"), wallet_dir("w8"))
|
||||
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), wallet_dir("w8"))
|
||||
|
||||
# create another dummy wallet for use in testing backups later
|
||||
self.start_node(0, ["-wallet="])
|
||||
self.start_node(0, ["-wallet=" + self.default_wallet_name])
|
||||
self.stop_nodes()
|
||||
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat')
|
||||
os.rename(wallet_dir("wallet.dat"), empty_wallet)
|
||||
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), empty_wallet)
|
||||
|
||||
# restart node with a mix of wallet names:
|
||||
# w1, w2, w3 - to verify new wallets created when non-existing paths specified
|
||||
@ -94,10 +94,10 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
# w7_symlink - to verify symlinked wallet path is initialized correctly
|
||||
# w8 - to verify existing wallet file is loaded correctly
|
||||
# '' - to verify default wallet file is created correctly
|
||||
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', '']
|
||||
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
|
||||
extra_args = ['-wallet={}'.format(n) for n in wallet_names]
|
||||
self.start_node(0, extra_args)
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
|
||||
|
||||
assert_equal(set(node.listwallets()), set(wallet_names))
|
||||
|
||||
@ -157,7 +157,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
self.restart_node(0, extra_args)
|
||||
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy'])
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy'])
|
||||
|
||||
wallets = [wallet(w) for w in wallet_names]
|
||||
wallet_bad = wallet("bad")
|
||||
@ -247,12 +247,12 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path), self.nodes[0].loadwallet, 'wallets')
|
||||
|
||||
# Fail to load duplicate wallets
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", self.wallet_data_filename)
|
||||
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, wallet_names[0])
|
||||
|
||||
# Fail to load duplicate wallets by different ways (directory and filepath)
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
|
||||
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat')
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", self.wallet_data_filename)
|
||||
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, self.wallet_data_filename)
|
||||
|
||||
# Fail to load if one wallet is a copy of another
|
||||
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
||||
@ -324,7 +324,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
assert_equal(self.nodes[0].listwallets(), ['w1'])
|
||||
assert_equal(w1.getwalletinfo()['walletname'], 'w1')
|
||||
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9'])
|
||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9'])
|
||||
|
||||
# Test backing up and restoring wallets
|
||||
self.log.info("Test wallet backup")
|
||||
|
@ -89,7 +89,7 @@ class ReorgsRestoreTest(BitcoinTestFramework):
|
||||
# Node0 wallet file is loaded on longest sync'ed node1
|
||||
self.stop_node(1)
|
||||
self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
|
||||
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallet.dat'))
|
||||
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, self.default_wallet_name, self.wallet_data_filename))
|
||||
self.start_node(1)
|
||||
tx_after_reorg = self.nodes[1].gettransaction(txid)
|
||||
# Check that normal confirmed tx is confirmed again but with different blockhash
|
||||
|
@ -156,7 +156,7 @@ class WalletSendTest(BitcoinTestFramework):
|
||||
def run_test(self):
|
||||
self.log.info("Setup wallets...")
|
||||
# w0 is a wallet with coinbase rewards
|
||||
w0 = self.nodes[0].get_wallet_rpc("")
|
||||
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||
# w1 is a regular wallet
|
||||
self.nodes[1].createwallet(wallet_name="w1")
|
||||
w1 = self.nodes[1].get_wallet_rpc("w1")
|
||||
|
Loading…
Reference in New Issue
Block a user