Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl for release allocations feature tests #580

Merged
merged 3 commits into from
Apr 11, 2022
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
6 changes: 6 additions & 0 deletions goth/runner/cli/yagna_payment_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ def payment_drivers(
args = make_args("payment", "drivers")
output = self.run_json_command(Dict, *args)
return {key: Driver.from_dict(val) for key, val in output.items()}

def payment_release_allocations(self: CommandRunner) -> None:
"""Run `<cmd> payment release-allocations` without any extra args."""

args = make_args("payment", "release-allocations")
self.run_command(*args)
42 changes: 40 additions & 2 deletions goth/runner/probe/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,50 @@ async def pay_invoices(
timestamp=datetime.now(timezone.utc),
payment_platform=self.payment_config.platform_string,
)
allocation_result = await self.api.payment.create_allocation(allocation)
logger.debug("Created allocation. id=%s", allocation_result)

allocation_result = await self._create_allocation(allocation)

acceptance = Acceptance(
total_amount_accepted=invoice_event.amount,
allocation_id=allocation_result.allocation_id,
)
await self.api.payment.accept_invoice(invoice_event.invoice_id, acceptance)
logger.debug("Accepted invoice. id=%s", invoice_event.invoice_id)

@step()
async def create_allocation(
self: ProbeProtocol, timeout: Optional[datetime] = None
) -> Allocation:
"""Call create_allocation on the market api."""

allocation = Allocation(
allocation_id="",
total_amount=0,
spent_amount=0,
remaining_amount=0,
make_deposit=True,
timestamp=datetime.now(timezone.utc),
timeout=timeout,
payment_platform=self.payment_config.platform_string,
)

allocation_result = await self._create_allocation(allocation)

return allocation_result

@step()
async def get_allocation(self: ProbeProtocol, allocation_id: str) -> Allocation:
"""Call get_allocation on the market api."""

allocation_result = await self.api.payment.get_allocation(allocation_id)

return allocation_result

async def _create_allocation(
self: ProbeProtocol, allocation: Allocation
) -> Allocation:

allocation_result = await self.api.payment.create_allocation(allocation)
logger.debug("Created allocation. id=%s", allocation_result.allocation_id)

return allocation_result