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

Function test_db_hook

tests/test_plugin.py:611–637  ·  view source on GitHub ↗

This tests the db hook.

(node_factory, executor)

Source from the content-addressed store, hash-verified

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