Skip to content

Commit

Permalink
Fix/network security change detection (#155)
Browse files Browse the repository at this point in the history
* Hotfix add missing requirement

* Fix change detection

* Add another testcase
  • Loading branch information
DollyVolley authored Mar 26, 2021
1 parent 2b73bb5 commit 6b560fc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 0 additions & 2 deletions bot/constants/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
KEYBOARD_PAGE_SIZE = 30

# Emojis

# Be aware that keys of STATUS_EMOJIS are displayed to the user
STATUS_EMOJIS = {
"unknown": "❓",
Expand Down Expand Up @@ -64,4 +63,3 @@
# Thorchain
SLASH_POINTS_NOTIFICATION_THRESHOLD_DEFAULT = 3
THORCHAIN_ONCHAIN_API_URL = "https://thorchain-service.b42.tech/v1/"

2 changes: 1 addition & 1 deletion bot/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def on_start_command(update, context):
if 'job_started' not in context.chat_data:
start_user_job(context, update.message.chat.id)

text = 'Heil ok sæll! I am your THORNode Bot runaning on ' + NETWORK_TYPE + '. 🤖\n\n'
text = f'Heil ok sæll! I am your THORNode Bot running on {NETWORK_TYPE}. 🤖\n\n'
text += 'I will notify you about changes of your THORNode\'s\n' \
'- *Status*\n' \
'- *Bond*\n' \
Expand Down
2 changes: 1 addition & 1 deletion bot/handlers/network_info_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def show_network_stats(update, context):
'{:.2f}'.format((int(network['blockRewards']['stakeReward']) / int(
network['blockRewards']['blockReward']) * 100)) + " %* (staker share)\n"

text += f"\n🔓 Network Security: *{network_security_ratio_to_string(get_network_security_ratio(network))}*\n"
text += f"\n🔓 Network Security: *{network_security_ratio_to_string(get_network_security_ratio(network)).value}*\n"

text += "\n↩️ Node ROI: *" + \
'{:.2f}'.format(float(network['bondingAPY']) * 100) \
Expand Down
2 changes: 1 addition & 1 deletion bot/jobs/thorchain_network_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def check_network_security(context):
return None

if network_health_status != context.bot_data["network_health_status"]:
context.bot_data["network_health_status"] = network_health_status.value
context.bot_data["network_health_status"] = network_health_status

if network_health_status is NetworkHealthStatus.OPTIMAL:
logger.info(f"Network is healthy again: {network_health_status.value}")
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/_trial_temp.lock
16 changes: 14 additions & 2 deletions test/unit_tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,34 @@ def test_solvency_check_success(self, mock_asgard_solvency_check, mock_yggdrasil
def test_check_network_security(self, mock_get_network_security_ratio):
mock_get_network_security_ratio.return_value = 0.66
network_security_message = check_network_security(self.context)
self.assertIs(network_security_message, None, "Can not trigger comparison difference. No previous value")
self.assertIs(network_security_message, None,
"Can not trigger comparison difference. No previous value")

mock_get_network_security_ratio.return_value = 0.66
network_security_message = check_network_security(self.context)
self.assertIs(network_security_message, None, "Network is optimal, but an warning is raised")
self.assertIs(network_security_message, None,
"Network is optimal, but an warning is raised")

mock_get_network_security_ratio.return_value = 0.8
network_security_message = check_network_security(self.context)
self.assertIn(get_network_health_warning(NetworkHealthStatus.OVERBONDED), network_security_message,
"Network state should have changed to OVERBONDED")

mock_get_network_security_ratio.return_value = 0.8
network_security_message = check_network_security(self.context)
self.assertIs(network_security_message, None,
"Network health state did not change but user was notified")

mock_get_network_security_ratio.return_value = 0.7
network_security_message = check_network_security(self.context)
self.assertIn(network_security_message, NETWORK_HEALTHY_AGAIN,
"Network state should have changed back to OPTIMAL again")

mock_get_network_security_ratio.return_value = 0.66
network_security_message = check_network_security(self.context)
self.assertIs(network_security_message, None,
"Network health state did not change but user was notified")

mock_get_network_security_ratio.return_value = 0.91
network_security_message = check_network_security(self.context)
self.assertIn(network_security_message, get_network_health_warning(NetworkHealthStatus.INEFFICIENT),
Expand Down

0 comments on commit 6b560fc

Please sign in to comment.