func test: allow for different bitcoin backends
This commit is contained in:
parent
1b04b29491
commit
a85d4887e9
@ -5,7 +5,12 @@ from concurrent import futures
|
||||
from test_framework.bitcoind import Bitcoind
|
||||
from test_framework.lianad import Lianad
|
||||
from test_framework.signer import SingleSigner, MultiSigner
|
||||
from test_framework.utils import EXECUTOR_WORKERS, USE_TAPROOT
|
||||
from test_framework.utils import (
|
||||
BITCOIN_BACKEND_TYPE,
|
||||
EXECUTOR_WORKERS,
|
||||
USE_TAPROOT,
|
||||
BitcoinBackendType,
|
||||
)
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
@ -115,6 +120,16 @@ def bitcoind(directory):
|
||||
bitcoind.cleanup()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bitcoin_backend(directory, bitcoind):
|
||||
|
||||
if BITCOIN_BACKEND_TYPE is BitcoinBackendType.Bitcoind:
|
||||
yield bitcoind
|
||||
bitcoind.cleanup()
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def xpub_fingerprint(hd):
|
||||
return _pubkey_to_fingerprint(hd.pubkey).hex()
|
||||
|
||||
@ -127,10 +142,9 @@ def single_key_desc(prim_fg, prim_xpub, reco_fg, reco_xpub, csv_value, is_taproo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lianad(bitcoind, directory):
|
||||
def lianad(bitcoin_backend, directory):
|
||||
datadir = os.path.join(directory, "lianad")
|
||||
os.makedirs(datadir, exist_ok=True)
|
||||
bitcoind_cookie = os.path.join(bitcoind.bitcoin_dir, "regtest", ".cookie")
|
||||
|
||||
signer = SingleSigner(is_taproot=USE_TAPROOT)
|
||||
(prim_fingerprint, primary_xpub), (reco_fingerprint, recovery_xpub) = (
|
||||
@ -155,8 +169,7 @@ def lianad(bitcoind, directory):
|
||||
datadir,
|
||||
signer,
|
||||
main_desc,
|
||||
bitcoind.rpcport,
|
||||
bitcoind_cookie,
|
||||
bitcoin_backend,
|
||||
)
|
||||
|
||||
try:
|
||||
@ -208,10 +221,9 @@ def multisig_desc(multi_signer, csv_value, is_taproot):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lianad_multisig(bitcoind, directory):
|
||||
def lianad_multisig(bitcoin_backend, directory):
|
||||
datadir = os.path.join(directory, "lianad")
|
||||
os.makedirs(datadir, exist_ok=True)
|
||||
bitcoind_cookie = os.path.join(bitcoind.bitcoin_dir, "regtest", ".cookie")
|
||||
|
||||
# A 3-of-4 that degrades into a 2-of-5 after 10 blocks
|
||||
csv_value = 10
|
||||
@ -224,8 +236,7 @@ def lianad_multisig(bitcoind, directory):
|
||||
datadir,
|
||||
signer,
|
||||
main_desc,
|
||||
bitcoind.rpcport,
|
||||
bitcoind_cookie,
|
||||
bitcoin_backend,
|
||||
)
|
||||
|
||||
try:
|
||||
@ -261,10 +272,9 @@ def multipath_desc(multi_signer, csv_values, is_taproot):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lianad_multipath(bitcoind, directory):
|
||||
def lianad_multipath(bitcoin_backend, directory):
|
||||
datadir = os.path.join(directory, "lianad")
|
||||
os.makedirs(datadir, exist_ok=True)
|
||||
bitcoind_cookie = os.path.join(bitcoind.bitcoin_dir, "regtest", ".cookie")
|
||||
|
||||
# A 3-of-4 that degrades into a 3-of-5 after 10 blocks and into a 1-of-10 after 20 blocks.
|
||||
csv_values = [10, 20]
|
||||
@ -279,8 +289,7 @@ def lianad_multipath(bitcoind, directory):
|
||||
datadir,
|
||||
signer,
|
||||
main_desc,
|
||||
bitcoind.rpcport,
|
||||
bitcoind_cookie,
|
||||
bitcoin_backend,
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@ -7,7 +7,14 @@ import time
|
||||
from decimal import Decimal
|
||||
from ephemeral_port_reserve import reserve
|
||||
from test_framework.authproxy import AuthServiceProxy
|
||||
from test_framework.utils import TailableProc, wait_for, TIMEOUT, BITCOIND_PATH, COIN
|
||||
from test_framework.utils import (
|
||||
BitcoinBackend,
|
||||
TailableProc,
|
||||
wait_for,
|
||||
TIMEOUT,
|
||||
BITCOIND_PATH,
|
||||
COIN,
|
||||
)
|
||||
|
||||
|
||||
class BitcoindRpcInterface:
|
||||
@ -35,7 +42,7 @@ class BitcoindRpcInterface:
|
||||
return f
|
||||
|
||||
|
||||
class Bitcoind(TailableProc):
|
||||
class Bitcoind(BitcoinBackend):
|
||||
def __init__(self, bitcoin_dir, rpcport=None):
|
||||
TailableProc.__init__(self, bitcoin_dir, verbose=False)
|
||||
|
||||
@ -275,3 +282,10 @@ class Bitcoind(TailableProc):
|
||||
except Exception:
|
||||
self.proc.kill()
|
||||
self.proc.wait()
|
||||
|
||||
def append_to_lianad_conf(self, conf_file):
|
||||
cookie_path = os.path.join(self.bitcoin_dir, "regtest", ".cookie")
|
||||
with open(conf_file, "a") as f:
|
||||
f.write("[bitcoind_config]\n")
|
||||
f.write(f"cookie_path = '{cookie_path}'\n")
|
||||
f.write(f"addr = '127.0.0.1:{self.rpcport}'\n")
|
||||
|
||||
@ -28,8 +28,7 @@ class Lianad(TailableProc):
|
||||
datadir,
|
||||
signer,
|
||||
multi_desc,
|
||||
bitcoind_rpc_port,
|
||||
bitcoind_cookie_path,
|
||||
bitcoin_backend,
|
||||
):
|
||||
TailableProc.__init__(self, datadir, verbose=VERBOSE)
|
||||
|
||||
@ -55,10 +54,7 @@ class Lianad(TailableProc):
|
||||
f.write("[bitcoin_config]\n")
|
||||
f.write('network = "regtest"\n')
|
||||
f.write("poll_interval_secs = 1\n")
|
||||
|
||||
f.write("[bitcoind_config]\n")
|
||||
f.write(f"cookie_path = '{bitcoind_cookie_path}'\n")
|
||||
f.write(f"addr = '127.0.0.1:{bitcoind_rpc_port}'\n")
|
||||
bitcoin_backend.append_to_lianad_conf(self.conf_file)
|
||||
|
||||
def finalize_psbt(self, psbt):
|
||||
"""Create a valid witness for all inputs in the PSBT.
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import abc
|
||||
import enum
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
@ -20,6 +22,16 @@ DEFAULT_MS_PATH = os.path.join(
|
||||
os.path.dirname(__file__), "..", "..", "target/debug/lianad"
|
||||
)
|
||||
LIANAD_PATH = os.getenv("LIANAD_PATH", DEFAULT_MS_PATH)
|
||||
|
||||
|
||||
class BitcoinBackendType(str, enum.Enum):
|
||||
Bitcoind = "bitcoind"
|
||||
|
||||
|
||||
DEFAULT_BITCOIN_BACKEND_TYPE = "bitcoind"
|
||||
BITCOIN_BACKEND_TYPE = BitcoinBackendType(
|
||||
os.getenv("BITCOIN_BACKEND_TYPE", DEFAULT_BITCOIN_BACKEND_TYPE)
|
||||
)
|
||||
DEFAULT_BITCOIND_PATH = "bitcoind"
|
||||
BITCOIND_PATH = os.getenv("BITCOIND_PATH", DEFAULT_BITCOIND_PATH)
|
||||
OLD_LIANAD_PATH = os.getenv("OLD_LIANAD_PATH", None)
|
||||
@ -421,3 +433,12 @@ class TailableProc(object):
|
||||
Convenience wrapper for the common case of only seeking a single entry.
|
||||
"""
|
||||
return self.wait_for_logs([regex], timeout)
|
||||
|
||||
|
||||
class BitcoinBackend(abc.ABC, TailableProc):
|
||||
"""All Bitcoin backends should derive from this class."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def append_to_lianad_conf(self, conf_file):
|
||||
"""Append backend config values to lianad config file."""
|
||||
...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user