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

Function test_scid_upgrade

tests/test_db.py:140–173  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

138@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "This test is based on a sqlite3 snapshot")
139@unittest.skipIf(TEST_NETWORK != 'regtest', "The network must match the DB snapshot")
140def test_scid_upgrade(node_factory, bitcoind):
141 bitcoind.generate_block(1)
142
143 # Created through the power of sed "s/X'\([0-9]*\)78\([0-9]*\)78\([0-9]*\)'/X'\13A\23A\3'/"
144 l1 = node_factory.get_node(dbfile='oldstyle-scids.sqlite3.xz',
145 start=False, expect_fail=True,
146 broken_log='Refusing to irreversibly upgrade db from version 104 to|Refusing to upgrade db from version 104 to')
147
148 # Will refuse to upgrade (if not in a release!)
149 version = subprocess.check_output(['lightningd/lightningd',
150 '--version']).decode('utf-8').splitlines()[0]
151 if not re.match('^v[0-9.]*$', version):
152 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
153 # Will have exited with non-zero status.
154 assert l1.daemon.proc.wait(TIMEOUT) != 0
155 assert l1.daemon.is_in_stderr('Refusing to irreversibly upgrade db from version [0-9]* to [0-9]* in non-final version ' + version + r' \(use --database-upgrade=true to override\)')
156
157 l1.daemon.opts['database-upgrade'] = False
158 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
159 assert l1.daemon.proc.wait(TIMEOUT) != 0
160 assert l1.daemon.is_in_stderr(r'Refusing to upgrade db from version [0-9]* to [0-9]* \(database-upgrade=false\)')
161
162 l1.daemon.opts['database-upgrade'] = True
163 l1.daemon.start()
164 assert l1.db_query('SELECT scid FROM channels;') == [{'scid': scid_to_int('103x1x1')}]
165 assert l1.db_query('SELECT failscid FROM payments;') == [{'failscid': scid_to_int('103x1x1')}]
166
167 faildetail_types = l1.db_query(
168 "SELECT id, typeof(faildetail) as type "
169 "FROM payments WHERE faildetail IS NOT NULL"
170 )
171 for row in faildetail_types:
172 assert row['type'] == 'text', \
173 f"Payment {row['id']}: faildetail has type {row['type']}, expected 'text'"
174
175
176@unittest.skipIf(not COMPAT, "needs COMPAT to convert obsolete db")

Callers

nothing calls this directly

Calls 8

scid_to_intFunction · 0.90
generate_blockMethod · 0.80
is_in_stderrMethod · 0.80
db_queryMethod · 0.80
get_nodeMethod · 0.45
decodeMethod · 0.45
startMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected