Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcoin.conf autodetection - additional tests for edge-cases #2084

Merged
merged 7 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/misc_testdata/rpc_autodetection/example2/bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
maxmempool=700
server=1
prune=700
[main]
[test]
[regtest]
prune=0
zmqpubrawblock=tcp://127.0.0.1:29000
zmqpubrawtx=tcp://127.0.0.1:29000
zmqpubhashtx=tcp://127.0.0.1:29000
zmqpubhashblock=tcp://127.0.0.1:29000
67 changes: 61 additions & 6 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def __init__(self, status_code, json, headers):
self.encoding = None


def test_get_rpcconfig(empty_data_folder):
def test_get_rpcconfig0(empty_data_folder):
c = _get_rpcconfig(empty_data_folder)
assert c["bitcoin.conf"]["default"] == {}
assert c["bitcoin.conf"]["main"] == {}
assert c["bitcoin.conf"]["regtest"] == {}
assert c["bitcoin.conf"]["test"] == {}
c = _get_rpcconfig("./tests/misc_testdata")


def test_get_rpcconfig1():
c = _get_rpcconfig("./tests/misc_testdata/rpc_autodetection/example1")
# Looks like this:
# regtest=1
# rpcconnect=bitcoin
Expand All @@ -57,8 +60,41 @@ def test_get_rpcconfig(empty_data_folder):
}


def test_detect_rpc_confs_via_datadir(empty_data_folder):
c = _detect_rpc_confs_via_datadir(datadir="./tests/misc_testdata")
def test_get_rpcconfig2(empty_data_folder):
c = _get_rpcconfig("./tests/misc_testdata/rpc_autodetection/example2")
# maxmempool=700
# server=1
# prune=700
# [main]
# [test]
# [regtest]
# prune=0
# zmqpubrawblock=tcp://127.0.0.1:29000
# zmqpubrawtx=tcp://127.0.0.1:29000
# zmqpubhashtx=tcp://127.0.0.1:29000
# zmqpubhashblock=tcp://127.0.0.1:29000
assert c["bitcoin.conf"] == {
"default": {
"maxmempool": "700",
"server": "1",
"prune": "700",
},
"main": {},
"regtest": {
"prune": "0",
"zmqpubrawblock": "tcp://127.0.0.1:29000",
"zmqpubrawtx": "tcp://127.0.0.1:29000",
"zmqpubhashtx": "tcp://127.0.0.1:29000",
"zmqpubhashblock": "tcp://127.0.0.1:29000",
},
"test": {},
}


def test_detect_rpc_confs_via_datadir1(empty_data_folder):
c = _detect_rpc_confs_via_datadir(
datadir="./tests/misc_testdata/rpc_autodetection/example1"
)
# Looks like this:
# regtest=1
# rpcconnect=bitcoin
Expand All @@ -72,6 +108,25 @@ def test_detect_rpc_confs_via_datadir(empty_data_folder):
]


def test_detect_rpc_confs_via_datadir2(caplog, empty_data_folder):
caplog.set_level(logging.DEBUG)
c = _detect_rpc_confs_via_datadir(
datadir="./tests/misc_testdata/rpc_autodetection/example2"
)
# maxmempool=700
# server=1
# prune=700
# [main]
# [test]
# [regtest]
# prune=0
# zmqpubrawblock=tcp://127.0.0.1:29000
# zmqpubrawtx=tcp://127.0.0.1:29000
# zmqpubhashtx=tcp://127.0.0.1:29000
# zmqpubhashblock=tcp://127.0.0.1:29000
assert c == []


def test_RpcError_response(caplog):
caplog.set_level(logging.DEBUG)
# Creating an RpcError with a Response object
Expand Down Expand Up @@ -172,6 +227,7 @@ def test_BitcoinRpc_methodNotExisting(rpc):
def test_BitcoinRpc_walletNotExisting(rpc):
# Errorhandling:
rpc = rpc.wallet("SomeWallet")
rpc.timeout = 0.1
try:
rpc.getwalletinfo()
except RpcError as rpce:
Expand All @@ -181,8 +237,8 @@ def test_BitcoinRpc_walletNotExisting(rpc):


def test_BitcoinRpc_timeout(rpc, caplog):
rpc.timeout = 0.001
try:
BitcoinRPC.default_timeout = 0.001
with pytest.raises(SpecterError) as se:
rpc.createwallet("some_test_wallet_name_392")
assert "Timeout after 0.001" in str(se.value)
Expand All @@ -203,7 +259,6 @@ def test_BitcoinRpc_timeout(rpc, caplog):
@pytest.fixture
def rpc(bitcoin_regtest):
brt = bitcoin_regtest # stupid long name
BitcoinRPC.default_timeout = 0.001
rpc = BitcoinRPC(
brt.rpcconn.rpcuser,
brt.rpcconn.rpcpassword,
Expand Down