diff options
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/feature_blockfilterindex_prune.py | 2 | ||||
-rwxr-xr-x | test/functional/feature_init.py | 10 | ||||
-rwxr-xr-x | test/functional/p2p_addr_relay.py | 37 | ||||
-rwxr-xr-x | test/functional/wallet_backup.py | 24 |
4 files changed, 47 insertions, 26 deletions
diff --git a/test/functional/feature_blockfilterindex_prune.py b/test/functional/feature_blockfilterindex_prune.py index 83a50c504e..2451988135 100755 --- a/test/functional/feature_blockfilterindex_prune.py +++ b/test/functional/feature_blockfilterindex_prune.py @@ -29,6 +29,8 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): self.log.info("prune some blocks") pruneheight = self.nodes[0].pruneblockchain(400) + # the prune heights used here and below are magic numbers that are determined by the + # thresholds at which block files wrap, so they depend on disk serialization and default block file size. assert_equal(pruneheight, 248) self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index cffbd40271..40468c66e2 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -57,19 +57,23 @@ class InitStressTest(BitcoinTestFramework): assert_equal(200, node.getblockcount()) lines_to_terminate_after = [ + 'Validating signatures for all blocks', 'scheduler thread start', + 'Starting HTTP server', 'Loading P2P addresses', 'Loading banlist', 'Loading block index', 'Switching active chainstate', + 'Checking all blk files are present', 'Loaded best chain:', 'init message: Verifying blocks', + 'init message: Starting network threads', + 'net thread start', + 'addcon thread start', 'loadblk thread start', # TODO: reenable - see above TODO # 'txindex thread start', - 'net thread start', - 'addcon thread start', - 'msghand thread start', + 'msghand thread start' ] if self.is_wallet_compiled(): lines_to_terminate_after.append('Verifying wallet') diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py index 5532056dbe..3218a9b14a 100755 --- a/test/functional/p2p_addr_relay.py +++ b/test/functional/p2p_addr_relay.py @@ -44,7 +44,7 @@ class AddrReceiver(P2PInterface): assert_equal(addr.nServices, 9) if not 8333 <= addr.port < 8343: raise AssertionError("Invalid addr.port of {} (8333-8342 expected)".format(addr.port)) - assert addr.ip.startswith('123.123.123.') + assert addr.ip.startswith('123.123.') def on_getaddr(self, message): # When the node sends us a getaddr, it increments the addr relay tokens for the connection by 1000 @@ -91,37 +91,31 @@ class AddrTest(BitcoinTestFramework): self.blocksonly_mode_tests() self.rate_limit_tests() - def setup_addr_msg(self, num): + def setup_addr_msg(self, num, sequential_ips=True): addrs = [] for i in range(num): addr = CAddress() - addr.time = self.mocktime + i + addr.time = self.mocktime + random.randrange(-100, 100) addr.nServices = P2P_SERVICES - addr.ip = f"123.123.123.{self.counter % 256}" + if sequential_ips: + assert self.counter < 256 ** 2 # Don't allow the returned ip addresses to wrap. + addr.ip = f"123.123.{self.counter // 256}.{self.counter % 256}" + self.counter += 1 + else: + addr.ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}" addr.port = 8333 + i addrs.append(addr) - self.counter += 1 msg = msg_addr() msg.addrs = addrs return msg - def setup_rand_addr_msg(self, num): - addrs = [] - for i in range(num): - addr = CAddress() - addr.time = self.mocktime + i - addr.nServices = P2P_SERVICES - addr.ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}" - addr.port = 8333 - addrs.append(addr) - msg = msg_addr() - msg.addrs = addrs - return msg - def send_addr_msg(self, source, msg, receivers): source.send_and_ping(msg) - # pop m_next_addr_send timer + # invoke m_next_addr_send timer: + # `addr` messages are sent on an exponential distribution with mean interval of 30s. + # Setting the mocktime 600s forward gives a probability of (1 - e^-(600/30)) that + # the event will occur (i.e. this fails once in ~500 million repeats). self.mocktime += 10 * 60 self.nodes[0].setmocktime(self.mocktime) for peer in receivers: @@ -282,7 +276,8 @@ class AddrTest(BitcoinTestFramework): block_relay_peer.send_and_ping(msg_getaddr()) inbound_peer.send_and_ping(msg_getaddr()) - self.mocktime += 5 * 60 + # invoke m_next_addr_send timer, see under send_addr_msg() function for rationale + self.mocktime += 10 * 60 self.nodes[0].setmocktime(self.mocktime) inbound_peer.wait_until(lambda: inbound_peer.addr_received() is True) @@ -313,7 +308,7 @@ class AddrTest(BitcoinTestFramework): def send_addrs_and_test_rate_limiting(self, peer, no_relay, *, new_addrs, total_addrs): """Send an addr message and check that the number of addresses processed and rate-limited is as expected""" - peer.send_and_ping(self.setup_rand_addr_msg(new_addrs)) + peer.send_and_ping(self.setup_addr_msg(new_addrs, sequential_ips=False)) peerinfo = self.nodes[0].getpeerinfo()[0] addrs_processed = peerinfo['addr_processed'] diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index 932df4fbff..292fe3a310 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -110,17 +110,32 @@ class WalletBackupTest(BitcoinTestFramework): 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 restore_invalid_wallet(self): + node = self.nodes[3] + invalid_wallet_file = os.path.join(self.nodes[0].datadir, 'invalid_wallet_file.bak') + open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet') + wallet_name = "res0" + not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file) + assert_raises_rpc_error(-18, error_message, node.restorewallet, wallet_name, invalid_wallet_file) + assert not os.path.exists(not_created_wallet_file) + def restore_nonexistent_wallet(self): node = self.nodes[3] nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak') wallet_name = "res0" assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file) + not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + assert not os.path.exists(not_created_wallet_file) def restore_wallet_existent_name(self): node = self.nodes[3] - wallet_file = os.path.join(self.nodes[0].datadir, 'wallet.bak') + backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak') wallet_name = "res0" - assert_raises_rpc_error(-8, "Wallet name already exists.", node.restorewallet, wallet_name, wallet_file) + wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + error_message = "Failed to create database path '{}'. Database already exists.".format(wallet_file) + assert_raises_rpc_error(-36, error_message, node.restorewallet, wallet_name, backup_file) + assert os.path.exists(wallet_file) def init_three(self): self.init_wallet(node=0) @@ -177,6 +192,7 @@ class WalletBackupTest(BitcoinTestFramework): ## self.log.info("Restoring wallets on node 3 using backup files") + self.restore_invalid_wallet() self.restore_nonexistent_wallet() backup_file_0 = os.path.join(self.nodes[0].datadir, 'wallet.bak') @@ -187,6 +203,10 @@ class WalletBackupTest(BitcoinTestFramework): self.nodes[3].restorewallet("res1", backup_file_1) self.nodes[3].restorewallet("res2", backup_file_2) + assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res0")) + assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res1")) + assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res2")) + res0_rpc = self.nodes[3].get_wallet_rpc("res0") res1_rpc = self.nodes[3].get_wallet_rpc("res1") res2_rpc = self.nodes[3].get_wallet_rpc("res2") |