diff --git a/tests/unit_tests/extrinsics/test_registration.py b/tests/unit_tests/extrinsics/test_registration.py index 77c6a0d3aa..c45bfd6214 100644 --- a/tests/unit_tests/extrinsics/test_registration.py +++ b/tests/unit_tests/extrinsics/test_registration.py @@ -80,40 +80,37 @@ def test_register_extrinsic_without_pow( mocker, ): # Arrange - with ( - mocker.patch.object( - mock_subtensor, "subnet_exists", return_value=subnet_exists - ), - mocker.patch.object( - mock_subtensor, - "get_neuron_for_pubkey_and_subnet", - return_value=mocker.MagicMock(is_null=neuron_is_null), - ), - mocker.patch("torch.cuda.is_available", return_value=cuda_available), - mocker.patch( - "bittensor.utils.registration.pow._get_block_with_retry", - return_value=(0, 0, "00ff11ee"), - ), - ): - # Act - result = registration.register_extrinsic( - subtensor=mock_subtensor, - wallet=mock_wallet, - netuid=123, - wait_for_inclusion=True, - wait_for_finalization=True, - max_allowed_attempts=3, - output_in_place=True, - cuda=True, - dev_id=0, - tpb=256, - num_processes=None, - update_interval=None, - log_verbose=False, - ) + mocker.patch.object(mock_subtensor, "subnet_exists", return_value=subnet_exists) + mocker.patch.object( + mock_subtensor, + "get_neuron_for_pubkey_and_subnet", + return_value=mocker.MagicMock(is_null=neuron_is_null), + ) + mocker.patch("torch.cuda.is_available", return_value=cuda_available) + mocker.patch( + "bittensor.utils.registration.pow._get_block_with_retry", + return_value=(0, 0, "00ff11ee"), + ) - # Assert - assert result == expected_result, f"Test failed for test_id: {test_id}" + # Act + result = registration.register_extrinsic( + subtensor=mock_subtensor, + wallet=mock_wallet, + netuid=123, + wait_for_inclusion=True, + wait_for_finalization=True, + max_allowed_attempts=3, + output_in_place=True, + cuda=True, + dev_id=0, + tpb=256, + num_processes=None, + update_interval=None, + log_verbose=False, + ) + + # Assert + assert result == expected_result, f"Test failed for test_id: {test_id}" @pytest.mark.parametrize( @@ -141,48 +138,47 @@ def test_register_extrinsic_with_pow( mocker, ): # Arrange - with ( - mocker.patch( - "bittensor.utils.registration.pow._solve_for_difficulty_fast", - return_value=mock_pow_solution if pow_success else None, - ), - mocker.patch( - "bittensor.utils.registration.pow._solve_for_difficulty_fast_cuda", - return_value=mock_pow_solution if pow_success else None, - ), - mocker.patch( - "bittensor.core.extrinsics.registration._do_pow_register", - return_value=(registration_success, "HotKeyAlreadyRegisteredInSubNet"), - ), - mocker.patch("torch.cuda.is_available", return_value=cuda), - ): - # Act - if pow_success: - mock_pow_solution.is_stale.return_value = pow_stale - - if not pow_success and hotkey_registered: - mock_subtensor.is_hotkey_registered = mocker.MagicMock( - return_value=hotkey_registered - ) - - result = registration.register_extrinsic( - subtensor=mock_subtensor, - wallet=mock_wallet, - netuid=123, - wait_for_inclusion=True, - wait_for_finalization=True, - max_allowed_attempts=3, - output_in_place=True, - cuda=cuda, - dev_id=0, - tpb=256, - num_processes=None, - update_interval=None, - log_verbose=False, + mocker.patch( + "bittensor.utils.registration.pow._solve_for_difficulty_fast", + return_value=mock_pow_solution if pow_success else None, + ) + mocker.patch( + "bittensor.utils.registration.pow._solve_for_difficulty_fast_cuda", + return_value=mock_pow_solution if pow_success else None, + ) + mocker.patch( + "bittensor.core.extrinsics.registration._do_pow_register", + return_value=(registration_success, "HotKeyAlreadyRegisteredInSubNet"), + ) + mocker.patch("torch.cuda.is_available", return_value=cuda) + + # Act + if pow_success: + mock_pow_solution.is_stale.return_value = pow_stale + + if not pow_success and hotkey_registered: + mock_subtensor.is_hotkey_registered = mocker.MagicMock( + return_value=hotkey_registered ) - # Assert - assert result == expected_result, f"Test failed for test_id: {test_id}." + result = registration.register_extrinsic( + subtensor=mock_subtensor, + wallet=mock_wallet, + netuid=123, + wait_for_inclusion=True, + wait_for_finalization=True, + max_allowed_attempts=3, + output_in_place=True, + cuda=cuda, + dev_id=0, + tpb=256, + num_processes=None, + update_interval=None, + log_verbose=False, + ) + + # Assert + assert result == expected_result, f"Test failed for test_id: {test_id}." @pytest.mark.parametrize( @@ -209,29 +205,26 @@ def test_burned_register_extrinsic( mocker, ): # Arrange - with ( - mocker.patch.object( - mock_subtensor, "subnet_exists", return_value=subnet_exists - ), - mocker.patch.object( - mock_subtensor, - "get_neuron_for_pubkey_and_subnet", - return_value=mocker.MagicMock(is_null=neuron_is_null), - ), - mocker.patch( - "bittensor.core.extrinsics.registration._do_burned_register", - return_value=(recycle_success, "Mock error message"), - ), - mocker.patch.object( - mock_subtensor, "is_hotkey_registered", return_value=is_registered - ), - ): - # Act - result = registration.burned_register_extrinsic( - subtensor=mock_subtensor, wallet=mock_wallet, netuid=123 - ) - # Assert - assert result == expected_result, f"Test failed for test_id: {test_id}" + mocker.patch.object(mock_subtensor, "subnet_exists", return_value=subnet_exists) + mocker.patch.object( + mock_subtensor, + "get_neuron_for_pubkey_and_subnet", + return_value=mocker.MagicMock(is_null=neuron_is_null), + ) + mocker.patch( + "bittensor.core.extrinsics.registration._do_burned_register", + return_value=(recycle_success, "Mock error message"), + ) + mocker.patch.object( + mock_subtensor, "is_hotkey_registered", return_value=is_registered + ) + + # Act + result = registration.burned_register_extrinsic( + subtensor=mock_subtensor, wallet=mock_wallet, netuid=123 + ) + # Assert + assert result == expected_result, f"Test failed for test_id: {test_id}" def test_set_subnet_identity_extrinsic_is_success(mock_subtensor, mock_wallet, mocker): diff --git a/tests/unit_tests/test_dendrite.py b/tests/unit_tests/test_dendrite.py index efbf302b48..38b2f8929f 100644 --- a/tests/unit_tests/test_dendrite.py +++ b/tests/unit_tests/test_dendrite.py @@ -305,7 +305,7 @@ async def test_dendrite__call__success_response( ) mock_aio_response.post( f"http://127.0.0.1:666/SynapseDummy", - body=expected_synapse.json(), + body=expected_synapse.model_dump_json(), ) synapse = await setup_dendrite.call(axon_info, synapse=input_synapse) diff --git a/tests/unit_tests/test_metagraph.py b/tests/unit_tests/test_metagraph.py index ca8a00ccf6..cdb735f627 100644 --- a/tests/unit_tests/test_metagraph.py +++ b/tests/unit_tests/test_metagraph.py @@ -129,10 +129,10 @@ def mock_subtensor(mocker): @pytest.fixture def metagraph_instance(mocker): metagraph = Metagraph(netuid=1337, sync=False) - metagraph._assign_neurons = mocker.AsyncMock() - metagraph._set_metagraph_attributes = mocker.AsyncMock() - metagraph._set_weights_and_bonds = mocker.AsyncMock() - metagraph._get_all_stakes_from_chain = mocker.AsyncMock() + metagraph._assign_neurons = mocker.Mock() + metagraph._set_metagraph_attributes = mocker.Mock() + metagraph._set_weights_and_bonds = mocker.Mock() + metagraph._get_all_stakes_from_chain = mocker.Mock() return metagraph diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 17c858c8a5..625a6aec62 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -2258,7 +2258,6 @@ def test_networks_during_connection(mock_substrate, mocker): sub.chain_endpoint = settings.NETWORK_MAP.get(network) -@pytest.mark.asyncio def test_get_stake_for_coldkey_and_hotkey(subtensor, mocker): netuids = [1, 2, 3] stake_info_dict = {