diff --git a/openvalidators/neuron.py b/openvalidators/neuron.py index 227d2c8..5711144 100644 --- a/openvalidators/neuron.py +++ b/openvalidators/neuron.py @@ -84,7 +84,11 @@ def __init__(self): self.wallet = bt.wallet(config=self.config) self.wallet.create_if_non_existent() if not self.config.wallet._mock: - self.wallet.reregister(subtensor=self.subtensor, netuid=self.config.netuid) + bt.utils.reregister( + wallet = self.wallet, + subtensor=self.subtensor, + netuid=self.config.netuid + ) bt.logging.debug(str(self.wallet)) # Init metagraph. diff --git a/requirements.txt b/requirements.txt index 18de33a..3afcb0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -bittensor==5.2.0 +bittensor==5.3.0 transformers<=4.28.0 wandb==0.15.3 datasets==2.12.0 @@ -10,3 +10,4 @@ click==8.1.3 torchmetrics sentencepiece numpy==1.21.6 +bittensor_wallet==0.0.2 diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py new file mode 100644 index 0000000..3ceb08d --- /dev/null +++ b/tests/helpers/__init__.py @@ -0,0 +1,25 @@ +# The MIT License (MIT) +# Copyright © 2023 Opentensor Technologies + +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the “Software”), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of +# the Software. + +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +from bittensor_wallet.mock import MockWallet as _MockWallet, utils as _mock_wallet_utils + +def __mock_wallet_factory__(*args, **kwargs) -> _MockWallet: + """Returns a mock wallet object.""" + + mock_wallet = _mock_wallet_utils.get_mock_wallet() + + return mock_wallet \ No newline at end of file diff --git a/tests/test_weights.py b/tests/test_weights.py index 933e6a0..6fb5c6b 100644 --- a/tests/test_weights.py +++ b/tests/test_weights.py @@ -20,13 +20,30 @@ import sys from openvalidators.neuron import neuron as Neuron from openvalidators.forward import run_step -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch + +from .helpers import __mock_wallet_factory__ CLI_ARGS_STR = "validators/openvalidators/neuron.py --mock --wallet._mock --wandb.off --neuron.followup_sample_size 10 --neuron.answer_sample_size 10" SYS_ARGV = sys.argv.copy() +patcher = None + +def setUpModule(): + """Runs once for the tests in this module.""" + global patcher + patcher = patch("bittensor.wallet.__new__", __mock_wallet_factory__ ) + patcher.start() + +def tearDownModule(): + """Runs once for the tests in this module.""" + global patcher + if patcher: + patcher.stop() + + def test_uid_weights_unchanged_unless_queried(n_steps=10, n_concurrent=1): """Test that the weights of unqueried uids do not over the course of a forward pass."""