mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-12 13:35:09 +02:00
Merge #17705: test: re-enable CLI test support by using EncodeDecimal in json.dumps()
b6f9e3576a
test: re-enable CLI test support by using EncodeDecimal in json.dumps() (fanquake) Pull request description: As mentioned in https://github.com/bitcoin/bitcoin/pull/17675#issuecomment-563188648. ACKs for top commit: practicalswift: ACKb6f9e3576a
assuming Travis is happy too -- diff looks correct :) MarcoFalke: > ACKb6f9e35
assuming Travis is happy too -- diff looks correct :) Tree-SHA512: 79fa535cc1756c8ee610a3d6a316a1c4f036797d6990a5620e44985393a2e52f78450f8e0021d0a148c08705fd1ba765508464a365f9030ae0d2cacbd7a93e19
This commit is contained in:
@ -30,6 +30,7 @@ from .util import (
|
||||
rpc_url,
|
||||
wait_until,
|
||||
p2p_port,
|
||||
EncodeDecimal,
|
||||
)
|
||||
|
||||
BITCOIND_PROC_WAIT_TIMEOUT = 60
|
||||
@ -489,7 +490,7 @@ def arg_to_cli(arg):
|
||||
if isinstance(arg, bool):
|
||||
return str(arg).lower()
|
||||
elif isinstance(arg, dict) or isinstance(arg, list):
|
||||
return json.dumps(arg)
|
||||
return json.dumps(arg, default=EncodeDecimal)
|
||||
else:
|
||||
return str(arg)
|
||||
|
||||
|
@ -190,6 +190,11 @@ def check_json_precision():
|
||||
if satoshis != 2000000000000003:
|
||||
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