generated from opentensor/bittensor-subnet-template
-
Notifications
You must be signed in to change notification settings - Fork 35
refactor and fix skip gold #196
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e08b2d
refactor and fix skip gold
Thykof 76a9962
handle negative delay
Thykof 860c96e
skip a failing test
Thykof 119cc34
select_delay: round_time_to_minutes
Thykof bde0742
clear high_frequency_launch
Thykof c6ee9b5
refactor and add tests
Thykof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import unittest | ||
| from unittest.mock import patch | ||
| from datetime import datetime, timezone | ||
|
|
||
|
|
||
| from neurons.validator import Validator | ||
| from synth.validator.prompt_config import HIGH_FREQUENCY, LOW_FREQUENCY | ||
|
|
||
|
|
||
| class TestValidator(unittest.TestCase): | ||
| def test_select_delay_immediate(self): | ||
| cycle_start_time = datetime(2025, 12, 3, 12, 0, 0) | ||
|
|
||
| # Test high frequency | ||
| delay = Validator.select_delay( | ||
| Validator.asset_list, cycle_start_time, HIGH_FREQUENCY, True | ||
| ) | ||
| self.assertEqual(delay, 0) | ||
|
|
||
| # Test low frequency | ||
| delay = Validator.select_delay( | ||
| Validator.asset_list, cycle_start_time, LOW_FREQUENCY, True | ||
| ) | ||
| self.assertEqual(delay, 60) | ||
|
|
||
| def test_select_delay(self): | ||
| cycle_start_time = datetime( | ||
| 2025, 12, 3, 12, 34, 56, 998, tzinfo=timezone.utc | ||
| ) | ||
|
|
||
| # Test high frequency | ||
| with patch( | ||
| "neurons.validator.get_current_time" | ||
| ) as mock_get_current_time: | ||
| mock_get_current_time.return_value = datetime( | ||
| 2025, 12, 3, 12, 36, 30, tzinfo=timezone.utc | ||
| ) | ||
| delay = Validator.select_delay( | ||
| Validator.asset_list, cycle_start_time, HIGH_FREQUENCY, False | ||
| ) | ||
| self.assertEqual(delay, 90) | ||
|
|
||
| def test_select_asset(self): | ||
| latest_asset = "ETH" | ||
| asset_list = ["BTC", "ETH", "LTC"] | ||
|
|
||
| with patch( | ||
| "neurons.validator.get_current_time" | ||
| ) as mock_get_current_time: | ||
| mock_get_current_time.return_value = datetime( | ||
| 2025, 12, 3, 12, 36, 30, tzinfo=timezone.utc | ||
| ) | ||
| selected_asset = Validator.select_asset( | ||
| latest_asset, asset_list, 0 | ||
| ) | ||
| self.assertEqual(selected_asset, "LTC") | ||
|
|
||
| def test_select_asset_gold(self): | ||
| latest_asset = "ETH" | ||
| asset_list = ["BTC", "ETH", "XAU", "LTC"] | ||
|
|
||
| with patch( | ||
| "neurons.validator.get_current_time" | ||
| ) as mock_get_current_time: | ||
| mock_get_current_time.return_value = datetime( | ||
| 2025, 12, 3, 12, 36, 30, tzinfo=timezone.utc | ||
| ) | ||
| with patch( | ||
| "neurons.validator.should_skip_xau" | ||
| ) as mock_should_skip_xau: | ||
| mock_should_skip_xau.return_value = True | ||
| selected_asset = Validator.select_asset( | ||
| latest_asset, asset_list, 0 | ||
| ) | ||
| self.assertEqual(selected_asset, "LTC") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.