mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge bitcoin/bitcoin#27884: test: Use TestNode datadir_path or chain_path where possible
aaaa3aefbdtest: Use TestNode *_path properties where possible (MarcoFalke)dddd89962btest: Allow pathlib.Path as RPC argument via authproxy (MarcoFalke)fa41614a0ascripted-diff: Use wallets_path and chain_path where possible (MarcoFalke)fa493fadfbtest: Use wallet_dir lambda in wallet_multiwallet test where possible (MarcoFalke) Pull request description: It seems inconsistent, fragile and verbose to: * Call `get_datadir_path` to recreate the path that already exists as field in TestNode * Call `os.path.join` with the hardcoded chain name or `self.chain` to recreate the TestNode `chain_path` property * Sometimes even use the hardcoded node dir name (`"node0"`) Fix all issues by using the TestNode properties. ACKs for top commit: willcl-ark: re-ACKaaaa3aefbdtheStack: Code-review ACKaaaa3aefbd🌊 Tree-SHA512: e4720278085beb8164e1fe6c1aa18f601558a9263494ce69a83764c1487007de63ebb51d1b1151862dc4d5b49ded6162a5c1553cd30ea1c28627d447db4d8e72
This commit is contained in:
@@ -39,6 +39,7 @@ from http import HTTPStatus
|
||||
import http.client
|
||||
import json
|
||||
import logging
|
||||
import pathlib
|
||||
import socket
|
||||
import time
|
||||
import urllib.parse
|
||||
@@ -62,6 +63,8 @@ class JSONRPCException(Exception):
|
||||
def EncodeDecimal(o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
return str(o)
|
||||
if isinstance(o, pathlib.Path):
|
||||
return str(o)
|
||||
raise TypeError(repr(o) + " is not JSON serializable")
|
||||
|
||||
class AuthServiceProxy():
|
||||
|
||||
@@ -22,7 +22,10 @@ import shlex
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .authproxy import JSONRPCException
|
||||
from .authproxy import (
|
||||
JSONRPCException,
|
||||
EncodeDecimal,
|
||||
)
|
||||
from .descriptors import descsum_create
|
||||
from .p2p import P2P_SUBVERSION
|
||||
from .util import (
|
||||
@@ -35,7 +38,6 @@ from .util import (
|
||||
rpc_url,
|
||||
wait_until_helper,
|
||||
p2p_port,
|
||||
EncodeDecimal,
|
||||
)
|
||||
|
||||
BITCOIND_PROC_WAIT_TIMEOUT = 60
|
||||
@@ -405,14 +407,22 @@ class TestNode():
|
||||
with open(self.bitcoinconf, 'w', encoding='utf8') as conf:
|
||||
conf.write(conf_data)
|
||||
|
||||
@property
|
||||
def datadir_path(self) -> Path:
|
||||
return Path(self.datadir)
|
||||
|
||||
@property
|
||||
def chain_path(self) -> Path:
|
||||
return Path(self.datadir) / self.chain
|
||||
return self.datadir_path / self.chain
|
||||
|
||||
@property
|
||||
def debug_log_path(self) -> Path:
|
||||
return self.chain_path / 'debug.log'
|
||||
|
||||
@property
|
||||
def wallets_path(self) -> Path:
|
||||
return self.chain_path / "wallets"
|
||||
|
||||
def debug_log_bytes(self) -> int:
|
||||
with open(self.debug_log_path, encoding='utf-8') as dl:
|
||||
dl.seek(0, 2)
|
||||
|
||||
@@ -211,12 +211,6 @@ def check_json_precision():
|
||||
raise RuntimeError("JSON encode/decode loses precision")
|
||||
|
||||
|
||||
def EncodeDecimal(o):
|
||||
if isinstance(o, Decimal):
|
||||
return str(o)
|
||||
raise TypeError(repr(o) + " is not JSON serializable")
|
||||
|
||||
|
||||
def count_bytes(hex_string):
|
||||
return len(bytearray.fromhex(hex_string))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user