-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1987 from opentensor/feature/opendansor/e2e-fauce…
…t-test Add E2E faucet test
- Loading branch information
Showing
3 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest | ||
|
||
import bittensor | ||
from bittensor import logging | ||
from bittensor.commands import ( | ||
RegisterCommand, | ||
RegisterSubnetworkCommand, | ||
RunFaucetCommand, | ||
) | ||
from tests.e2e_tests.utils import ( | ||
setup_wallet, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("local_chain", [False], indirect=True) | ||
def test_faucet(local_chain): | ||
# Register root as Alice | ||
keypair, exec_command, wallet_path = setup_wallet("//Alice") | ||
exec_command(RegisterSubnetworkCommand, ["s", "create"]) | ||
|
||
# Verify subnet 1 created successfully | ||
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize() | ||
|
||
# Register a neuron to the subnet | ||
exec_command( | ||
RegisterCommand, | ||
[ | ||
"s", | ||
"register", | ||
"--netuid", | ||
"1", | ||
"--wallet.name", | ||
"default", | ||
"--wallet.hotkey", | ||
"default", | ||
"--subtensor.network", | ||
"local", | ||
"--subtensor.chain_endpoint", | ||
"ws://localhost:9945", | ||
"--no_prompt", | ||
], | ||
) | ||
|
||
subtensor = bittensor.subtensor(network="ws://localhost:9945") | ||
|
||
# verify current balance | ||
wallet_balance = subtensor.get_balance(keypair.ss58_address) | ||
assert wallet_balance.tao == 998999.0 | ||
|
||
# run faucet 3 times | ||
for i in range(3): | ||
logging.info(f"faucet run #:{i+1}") | ||
try: | ||
exec_command( | ||
RunFaucetCommand, | ||
[ | ||
"wallet", | ||
"faucet", | ||
"--wallet.name", | ||
"default", | ||
"--wallet.hotkey", | ||
"default", | ||
"--subtensor.chain_endpoint", | ||
"ws://localhost:9945", | ||
], | ||
) | ||
logging.info( | ||
f"wallet balance is {subtensor.get_balance(keypair.ss58_address).tao} tao" | ||
) | ||
except SystemExit as e: | ||
logging.warning( | ||
"Block not generated fast enough to be within 3 block seconds window." | ||
) | ||
# Handle the SystemExit exception | ||
assert e.code == 1 # Assert that the exit code is 1 | ||
except Exception as e: | ||
logging.warning(f"Unexpected exception occurred on faucet: {e}") | ||
|
||
subtensor = bittensor.subtensor(network="ws://localhost:9945") | ||
|
||
new_wallet_balance = subtensor.get_balance(keypair.ss58_address) | ||
# verify balance increase | ||
assert wallet_balance.tao < new_wallet_balance.tao | ||
assert ( | ||
new_wallet_balance.tao == 999899.0 | ||
) # after 3 runs we should see an increase of 900 tao |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters