コード例 #1
0
    def test_purchase_choice_error(self):
        self.config = PlebNetConfig.get
        self.triblerwallet = TriblerWallet.__init__
        self.settings = plebnet_settings.Init.wallets_testnet_created
        self.purchase = blueAngel.BlueAngelHost.purchase
        self.logger = Logger.warning

        self.error = Logger.error
        self.issue = git_issuer.handle_error

        PlebNetConfig.get = MagicMock(side_effect=self.side_effect)
        plebnet_settings.Init.wallets_testnet_created = MagicMock(
            return_value=None)
        TriblerWallet.__init__ = MagicMock(return_value=None)
        blueAngel.BlueAngelHost.purchase = MagicMock(side_effect=Exception)
        Logger.warning = MagicMock()
        Logger.error = MagicMock()
        git_issuer.handle_error = MagicMock()

        self.assertEquals(cloudomate.purchase_choice(PlebNetConfig()),
                          plebnet_settings.FAILURE)

        PlebNetConfig.get = self.config
        TriblerWallet.__init__ = self.triblerwallet
        plebnet_settings.Init.wallets_testnet_created = self.settings
        blueAngel.BlueAngelHost.purchase = self.purchase
        Logger.warning = self.logger
        Logger.error = self.error
        git_issuer.handle_error = self.issue
コード例 #2
0
def attempt_purchase():
    """
    Check if enough money to buy a server, and if so, do so,
    """
    (provider, option, _) = config.get('chosen_provider')
    if settings.wallets_testnet():
        domain = 'TBTC'
    else:
        domain = 'BTC'
    if market_controller.get_balance(domain) >= (
            cloudomate_controller.calculate_price(provider, option) +
            cloudomate_controller.calculate_price_vpn()):
        logger.log("Try to buy a new server from %s" % provider, log_name)
        success = cloudomate_controller.purchase_choice(config)
        if success == plebnet_settings.SUCCESS:
            # Evolve yourself positively if you are successful
            dna.evolve(True)
            logger.log(
                "Purchasing vps for child %s successful" %
                (dna.get_own_tree() + '.' + str(config.get('child_index'))))
            # purchase VPN with same config if server allows for it
            if cloudomate_controller.get_vps_providers(
            )[provider].TUN_TAP_SETTINGS:
                attempt_purchase_vpn()
        elif success == plebnet_settings.FAILURE:
            # Evolve provider negatively if not successful
            dna.evolve(False, provider)

        config.increment_child_index()
        fake_generator.generate_child_account()
        config.set('chosen_provider', None)
        config.save()
コード例 #3
0
ファイル: core.py プロジェクト: louis-xer/Dollynator
def attempt_purchase():
    """
    Check if enough money to buy a server, and if so, do so,
    """
    (provider, option, _) = config.get('chosen_provider')
    provider_offer_ID = str(provider).lower() + "_" + str(option).lower()
    if settings.wallets_testnet():
        domain = 'TBTC'
    else:
        domain = 'BTC'
    btc_balance = satoshi_to_btc(market_controller.get_balance(domain))
    vps_price = cloudomate_controller.calculate_price(provider, option)
    vpn_price = cloudomate_controller.calculate_price_vpn()
    logger.log('Selected VPS: %s (%s), %s BTC' % (provider, option, vps_price),
               log_name)
    logger.log('Selected VPN: %s, %s BTC' % ("mullvad", vpn_price), log_name)
    logger.log("Balance: %s %s" % (btc_balance, domain), log_name)
    if btc_balance >= vps_price + vpn_price:
        logger.log(
            "Before trying to purchase VPS share current QTable with other agents"
        )
        qtable.share_qtable()
        logger.log("Try to buy a new server from %s" % provider, log_name)
        success = cloudomate_controller.purchase_choice(config)
        if success == plebnet_settings.SUCCESS:
            # Update qtable yourself positively if you are successful
            qtable.update_qtable(remote_tables, provider_offer_ID, True,
                                 get_reward_qlearning())
            # purchase VPN with same config if server allows for it
            # purchase VPN with same config if server allows for it
            if cloudomate_controller.get_vps_providers(
            )[provider].TUN_TAP_SETTINGS:
                attempt_purchase_vpn()
        elif success == plebnet_settings.FAILURE:
            # Update qtable provider negatively if not successful
            qtable.update_qtable(remote_tables, provider_offer_ID, False,
                                 get_reward_qlearning())

        qtable.write_dictionary()
        config.increment_child_index()
        fake_generator.generate_child_account()
        config.set('chosen_provider', None)
        config.save()
コード例 #4
0
    def test_purchase_choice(self):
        self.config = PlebNetConfig.get
        self.triblerwallet = TriblerWallet.__init__
        self.settings = plebnet_settings.Init.wallets_testnet_created
        self.purchase = blueAngel.BlueAngelHost.purchase
        self.logger = Logger.warning

        PlebNetConfig.get = MagicMock(side_effect=self.side_effect)
        plebnet_settings.Init.wallets_testnet_created = MagicMock(return_value=None)
        TriblerWallet.__init__ = MagicMock(return_value=None)
        blueAngel.BlueAngelHost.purchase = MagicMock(return_value=('Hash', 0))
        Logger.warning = MagicMock()

        self.assertEquals(cloudomate.purchase_choice(PlebNetConfig()), plebnet_settings.SUCCESS)

        PlebNetConfig.get = self.config
        TriblerWallet.__init__ = self.triblerwallet
        plebnet_settings.Init.wallets_testnet_created = self.settings
        blueAngel.BlueAngelHost.purchase = self.purchase
        Logger.warning = self.logger
コード例 #5
0
ファイル: core.py プロジェクト: thijmensjf/PlebNet
def attempt_purchase():
    """
    Check if rich enough to buy a server, and if so, do so
    :return: None
    :rtype: None
    """
    # try to purchase the chosen vps.
    (provider, option, _) = config.get('chosen_provider')
    if settings.wallets_testnet():
        domain = 'TBTC'
    else:
        domain = 'BTC'
    if market_controller.get_balance(domain) >= cloudomate_controller.calculate_price(provider, option):
        logger.log("Try to buy a new server from %s" % provider, log_name)
        success = cloudomate_controller.purchase_choice(config)
        if success == plebnet_settings.SUCCESS:
            # evolve yourself positively if you are successful
            DNA().evolve(True)
        elif success == plebnet_settings.FAILURE:
            # evolve provider negatively if not successful
            DNA().evolve(False)
コード例 #6
0
    def test_purchase_choice_failure(self):
        self.config = PlebNetConfig.get
        self.triblerwallet = TriblerWallet.__init__
        self.settings = plebnet_settings.Init.wallets_testnet_created
        self.purchase = linevast.LineVast.purchase
        self.logger = Logger.warning

        PlebNetConfig.get = MagicMock(side_effect=self.side_effect)
        plebnet_settings.Init.wallets_testnet_created = MagicMock(
            return_value=None)
        TriblerWallet.__init__ = MagicMock(return_value=None)
        linevast.LineVast.purchase = MagicMock(
            side_effect=Exception("Purchase failed"))
        Logger.warning = MagicMock()

        self.assertEquals(cloudomate.purchase_choice(PlebNetConfig()),
                          plebnet_settings.FAILURE)

        PlebNetConfig.get = self.config
        TriblerWallet.__init__ = self.triblerwallet
        plebnet_settings.Init.wallets_testnet_created = self.settings
        linevast.LineVast.purchase = self.purchase
        Logger.warning = self.logger