Skip to content

Commit

Permalink
Add get_transaction_count to payments service and its usage in Databa…
Browse files Browse the repository at this point in the history
…seTransactionStorage
  • Loading branch information
Radoslaw Wrzesien committed Jul 10, 2018
1 parent 6292c4b commit b23e536
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions concent_api/core/payments/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ def is_account_status_positive(
client_eth_address = client_eth_address,
pending_value = pending_value,
)


@_add_backend
def get_transaction_count(backend: str) -> int:
return backend.get_transaction_count()
4 changes: 4 additions & 0 deletions concent_api/core/payments/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ def make_force_payment_to_provider(requestor_eth_address = None, provider_eth_ad

def is_account_status_positive(client_eth_address = None, pending_value = None): # pylint: disable=unused-argument
return pending_value > 0


def get_transaction_count() -> int:
return 0
4 changes: 4 additions & 0 deletions concent_api/core/payments/sci_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def is_account_status_positive(
return client_acc_balance > pending_value


def get_transaction_count() -> int:
return ConcentRPC().get_transaction_count()


class TransactionType(Enum):
BATCH = 'batch'
FORCE = 'force'
5 changes: 2 additions & 3 deletions concent_api/core/payments/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from django.db import transaction

from common.singleton import ConcentRPC
import core.payments.base
from core.models import GlobalTransactionState
from core.models import PendingEthereumTransaction

Expand All @@ -27,10 +27,9 @@ def __init__(self, *args: List, **kwargs: Dict) -> None:
super().__init__(*args, **kwargs)

if not GlobalTransactionState.objects.filter(pk=0).exists():
concent_rpc = ConcentRPC()
global_transaction_state = GlobalTransactionState(
pk=0,
nonce=concent_rpc.get_transaction_count(), # TODO: Get it via backend
nonce=core.payments.base.get_transaction_count(),
)
global_transaction_state.full_clean()
global_transaction_state.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
from core.payments.storage import DatabaseTransactionsStorage


class ConcentRPCMock:
def get_transaction_count(self):
return 5


class DatabaseTransactionsStorageTest(TestCase):

multi_db = True

def setUp(self):
super().setUp()

with mock.patch('core.payments.storage.ConcentRPC', side_effect=ConcentRPCMock):
with mock.patch('core.payments.storage.core.payments.base.get_transaction_count', return_value=5):
self.storage = DatabaseTransactionsStorage()

self.global_transaction_state = GlobalTransactionState.objects.get(pk=0)
Expand Down

0 comments on commit b23e536

Please sign in to comment.