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

Function test_local_basepoints_cache

tests/test_db.py:374–426  ·  view source on GitHub ↗

XXX started caching the local basepoints as well as the remote ones. This tests that we can successfully migrate a DB from the pre-caching state to the caching state, by simply starting the node up once, issue the HSMd requests, and then store them in the DB.

(bitcoind, node_factory)

Source from the content-addressed store, hash-verified

372 "This test is based on a sqlite3 snapshot"
373)
374def test_local_basepoints_cache(bitcoind, node_factory):
375 """XXX started caching the local basepoints as well as the remote ones.
376
377 This tests that we can successfully migrate a DB from the
378 pre-caching state to the caching state, by simply starting the
379 node up once, issue the HSMd requests, and then store them in the
380 DB.
381
382 """
383 # Reestablish the blockheight we had when generating the DB
384 bitcoind.generate_block(6)
385 l1 = node_factory.get_node(
386 dbfile='no-local-basepoints.sqlite3.xz',
387 start=False,
388 # Our db had the old non-DER sig in psbt!
389 broken_log='Forced database repair of psbt',
390 old_hsmsecret=True,
391 options={'database-upgrade': True}
392 )
393
394 fields = [
395 "revocation_basepoint_local",
396 "payment_basepoint_local",
397 "htlc_basepoint_local",
398 "delayed_payment_basepoint_local",
399 ]
400 q = "SELECT {fields} FROM channels".format(fields=", ".join(fields))
401
402 # Make sure the DB doesn't have the fields yet.
403 missing = l1.db.query("SELECT * FROM channels")[0]
404 for f in fields:
405 assert(f not in missing)
406
407 # Starting this should cause us to migrate the DB, but none of
408 # these fields will be set.
409 l1.start()
410
411 present = l1.db.query(q)[0]
412 for f in fields:
413 assert(f in present)
414 assert(present[f] is not None)
415
416 # New channels should automatically have the basepoints cached.
417 l2, l3 = node_factory.line_graph(2)
418 present = l2.db.query(q)[0]
419 for f in fields:
420 assert(f in present)
421 assert(present[f] is not None)
422
423 # Restarting will ask hsmd and verify they're unchanged. Remove
424 # after we verified.
425 l1.restart()
426 l2.restart()
427
428
429@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Tests a feature unique to SQLITE3 backend")

Callers

nothing calls this directly

Calls 7

generate_blockMethod · 0.80
joinMethod · 0.80
line_graphMethod · 0.80
restartMethod · 0.80
get_nodeMethod · 0.45
queryMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected