From 621b6c7a84ead88f127310de5541c0270e507934 Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Thu, 22 Apr 2021 16:08:47 +0200
Subject: [PATCH] Fix number formatting
---
nucypher/cli/literature.py | 4 ++--
nucypher/cli/painting/staking.py | 6 ++----
.../cli/test_stake_cli_functionality.py | 14 +++++++++-----
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/nucypher/cli/literature.py b/nucypher/cli/literature.py
index c03c062c1..bd5cdcb91 100644
--- a/nucypher/cli/literature.py
+++ b/nucypher/cli/literature.py
@@ -311,11 +311,11 @@ NO_TOKENS_TO_WITHDRAW = "No tokens can be withdrawn."
NO_FEE_TO_WITHDRAW = "No policy fee can be withdrawn."
-TOKEN_REWARD_CURRENT = 'Available staking rewards: {reward_amount:.18g} NU.'
+TOKEN_REWARD_CURRENT = 'Available staking rewards: {reward_amount} NU.'
TOKEN_REWARD_PAST_HEADER = 'Staking rewards in the last {periods} periods ({days} days):'
-TOKEN_REWARD_PAST = 'Total staking rewards: {reward_amount:.18g} NU.'
+TOKEN_REWARD_PAST = 'Total staking rewards: {reward_amount} NU.'
TOKEN_REWARD_NOT_FOUND = "No staking rewards found."
diff --git a/nucypher/cli/painting/staking.py b/nucypher/cli/painting/staking.py
index 3e2d70066..8f938ee23 100644
--- a/nucypher/cli/painting/staking.py
+++ b/nucypher/cli/painting/staking.py
@@ -317,8 +317,6 @@ def paint_staking_rewards(stakeholder, blockchain, emitter, past_periods, stakin
periods_as_days = math.floor(economics.days_per_period * past_periods)
emitter.echo(message=TOKEN_REWARD_PAST_HEADER.format(periods=past_periods, days=periods_as_days))
- emitter.echo(tabulate.tabulate(rows,
- headers=REWARDS_TABLE_COLUMNS,
- tablefmt="fancy_grid",
- floatfmt=".18g"))
+ emitter.echo(tabulate.tabulate(rows, headers=REWARDS_TABLE_COLUMNS, tablefmt="fancy_grid"))
+ rewards_total = NU(rewards_total, 'NU').to_tokens()
emitter.echo(message=TOKEN_REWARD_PAST.format(reward_amount=rewards_total))
diff --git a/tests/integration/cli/test_stake_cli_functionality.py b/tests/integration/cli/test_stake_cli_functionality.py
index e666285df..9a7d04dd4 100644
--- a/tests/integration/cli/test_stake_cli_functionality.py
+++ b/tests/integration/cli/test_stake_cli_functionality.py
@@ -1415,7 +1415,7 @@ def test_stake_list_all(click_runner, surrogate_stakers, surrogate_stakes, token
@pytest.mark.usefixtures("test_registry_source_manager", "patch_stakeholder_configuration")
-def test_show_rewards(click_runner, surrogate_stakers, mock_staking_agent, mocker):
+def test_show_rewards(click_runner, surrogate_stakers, mock_staking_agent):
reward_amount = 1
reward = NU(reward_amount, 'NU')
mock_staking_agent.calculate_staking_reward.return_value = reward.to_nunits()
@@ -1436,7 +1436,7 @@ def test_show_rewards(click_runner, surrogate_stakers, mock_staking_agent, mocke
@pytest.mark.usefixtures("test_registry_source_manager", "patch_stakeholder_configuration")
def test_show_rewards_for_period(click_runner, surrogate_stakers, mock_staking_agent, token_economics, mocker):
periods = 30
- periods_per_day = token_economics.hours_per_period / 24
+ periods_per_day = token_economics.hours_per_period // 24
seconds_per_period = token_economics.seconds_per_period
latest_block = 100_000_000
latest_period = 15_000
@@ -1445,7 +1445,7 @@ def test_show_rewards_for_period(click_runner, surrogate_stakers, mock_staking_a
nr_of_events = 3
events = [{
'args': {
- 'value': NU(Decimal(reward_amount), 'NU').to_nunits(),
+ 'value': NU(reward_amount + i/100*i, 'NU').to_nunits(),
'period': latest_period - i,
},
'block_number': estimate_block_number_for_period(latest_period - i,
@@ -1469,16 +1469,20 @@ def test_show_rewards_for_period(click_runner, surrogate_stakers, mock_staking_a
'--network', TEMPORARY_DOMAIN,
'--staking-address', surrogate_stakers[0],
'--periods', periods)
-
result = click_runner.invoke(stake, collection_args, catch_exceptions=False)
+
assert result.exit_code == 0
periods_as_days = math.floor(periods_per_day*periods)
+
assert TOKEN_REWARD_PAST_HEADER.format(periods=periods, days=periods_as_days) in result.output
for header in REWARDS_TABLE_COLUMNS:
assert header in result.output
for event in events:
assert str(event['block_number']) in result.output
- assert TOKEN_REWARD_PAST.format(reward_amount=reward_amount * nr_of_events)
+
+ rewards_total = sum([e['args']['value'] for e in events])
+ rewards_total = NU(rewards_total, 'NU').to_tokens()
+ assert TOKEN_REWARD_PAST.format(reward_amount=rewards_total)
mock_staking_agent.get_current_period.assert_called()
mock_staking_agent.contract.events[event_name].getLogs.assert_called()