Skip to content

Commit e1d6b5c

Browse files
basfromanopendansoribraheem-abe
authored
Fix tests to be ready for rust-based bittensor-wallet (#2336)
* replace `from substrateinterface import Keypair` to `from bittensor_wallet import Keypair` * apply raise to the test * use Keypair from bittensor_wallet for whole repo * change test name * ruff linting * set wallet to v 1.0.0 * Bittensor wallet -> 2.0.0 * test Axon online debug * test Axon online debug 2 * test Axon online debug 3 * test Axon online debug 4 * test Axon online debug 5 * test Axon online debug 6 * fixed tests, ruff --------- Co-authored-by: opendansor <[email protected]> Co-authored-by: ibraheem-opentensor <[email protected]> Co-authored-by: ibraheem-opentensor <[email protected]>
1 parent fe3a72e commit e1d6b5c

File tree

11 files changed

+36
-24
lines changed

11 files changed

+36
-24
lines changed

bittensor/core/axon.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
from typing import Any, Awaitable, Callable, Optional, Tuple
3333

3434
import uvicorn
35-
from bittensor_wallet import Wallet
35+
from bittensor_wallet import Wallet, Keypair
36+
3637
from fastapi import APIRouter, Depends, FastAPI
3738
from fastapi.responses import JSONResponse
3839
from fastapi.routing import serialize_response
3940
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
4041
from starlette.requests import Request
4142
from starlette.responses import Response
42-
from substrateinterface import Keypair
43+
4344

4445
from bittensor.core.chain_data import AxonInfo
4546
from bittensor.core.config import Config

bittensor/core/dendrite.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from typing import Any, AsyncGenerator, Optional, Union, Type
2424

2525
import aiohttp
26-
from bittensor_wallet import Wallet
27-
from substrateinterface import Keypair
26+
from bittensor_wallet import Keypair, Wallet
2827

2928
from bittensor.core.axon import Axon
3029
from bittensor.core.chain_data import AxonInfo

bittensor/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# DEALINGS IN THE SOFTWARE.
1717

1818
import hashlib
19-
from typing import List, Dict, Literal, Union, Optional, TYPE_CHECKING
19+
from typing import Literal, Union, Optional, TYPE_CHECKING
2020

2121
import scalecodec
22-
from substrateinterface import Keypair
22+
from bittensor_wallet import Keypair
2323
from substrateinterface.utils import ss58
2424

2525
from bittensor.core.settings import SS58_FORMAT
@@ -245,7 +245,7 @@ def _is_valid_ed25519_pubkey(public_key: Union[str, bytes]) -> bool:
245245
else:
246246
raise ValueError("public_key must be a string or bytes")
247247

248-
keypair = Keypair(public_key=public_key, ss58_format=SS58_FORMAT)
248+
keypair = Keypair(public_key=public_key)
249249

250250
ss58_addr = keypair.ss58_address
251251
return ss58_addr is not None

bittensor/utils/deprecated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
Keyfile,
4343
)
4444
from bittensor_wallet.wallet import display_mnemonic_msg, Wallet # noqa: F401
45-
from substrateinterface import Keypair # noqa: F401
45+
from bittensor_wallet import Keypair # noqa: F401
4646

4747
from bittensor.core import settings
4848
from bittensor.core.axon import Axon

bittensor/utils/weight_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from numpy.typing import NDArray
2828
from scalecodec import U16, ScaleBytes, Vec
29-
from substrateinterface import Keypair
29+
from bittensor_wallet import Keypair
3030

3131
from bittensor.utils.btlogging import logging
3232
from bittensor.utils.registration import legacy_torch_api_compat, torch, use_torch

requirements/prod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ python-Levenshtein
2020
scalecodec==1.2.11
2121
substrate-interface~=1.7.9
2222
uvicorn
23-
bittensor-wallet==1.0.0
23+
bittensor-wallet==2.0.0

tests/e2e_tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def local_chain(request):
4545

