def apply(self):
     """
     If there are no transaction history the strategy is useless so it defaults to LastDaySell
     """
     if len(self.transactions
            ) == 0:  # Fallback to last_day_sell if can't apply strategy
         logger.log(
             "No transactions saved. Defaulting to Last Day Sell strategy",
             self.log_name)
         return LastDaySell().apply()
     self.time_accumulated += ITERATION_TIME_DIFF
     self.bid = self.sell_reputation()
     self.write_iteration_info()
     from plebnet.agent.core import attempt_purchase
     attempt_purchase()
Exemplo n.º 2
0
    def test_attempt_purchase(self):
        self.log = logger.log
        self.testnet = plebnet_settings.Init.wallets_testnet
        self.get = PlebNetConfig.get
        self.get_balance = market_controller.get_balance
        self.calculate_price = cloudomate_controller.calculate_price
        self.purchase_choice = cloudomate_controller.purchase_choice
        self.evolve = DNA.evolve
        self.set = PlebNetConfig.set
        self.save = PlebNetConfig.save
        self.vpn = Core.attempt_purchase_vpn
        self.new = PlebNetConfig.increment_child_index
        self.provider = cloudomate_controller.get_vps_providers
        self.fg = fake_generator.generate_child_account
        self.tree = DNA.get_own_tree

        logger.log = MagicMock()
        plebnet_settings.Init.wallets_testnet = MagicMock(return_value=True)
        PlebNetConfig.get = MagicMock(return_value=['linevast', 'test', 0])
        market_controller.get_balance = MagicMock(return_value=300)
        DNA.get_own_tree = MagicMock()

        Core.attempt_purchase_vpn = MagicMock(return_value=False)
        cloudomate_controller.calculate_price = MagicMock(return_value=500)
        cloudomate_controller.purchase_choice = MagicMock(return_value=plebnet_settings.SUCCESS)
        DNA.evolve = MagicMock()
        PlebNetConfig.set = MagicMock()
        PlebNetConfig.save = MagicMock()
        PlebNetConfig.increment_child_index = MagicMock()
        cloudomate_controller.get_vps_providers = MagicMock()
        fake_generator.generate_child_account = MagicMock()

        Core.config = PlebNetConfig
        Core.dna = DNA
        Core.attempt_purchase()

        plebnet_settings.Init.wallets_testnet = MagicMock(return_value=False)
        market_controller.get_balance = MagicMock(return_value=700)
        Core.attempt_purchase()
        DNA.evolve.assert_called_with(True)

        cloudomate_controller.purchase_choice = MagicMock(return_value=plebnet_settings.FAILURE)
        Core.attempt_purchase()
        DNA.evolve.assert_called_with(False, 'linevast')

        logger.log = self.log
        plebnet_settings.Init.wallets_testnet = self.testnet
        PlebNetConfig.get = self.get
        market_controller.get_balance = self.get_balance
        cloudomate_controller.calculate_price = self.calculate_price
        cloudomate_controller.purchase_choice = self.purchase_choice
        DNA.evolve = self.evolve
        Core.attempt_purchase_vpn = self.vpn
        PlebNetConfig.set = self.set
        PlebNetConfig.save = self.save
        PlebNetConfig.increment_child_index = self.new
        cloudomate_controller.get_vps_providers = self.provider
        fake_generator.generate_child_account = self.fg
        DNA.get_own_tree = self.tree
Exemplo n.º 3
0
    def test_attempt_purchase(self, mock1, mock2):
        self.log = logger.log
        self.testnet = plebnet_settings.Init.wallets_testnet
        self.get = PlebNetConfig.get
        self.get_balance = market_controller.get_balance
        self.calculate_price = cloudomate_controller.calculate_price
        self.purchase_choice = cloudomate_controller.purchase_choice
        self.set = PlebNetConfig.set
        self.save = PlebNetConfig.save
        self.vpn = Core.attempt_purchase_vpn
        self.new = PlebNetConfig.increment_child_index
        self.provider = cloudomate_controller.get_vps_providers
        self.fg = fake_generator.generate_child_account
        self.qtable = QTable()
        self.providers = cloudomate_controller.get_vps_providers()
        providers = cloudomate_controller.get_vps_providers()
        self.qtable.init_qtable_and_environment(providers)
        self.qtable.set_self_state(VPSState("blueangelhost", "Basic Plan"))

        logger.log = MagicMock()
        plebnet_settings.Init.wallets_testnet = MagicMock(return_value=False)
        PlebNetConfig.get = MagicMock(
            return_value=['blueangelhost', 'Basic Plan', 0])
        market_controller.get_balance = MagicMock(return_value=100000000)

        Core.qtable = self.qtable
        Core.attempt_purchase_vpn = MagicMock(return_value=False)
        cloudomate_controller.calculate_price = MagicMock(return_value=0.01)
        cloudomate_controller.purchase_choice = MagicMock(
            return_value=plebnet_settings.SUCCESS)
        PlebNetConfig.set = MagicMock()
        PlebNetConfig.save = MagicMock()
        PlebNetConfig.increment_child_index = MagicMock()
        cloudomate_controller.get_vps_providers = MagicMock()
        fake_generator.generate_child_account = MagicMock()

        Core.config = PlebNetConfig
        qtable_copy = copy.deepcopy(Core.qtable.qtable)

        Core.attempt_purchase()

        self.assertLess(
            qtable_copy['blueangelhost_basic plan']
            ['blueangelhost_basic plan'],
            Core.qtable.qtable['blueangelhost_basic plan']
            ['blueangelhost_basic plan'])

        qtable_copy = copy.deepcopy(Core.qtable.qtable)
        cloudomate_controller.purchase_choice = MagicMock(
            return_value=plebnet_settings.FAILURE)
        Core.attempt_purchase()

        self.assertGreater(
            qtable_copy['blueangelhost_basic plan']
            ['blueangelhost_basic plan'],
            Core.qtable.qtable['blueangelhost_basic plan']
            ['blueangelhost_basic plan'])

        logger.log = self.log
        plebnet_settings.Init.wallets_testnet = self.testnet
        PlebNetConfig.get = self.get
        market_controller.get_balance = self.get_balance
        cloudomate_controller.calculate_price = self.calculate_price
        cloudomate_controller.purchase_choice = self.purchase_choice
        Core.attempt_purchase_vpn = self.vpn
        PlebNetConfig.set = self.set
        PlebNetConfig.save = self.save
        PlebNetConfig.increment_child_index = self.new
        cloudomate_controller.get_vps_providers = self.provider
        fake_generator.generate_child_account = self.fg
Exemplo n.º 4
0
 def apply(self):
     from plebnet.agent.core import attempt_purchase
     self.sell_reputation()
     for i in range(0, self.target_vps_count):
         attempt_purchase()