Skip to content

Commit c8a5aff

Browse files
author
Roman
committed
add different weights generator
1 parent 0024a19 commit c8a5aff

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tests/e2e_tests/test_commit_weights.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,19 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
226226
# wait while weights_rate_limit changes applied.
227227
subtensor.wait_for_block(subnet_tempo + 1)
228228

229-
# Commit-reveal values
230-
uids = np.array([0], dtype=np.int64)
231-
weights = np.array([0.1], dtype=np.float32)
232-
salt = [18, 179, 107, 0, 165, 211, 141, 197]
233-
weight_uids, weight_vals = convert_weights_and_uids_for_emit(
234-
uids=uids, weights=weights
235-
)
236-
237-
# Make a second salt
238-
salt2 = salt.copy()
239-
salt2[0] += 1 # Increment the first byte to produce a different commit hash
240-
241-
# Make a third salt
242-
salt3 = salt.copy()
243-
salt3[0] += 2 # Increment the first byte to produce a different commit hash
229+
# create different commited data to avoid coming into pool black list with the error
230+
# Failed to commit weights: Subtensor returned `Custom type(1012)` error. This means: `Transaction is temporarily
231+
# banned`.Failed to commit weights: Subtensor returned `Custom type(1012)` error. This means: `Transaction is
232+
# temporarily banned`.`
233+
def get_weights_and_salt(counter: int):
234+
# Commit-reveal values
235+
salt_ = [18, 179, 107, counter, 165, 211, 141, 197]
236+
uids_ = np.array([0], dtype=np.int64)
237+
weights_ = np.array([counter / 10], dtype=np.float32)
238+
weight_uids_, weight_vals_ = convert_weights_and_uids_for_emit(
239+
uids=uids_, weights=weights_
240+
)
241+
return salt_, weight_uids_, weight_vals_
244242

245243
logging.console.info(
246244
f"[orange]Nonce before first commit_weights: "
@@ -250,23 +248,24 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
250248
# 3 time doing call if nonce wasn't updated, then raise error
251249
@retry.retry(exceptions=Exception, tries=3, delay=1)
252250
@execute_and_wait_for_next_nonce(subtensor=subtensor, wallet=alice_wallet)
253-
def send_commit(salt_):
251+
def send_commit(salt_, weight_uids_, weight_vals_):
254252
success, message = subtensor.commit_weights(
255253
wallet=alice_wallet,
256254
netuid=netuid,
257255
salt=salt_,
258-
uids=weight_uids,
259-
weights=weight_vals,
256+
uids=weight_uids_,
257+
weights=weight_vals_,
260258
wait_for_inclusion=True,
261259
wait_for_finalization=True,
262260
)
263261
assert success is True, message
264262

265-
send_commit(salt)
266-
267-
send_commit(salt2)
263+
# send some amount of commit weights
264+
AMOUNT_OF_COMMIT_WEIGHTS = 3
265+
for call in range(AMOUNT_OF_COMMIT_WEIGHTS):
266+
weight_uids, weight_vals, salt = get_weights_and_salt(call)
268267

269-
send_commit(salt3)
268+
send_commit(salt, weight_uids, weight_vals)
270269

271270
logging.console.info(
272271
f"[orange]Nonce after third commit_weights: "
@@ -288,4 +287,6 @@ def send_commit(salt_):
288287
assert commit_block > 0, f"Invalid block number: {commit_block}"
289288

290289
# Check for three commits in the WeightCommits storage map
291-
assert len(weight_commits.value) == 3, "Expected 3 weight commits"
290+
assert (
291+
len(weight_commits.value) == AMOUNT_OF_COMMIT_WEIGHTS
292+
), "Expected exact list of weight commits"

0 commit comments

Comments
 (0)