MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_db_hook

Function test_db_hook

tests/test_plugin.py:612–638  ·  view source on GitHub ↗

This tests the db hook.

(node_factory, executor)

Source from the content-addressed store, hash-verified

610
611@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Only sqlite3 implements the db_write_hook currently")
612def test_db_hook(node_factory, executor):
613 """This tests the db hook."""
614 dbfile = os.path.join(node_factory.directory, "dblog.sqlite3")
615 l1 = node_factory.get_node(options={**BWATCH_OPTS,
616 'plugin': os.path.join(os.getcwd(), 'tests/plugins/dblog.py'),
617 'dblog-file': dbfile})
618
619 # It should see the db being created, and sometime later actually get
620 # initted.
621 # This precedes startup, so needle already past
622 assert l1.daemon.is_in_log(r'plugin-dblog.py: deferring \d+ commands')
623 l1.daemon.logsearch_start = 0
624 l1.daemon.wait_for_log('plugin-dblog.py: replaying pre-init data:')
625 l1.daemon.wait_for_log('plugin-dblog.py: CREATE TABLE version \\(version INTEGER\\)')
626 l1.daemon.wait_for_log("plugin-dblog.py: initialized.* 'startup': True")
627
628 # bwatch's first block-history write is async; if we stop before it runs,
629 # the main DB can diverge from dblog's mirror (hook may not run in time).
630 wait_bwatch_caught_up(l1)
631
632 l1.stop()
633
634 # Databases should be identical.
635 db1 = sqlite3.connect(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'lightningd.sqlite3'))
636 db2 = sqlite3.connect(dbfile)
637
638 assert [x for x in db1.iterdump()] == [x for x in db2.iterdump()]
639
640
641@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Only sqlite3 implements the db_write_hook currently")

Callers

nothing calls this directly

Calls 7

wait_bwatch_caught_upFunction · 0.85
joinMethod · 0.80
is_in_logMethod · 0.80
wait_for_logMethod · 0.80
get_nodeMethod · 0.45
stopMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected