def test__model__miner__update_miner__not_running(self):
        miner = Miner()
        service = Service(running=False)
        self.query_service.get.return_value = service

        self.assertEqual(0, miner.update_miner())
        self.query_service.get.assert_called_with(miner.uuid)
Ejemplo n.º 2
0
def create_service(name: str, data: dict, user: str):
    uuid: str = str(uuid4())

    if name == "bruteforce":
        Bruteforce.create(uuid)
    elif name == "miner":
        # First check for name then validate for special information
        if "wallet_uuid" not in data:
            return invalid_request
        wallet_uuid: str = data["wallet_uuid"]
        if not isinstance(wallet_uuid, str):
            return invalid_request
        if not exists_wallet(wallet_uuid):
            return wallet_not_found
        Miner.create(uuid, data["wallet_uuid"])

    speed: float = 0
    running: bool = False
    if config["services"][name]["auto_start"]:
        speed: float = register_service(data["device_uuid"], uuid, name, user)
        if speed == -1:
            speed: float = 0
        else:
            running: bool = True

    service: Service = Service.create(uuid, data["device_uuid"], user, name,
                                      speed, running)

    return service.serialize
    def test__model__miner__update_miner__successful(self, time_patch):
        miner = Miner(started=13)
        service = Service(running=True, speed=0.8)
        self.query_service.get.return_value = service
        time_patch.return_value = 37

        expected_result = int((37000 - 13) * 0.8)
        actual_result = miner.update_miner()

        self.assertEqual(expected_result, actual_result)
        self.assertEqual(37000, miner.started)
        mock.wrapper.session.commit.assert_called_with()
Ejemplo n.º 4
0
def run_miner():
    global blockchain
    """
    Any models in the network can become a miner and start mining blocks.
    :return:
    """
    miner = Miner(blockchain, wallet.get_address())
    new_block = miner.run_mining()
    blockchain.add_block(new_block)

    for key, value in neighbors.items():
        recipient = 'http://{}:{}/blockchain/post'.format(value[0], value[1])
        # send the new chain to all the miners
        requests.post(recipient, data=json.dumps(blockchain.to_json()))

    return 'The block was created', 200
Ejemplo n.º 5
0
 def __init__(self, ip, login='******', password='******'):
     Miner.__init__(self, ip, login, password)
     self.__stats = {}
     self.existence = False
     self.__get_stats()
     if self.existence:
         self.__total_chips = 0
         self.__o_chips = 0
         self.__x_chips = 0
         self.__i_chips = 0
         self.__last_scanned = None
         self.get_type()
         self.__get_pools()
         self.get_temps()
         self.get_fans()
         self.get_rates()
         self.get_chips()
    def test__model__miner__create(self):
        actual_result = Miner.create("my-miner", "some-wallet")

        self.assertIsInstance(actual_result, Miner)
        self.assertEqual("my-miner", actual_result.uuid)
        self.assertEqual("some-wallet", actual_result.wallet)
        self.assertEqual(None, actual_result.started)
        self.assertEqual(0, actual_result.power)
Ejemplo n.º 7
0
def update_miner(miner: Miner):
    mined_coins: int = miner.update_miner()
    if mined_coins > 0:
        m.contact_microservice(
            "currency", ["put"], {
                "destination_uuid": miner.wallet,
                "amount": mined_coins,
                "create_transaction": False
            })
    def test__model__miner__serialize(self):
        miner = Miner(uuid="my-miner",
                      wallet="some-wallet",
                      started=1337,
                      power=0.83)

        expected_result = {
            "uuid": "my-miner",
            "wallet": "some-wallet",
            "started": 1337,
            "power": 0.83
        }
        serialized = miner.serialize

        self.assertEqual(expected_result, serialized)

        serialized["uuid"] = "something-different"
        self.assertEqual(expected_result, miner.serialize)