Skip to content

Commit

Permalink
Merge pull request #1952 from opentensor/chore/opendansor/fix-commit-…
Browse files Browse the repository at this point in the history
…reveal-e2e

Fix E2E test for Commit/Reveal with Salt flag
  • Loading branch information
opendansor authored and gus-opentensor committed Jun 5, 2024
1 parent 515ee09 commit 536b23c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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

0 comments on commit 536b23c

Please sign in to comment.