Пример #1
0
    def test_access_wallet_with_bitcoind_running(self):
        '''
            Test accessing the wallet with bitcoind already running.
        '''
        # start bitcoind and wait for it to get started
        test_utils.start_bitcoind()
        while not is_bitcoind_running():
            sleep(1)

        request = self.factory.get('/bitcoin/access_wallet/')
        response = AccessWallet.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nBitcoinD Is Running | Blockchain Backup\n</title>" in
            response.content)
        self.assertTrue(
            b'BitcoinD, one of the Bitcoin Core programs, appears to be running'
            in response.content)
        self.assertFalse(
            b'Bitcoin-QT, one of the Bitcoin Core programs, appears to be running'
            in response.content)
        self.assertFalse(
            b'Bitcoin-TX, one of the Bitcoin Core programs, appears to be running'
            in response.content)

        test_utils.stop_bitcoind()
Пример #2
0
    def test_update_with_bitcoin_d_running(self):
        '''
            Test updating with bitcoind already running.
        '''
        # start bitcoind and wait for it to get started
        test_utils.start_bitcoind()
        while not is_bitcoind_running():
            sleep(1)
        log('bitcoind is running')

        request = self.factory.get('/bitcoin/update/')
        response = Update.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            b"<title>\nBitcoinD Is Running | Blockchain Backup\n</title>" in
            response.content)
        self.assertTrue(
            b'BitcoinD, one of the Bitcoin Core programs, appears to be running'
            in response.content)
        self.assertFalse(
            b'Bitcoin-QT, one of the Bitcoin Core programs, appears to be running'
            in response.content)
        self.assertFalse(
            b'Bitcoin-TX, one of the Bitcoin Core programs, appears to be running'
            in response.content)

        if is_bitcoind_running():
            test_utils.stop_bitcoind()

        self.assertTrue(get_backups_enabled())
Пример #3
0
    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)
Пример #4
0
    def test_backup(self):
        '''
            Start the backup via views and wait 1 minute,
            then interrupt it.
        '''

        request = self.factory.get('/bitcoin/backup/')
        response = views.Backup.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nBacking Up Bitcoin's Blockchain | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b"WARNING: Stopping the backup could damage the ability to restore the blockchain." in response.content)
        self.assertTrue(b'If you need to stop the backup, then <a class="btn btn-secondary " href="/bitcoin/interrupt_backup/" role="button" id="stop-button" title="Click to stop backing up the blockchain">click here</a>.' in response.content)
        self.assertTrue(b'Starting to back up the blockchain' in response.content)

        sleep(60)
        test_utils.stop_bitcoind()
Пример #5
0
    def tearDown(self):

        # make sure nothing is left running
        test_utils.stop_bitcoin_core_apps()
        if is_restore_running():
            views.InterruptRestore.as_view()(self.factory.get('/bitcoin/interrupt_restore/'))
            sleep(20)
        if is_backup_running():
            views.InterruptBackup.as_view()(self.factory.get('/bitcoin/interrupt_backup/'))
            sleep(20)

        test_utils.stop_bitcoind()
        sleep(20)

        # some tests might create a .bitcon in the home dir
        test_utils.delete_home_bitcoin_subdir(self.home_bitcoin_subdir_exists)
Пример #6
0
    def test_backup_with_bitcoind_running(self):
        '''
            Test backing up with bitcoind already running.
        '''
        test_utils.start_bitcoind()
        while not is_bitcoind_running():
            sleep(5)

        request = self.factory.get('/bitcoin/backup/')
        response = views.Backup.as_view()(request)

        # stop bitcoin in case any tests fail
        test_utils.stop_bitcoind()

        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nBitcoinD Is Running | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b'BitcoinD, one of the Bitcoin Core programs, appears to be running' in response.content)
        self.assertFalse(b'Bitcoin-QT, one of the Bitcoin Core programs, appears to be running' in response.content)
        self.assertFalse(b'Bitcoin-TX, one of the Bitcoin Core programs, appears to be running' in response.content)
Пример #7
0
    def test_restore_with_bitcoind_running(self):
        '''
            Test restoring with bitcoind already running.
        '''
        test_utils.start_bitcoind()
        while not is_bitcoind_running():
            sleep(5)

        request = self.factory.get('/bitcoin/restore/')
        response = views.Restore.as_view()(request)

        # stop the task before we start tests in case something fails
        test_utils.stop_bitcoind()

        self.assertEqual(response.status_code, 200)
        self.assertTrue(b"<title>\nBitcoinD Is Running | Blockchain Backup\n</title>" in response.content)
        self.assertTrue(b'BitcoinD, one of the Bitcoin Core programs, appears to be running' in response.content)
        self.assertFalse(b'Bitcoin-QT, one of the Bitcoin Core programs, appears to be running' in response.content)
        self.assertFalse(b'Bitcoin-TX, one of the Bitcoin Core programs, appears to be running' in response.content)
Пример #8
0
    def test_update(self):
        '''
            Start the update via views,
            wait a few minutes, then interrupt it.
        '''

        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(180)
        if is_bitcoind_running():
            test_utils.stop_bitcoind()