-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
func test: allow to run using electrs backend
- Loading branch information
Showing
6 changed files
with
108 additions
and
0 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
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,72 @@ | ||
import logging | ||
import os | ||
|
||
from ephemeral_port_reserve import reserve | ||
from test_framework.utils import BitcoinBackend, TailableProc, ELECTRS_PATH | ||
|
||
|
||
class Electrs(BitcoinBackend): | ||
def __init__( | ||
self, | ||
bitcoind_dir, | ||
bitcoind_rpcport, | ||
bitcoind_p2pport, | ||
electrs_dir, | ||
rpcport=None, | ||
): | ||
TailableProc.__init__(self, electrs_dir, verbose=False) | ||
|
||
if rpcport is None: | ||
rpcport = reserve() | ||
|
||
self.electrs_dir = electrs_dir | ||
self.rpcport = rpcport | ||
|
||
regtestdir = os.path.join(electrs_dir, "regtest") | ||
if not os.path.exists(regtestdir): | ||
os.makedirs(regtestdir) | ||
|
||
self.cmd_line = [ | ||
ELECTRS_PATH, | ||
"--conf", | ||
"{}/electrs.toml".format(regtestdir), | ||
] | ||
electrs_conf = { | ||
"daemon_dir": bitcoind_dir, | ||
"cookie_file": os.path.join(bitcoind_dir, "regtest", ".cookie"), | ||
"daemon_rpc_addr": f"127.0.0.1:{bitcoind_rpcport}", | ||
"daemon_p2p_addr": f"127.0.0.1:{bitcoind_p2pport}", | ||
"db_dir": electrs_dir, | ||
"network": "regtest", | ||
"electrum_rpc_addr": f"127.0.0.1:{self.rpcport}", | ||
} | ||
self.conf_file = os.path.join(regtestdir, "electrs.toml") | ||
with open(self.conf_file, "w") as f: | ||
for k, v in electrs_conf.items(): | ||
f.write(f'{k} = "{v}"\n') | ||
|
||
def start(self): | ||
TailableProc.start(self) | ||
logging.info("Electrs started") | ||
|
||
def startup(self): | ||
try: | ||
self.start() | ||
except Exception: | ||
self.stop() | ||
raise | ||
|
||
def stop(self): | ||
return TailableProc.stop(self) | ||
|
||
def cleanup(self): | ||
try: | ||
self.stop() | ||
except Exception: | ||
self.proc.kill() | ||
self.proc.wait() | ||
|
||
def append_to_lianad_conf(self, conf_file): | ||
with open(conf_file, "a") as f: | ||
f.write("[electrum_config]\n") | ||
f.write(f"addr = '127.0.0.1:{self.rpcport}'\n") |
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
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