Skip to content
Open
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
4 changes: 3 additions & 1 deletion gittensor/cli/issue_commands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def admin_payout(
with err_console.status('[bold cyan]Submitting payout...', spinner='dots'):
result = client.payout_bounty(issue_id, wallet)

if result:
# payout_bounty returns a non-None amount on success (0 is valid when the
# pre-read bounty is unavailable) and None only on failure.
if result is not None:
print_success(f'Payout successful! Amount: {format_alpha(result, 4)} ALPHA')
else:
print_error('Payout failed.')
Expand Down
55 changes: 54 additions & 1 deletion tests/cli/test_cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import json
from decimal import Decimal
from types import SimpleNamespace
from typing import Any, Dict, Optional
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import click
import pytest
Expand Down Expand Up @@ -743,6 +744,58 @@ def test_admin_payout_rejects_issue_id_zero(self, cli_root, runner):
assert 'between' in result.output or '1' in result.output


class TestCliAdminPayoutResultHandling:
"""Ensure admin payout-issue interprets the payout return value correctly.

``payout_bounty`` returns a non-None amount on success (0 is a valid amount
when the pre-read bounty is unavailable) and None only on failure, so the
success check must be ``is not None`` rather than truthiness.
"""

def _invoke_payout(self, cli_root, runner, payout_return):
issue = SimpleNamespace(
id=1,
repository_full_name='entrius/gittensor',
issue_number=223,
bounty_amount=0,
target_bounty=2000,
status=SimpleNamespace(name='COMPLETED'),
)
client = MagicMock()
client.get_issue.return_value = issue
client.payout_bounty.return_value = payout_return
with (
patch(
'gittensor.cli.issue_commands.admin._resolve_contract_and_network',
return_value=(
'0x1234567890123456789012345678901234567890',
'wss://entrypoint-finney.opentensor.ai:443',
'finney',
),
),
patch(
'gittensor.cli.issue_commands.admin._make_contract_client',
return_value=(MagicMock(), client),
),
):
return runner.invoke(
cli_root,
['admin', 'payout-issue', '1', '--yes'],
catch_exceptions=False,
)

def test_zero_payout_reported_as_success(self, cli_root, runner):
result = self._invoke_payout(cli_root, runner, 0)
assert result.exit_code == 0
assert 'Payout successful' in result.output
assert 'Payout failed' not in result.output

def test_none_payout_reported_as_failure(self, cli_root, runner):
result = self._invoke_payout(cli_root, runner, None)
assert result.exit_code != 0
assert 'Payout failed' in result.output


class TestCliVoteCancelValidation:
"""Ensure vote cancel rejects invalid issue_id."""

Expand Down