def test_access_wallet_with_bad_data(self): ''' Test access wallet with bad data ''' MINUTE = 60 WAIT_SECONDS = 10 MAX_SECONDS = 3 * MINUTE # remove a block from the blockchain block_filename = os.path.join(get_data_dir(), 'blocks', 'blk00000.dat') if os.path.exists(block_filename): os.remove(block_filename) request = self.factory.get('/bitcoin/access_wallet/') response = AccessWallet.as_view()(request) self.assertEqual(response.status_code, 200) self.assertTrue( b"<title>\nAccessing Bitcoin Core Wallet | Blockchain Backup\n</title>" in response.content) self.assertTrue( b"WARNING: Do not shut down your computer until Bitcoin-QT stops completely." in response.content) self.assertTrue( b'Bitcoin-QT will start in another window.' in response.content) self.assertFalse( b'Shutting down before this window says it is safe <em>could damage the blockchain</em>.' in response.content) done = False error_found = False error_message = None secs = 0 while not done: shutdown, error_message = test_utils.check_bitcoin_log() if error_message: error = error_message.strip(' ') error_found = 'Fatal LevelDB error' in error or 'Error opening block database' in error done = shutdown or error_found or not get_backups_enabled( ) or secs > MAX_SECONDS if not done: sleep(WAIT_SECONDS) secs += WAIT_SECONDS if not error_found: shutdown, error_message = test_utils.check_bitcoin_log() self.assertTrue(shutdown) error = error_message.strip(' ') error_found = 'Fatal LevelDB error' in error or 'Error opening block database' in error self.assertTrue(error_found) test_utils.stop_bitcoin_qt() self.assertFalse(get_backups_enabled())
def test_restore_with_missing_blocks(self): ''' Test restore with missing blocks in blockchain. ''' MINUTE = 60 MAX_SECONDS = 2 * MINUTE # remove a block from the blockchain data_dir = preferences.get_data_dir() block_filename = os.path.join(data_dir, 'blocks', 'blk00000.dat') if os.path.exists(block_filename): os.remove(block_filename) __, preselected_date_dir = state.get_backup_dates_and_dirs() request = self.factory.get('/bitcoin/restore/') response = views.Restore.as_view()(request) self.assertEqual(response.status_code, 200) self.assertTrue(b"<title>\nAre you sure you want to restore the Bitcoin blockchain? | Blockchain Backup\n</title>" in response.content) self.assertTrue(b'Select backup to restore:' in response.content) self.assertTrue(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button" title="Restore the blockchain now"/>' in response.content) self.assertTrue(b'<input type="submit" value="No, cancel restore" name="no-cancel-restore-button" id="no-cancel-restore-id" alt="No, cancel restore" class="btn btn-secondary font-weight-bold " role="button" title="Do not restore the blockchain."/>' in response.content) client = Client() response = client.post('/bitcoin/restore/', {'backup_dates_with_dirs': preselected_date_dir[0] }) self.assertEqual(response.status_code, 200) self.assertTrue(b"<title>\nRestoring Bitcoin Blockchain | Blockchain Backup\n</title>" in response.content) self.assertTrue(b'WARNING: Do not shut down your computer until the restore finishes.' in response.content) self.assertTrue(b'Starting to restore the blockchain' in response.content) self.assertFalse(b'<input type="submit" value="Yes, start restoring" name="yes-start-restoring-button" id="yes-start-restoring-id" alt="Yes, start restoring" class="btn btn-primary font-weight-bold " role="button" title="Restore the blockchain now"/>' in response.content) # wait until the restore finishes seconds = 0 while not is_restore_running() and seconds < MAX_SECONDS: sleep(MINUTE) seconds += MINUTE # wait until bitcoind starts test_utils.start_bitcoind() seconds = 0 while not is_bitcoind_running() and seconds < MAX_SECONDS: sleep(MINUTE) seconds += MINUTE self.assertTrue(is_bitcoind_running()) # allow bitcoind to run for a while seconds = 0 while is_bitcoind_running() and seconds < MAX_SECONDS: sleep(MINUTE) seconds += MINUTE if is_bitcoind_running(): test_utils.stop_bitcoind() shutdown, error_message = test_utils.check_bitcoin_log(is_bitcoind_running) self.assertTrue(shutdown) self.assertTrue(error_message is None)
def test_update_with_missing_links(self): ''' Start the update with missing links. ''' # remove links from the chainstate dirname = os.path.join(get_data_dir(), 'chainstate') entries = os.scandir(dirname) for entry in entries: if entry.name.endswith('.ldb'): os.remove(entry.path) request = self.factory.get('/bitcoin/update/') response = Update.as_view()(request) self.assertEqual(response.status_code, 200) self.assertTrue( b"<title>\nUpdating Bitcoin's Blockchain | Blockchain Backup\n</title>" in response.content) self.assertTrue(b"WARNING: Don't shut down your computer before you" in response.content) self.assertTrue( b'<a class="btn btn-secondary " role="button" id="stop_button" href="/bitcoin/interrupt_update/" title="Click to stop updating the blockchain">Stop update</a>' in response.content) self.assertTrue( b'Shutting down before this window says it is safe <em>could damage the blockchain</em>.' in response.content) sleep(60) self.assertFalse(is_bitcoind_running()) shutdown, error_message = test_utils.check_bitcoin_log( is_bitcoind_running) self.assertTrue(shutdown) log(error_message) self.assertTrue( 'Aborted block database rebuild. Exiting.' in error_message or 'Error opening block database.' in error_message or 'Fatal LevelDB error' in error_message) self.assertFalse(get_backups_enabled())
def test_update_with_missing_blocks(self): ''' Start the update with missing blocks. ''' # remove a block from the blockchain block_filename = os.path.join(get_data_dir(), 'blocks', 'blk00000.dat') if os.path.exists(block_filename): os.remove(block_filename) request = self.factory.get('/bitcoin/update/') response = Update.as_view()(request) self.assertEqual(response.status_code, 200) self.assertTrue( b"<title>\nUpdating Bitcoin's Blockchain | Blockchain Backup\n</title>" in response.content) self.assertTrue(b"WARNING: Don't shut down your computer before you" in response.content) self.assertTrue( b'<a class="btn btn-secondary " role="button" id="stop_button" href="/bitcoin/interrupt_update/" title="Click to stop updating the blockchain">Stop update</a>' in response.content) self.assertTrue( b'Shutting down before this window says it is safe <em>could damage the blockchain</em>.' in response.content) sleep(60) self.assertFalse(is_bitcoind_running()) shutdown, error_message = test_utils.check_bitcoin_log( is_bitcoind_running) self.assertTrue(shutdown) error = error_message.strip(' ') error_found = 'Fatal LevelDB error' in error or 'Error opening block database' in error self.assertTrue(error_found) self.assertFalse(get_backups_enabled())