mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
test: Allow pathlib.Path as RPC argument via authproxy
Also, add datadir_path property to TestNode
This commit is contained in:
parent
fa41614a0a
commit
dddd89962b
4 changed files with 13 additions and 10 deletions
|
@ -52,7 +52,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
|
|||
# Specifying a path to an existing or invalid file will fail.
|
||||
assert_raises_rpc_error(
|
||||
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
|
||||
invalid_path = str(Path(node.datadir) / "invalid" / "path")
|
||||
invalid_path = node.datadir_path / "invalid" / "path"
|
||||
assert_raises_rpc_error(
|
||||
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path)
|
||||
|
||||
|
|
|
@ -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,9 +407,13 @@ 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:
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue