Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E2E test for Commit/Reveal with Salt flag #1952

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions bittensor/commands/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

import numpy as np
from rich.prompt import Prompt, Confirm
import bittensor.utils.weight_utils as weight_utils

import bittensor
import bittensor.utils.weight_utils as weight_utils
from . import defaults # type: ignore


Expand Down Expand Up @@ -90,15 +91,21 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
uids=uids, weights=weights
)

# Generate random salt
salt_length = 8
salt = list(os.urandom(salt_length))

if not Confirm.ask(
f"Have you recorded the [red]salt[/red]: [bold white]'{salt}'[/bold white]? It will be "
f"required to reveal weights."
):
return False, "User cancelled the operation."
if not cli.config.is_set("salt"):
# Generate random salt
salt_length = 8
salt = list(os.urandom(salt_length))

if not Confirm.ask(
f"Have you recorded the [red]salt[/red]: [bold white]'{salt}'[/bold white]? It will be "
f"required to reveal weights."
):
return False, "User cancelled the operation."
else:
salt = np.array(
[int(x) for x in re.split(r"[ ,]+", cli.config.salt)],
dtype=np.int64,
).tolist()

# Run the commit weights operation
success, message = subtensor.commit_weights(
Expand Down
17 changes: 12 additions & 5 deletions tests/e2e_tests/subcommands/weights/test_commit_weights.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import re
import time

import numpy as np

import bittensor
import bittensor.utils.weight_utils as weight_utils
from bittensor.commands import (
RegisterCommand,
StakeCommand,
RegisterSubnetworkCommand,
CommitWeightCommand,
RevealWeightCommand,
)
import bittensor
from tests.e2e_tests.utils import setup_wallet
import time
import bittensor.utils.weight_utils as weight_utils
import re
import numpy as np


def test_commit_and_reveal_weights(local_chain):
Expand All @@ -21,6 +23,7 @@ def test_commit_and_reveal_weights(local_chain):
# define values
weights = 0.1
uid = 0
salt = "18, 179, 107, 0, 165, 211, 141, 197"

# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
Expand Down Expand Up @@ -101,6 +104,8 @@ def test_commit_and_reveal_weights(local_chain):
str(uid),
"--weights",
str(weights),
"--salt",
str(salt),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand Down Expand Up @@ -150,6 +155,8 @@ def test_commit_and_reveal_weights(local_chain):
str(uid),
"--weights",
str(weights),
"--salt",
str(salt),
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
Expand Down