3939 imperative to do so
4040 - the websocket logger will include the id of the request: these should be stripped away, as they are dynamically
4141 created in SubstrateInterface, and then attached to the next response by FakeWebsocket
42- """
42+ """
43+
44+ import logging
45+
46+ from async_substrate_interface .sync_substrate import (
47+ raw_websocket_logger ,
48+ SubstrateInterface ,
49+ )
50+ from bittensor .core .subtensor import Subtensor
51+
52+ from bittensor .core .settings import LATENT_LITE_ENTRYPOINT
53+
54+ RAW_WS_LOG = "/tmp/bittensor-raw-ws.log"
55+ OUTPUT_DIR = "/tmp/bittensor-ws-output.txt"
56+
57+
58+ def main (seed : str , method : str , * args , ** kwargs ):
59+ """
60+ Runs the given method on Subtensor, processes the websocket data that occurred during that method's execution,
61+ attaches it with the "seed" arg as a key to a new tmp file ("/tmp/bittensor-ws-output.txt")
62+
63+ This data should then be manually added to the `bittensor/tests/helpers/integration_websocket_data.py` file
64+
65+ While we could automate this, I think it could potentially cause users to accidentally run and then submit this as
66+ part of a PR.
67+
68+ """
69+ raw_websocket_logger .setLevel (logging .DEBUG )
70+ handler = logging .FileHandler (RAW_WS_LOG )
71+ handler .setLevel (logging .DEBUG )
72+ raw_websocket_logger .addHandler (handler )
73+
74+ # we're essentially throwing away Subtensor's underlying Substrate connection, because there's no way to
75+ # initialize it with `_log_raw_websockets=True` from Subtensor (nor should there be)
76+ subtensor = Subtensor (LATENT_LITE_ENTRYPOINT )
77+ subtensor .substrate .close ()
78+ subtensor .substrate = SubstrateInterface (
79+ LATENT_LITE_ENTRYPOINT ,
80+ chain_name = "Bittensor" ,
81+ ss58_format = 42 ,
82+ _log_raw_websockets = True ,
83+ )
84+
85+ executor = getattr (subtensor , method )
86+ result = executor (* args , ** kwargs )
87+ print (result )
88+
89+ subtensor .close ()
90+ raw_websocket_logger .removeHandler (handler )
91+
92+ with open (RAW_WS_LOG , "r" ) as f :
93+ all_ws_data = f .readlines ()
0 commit comments