mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 02:27:51 +01:00
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.
This commit is contained in:
parent
121595935a
commit
c0aefad8e3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user