Skip to content

Commit 28050cd

Browse files
committed
[WIP] Tests passing
1 parent 4e2938a commit 28050cd

File tree

12 files changed

+84
-43
lines changed

12 files changed

+84
-43
lines changed

bittensor/core/async_subtensor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ async def sign_and_send_extrinsic(
26852685
sign_with: str = "coldkey",
26862686
use_nonce: bool = False,
26872687
period: Optional[int] = None,
2688-
nonce_key: str = "hotkey"
2688+
nonce_key: str = "hotkey",
26892689
) -> tuple[bool, str]:
26902690
"""
26912691
Helper method to sign and submit an extrinsic call to chain.
@@ -2712,14 +2712,14 @@ async def sign_and_send_extrinsic(
27122712
raise AttributeError(
27132713
f"'nonce_key' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{nonce_key}'"
27142714
)
2715-
next_nonce = await self.substrate.get_account_next_index(getattr(wallet, nonce_key).ss58_address)
2715+
next_nonce = await self.substrate.get_account_next_index(
2716+
getattr(wallet, nonce_key).ss58_address
2717+
)
27162718
extrinsic_data["nonce"] = next_nonce
27172719
if period is not None:
27182720
extrinsic_data["era"] = {"period": period}
27192721

2720-
extrinsic = await self.substrate.create_signed_extrinsic(
2721-
**extrinsic_data
2722-
)
2722+
extrinsic = await self.substrate.create_signed_extrinsic(**extrinsic_data)
27232723
try:
27242724
response = await self.substrate.submit_extrinsic(
27252725
extrinsic,

bittensor/core/extrinsics/asyncex/staking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def add_stake_extrinsic(
118118
wait_for_finalization,
119119
nonce_key="coldkeypub",
120120
sign_with="coldkey",
121-
use_nonce=True
121+
use_nonce=True,
122122
)
123123
if staking_response is True: # If we successfully staked.
124124
# We only wait here if we expect finalization.
@@ -308,7 +308,7 @@ async def add_stake_multiple_extrinsic(
308308
wait_for_finalization,
309309
nonce_key="coldkeypub",
310310
sign_with="coldkey",
311-
use_nonce=True
311+
use_nonce=True,
312312
)
313313

314314
if staking_response is True: # If we successfully staked.

bittensor/core/extrinsics/asyncex/unstaking.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ async def unstake_extrinsic(
9898
},
9999
)
100100
staking_response, err_msg = await subtensor.sign_and_send_extrinsic(
101-
call, wallet, wait_for_inclusion, wait_for_finalization,
102-
nonce_key="coldkeypub", sign_with="coldkey", use_nonce=True
101+
call,
102+
wallet,
103+
wait_for_inclusion,
104+
wait_for_finalization,
105+
nonce_key="coldkeypub",
106+
sign_with="coldkey",
107+
use_nonce=True,
103108
)
104109

105110
if staking_response is True: # If we successfully unstaked.
@@ -270,7 +275,7 @@ async def unstake_multiple_extrinsic(
270275
wait_for_finalization,
271276
nonce_key="coldkeypub",
272277
sign_with="coldkey",
273-
use_nonce=True
278+
use_nonce=True,
274279
)
275280

276281
if staking_response is True: # If we successfully unstaked.

bittensor/core/extrinsics/asyncex/weights.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ async def _do_commit_weights(
5252
},
5353
)
5454
return await subtensor.sign_and_send_extrinsic(
55-
call, wallet, wait_for_inclusion, wait_for_finalization, use_nonce=True,
56-
nonce_key="hotkey", sign_with="hotkey"
55+
call,
56+
wallet,
57+
wait_for_inclusion,
58+
wait_for_finalization,
59+
use_nonce=True,
60+
nonce_key="hotkey",
61+
sign_with="hotkey",
5762
)
5863

5964

@@ -150,8 +155,13 @@ async def _do_reveal_weights(
150155
},
151156
)
152157
return await subtensor.sign_and_send_extrinsic(
153-
call, wallet, wait_for_inclusion, wait_for_finalization,
154-
sign_with="hotkey", nonce_key="hotkey", use_nonce=True,
158+
call,
159+
wallet,
160+
wait_for_inclusion,
161+
wait_for_finalization,
162+
sign_with="hotkey",
163+
nonce_key="hotkey",
164+
use_nonce=True,
155165
)
156166

157167

@@ -257,8 +267,14 @@ async def _do_set_weights(
257267
},
258268
)
259269
return await subtensor.sign_and_send_extrinsic(
260-
call, wallet, wait_for_inclusion, wait_for_finalization, period=period,
261-
use_nonce=True, nonce_key="hotkey", sign_with="hotkey"
270+
call,
271+
wallet,
272+
wait_for_inclusion,
273+
wait_for_finalization,
274+
period=period,
275+
use_nonce=True,
276+
nonce_key="hotkey",
277+
sign_with="hotkey",
262278
)
263279

264280

bittensor/core/extrinsics/commit_weights.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ def _do_commit_weights(
4545
},
4646
)
4747
return subtensor.sign_and_send_extrinsic(
48-
call, wallet, wait_for_inclusion, wait_for_finalization,
49-
use_nonce=True, sign_with="hotkey", nonce_key="hotkey"
48+
call,
49+
wallet,
50+
wait_for_inclusion,
51+
wait_for_finalization,
52+
use_nonce=True,
53+
sign_with="hotkey",
54+
nonce_key="hotkey",
5055
)
5156

5257

@@ -141,8 +146,13 @@ def _do_reveal_weights(
141146
},
142147
)
143148
return subtensor.sign_and_send_extrinsic(
144-
call, wallet, wait_for_inclusion, wait_for_finalization,
145-
use_nonce=True, sign_with="hotkey", nonce_key="hotkey"
149+
call,
150+
wallet,
151+
wait_for_inclusion,
152+
wait_for_finalization,
153+
use_nonce=True,
154+
sign_with="hotkey",
155+
nonce_key="hotkey",
146156
)
147157

148158

bittensor/core/extrinsics/staking.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ def add_stake_extrinsic(
107107
},
108108
)
109109
staking_response, err_msg = subtensor.sign_and_send_extrinsic(
110-
call, wallet, wait_for_inclusion, wait_for_finalization,
111-
use_nonce=True, sign_with="coldkey", nonce_key="coldkeypub"
110+
call,
111+
wallet,
112+
wait_for_inclusion,
113+
wait_for_finalization,
114+
use_nonce=True,
115+
sign_with="coldkey",
116+
nonce_key="coldkeypub",
112117
)
113118
if staking_response is True: # If we successfully staked.
114119
# We only wait here if we expect finalization.
@@ -281,8 +286,13 @@ def add_stake_multiple_extrinsic(
281286
},
282287
)
283288
staking_response, err_msg = subtensor.sign_and_send_extrinsic(
284-
call, wallet, wait_for_inclusion, wait_for_finalization,
285-
use_nonce=True, nonce_key="coldkeypub", sign_with="coldkey"
289+
call,
290+
wallet,
291+
wait_for_inclusion,
292+
wait_for_finalization,
293+
use_nonce=True,
294+
nonce_key="coldkeypub",
295+
sign_with="coldkey",
286296
)
287297

288298
if staking_response is True: # If we successfully staked.

bittensor/core/extrinsics/unstaking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def unstake_extrinsic(
9999
wait_for_finalization,
100100
nonce_key="coldkeypub",
101101
sign_with="coldkey",
102-
use_nonce=True
102+
use_nonce=True,
103103
)
104104

105105
if staking_response is True: # If we successfully unstaked.
@@ -260,7 +260,7 @@ def unstake_multiple_extrinsic(
260260
wait_for_finalization,
261261
nonce_key="coldkeypub",
262262
sign_with="coldkey",
263-
use_nonce=True
263+
use_nonce=True,
264264
)
265265

266266
if staking_response is True: # If we successfully unstaked.

bittensor/core/subtensor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ def sign_and_send_extrinsic(
20312031
sign_with: str = "coldkey",
20322032
use_nonce: bool = False,
20332033
period: Optional[int] = None,
2034-
nonce_key: str = "hotkey"
2034+
nonce_key: str = "hotkey",
20352035
) -> tuple[bool, str]:
20362036
"""
20372037
Helper method to sign and submit an extrinsic call to chain.
@@ -2059,14 +2059,14 @@ def sign_and_send_extrinsic(
20592059
raise AttributeError(
20602060
f"'nonce_key' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{nonce_key}'"
20612061
)
2062-
next_nonce = self.substrate.get_account_next_index(getattr(wallet, nonce_key).ss58_address)
2062+
next_nonce = self.substrate.get_account_next_index(
2063+
getattr(wallet, nonce_key).ss58_address
2064+
)
20632065
extrinsic_data["nonce"] = next_nonce
20642066
if period is not None:
20652067
extrinsic_data["era"] = {"period": period}
20662068

2067-
extrinsic = self.substrate.create_signed_extrinsic(
2068-
**extrinsic_data
2069-
)
2069+
extrinsic = self.substrate.create_signed_extrinsic(**extrinsic_data)
20702070
try:
20712071
response = self.substrate.submit_extrinsic(
20722072
extrinsic,

tests/unit_tests/extrinsics/asyncex/test_weights.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def fake_is_success():
5656

5757
# Asserts
5858
assert result is True
59-
assert message is None
59+
assert message is ""
6060

6161

6262
@pytest.mark.asyncio
@@ -146,7 +146,7 @@ async def test_do_set_weights_no_waiting(subtensor, mocker):
146146

147147
# Asserts
148148
assert result is True
149-
assert message is None
149+
assert message is ""
150150

151151

152152
@pytest.mark.asyncio
@@ -316,7 +316,7 @@ async def fake_is_success():
316316

317317
# Asserts
318318
assert result is True
319-
assert message is None
319+
assert message is ""
320320

321321

322322
@pytest.mark.asyncio
@@ -399,7 +399,7 @@ async def test_do_commit_weights_no_waiting(subtensor, mocker):
399399

400400
# Asserts
401401
assert result is True
402-
assert message is None
402+
assert message is ""
403403

404404

405405
@pytest.mark.asyncio

tests/unit_tests/extrinsics/test_commit_weights.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def test_do_commit_weights(subtensor, mocker):
6363
assert kwargs["keypair"] == fake_wallet.hotkey
6464

6565
subtensor.substrate.submit_extrinsic.assert_called_once_with(
66-
extrinsic=subtensor.substrate.create_signed_extrinsic.return_value,
66+
subtensor.substrate.create_signed_extrinsic.return_value,
6767
wait_for_inclusion=wait_for_inclusion,
68-
wait_for_finalization=1,
68+
wait_for_finalization=wait_for_finalization,
6969
)
7070

7171
mocked_format_error_message.assert_called_once_with(
@@ -95,7 +95,7 @@ def test_do_reveal_weights(subtensor, mocker):
9595

9696
mocked_format_error_message = mocker.Mock()
9797
mocker.patch(
98-
"bittensor.core.extrinsics.utils.format_error_message",
98+
"bittensor.core.subtensor.format_error_message",
9999
mocked_format_error_message,
100100
)
101101

@@ -132,7 +132,7 @@ def test_do_reveal_weights(subtensor, mocker):
132132
)
133133

134134
subtensor.substrate.submit_extrinsic.assert_called_once_with(
135-
extrinsic=subtensor.substrate.create_signed_extrinsic.return_value,
135+
subtensor.substrate.create_signed_extrinsic.return_value,
136136
wait_for_inclusion=wait_for_inclusion,
137137
wait_for_finalization=wait_for_finalization,
138138
)

0 commit comments

Comments
 (0)