|
| 1 | +from bittensor.core.subtensor import Subtensor |
| 2 | +from bittensor.core.subtensor_api import SubtensorApi |
| 3 | + |
| 4 | + |
| 5 | +def test_properties_methods_comparable(): |
| 6 | + """Verifies that methods in SubtensorApi and its properties contains all Subtensors methods.""" |
| 7 | + # Preps |
| 8 | + subtensor = Subtensor(_mock=True) |
| 9 | + subtensor_api = SubtensorApi(_mock=True) |
| 10 | + |
| 11 | + subtensor_methods = [m for m in dir(subtensor) if not m.startswith("_")] |
| 12 | + |
| 13 | + excluded_subtensor_methods = ["commit"] |
| 14 | + |
| 15 | + subtensor_api_methods = [m for m in dir(subtensor_api) if not m.startswith("_")] |
| 16 | + chain_methods = [m for m in dir(subtensor_api.chain) if not m.startswith("_")] |
| 17 | + commitments_methods = [ |
| 18 | + m for m in dir(subtensor_api.commitments) if not m.startswith("_") |
| 19 | + ] |
| 20 | + delegates_methods = [ |
| 21 | + m for m in dir(subtensor_api.delegates) if not m.startswith("_") |
| 22 | + ] |
| 23 | + extrinsics_methods = [ |
| 24 | + m for m in dir(subtensor_api.extrinsics) if not m.startswith("_") |
| 25 | + ] |
| 26 | + metagraphs_methods = [ |
| 27 | + m for m in dir(subtensor_api.metagraphs) if not m.startswith("_") |
| 28 | + ] |
| 29 | + neurons_methods = [m for m in dir(subtensor_api.neurons) if not m.startswith("_")] |
| 30 | + queries_methods = [m for m in dir(subtensor_api.queries) if not m.startswith("_")] |
| 31 | + stakes_methods = [m for m in dir(subtensor_api.stakes) if not m.startswith("_")] |
| 32 | + subnets_methods = [m for m in dir(subtensor_api.subnets) if not m.startswith("_")] |
| 33 | + wallets_methods = [m for m in dir(subtensor_api.wallets) if not m.startswith("_")] |
| 34 | + |
| 35 | + all_subtensor_api_methods = ( |
| 36 | + subtensor_api_methods |
| 37 | + + chain_methods |
| 38 | + + commitments_methods |
| 39 | + + delegates_methods |
| 40 | + + extrinsics_methods |
| 41 | + + metagraphs_methods |
| 42 | + + neurons_methods |
| 43 | + + queries_methods |
| 44 | + + stakes_methods |
| 45 | + + subnets_methods |
| 46 | + + wallets_methods |
| 47 | + ) |
| 48 | + |
| 49 | + # Assertions |
| 50 | + for method in subtensor_methods: |
| 51 | + # skipp excluded methods |
| 52 | + if method in excluded_subtensor_methods: |
| 53 | + continue |
| 54 | + assert method in all_subtensor_api_methods, ( |
| 55 | + f"`Subtensor.{method}`is not present in class `SubtensorApi`." |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def test__methods_comparable_with_passed_subtensor_fields(): |
| 60 | + """Verifies that methods in SubtensorApi contains all Subtensors methods if `subtensor_fields=True` is passed.""" |
| 61 | + # Preps |
| 62 | + subtensor = Subtensor(_mock=True) |
| 63 | + subtensor_api = SubtensorApi(_mock=True, subtensor_fields=True) |
| 64 | + |
| 65 | + subtensor_methods = [m for m in dir(subtensor) if not m.startswith("_")] |
| 66 | + subtensor_api_methods = [m for m in dir(subtensor_api) if not m.startswith("_")] |
| 67 | + |
| 68 | + excluded_subtensor_methods = ["commit"] |
| 69 | + |
| 70 | + # Assertions |
| 71 | + for method in subtensor_methods: |
| 72 | + # skipp excluded methods |
| 73 | + if method in excluded_subtensor_methods: |
| 74 | + continue |
| 75 | + assert method in subtensor_api_methods, ( |
| 76 | + f"`Subtensor.{method}`is not present in class `SubtensorApi`." |
| 77 | + ) |
0 commit comments