From c0aefad8e31900794fa13970f3d5ff271996cd68 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 14 Aug 2017 15:59:35 +0200 Subject: [PATCH] pytest: Add a small helper to run queries against the node's DB This should simplify checking that some actions have been persisted to DB. --- tests/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/utils.py b/tests/utils.py index 692b957af..645dd7af6 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -4,6 +4,7 @@ from lightning import LightningRpc import logging import os import re +import sqlite3 import subprocess import threading import time @@ -301,3 +302,17 @@ class LightningNode(object): self.bitcoin.rpc.generate(6) self.daemon.wait_for_log('-> CHANNELD_NORMAL|STATE_NORMAL') + def db_query(self, query): + db = sqlite3.connect(os.path.join(self.daemon.lightning_dir, "lightningd.sqlite3")) + db.row_factory = sqlite3.Row + c = db.cursor() + c.execute(query) + rows = c.fetchall() + + result = [] + for row in rows: + result.append(dict(zip(row.keys(), row))) + + c.close() + db.close() + return result