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

Commit

Permalink
[review] Grant @Krigpl 's wish
Browse files Browse the repository at this point in the history
  • Loading branch information
jiivan committed May 31, 2019
1 parent 3a832ad commit c47a5d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 5 additions & 9 deletions golem/ethereum/paymentprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections import defaultdict
from typing import (
List,
TYPE_CHECKING,
)

from ethereum.utils import denoms
Expand All @@ -18,10 +17,6 @@
from golem.core.variables import PAYMENT_DEADLINE
PAYMENT_DEADLINE_TD = datetime.timedelta(seconds=PAYMENT_DEADLINE)

if TYPE_CHECKING:
# pylint: disable=unused-import
from golem_messages.datastructures import tasks as dt_tasks

log = logging.getLogger(__name__)

# We reserve 30 minutes for the payment to go through
Expand Down Expand Up @@ -154,9 +149,10 @@ def _payment_confirmed(payment: model.TaskPayment, timestamp: int) -> None:
delay=delay,
)

def add(
def add( # pylint: disable=too-many-arguments
self,
task_header: 'dt_tasks.TaskHeader',
node_id: str,
task_id: str,
subtask_id: str,
eth_addr: str,
value: int,
Expand All @@ -176,8 +172,8 @@ def add(
currency=model.WalletOperation.CURRENCY.GNT,
amount=value,
),
node=task_header.task_owner.key,
task=task_header.task_id,
node=node_id,
task=task_id,
subtask=subtask_id,
expected_amount=value,
)
Expand Down
3 changes: 2 additions & 1 deletion golem/ethereum/transactionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def add_payment_info(
if not self._payment_processor:
raise Exception('Start was not called')
return self._payment_processor.add(
task_header=task_header,
node_id=task_header.task_owner.key,
task_id=task_header.task_id,
subtask_id=subtask_id,
eth_addr=eth_address,
value=value,
Expand Down
12 changes: 9 additions & 3 deletions tests/golem/ethereum/test_paymentprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ def test_monitor_progress(self):
assert self.pp.recipients_count == 0

gnt_value = 10**17
header = dt_tasks_factory.TaskHeaderFactory()
self.pp.add(
subtask_id="test_subtask_id",
eth_addr=urandom(20),
value=gnt_value,
task_header=dt_tasks_factory.TaskHeaderFactory(),
node_id=header.task_owner.key, # pylint: disable=no-member
task_id=header.task_id,
)
assert self.pp.reserved_gntb == gnt_value
assert self.pp.recipients_count == 1
Expand Down Expand Up @@ -203,11 +205,13 @@ def test_failed_transaction(self):
self.sci.get_gntb_balance.return_value = balance_gntb

gnt_value = 10**17
header = dt_tasks_factory.TaskHeaderFactory()
self.pp.add(
subtask_id="test_subtask_id",
eth_addr=encode_hex(urandom(20)),
value=gnt_value,
task_header=dt_tasks_factory.TaskHeaderFactory(),
node_id=header.task_owner.key, # pylint: disable=no-member
task_id=header.task_id,
)

self.pp.CLOSURE_TIME_DELAY = 0
Expand Down Expand Up @@ -239,11 +243,13 @@ def _add_payment(pp, value=None, ts=None):
ts = int(time.time())
freezed = timestamp_to_datetime(ts)
with freeze_time(freezed):
header = dt_tasks_factory.TaskHeaderFactory()
payment = pp.add(
subtask_id=uuid.uuid4(),
eth_addr=payee,
value=value,
task_header=dt_tasks_factory.TaskHeaderFactory(),
node_id=header.task_owner.key, # pylint: disable=no-member
task_id=header.task_id,
)
assert payment.created_date == freezed
return golem_sci.Payment(payee, value)
Expand Down

0 comments on commit c47a5d3

Please # to comment.