4646
# install neuron templates
4747
logging.info("downloading and installing neuron templates from github")
48-
templates_dir = clone_or_update_templates()
48+
# commit with subnet-template-repo changes for rust wallet
49+
templates_dir = clone_or_update_templates(
50+
"334d3da101279218b3a4c9d72a12d517f6e39be3"
51+
)
4952
install_templates(templates_dir)
5053

5154
timestamp = int(time.time())

tests/e2e_tests/utils/e2e_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import sys
55

6-
from substrateinterface import Keypair
6+
from bittensor_wallet import Keypair
77

88
import bittensor
99

tests/integration_tests/test_subtensor_integration.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import unittest
1919
from unittest.mock import MagicMock, patch
2020

21-
from substrateinterface import Keypair
21+
import pytest
22+
from bittensor_wallet import Keypair
2223

2324
import bittensor
2425
from bittensor.core import settings
26+
from bittensor.core.extrinsics import transfer
2527
from bittensor.utils.balance import Balance
2628
from bittensor.utils.mock import MockSubtensor
2729
from tests.helpers import (
@@ -30,7 +32,6 @@
3032
get_mock_keypair,
3133
get_mock_wallet,
3234
)
33-
from bittensor.core.extrinsics import transfer
3435

3536

3637
class TestSubtensor(unittest.TestCase):
@@ -171,7 +172,7 @@ def test_transfer_invalid_dest(self):
171172
)
172173
self.assertFalse(fail, msg="Transfer should fail because of invalid dest")
173174

174-
def test_transfer_dest_as_bytes(self):
175+
def test_transfer_dest_as_bytes_fails(self):
175176
fake_coldkey = get_mock_coldkey(1)
176177
with patch(
177178
"bittensor.core.extrinsics.transfer.do_transfer",
@@ -183,13 +184,14 @@ def test_transfer_dest_as_bytes(self):
183184
self.subtensor.get_balance = MagicMock(return_value=self.balance)
184185

185186
dest_as_bytes: bytes = Keypair(fake_coldkey).public_key
186-
success = self.subtensor.transfer(
187-
self.wallet,
188-
dest_as_bytes, # invalid dest
189-
amount=200,
190-
wait_for_inclusion=True,
191-
)
192-
self.assertTrue(success, msg="Transfer should succeed")
187+
188+
with pytest.raises(TypeError):
189+
self.subtensor.transfer(
190+
self.wallet,
191+
dest_as_bytes, # invalid dest
192+
amount=200,
193+
wait_for_inclusion=True,
194+
)
193195

194196
def test_set_weights(self):
195197
chain_weights = [0]

tests/unit_tests/test_axon.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,16 @@ def test_to_string(info_return, expected_output, test_id):
380380
)
381381
def test_valid_ipv4_and_ipv6_address(ip, port, expected_ip_type, test_id):
382382
# Arrange
383+
hotkey = MockHotkey("5EemgxS7cmYbD34esCFoBgUZZC8JdnGtQvV5Qw3QFUCRRtGP")
384+
coldkey = MockHotkey("5EemgxS7cmYbD34esCFoBgUZZC8JdnGtQvV5Qw3QFUCRRtGP")
385+
coldkeypub = MockHotkey("5EemgxS7cmYbD34esCFoBgUZZC8JdnGtQvV5Qw3QFUCRRtGP")
386+
wallet = MockWallet(hotkey, coldkey, coldkeypub)
387+
383388
axon = Axon()
384389
axon.ip = ip
385390
axon.external_ip = ip
386391
axon.port = port
392+
axon.wallet = wallet
387393

388394
# Act
389395
ip_type = axon.info().ip_type
@@ -586,7 +592,7 @@ async def test_ping__no_dendrite(self, http_client):
586592
assert (response.status_code, response.json()) == (
587593
401,
588594
{
589-
"message": "Not Verified with error: No SS58 formatted address or public key provided"
595+
"message": "Not Verified with error: No SS58 formatted address or public key provided."
590596
},
591597
)
592598

0 commit comments

Comments
 (0)