From ca261c049e24ac618bcb80631fe0afc396e5756a Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 18:37:49 -0700 Subject: [PATCH 01/32] add BUILD_BINARY=0 --- tests/e2e_tests/conftest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index b4770ed053..ba26c41e9c 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -66,8 +66,12 @@ def read_output(): reader_thread = threading.Thread(target=read_output, daemon=True) reader_thread.start() + env = os.environ.copy() + env["BUILD_BINARY"] = "0" + with subprocess.Popen( cmds, + env=env, start_new_session=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, From 0074c9b77456b1efc21412588c9cfe7a327542c6 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 18:38:45 -0700 Subject: [PATCH 02/32] replace devnet-ready to devnet-ready-with-nodes --- btwa_testing.py | 8 +++++ manual_testing.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 btwa_testing.py create mode 100644 manual_testing.py diff --git a/btwa_testing.py b/btwa_testing.py new file mode 100644 index 0000000000..a9e7f90b3b --- /dev/null +++ b/btwa_testing.py @@ -0,0 +1,8 @@ +from bittensor_wallet import Keypair, Keyfile, Wallet, Config + + + +wallet = Wallet(name="tmp") +wallet.coldkeyfile.save_to_env + +print(wallet.coldkey) diff --git a/manual_testing.py b/manual_testing.py new file mode 100644 index 0000000000..90b4e95b02 --- /dev/null +++ b/manual_testing.py @@ -0,0 +1,91 @@ +from bittensor.core.subtensor import Subtensor +from bittensor.utils.balance import tao +from bittensor_wallet.wallet import Wallet + +COLDKEY = "5G4T9VnZfUDD2vD3MdKsgmbSAsKQq5rtZ73JtQuFA8SRfW14" +HOTKEY = "5GQenM6A7sWGxgmPPAorKGnFQsBWczXDhGhZjkbZq3Wr9wtX" +HOTKEY_NETUIDS = [0, 4, 6] + +DEVNET = "wss://dev.chain.opentensor.ai:443" +wallet = Wallet(path="~/.bittensor/wallets", name="alice") + + +subtensor = Subtensor(network="test") + + +def main(): + # print(subtensor.get_hyperparameter("LastUpdate", 1)) + # print(subtensor.get_hyperparameter("MinDifficulty", 1)) # does not exist + # print(subtensor.all_subnets()) + # print(subtensor.blocks_since_last_update(1, 1)) + # print(subtensor.bonds(1)) # looking into + # print(subtensor.commit_reveal_enabled(1)) + # print(subtensor.difficulty(1)) + # print(subtensor.does_hotkey_exist(HOTKEY)) + # print(subtensor.get_all_subnets_info()) + # print(subtensor.get_balance(COLDKEY)) + # print(subtensor.get_balances(COLDKEY)) + + # print(current_block := subtensor.get_current_block()) + + # print(subtensor._get_block_hash(current_block)) + # print(subtensor.get_block_hash(current_block)) + # print(subtensor.get_children(HOTKEY, 1)) # maybe not working + # print(subtensor.get_metagraph_info(1)) + # print(subtensor.subnet(1)) + # print(subtensor.get_all_metagraphs_info()) + # print(subtensor.get_netuids_for_hotkey(HOTKEY)) + # print(subtensor.get_neuron_certificate()) # untested + # print(subtensor.get_neuron_for_pubkey_and_subnet(HOTKEY, HOTKEY_NETUIDS[1])) + # print(subtensor.get_stake(COLDKEY, HOTKEY, HOTKEY_NETUIDS[1])) + # print(subtensor.get_stake_for_coldkey_and_hotkey(COLDKEY, HOTKEY, HOTKEY_NETUIDS)) + # print(subtensor.get_stake_for_coldkey(COLDKEY)) + # print(type(subtensor.get_subnet_burn_cost())) + + # print(subtensor.get_subnet_hyperparameters(111)) + # print(subtensor.get_subnets(block=current_block-20)) + # print(subtensor.get_total_stake_for_hotkey(HOTKEY)) + # print(subtensor.get_total_subnets()) + # print(subtensor.get_transfer_fee(wallet=wallet, dest=COLDKEY, value=tao(1.0))) + # print(subtensor.get_uid_for_hotkey_on_subnet(HOTKEY, HOTKEY_NETUIDS[1])) + # print(subtensor.immunity_period(HOTKEY_NETUIDS[1])) + # print(subtensor.is_hotkey_delegate(COLDKEY)) + # print(subtensor.is_hotkey_registered(HOTKEY, HOTKEY_NETUIDS[1])) + # print(subtensor.is_hotkey_registered_any(HOTKEY)) + # print(subtensor.is_hotkey_registered_on_subnet(HOTKEY, HOTKEY_NETUIDS[1])) + # print(subtensor.last_drand_round()) + # print(subtensor.max_weight_limit(HOTKEY_NETUIDS[1])) + # print(subtensor.metagraph(HOTKEY_NETUIDS[1], lite=True)) + # print(subtensor.metagraph(HOTKEY_NETUIDS[1], lite=False)) + # print(subtensor.min_allowed_weights(HOTKEY_NETUIDS[1])) + # print(subtensor.neuron_for_uid(1, HOTKEY_NETUIDS[1])) + # print(subtensor.neurons(HOTKEY_NETUIDS[1])) + # print(subtensor.neurons_lite(HOTKEY_NETUIDS[1])) + # print(subtensor.query_identity(HOTKEY)) + # print(subtensor.recycle(HOTKEY_NETUIDS[1])) + # print(subtensor.subnet_exists(2)) + # print(subtensor.subnet_exists(200)) + # print(subtensor.subnetwork_n(HOTKEY_NETUIDS[1])) + # print(subtensor.tempo(HOTKEY_NETUIDS[1])) + # print(subtensor.tx_rate_limit()) + # print(subtensor.wait_for_block()) + # print(subtensor.wait_for_block(current_block+5)) + # for subnet in subtensor.get_subnets(): + # print(subtensor.weights(subnet)) + # print(subtensor.weights_rate_limit(HOTKEY_NETUIDS[1])) + print(block := subtensor.block) + # for uid in range(0, 7): + # print(subtensor.get_commitment(2, uid, block=block)) + # print(subtensor.get_current_weight_commit_info(1)) + # print(subtensor.get_delegate_by_hotkey(HOTKEY)) + # print(subtensor.get_delegate_identities()) + # print(subtensor.get_delegate_take("5GP7c3fFazW9GXK8Up3qgu2DJBk8inu4aK9TZy3RuoSWVCMi", block=block)) + # print(subtensor.get_delegated(COLDKEY, block=block)) + # print(subtensor.get_delegates(block=block)) + # print(subtensor.get_existential_deposit(block=block)) + # print(subtensor.get_hotkey_owner("5DcpkDYwWHgtkhLhKFCMqTQeU1ggRKjQEoLCf1e3X47VxZzw")) + # print(subtensor.get_minimum_required_stake()) + + +if __name__ == "__main__": + main() From a810aae2608c95f4e80018df7b9c10a178f97f50 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 18:52:05 -0700 Subject: [PATCH 03/32] trigger actions --- .github/workflows/e2e-subtensor-tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index a32971a918..5d61bcc466 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -23,6 +23,7 @@ env: CARGO_TERM_COLOR: always VERBOSE: ${{ github.event.inputs.verbose }} + # job to run tests in parallel jobs: # Job to find all test files @@ -90,7 +91,7 @@ jobs: - name: Setup subtensor repo working-directory: ${{ github.workspace }}/subtensor - run: git checkout devnet-ready + run: git checkout devnet-ready-with-nodes - name: Install uv uses: astral-sh/setup-uv@v4 From de812b9fe3487151ba2c906c597b2dd19fc88f1e Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 18:58:16 -0700 Subject: [PATCH 04/32] add debug --- .github/workflows/e2e-subtensor-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 5d61bcc466..6705eea02d 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -101,6 +101,7 @@ jobs: - name: Run tests run: | + ls -lash ${{ github.workspace }}/subtensor/nodes LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s - name: Retry failed tests From e66c9ed97c15375861ff294aaf17efd7e93f0557 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 21:04:25 -0700 Subject: [PATCH 05/32] return proper runner --- .github/workflows/e2e-subtensor-tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 6705eea02d..27254dc51e 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -23,7 +23,6 @@ env: CARGO_TERM_COLOR: always VERBOSE: ${{ github.event.inputs.verbose }} - # job to run tests in parallel jobs: # Job to find all test files From 99390bac320a64bea667ff13d3c33c3dcf48fe47 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 21:59:06 -0700 Subject: [PATCH 06/32] get-latest-artifact-id --- .github/workflows/e2e-subtensor-tests.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 27254dc51e..7846528af8 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -25,6 +25,28 @@ env: # job to run tests in parallel jobs: + + get-latest-artifact-id: + runs-on: ubuntu-latest + + steps: + - name: Fetch Artifacts List + id: fetch_artifacts + run: | + ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/opentensor/subtensor/actions/actions/artifacts) + echo "$ARTIFACTS" > artifacts.json + + - name: Parse Latest Artifact ID + id: parse_artifact + run: | + LATEST_ARTIFACT_ID=$(jq -r '.artifacts[0].id' artifacts.json) + echo "LATEST_ARTIFACT_ID=$LATEST_ARTIFACT_ID" >> $GITHUB_ENV + + - name: Print Latest Artifact ID + run: | + echo "Latest Artifact ID: ${{ env.LATEST_ARTIFACT_ID }}" + # Job to find all test files find-tests: runs-on: ubuntu-latest From 83ef99ffcaf7f3d8e8869f31eca2aa0d1bf08175 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 22:57:00 -0700 Subject: [PATCH 07/32] try tests with compatible architecture --- .github/workflows/e2e-subtensor-tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 7846528af8..2f377ba644 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -36,6 +36,9 @@ jobs: ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/opentensor/subtensor/actions/actions/artifacts) echo "$ARTIFACTS" > artifacts.json + + echo "Raw ARTIFACTS response:" + echo "$ARTIFACTS" - name: Parse Latest Artifact ID id: parse_artifact From a04018c289f4a356c4dbd0a330f8661f5c8d7088 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:03:39 -0700 Subject: [PATCH 08/32] use the same runner --- .github/workflows/e2e-subtensor-tests.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 2f377ba644..12a7e9b371 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -33,8 +33,7 @@ jobs: - name: Fetch Artifacts List id: fetch_artifacts run: | - ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/opentensor/subtensor/actions/actions/artifacts) + ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/opentensor/subtensor/actions/artifacts) echo "$ARTIFACTS" > artifacts.json echo "Raw ARTIFACTS response:" @@ -70,7 +69,7 @@ jobs: # Job to run tests in parallel run: needs: find-tests - runs-on: SubtensorCI + runs-on: ubuntu-latest timeout-minutes: 45 strategy: fail-fast: false # Allow other matrix jobs to run even if this job fails From 3210071975b582ade852bd839ab1cef8c5311feb Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:09:31 -0700 Subject: [PATCH 09/32] debug --- .github/workflows/e2e-subtensor-tests.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 12a7e9b371..0bbf631d53 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -82,12 +82,12 @@ jobs: os: - ubuntu-latest test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }} - env: - RELEASE_NAME: development - RUSTV: ${{ matrix.rust-branch }} - RUST_BACKTRACE: full - RUST_BIN_DIR: target/${{ matrix.rust-target }} - TARGET: ${{ matrix.rust-target }} +# env: +# RELEASE_NAME: development +# RUSTV: ${{ matrix.rust-branch }} +# RUST_BACKTRACE: full +# RUST_BIN_DIR: target/${{ matrix.rust-target }} +# TARGET: ${{ matrix.rust-target }} steps: - name: Check-out repository under $GITHUB_WORKSPACE uses: actions/checkout@v4 From 1ce957801082980d5ed3c41584c19631029844af Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:17:48 -0700 Subject: [PATCH 10/32] debug file --- .github/workflows/e2e-subtensor-tests.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 0bbf631d53..e829d1e9eb 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -116,19 +116,22 @@ jobs: working-directory: ${{ github.workspace }}/subtensor run: git checkout devnet-ready-with-nodes - - name: Install uv - uses: astral-sh/setup-uv@v4 - - - name: install dependencies - run: uv sync --all-extras --dev + - name: Print file + working-directory: ${{ github.workspace }}/subtensor + run: | + apt install file + echo "File fast-blocks" + file ${{ github.workspace }}/subtensor/nodes/fast-blocks/release/node-subtensor + echo "File non-fast-blocks" + file ${{ github.workspace }}/subtensor/nodes/non-fast-blocks/release/node-subtensor - name: Run tests run: | ls -lash ${{ github.workspace }}/subtensor/nodes - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s + LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" pytest ${{ matrix.test-file }} -s - name: Retry failed tests if: failure() run: | sleep 10 - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s + LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" pytest ${{ matrix.test-file }} -s From b6716550c8b38a69865983feeb31b54292a9232f Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:22:37 -0700 Subject: [PATCH 11/32] sudo --- .github/workflows/e2e-subtensor-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index e829d1e9eb..3aa09e481a 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -119,7 +119,7 @@ jobs: - name: Print file working-directory: ${{ github.workspace }}/subtensor run: | - apt install file + sudo apt install file echo "File fast-blocks" file ${{ github.workspace }}/subtensor/nodes/fast-blocks/release/node-subtensor echo "File non-fast-blocks" From f1f0898e1d67e6cdd014e5f8de154bc839bb9ef3 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:34:40 -0700 Subject: [PATCH 12/32] more debug info --- .github/workflows/e2e-subtensor-tests.yaml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 3aa09e481a..b81030a682 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -77,8 +77,8 @@ jobs: matrix: rust-branch: - stable - rust-target: - - x86_64-unknown-linux-gnu +# rust-target: +# - x86_64-unknown-linux-gnu os: - ubuntu-latest test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }} @@ -116,7 +116,7 @@ jobs: working-directory: ${{ github.workspace }}/subtensor run: git checkout devnet-ready-with-nodes - - name: Print file + - name: Print files and OS info working-directory: ${{ github.workspace }}/subtensor run: | sudo apt install file @@ -124,6 +124,21 @@ jobs: file ${{ github.workspace }}/subtensor/nodes/fast-blocks/release/node-subtensor echo "File non-fast-blocks" file ${{ github.workspace }}/subtensor/nodes/non-fast-blocks/release/node-subtensor + + echo "uname -m && uname -r" + uname -m && uname -r + + echo "ldd" + ldd ${{ github.workspace }}/subtensor/nodes/non-fast-blocks/release/node-subtensor + + echo "/lib/ld-linux-aarch64.so.1 exist" + ls /lib/ld-linux-aarch64.so.1 + + - name: Install uv + uses: astral-sh/setup-uv@v4 + + - name: install dependencies + run: uv sync --all-extras --dev - name: Run tests run: | From d044f89f81544fd5751289e9e969503117a2f98a Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:38:10 -0700 Subject: [PATCH 13/32] more debug info --- .github/workflows/e2e-subtensor-tests.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index b81030a682..c9b50630ba 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -128,9 +128,6 @@ jobs: echo "uname -m && uname -r" uname -m && uname -r - echo "ldd" - ldd ${{ github.workspace }}/subtensor/nodes/non-fast-blocks/release/node-subtensor - echo "/lib/ld-linux-aarch64.so.1 exist" ls /lib/ld-linux-aarch64.so.1 From 3007f679a78646fc22646ffa5023733accaff018 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:50:19 -0700 Subject: [PATCH 14/32] more debug info --- .github/workflows/e2e-subtensor-tests.yaml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index c9b50630ba..06ef6d1e1f 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -77,17 +77,17 @@ jobs: matrix: rust-branch: - stable -# rust-target: -# - x86_64-unknown-linux-gnu + rust-target: + - x86_64-unknown-linux-gnu os: - ubuntu-latest test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }} -# env: -# RELEASE_NAME: development -# RUSTV: ${{ matrix.rust-branch }} -# RUST_BACKTRACE: full -# RUST_BIN_DIR: target/${{ matrix.rust-target }} -# TARGET: ${{ matrix.rust-target }} + env: + RELEASE_NAME: development + RUSTV: ${{ matrix.rust-branch }} + RUST_BACKTRACE: full + RUST_BIN_DIR: target/${{ matrix.rust-target }} + TARGET: ${{ matrix.rust-target }} steps: - name: Check-out repository under $GITHUB_WORKSPACE uses: actions/checkout@v4 @@ -127,9 +127,6 @@ jobs: echo "uname -m && uname -r" uname -m && uname -r - - echo "/lib/ld-linux-aarch64.so.1 exist" - ls /lib/ld-linux-aarch64.so.1 - name: Install uv uses: astral-sh/setup-uv@v4 From 336af8ec9638df1eeeae6ab2881f64f6eda64c5a Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Mar 2025 23:56:28 -0700 Subject: [PATCH 15/32] more debug info --- .github/workflows/e2e-subtensor-tests.yaml | 4 ++-- btwa_testing.py | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 btwa_testing.py diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 06ef6d1e1f..b79eaa2fa0 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -137,10 +137,10 @@ jobs: - name: Run tests run: | ls -lash ${{ github.workspace }}/subtensor/nodes - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" pytest ${{ matrix.test-file }} -s + LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s - name: Retry failed tests if: failure() run: | sleep 10 - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" pytest ${{ matrix.test-file }} -s + LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s diff --git a/btwa_testing.py b/btwa_testing.py deleted file mode 100644 index a9e7f90b3b..0000000000 --- a/btwa_testing.py +++ /dev/null @@ -1,8 +0,0 @@ -from bittensor_wallet import Keypair, Keyfile, Wallet, Config - - - -wallet = Wallet(name="tmp") -wallet.coldkeyfile.save_to_env - -print(wallet.coldkey) From bb2d7952138683816e7c092f46dd21cdf7286afe Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:26:50 -0700 Subject: [PATCH 16/32] ruff --- tests/e2e_tests/conftest.py | 154 ++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 40 deletions(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index ba26c41e9c..b93c42daf2 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -1,27 +1,82 @@ import os import re +import shutil import shlex import signal import subprocess -import time +import sys import threading +import time +from bittensor.utils.btlogging import logging import pytest from async_substrate_interface import SubstrateInterface from bittensor.core.async_subtensor import AsyncSubtensor from bittensor.core.subtensor import Subtensor -from bittensor.utils.btlogging import logging from tests.e2e_tests.utils.e2e_test_utils import ( Templates, setup_wallet, ) -# Fixture for setting up and tearing down a localnet.sh chain between tests +def wait_for_node_start(process, timestamp=None): + """Waits for node to start in the docker.""" + while True: + line = process.stdout.readline() + if not line: + break + + timestamp = timestamp or int(time.time()) + print(line.strip()) + # 10 min as timeout + if int(time.time()) - timestamp > 20 * 30: + print("Subtensor not started in time") + raise TimeoutError + + pattern = re.compile(r"Imported #1") + if pattern.search(line): + print("Node started!") + break + + # Start a background reader after pattern is found + # To prevent the buffer filling up + def read_output(): + while True: + if not process.stdout.readline(): + break + + reader_thread = threading.Thread(target=read_output, daemon=True) + reader_thread.start() + + @pytest.fixture(scope="function") def local_chain(request): - param = request.param if hasattr(request, "param") else None + """Determines whether to run the localnet.sh script in a subprocess or a Docker container.""" + args = request.param if hasattr(request, "param") else None + params = "" if args is None else f"{args}" + if shutil.which("docker"): + yield from docker_runner(params) + return + + if sys.platform.startswith("linux"): + docker_commend = ( + "Install docker with command " + "[blue]sudo apt-get update && sudo apt-get install docker.io -y[/blue]" + ) + elif sys.platform == "darwin": + docker_commend = "Install docker with command [blue]brew install docker[/blue]" + else: + docker_commend = "[blue]Unknown OS, install Docker manually: https://docs.docker.com/get-docker/[/blue]" + + logging.warning("Docker not found in the operating system!") + logging.warning(docker_commend) + logging.warning("Tests are run in legacy mode.") + yield from legacy_runner(request) + + +def legacy_runner(params): + """Runs the localnet.sh script in a subprocess and waits for it to start.""" # Get the environment variable for the script path script_path = os.getenv("LOCALNET_SH_PATH") @@ -31,54 +86,20 @@ def local_chain(request): pytest.skip("LOCALNET_SH_PATH environment variable is not set.") # Check if param is None, and handle it accordingly - args = "" if param is None else f"{param}" + args = "" if params is None else f"{params}" # Compile commands to send to process cmds = shlex.split(f"{script_path} {args}") - # Pattern match indicates node is compiled and ready - pattern = re.compile(r"Imported #1") - timestamp = int(time.time()) - - def wait_for_node_start(process, pattern): - while True: - line = process.stdout.readline() - if not line: - break - - print(line.strip()) - # 10 min as timeout - if int(time.time()) - timestamp > 20 * 60: - print("Subtensor not started in time") - raise TimeoutError - if pattern.search(line): - print("Node started!") - break - - # Start a background reader after pattern is found - # To prevent the buffer filling up - def read_output(): - while True: - line = process.stdout.readline() - if not line: - break - - reader_thread = threading.Thread(target=read_output, daemon=True) - reader_thread.start() - - env = os.environ.copy() - env["BUILD_BINARY"] = "0" - with subprocess.Popen( cmds, - env=env, start_new_session=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, text=True, ) as process: try: - wait_for_node_start(process, pattern) + wait_for_node_start(process) except TimeoutError: raise else: @@ -95,6 +116,59 @@ def read_output(): process.wait() +def docker_runner(params): + """Starts a Docker container before tests and gracefully terminates it after.""" + + container_name = f"test_local_chain_{str(time.time()).replace(".", "_")}" + image_name = "ghcr.io/opentensor/subtensor-localnet:latest" + + # Command to start container + cmds = [ + "docker", + "run", + "--rm", + "--name", + container_name, + "-p", + "9944:9944", + "-p", + "9945:9945", + image_name, + params, + ] + + # Start container + with subprocess.Popen( + cmds, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + start_new_session=True, + ) as process: + try: + try: + wait_for_node_start(process, int(time.time())) + except TimeoutError: + raise + + result = subprocess.run( + ["docker", "ps", "-q", "-f", f"name={container_name}"], + capture_output=True, + text=True, + ) + if not result.stdout.strip(): + raise RuntimeError("Docker container failed to start.") + + yield SubstrateInterface(url="ws://127.0.0.1:9944") + + finally: + try: + subprocess.run(["docker", "kill", container_name]) + process.wait() + except subprocess.TimeoutExpired: + os.killpg(os.getpgid(process.pid), signal.SIGKILL) + + @pytest.fixture(scope="session") def templates(): with Templates() as templates: From 153815257f056d0f285ed8db64a5cf673fe92306 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:27:13 -0700 Subject: [PATCH 17/32] update e2e tests workflow --- .github/workflows/e2e-subtensor-tests.yaml | 114 ++++++--------------- 1 file changed, 33 insertions(+), 81 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 96bd4519dc..0106005179 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -26,30 +26,6 @@ env: # job to run tests in parallel jobs: - get-latest-artifact-id: - runs-on: ubuntu-latest - - steps: - - name: Fetch Artifacts List - id: fetch_artifacts - run: | - ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/opentensor/subtensor/actions/artifacts) - echo "$ARTIFACTS" > artifacts.json - - echo "Raw ARTIFACTS response:" - echo "$ARTIFACTS" - - - name: Parse Latest Artifact ID - id: parse_artifact - run: | - LATEST_ARTIFACT_ID=$(jq -r '.artifacts[0].id' artifacts.json) - echo "LATEST_ARTIFACT_ID=$LATEST_ARTIFACT_ID" >> $GITHUB_ENV - - - name: Print Latest Artifact ID - run: | - echo "Latest Artifact ID: ${{ env.LATEST_ARTIFACT_ID }}" - - # Job to find all test files find-tests: runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }} @@ -66,81 +42,57 @@ jobs: echo "::set-output name=test-files::$test_files" shell: bash + pull-docker-image: + runs-on: ubuntu-latest + steps: + - name: Log in to GitHub Container Registry (если образ приватный) + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin + + - name: Pull Docker Image + run: docker pull ghcr.io/opentensor/subtensor-localnet:latest + + - name: Save Docker Image to Cache + run: docker save -o subtensor-localnet.tar ghcr.io/opentensor/subtensor-localnet:latest + + - name: Upload Docker Image as Artifact + uses: actions/upload-artifact@v3 + with: + name: subtensor-localnet + path: subtensor-localnet.tar + retention-days: 1 + # Job to run tests in parallel run: - needs: find-tests + needs: + - find-tests + - pull-docker-image runs-on: ubuntu-latest timeout-minutes: 45 strategy: fail-fast: false # Allow other matrix jobs to run even if this job fails max-parallel: 8 # Set the maximum number of parallel jobs matrix: - rust-branch: - - stable - rust-target: - - x86_64-unknown-linux-gnu os: - ubuntu-latest test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }} - env: - RELEASE_NAME: development - RUSTV: ${{ matrix.rust-branch }} - RUST_BACKTRACE: full - RUST_BIN_DIR: target/${{ matrix.rust-target }} - TARGET: ${{ matrix.rust-target }} steps: - name: Check-out repository under $GITHUB_WORKSPACE uses: actions/checkout@v4 - - name: Install dependencies - run: | - sudo apt-get update && - sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler +# - name: Install uv +# uses: astral-sh/setup-uv@v4 +# +# - name: install dependencies +# run: uv sync --all-extras --dev - - name: Install Rust ${{ matrix.rust-branch }} - uses: actions-rs/toolchain@v1.0.6 + - name: Download Cached Docker Image + uses: actions/download-artifact@v4 with: - toolchain: ${{ matrix.rust-branch }} - components: rustfmt - profile: minimal - - - name: Add wasm32-unknown-unknown target - run: | - rustup target add wasm32-unknown-unknown --toolchain stable-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain stable-x86_64-unknown-linux-gnu - - - name: Clone subtensor repo - run: git clone https://github.com/opentensor/subtensor.git + name: subtensor-localnet - - name: Setup subtensor repo - working-directory: ${{ github.workspace }}/subtensor - run: git checkout devnet-ready-with-nodes - - - name: Print files and OS info - working-directory: ${{ github.workspace }}/subtensor - run: | - sudo apt install file - echo "File fast-blocks" - file ${{ github.workspace }}/subtensor/nodes/fast-blocks/release/node-subtensor - echo "File non-fast-blocks" - file ${{ github.workspace }}/subtensor/nodes/non-fast-blocks/release/node-subtensor - - echo "uname -m && uname -r" - uname -m && uname -r - - - name: Install uv - uses: astral-sh/setup-uv@v4 - - - name: install dependencies - run: uv sync --all-extras --dev + - name: Load Docker Image + run: docker load -i subtensor-localnet.tar - name: Run tests run: | - ls -lash ${{ github.workspace }}/subtensor/nodes - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s - - - name: Retry failed tests - if: failure() - run: | - sleep 10 - LOCALNET_SH_PATH="${{ github.workspace }}/subtensor/scripts/localnet.sh" uv run pytest ${{ matrix.test-file }} -s + pytest ${{ matrix.test-file }} -s From 99aab1b4ca1aaac121029ca5adfa1aebf4e82dd0 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:36:54 -0700 Subject: [PATCH 18/32] fix --- .github/workflows/e2e-subtensor-tests.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 0106005179..67041d1e6e 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -45,7 +45,7 @@ jobs: pull-docker-image: runs-on: ubuntu-latest steps: - - name: Log in to GitHub Container Registry (если образ приватный) + - name: Log in to GitHub Container Registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - name: Pull Docker Image @@ -55,11 +55,10 @@ jobs: run: docker save -o subtensor-localnet.tar ghcr.io/opentensor/subtensor-localnet:latest - name: Upload Docker Image as Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: subtensor-localnet path: subtensor-localnet.tar - retention-days: 1 # Job to run tests in parallel run: From 8841166763104cf16e5c14923c1c9231047150bf Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:38:24 -0700 Subject: [PATCH 19/32] add reqs --- .github/workflows/e2e-subtensor-tests.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 67041d1e6e..f14e68fe92 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -94,4 +94,6 @@ jobs: - name: Run tests run: | + pip install -e .[dev] + pip install pytest pytest ${{ matrix.test-file }} -s From f42de89ea47aad04ef21fcf201f66f19aede5fd9 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:56:35 -0700 Subject: [PATCH 20/32] try improvement --- .github/workflows/e2e-subtensor-tests.yaml | 46 +++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index f14e68fe92..e29773fd00 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -60,6 +60,30 @@ jobs: name: subtensor-localnet path: subtensor-localnet.tar + create_venv: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Install Python + uses: actions/setup-python@v4 + + - name: Create Python virtual environment + run: python -m venv ${{ github.workspace }}/venv + + - name: Install dependencies + run: | + ${{ github.workspace }}/venv/bin/pip install -e .[dev] + ${{ github.workspace }}/venv/bin/pip install pytest + + - name: Upload virtual environment as artifact + uses: actions/upload-artifact@v4 + with: + name: venv + path: ${{ github.workspace }}/venv + + # Job to run tests in parallel run: needs: @@ -69,15 +93,29 @@ jobs: timeout-minutes: 45 strategy: fail-fast: false # Allow other matrix jobs to run even if this job fails - max-parallel: 8 # Set the maximum number of parallel jobs + max-parallel: 32 # Set the maximum number of parallel jobs (same as we have cores in SubtensorCI runner) matrix: os: - ubuntu-latest test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }} steps: - - name: Check-out repository under $GITHUB_WORKSPACE + - name: Check-out repository uses: actions/checkout@v4 + - name: Download virtual environment + uses: actions/download-artifact@v4 + with: + name: venv + path: venv + + - name: Install Python + uses: actions/setup-python@v4 + + - name: Install requirements + run: | + ${{ github.workspace }}/venv/bin/pip install -e .[dev] + ${{ github.workspace }}/venv/bin/pip install pytest + # - name: Install uv # uses: astral-sh/setup-uv@v4 # @@ -94,6 +132,4 @@ jobs: - name: Run tests run: | - pip install -e .[dev] - pip install pytest - pytest ${{ matrix.test-file }} -s + ${{ github.workspace }}/venv/bin/pytest ${{ matrix.test-file }} -s From c3595ea67cde6fcc24f1743029b8a3988303edcc Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 17:57:47 -0700 Subject: [PATCH 21/32] add needs --- .github/workflows/e2e-subtensor-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index e29773fd00..9ca618439b 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -89,6 +89,7 @@ jobs: needs: - find-tests - pull-docker-image + - create_venv runs-on: ubuntu-latest timeout-minutes: 45 strategy: From 93d8b1c94e54810cfeb259f89f6a0f953214ba3c Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:04:29 -0700 Subject: [PATCH 22/32] remove venv job --- .github/workflows/e2e-subtensor-tests.yaml | 40 +++++----------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 9ca618439b..4f79c60ced 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -60,36 +60,11 @@ jobs: name: subtensor-localnet path: subtensor-localnet.tar - create_venv: - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Install Python - uses: actions/setup-python@v4 - - - name: Create Python virtual environment - run: python -m venv ${{ github.workspace }}/venv - - - name: Install dependencies - run: | - ${{ github.workspace }}/venv/bin/pip install -e .[dev] - ${{ github.workspace }}/venv/bin/pip install pytest - - - name: Upload virtual environment as artifact - uses: actions/upload-artifact@v4 - with: - name: venv - path: ${{ github.workspace }}/venv - - # Job to run tests in parallel run: needs: - find-tests - pull-docker-image - - create_venv runs-on: ubuntu-latest timeout-minutes: 45 strategy: @@ -111,11 +86,8 @@ jobs: - name: Install Python uses: actions/setup-python@v4 - - - name: Install requirements - run: | - ${{ github.workspace }}/venv/bin/pip install -e .[dev] - ${{ github.workspace }}/venv/bin/pip install pytest + with: + python-version: '3.12' # - name: Install uv # uses: astral-sh/setup-uv@v4 @@ -131,6 +103,10 @@ jobs: - name: Load Docker Image run: docker load -i subtensor-localnet.tar - - name: Run tests + - name: Install requirements run: | - ${{ github.workspace }}/venv/bin/pytest ${{ matrix.test-file }} -s + pip install -e .[dev] + pip install pytest + + - name: Run tests + run: pytest ${{ matrix.test-file }} -s From 096a312151a0d97fbd73763720157cbac32bb13b Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:05:39 -0700 Subject: [PATCH 23/32] fix --- .github/workflows/e2e-subtensor-tests.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 4f79c60ced..013db0c44d 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -78,12 +78,6 @@ jobs: - name: Check-out repository uses: actions/checkout@v4 - - name: Download virtual environment - uses: actions/download-artifact@v4 - with: - name: venv - path: venv - - name: Install Python uses: actions/setup-python@v4 with: From 85067d2462cd085c35da417e3ca7bbc8e2b2a598 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:15:38 -0700 Subject: [PATCH 24/32] test time with uv --- .github/workflows/e2e-subtensor-tests.yaml | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 013db0c44d..bf76b57161 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -78,16 +78,16 @@ jobs: - name: Check-out repository uses: actions/checkout@v4 - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.12' +# - name: Install Python +# uses: actions/setup-python@v4 +# with: +# python-version: '3.12' + + - name: Install uv + uses: astral-sh/setup-uv@v4 -# - name: Install uv -# uses: astral-sh/setup-uv@v4 -# -# - name: install dependencies -# run: uv sync --all-extras --dev + - name: install dependencies + run: uv sync --all-extras --dev - name: Download Cached Docker Image uses: actions/download-artifact@v4 @@ -97,10 +97,10 @@ jobs: - name: Load Docker Image run: docker load -i subtensor-localnet.tar - - name: Install requirements - run: | - pip install -e .[dev] - pip install pytest +# - name: Install requirements +# run: | +# pip install -e .[dev] +# pip install pytest - name: Run tests run: pytest ${{ matrix.test-file }} -s From 049aeb8f5c95bfc45762534a78836202523e87e6 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:16:44 -0700 Subject: [PATCH 25/32] test time with uv --- .github/workflows/e2e-subtensor-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index bf76b57161..86c7f0f928 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -103,4 +103,4 @@ jobs: # pip install pytest - name: Run tests - run: pytest ${{ matrix.test-file }} -s + run: uv run pytest ${{ matrix.test-file }} -s From a594e7370cf429acd7a598261bb27ea74c8d374d Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:21:15 -0700 Subject: [PATCH 26/32] remove debug file --- manual_testing.py | 91 ----------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 manual_testing.py diff --git a/manual_testing.py b/manual_testing.py deleted file mode 100644 index 90b4e95b02..0000000000 --- a/manual_testing.py +++ /dev/null @@ -1,91 +0,0 @@ -from bittensor.core.subtensor import Subtensor -from bittensor.utils.balance import tao -from bittensor_wallet.wallet import Wallet - -COLDKEY = "5G4T9VnZfUDD2vD3MdKsgmbSAsKQq5rtZ73JtQuFA8SRfW14" -HOTKEY = "5GQenM6A7sWGxgmPPAorKGnFQsBWczXDhGhZjkbZq3Wr9wtX" -HOTKEY_NETUIDS = [0, 4, 6] - -DEVNET = "wss://dev.chain.opentensor.ai:443" -wallet = Wallet(path="~/.bittensor/wallets", name="alice") - - -subtensor = Subtensor(network="test") - - -def main(): - # print(subtensor.get_hyperparameter("LastUpdate", 1)) - # print(subtensor.get_hyperparameter("MinDifficulty", 1)) # does not exist - # print(subtensor.all_subnets()) - # print(subtensor.blocks_since_last_update(1, 1)) - # print(subtensor.bonds(1)) # looking into - # print(subtensor.commit_reveal_enabled(1)) - # print(subtensor.difficulty(1)) - # print(subtensor.does_hotkey_exist(HOTKEY)) - # print(subtensor.get_all_subnets_info()) - # print(subtensor.get_balance(COLDKEY)) - # print(subtensor.get_balances(COLDKEY)) - - # print(current_block := subtensor.get_current_block()) - - # print(subtensor._get_block_hash(current_block)) - # print(subtensor.get_block_hash(current_block)) - # print(subtensor.get_children(HOTKEY, 1)) # maybe not working - # print(subtensor.get_metagraph_info(1)) - # print(subtensor.subnet(1)) - # print(subtensor.get_all_metagraphs_info()) - # print(subtensor.get_netuids_for_hotkey(HOTKEY)) - # print(subtensor.get_neuron_certificate()) # untested - # print(subtensor.get_neuron_for_pubkey_and_subnet(HOTKEY, HOTKEY_NETUIDS[1])) - # print(subtensor.get_stake(COLDKEY, HOTKEY, HOTKEY_NETUIDS[1])) - # print(subtensor.get_stake_for_coldkey_and_hotkey(COLDKEY, HOTKEY, HOTKEY_NETUIDS)) - # print(subtensor.get_stake_for_coldkey(COLDKEY)) - # print(type(subtensor.get_subnet_burn_cost())) - - # print(subtensor.get_subnet_hyperparameters(111)) - # print(subtensor.get_subnets(block=current_block-20)) - # print(subtensor.get_total_stake_for_hotkey(HOTKEY)) - # print(subtensor.get_total_subnets()) - # print(subtensor.get_transfer_fee(wallet=wallet, dest=COLDKEY, value=tao(1.0))) - # print(subtensor.get_uid_for_hotkey_on_subnet(HOTKEY, HOTKEY_NETUIDS[1])) - # print(subtensor.immunity_period(HOTKEY_NETUIDS[1])) - # print(subtensor.is_hotkey_delegate(COLDKEY)) - # print(subtensor.is_hotkey_registered(HOTKEY, HOTKEY_NETUIDS[1])) - # print(subtensor.is_hotkey_registered_any(HOTKEY)) - # print(subtensor.is_hotkey_registered_on_subnet(HOTKEY, HOTKEY_NETUIDS[1])) - # print(subtensor.last_drand_round()) - # print(subtensor.max_weight_limit(HOTKEY_NETUIDS[1])) - # print(subtensor.metagraph(HOTKEY_NETUIDS[1], lite=True)) - # print(subtensor.metagraph(HOTKEY_NETUIDS[1], lite=False)) - # print(subtensor.min_allowed_weights(HOTKEY_NETUIDS[1])) - # print(subtensor.neuron_for_uid(1, HOTKEY_NETUIDS[1])) - # print(subtensor.neurons(HOTKEY_NETUIDS[1])) - # print(subtensor.neurons_lite(HOTKEY_NETUIDS[1])) - # print(subtensor.query_identity(HOTKEY)) - # print(subtensor.recycle(HOTKEY_NETUIDS[1])) - # print(subtensor.subnet_exists(2)) - # print(subtensor.subnet_exists(200)) - # print(subtensor.subnetwork_n(HOTKEY_NETUIDS[1])) - # print(subtensor.tempo(HOTKEY_NETUIDS[1])) - # print(subtensor.tx_rate_limit()) - # print(subtensor.wait_for_block()) - # print(subtensor.wait_for_block(current_block+5)) - # for subnet in subtensor.get_subnets(): - # print(subtensor.weights(subnet)) - # print(subtensor.weights_rate_limit(HOTKEY_NETUIDS[1])) - print(block := subtensor.block) - # for uid in range(0, 7): - # print(subtensor.get_commitment(2, uid, block=block)) - # print(subtensor.get_current_weight_commit_info(1)) - # print(subtensor.get_delegate_by_hotkey(HOTKEY)) - # print(subtensor.get_delegate_identities()) - # print(subtensor.get_delegate_take("5GP7c3fFazW9GXK8Up3qgu2DJBk8inu4aK9TZy3RuoSWVCMi", block=block)) - # print(subtensor.get_delegated(COLDKEY, block=block)) - # print(subtensor.get_delegates(block=block)) - # print(subtensor.get_existential_deposit(block=block)) - # print(subtensor.get_hotkey_owner("5DcpkDYwWHgtkhLhKFCMqTQeU1ggRKjQEoLCf1e3X47VxZzw")) - # print(subtensor.get_minimum_required_stake()) - - -if __name__ == "__main__": - main() From c117432e78535474c433826519af5b6859ce798c Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 14 Mar 2025 18:33:13 -0700 Subject: [PATCH 27/32] clean up --- .github/workflows/e2e-subtensor-tests.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yaml b/.github/workflows/e2e-subtensor-tests.yaml index 86c7f0f928..97df3354be 100644 --- a/.github/workflows/e2e-subtensor-tests.yaml +++ b/.github/workflows/e2e-subtensor-tests.yaml @@ -78,11 +78,6 @@ jobs: - name: Check-out repository uses: actions/checkout@v4 -# - name: Install Python -# uses: actions/setup-python@v4 -# with: -# python-version: '3.12' - - name: Install uv uses: astral-sh/setup-uv@v4 @@ -97,10 +92,5 @@ jobs: - name: Load Docker Image run: docker load -i subtensor-localnet.tar -# - name: Install requirements -# run: | -# pip install -e .[dev] -# pip install pytest - - name: Run tests run: uv run pytest ${{ matrix.test-file }} -s From 0ac6ffc522731329e607fa829182369a543301a1 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Mar 2025 11:45:37 -0700 Subject: [PATCH 28/32] fix comments + new logic --- tests/e2e_tests/conftest.py | 84 +++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index b93c42daf2..a9037ee127 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -1,19 +1,19 @@ import os import re -import shutil import shlex +import shutil import signal import subprocess import sys import threading import time -from bittensor.utils.btlogging import logging import pytest from async_substrate_interface import SubstrateInterface from bittensor.core.async_subtensor import AsyncSubtensor from bittensor.core.subtensor import Subtensor +from bittensor.utils.btlogging import logging from tests.e2e_tests.utils.e2e_test_utils import ( Templates, setup_wallet, @@ -55,24 +55,24 @@ def local_chain(request): """Determines whether to run the localnet.sh script in a subprocess or a Docker container.""" args = request.param if hasattr(request, "param") else None params = "" if args is None else f"{args}" - if shutil.which("docker"): + if shutil.which("docker") and not os.getenv("USE_DOCKER") == "0": yield from docker_runner(params) - return - - if sys.platform.startswith("linux"): - docker_commend = ( - "Install docker with command " - "[blue]sudo apt-get update && sudo apt-get install docker.io -y[/blue]" - ) - elif sys.platform == "darwin": - docker_commend = "Install docker with command [blue]brew install docker[/blue]" else: - docker_commend = "[blue]Unknown OS, install Docker manually: https://docs.docker.com/get-docker/[/blue]" - - logging.warning("Docker not found in the operating system!") - logging.warning(docker_commend) - logging.warning("Tests are run in legacy mode.") - yield from legacy_runner(request) + if not os.getenv("USE_DOCKER") == "0": + if sys.platform.startswith("linux"): + docker_command = ( + "Install docker with command " + "[blue]sudo apt-get update && sudo apt-get install docker.io -y[/blue]" + ) + elif sys.platform == "darwin": + docker_command = "Install docker with command [blue]brew install docker[/blue] or use documentation [blue]https://docs.docker.com/engine/install/[/blue]" + else: + docker_command = "[blue]Unknown OS, install Docker manually: https://docs.docker.com/get-docker/[/blue]" + + logging.warning("Docker not found in the operating system!") + logging.warning(docker_command) + logging.warning("Tests are run in legacy mode.") + yield from legacy_runner(request) def legacy_runner(params): @@ -103,7 +103,8 @@ def legacy_runner(params): except TimeoutError: raise else: - yield SubstrateInterface(url="ws://127.0.0.1:9944") + with SubstrateInterface(url="ws://127.0.0.1:9944") as substrate: + yield substrate finally: # Terminate the process group (includes all child processes) os.killpg(os.getpgid(process.pid), signal.SIGTERM) @@ -119,6 +120,44 @@ def legacy_runner(params): def docker_runner(params): """Starts a Docker container before tests and gracefully terminates it after.""" + def is_docker_running(): + """Check if Docker has been run.""" + try: + subprocess.run( + ["docker", "info"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True, + ) + return True + except subprocess.CalledProcessError: + return False + + def try_start_docker(): + """Run docker based on OS.""" + try: + subprocess.run(["open", "-a", "Docker"], check=True) # macOS + except FileNotFoundError: + try: + subprocess.run(["systemctl", "start", "docker"], check=True) # Linux + except FileNotFoundError: + try: + subprocess.run( + ["sudo", "service", "docker", "start"], check=True + ) # Linux alternative + except FileNotFoundError: + print("Failed to start Docker. Manual start may be required.") + return False + + # Wait Docker run 10 attempts with 3 sec waits + for _ in range(10): + if is_docker_running(): + return True + time.sleep(3) + + print("Docker wasn't run. Manual start may be required.") + return False + container_name = f"test_local_chain_{str(time.time()).replace(".", "_")}" image_name = "ghcr.io/opentensor/subtensor-localnet:latest" @@ -137,6 +176,8 @@ def docker_runner(params): params, ] + try_start_docker() + # Start container with subprocess.Popen( cmds, @@ -147,7 +188,7 @@ def docker_runner(params): ) as process: try: try: - wait_for_node_start(process, int(time.time())) + wait_for_node_start(process, timestamp=int(time.time())) except TimeoutError: raise @@ -159,7 +200,8 @@ def docker_runner(params): if not result.stdout.strip(): raise RuntimeError("Docker container failed to start.") - yield SubstrateInterface(url="ws://127.0.0.1:9944") + with SubstrateInterface(url="ws://127.0.0.1:9944") as substrate: + yield substrate finally: try: From 9a2c53173d59267a54d28eb4d0313b611a83fa35 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Mar 2025 11:46:04 -0700 Subject: [PATCH 29/32] update README.md --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 109a321030..8de9667c7d 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,49 @@ The Python interpreter output will look like below. >>> ``` +### Testing +You can run integration and unit tests in interactive mode of IDE or in terminal mode using the command: +```bash +pytest tests/integration_tests +pytest tests/unit_tests +``` + +#### E2E tests have 2 options for launching (legacy runner): +- using a compiler based on the substrait code +- using an already built docker image (docker runner) + +#### Using `docker runner` (default for now): +- E2E tests with docker image do not require preliminary compilation +- are executed very quickly +- require docker installed in OS + +Ho to use: +```bash +pytest tests/e2e_tests +``` + +#### TUsing `legacy runner`: +- Will start compilation of the collected code in your subtensor repository +- you must provide the `LOCALNET_SH_PATH` variable in the local environment with the path to the file `/scripts/localnet.sh` in the cloned repository within your OS +- you can use the `BUILD_BINARY=0` variable, this will skip the copy step for each test. +- you can use the `USE_DOCKER=0` variable, this will run tests using the "legacy runner", even if docker is installed in your OS + +#### Ho to use: +Regular e2e tests run +```bash +LOCALNET_SH_PATH=/path/to/your/localnet.sh pytest tests/e2e_tests +``` + +If you want to skip re-build process for each e2e test +```bash +BUILD_BINARY=0 LOCALNET_SH_PATH=/path/to/your/localnet.sh pytest tests/e2e_tests +``` + +If you want to use legacy runner even with installed Docker in your OS +```bash +USE_DOCKER=0 BUILD_BINARY=0 LOCALNET_SH_PATH=/path/to/your/localnet.sh pytest tests/e2e_tests +``` + --- ## Release Guidelines From ef8798648076eac260ef333c5ed1ec69f95ff850 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Mar 2025 11:48:17 -0700 Subject: [PATCH 30/32] refactor --- tests/e2e_tests/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index a9037ee127..d0b270cf65 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -63,9 +63,10 @@ def local_chain(request): docker_command = ( "Install docker with command " "[blue]sudo apt-get update && sudo apt-get install docker.io -y[/blue]" + " or use documentation [blue]https://docs.docker.com/engine/install/[/blue]" ) elif sys.platform == "darwin": - docker_command = "Install docker with command [blue]brew install docker[/blue] or use documentation [blue]https://docs.docker.com/engine/install/[/blue]" + docker_command = "Install docker with command [blue]brew install docker[/blue]" else: docker_command = "[blue]Unknown OS, install Docker manually: https://docs.docker.com/get-docker/[/blue]" From 5022a5febc37ed274158ee5ccbb17d3cb7af0e82 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Mar 2025 11:48:25 -0700 Subject: [PATCH 31/32] ruff --- tests/e2e_tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index d0b270cf65..fd36947885 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -66,7 +66,9 @@ def local_chain(request): " or use documentation [blue]https://docs.docker.com/engine/install/[/blue]" ) elif sys.platform == "darwin": - docker_command = "Install docker with command [blue]brew install docker[/blue]" + docker_command = ( + "Install docker with command [blue]brew install docker[/blue]" + ) else: docker_command = "[blue]Unknown OS, install Docker manually: https://docs.docker.com/get-docker/[/blue]" From a23f2cd60be4fc47ab9fa55c38858f0b5b4fee03 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Mar 2025 11:51:38 -0700 Subject: [PATCH 32/32] fix except --- tests/e2e_tests/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index fd36947885..51a865b1b8 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -140,15 +140,15 @@ def try_start_docker(): """Run docker based on OS.""" try: subprocess.run(["open", "-a", "Docker"], check=True) # macOS - except FileNotFoundError: + except (FileNotFoundError, subprocess.CalledProcessError): try: subprocess.run(["systemctl", "start", "docker"], check=True) # Linux - except FileNotFoundError: + except (FileNotFoundError, subprocess.CalledProcessError): try: subprocess.run( ["sudo", "service", "docker", "start"], check=True ) # Linux alternative - except FileNotFoundError: + except (FileNotFoundError, subprocess.CalledProcessError): print("Failed to start Docker. Manual start may be required.") return False