Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Add tests for subtask_accepted & get_incomes_list #4357

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions golem/rpc/api/ethereum_.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def get_incomes_list(self) -> typing.List[typing.Dict[str, typing.Any]]:
def item(o):
return {
"subtask": common.to_unicode(o.subtask),
"payer": common.to_unicode(o.sender_node),
"value": common.to_unicode(o.value),
"status": common.to_unicode(o.status.name),
"transaction": common.to_unicode(o.transaction),
"payer": common.to_unicode(o.node),
"value": common.to_unicode(o.wallet_operation.amount),
"status": common.to_unicode(o.wallet_operation.status.name),
"transaction": common.to_unicode(o.wallet_operation.tx_hash),
"created": common.datetime_to_timestamp_utc(o.created_date),
"modified": common.datetime_to_timestamp_utc(o.modified_date),
"node": lru_node(o.sender_node),
"node": lru_node(o.node),
}

return [item(income) for income in incomes]
Expand Down
1 change: 0 additions & 1 deletion golem/task/taskserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def sync_network(self, timeout=None):

for job in jobs:
try:
#logger.debug("TServer sync running: job=%r", job)
job()
except Exception: # pylint: disable=broad-except
logger.exception("TaskServer.sync_network job %r failed", job)
Expand Down
2 changes: 1 addition & 1 deletion golem/task/tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def _react_to_subtask_results_accepted(
)

self.task_server.subtask_accepted(
sender_node=self.key_id,
sender_node_id=self.key_id,
task_id=msg.task_id,
subtask_id=msg.subtask_id,
payer_address=msg.task_to_compute.requestor_ethereum_address,
Expand Down
35 changes: 35 additions & 0 deletions tests/golem/rpc/api/test_ethereum.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import datetime
from unittest import TestCase, mock

from golem_messages.datastructures import p2p as dt_p2p

from golem import model
from golem.ethereum.transactionsystem import TransactionSystem
from golem.rpc.api.ethereum_ import ETSProvider

from tests.factories.model import TaskPayment as TaskPaymentFactory


class TestEthereum(TestCase):
def setUp(self):
self.maxDiff = None
self.ets = mock.Mock(spec_set=TransactionSystem)
self.ets_provider = ETSProvider(self.ets)

Expand Down Expand Up @@ -54,3 +59,33 @@ def test_one(self):
expected,
self.ets_provider.get_deposit_payments_list(),
)

@mock.patch('golem.network.nodeskeeper.get', return_value=None)
def test_get_incomes_list(self, *_):
ts = 1514761200.0
dt = datetime.datetime.fromtimestamp(
ts,
tz=datetime.timezone.utc,
)
instance = TaskPaymentFactory(
created_date=dt,
modified_date=dt,
)
self.ets.get_incomes_list.return_value = [instance]

expected = [
{
'subtask': instance.subtask,
'payer': instance.node,
'value': str(instance.wallet_operation.amount),
'status': 'awaiting',
'transaction': instance.wallet_operation.tx_hash,
'created': ts,
'modified': ts,
'node': dt_p2p.Node(key=instance.node).to_dict(),
},
]
self.assertEqual(
expected,
self.ets_provider.get_incomes_list(),
)
11 changes: 8 additions & 3 deletions tests/golem/task/test_tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from golem.resource.base.resourceserver import BaseResourceServer
from golem.resource.dirmanager import DirManager
from golem.resource.hyperdrive.resourcesmanager import HyperdriveResourceManager
from golem.task import taskserver
from golem.task import taskstate
from golem.task.result.resultpackage import ZipPackager
from golem.task.taskkeeper import CompTaskKeeper
Expand Down Expand Up @@ -277,7 +278,7 @@ def _fake_send_ttc(self):
ctd = msg_factories.tasks.ComputeTaskDefFactory(task_id=wtct.task_id)
ctd["resources"] = self.additional_dir_content([5, [2], [4]])
ctd["deadline"] = timeout_to_deadline(120)
_task_state = self._set_task_state()
self._set_task_state()

ts.task_manager.get_next_subtask.return_value = ctd
ts.task_manager.should_wait_for_node.return_value = False
Expand Down Expand Up @@ -917,7 +918,11 @@ class SubtaskResultsAcceptedTest(TestCase):
def setUp(self):
self.task_session = TaskSession(Mock())
self.task_session.verified = True
self.task_server = Mock()
self.task_server = Mock(spec=taskserver.TaskServer)
self.task_server.keys_auth = Mock()
self.task_server.task_manager = Mock()
self.task_server.client = Mock()
self.task_server.pending_sessions = set()
self.task_session.conn.server = self.task_server
self.requestor_keys = cryptography.ECCx(None)
self.requestor_key_id = encode_hex(self.requestor_keys.raw_pubkey)
Expand Down Expand Up @@ -956,7 +961,7 @@ def test_react_to_subtask_results_accepted(self):

# then
self.task_server.subtask_accepted.assert_called_once_with(
sender_node=self.requestor_key_id,
sender_node_id=self.requestor_key_id,
task_id=sra.task_id,
subtask_id=sra.subtask_id,
payer_address=sra.task_to_compute.requestor_ethereum_address, # noqa pylint:disable=no-member
Expand Down