Skip to content

Commit e75ed88

Browse files
al-munazzimNazim
andauthored
fix: constrain CI dependencies (#64)
* fix: constrain CI dependencies * ci: wait for Nigiri RPC before integration tests * fix: support Bitcoin Core JSON-RPC responses without error field * test: relax Electrum ping timeout in integration test --------- Co-authored-by: Nazim <nazim@openclaw.ai> Co-authored-by: al-munazzim <al-munazzim@users.noreply.github.com>
1 parent 897629f commit e75ed88

5 files changed

Lines changed: 50 additions & 6 deletions

File tree

.github/workflows/nigiri-infra.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ jobs:
3232
uses: vulpemventures/nigiri-github-action@v1
3333
with:
3434
use_liquid: false
35+
- name: Wait for Bitcoin RPC
36+
run: |
37+
python3 - <<'PY'
38+
import json
39+
import time
40+
import urllib.error
41+
import urllib.request
42+
43+
url = "http://localhost:18443"
44+
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
45+
password_mgr.add_password(None, url, "admin1", "123")
46+
opener = urllib.request.build_opener(
47+
urllib.request.HTTPBasicAuthHandler(password_mgr)
48+
)
49+
payload = json.dumps({
50+
"jsonrpc": "2.0",
51+
"id": "ci-ready",
52+
"method": "getblockchaininfo",
53+
"params": [],
54+
}).encode()
55+
56+
deadline = time.time() + 120
57+
last_error = None
58+
while time.time() < deadline:
59+
try:
60+
request = urllib.request.Request(
61+
url,
62+
data=payload,
63+
headers={"content-type": "application/json"},
64+
)
65+
with opener.open(request, timeout=5) as response:
66+
result = json.loads(response.read())["result"]
67+
print("Bitcoin RPC ready:", result["chain"], result["blocks"])
68+
raise SystemExit(0)
69+
except Exception as exc:
70+
last_error = exc
71+
print("Waiting for Bitcoin RPC:", exc)
72+
time.sleep(2)
73+
74+
raise SystemExit(f"Bitcoin RPC did not become ready: {last_error}")
75+
PY
3576
- name: Run integration tests
3677
run: |
3778
pytest tests/integration/basics.py

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ test = [
5454
"mock",
5555
"black",
5656
"pre-commit",
57-
"bdkpython"
58-
]
57+
"Werkzeug<3",
58+
"bdkpython==0.32.1"
59+
]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
embit>=0.6.1
2-
Flask>=2.1.1
2+
Flask>=2.1.1,<2.3
33
Flask-SQLAlchemy==2.5.1
44
sqlalchemy>=1.4.42,<2.0
55
psycopg2-binary

src/cryptoadvance/spectrum/util_specter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ def trace_call_after(cls, url, payload, timestamp):
295295
def __getattr__(self, method):
296296
def fn(*args, **kwargs):
297297
r = self.multi([(method, *args)], **kwargs)[0]
298-
if r["error"] is not None:
298+
# Bitcoin Core 30.0 omits the JSON-RPC "error" field from successful
299+
# responses instead of returning "error": null.
300+
if r.get("error") is not None:
299301
raise Exception(
300302
f"Request error for method {method}{args}: {r['error']['message']}",
301303
r,

tests/integration/elsock_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def callback(something):
3535
port=50002,
3636
callback=callback,
3737
use_ssl=True,
38-
call_timeout=1,
38+
call_timeout=10,
3939
)
4040
ts = elsock.ping()
4141
logger.info(f"First working ping in {ts} ms")
@@ -80,7 +80,7 @@ def callback(something):
8080
logger.info(elsock._socket)
8181
ts = elsock.ping()
8282
logger.info(f"second working ping in {ts} ms")
83-
assert ts < 1
83+
assert ts < 10
8484
assert caplog.text.count("ElectrumSocket Status changed") == 9
8585

8686
assert (

0 commit comments

Comments
 (0)