| 428 | |
| 429 | @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Tests a feature unique to SQLITE3 backend") |
| 430 | def test_sqlite3_builtin_backup(bitcoind, node_factory): |
| 431 | l1 = node_factory.get_node(start=False) |
| 432 | |
| 433 | # Figure out the path to the actual db. |
| 434 | main_db_file = l1.db.path |
| 435 | # Create a backup copy in the same location with the suffix .bak |
| 436 | backup_db_file = main_db_file + ".bak" |
| 437 | |
| 438 | # Provide the --wallet option and start. |
| 439 | l1.daemon.opts['wallet'] = "sqlite3://" + main_db_file + ':' + backup_db_file |
| 440 | l1.start() |
| 441 | |
| 442 | # Get an address and put some funds. |
| 443 | addr = l1.rpc.newaddr('bech32')['bech32'] |
| 444 | bitcoind.rpc.sendtoaddress(addr, 1) |
| 445 | bitcoind.generate_block(1) |
| 446 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) |
| 447 | |
| 448 | # Stop the node. |
| 449 | l1.stop() |
| 450 | |
| 451 | # Copy the backup over the main db file. |
| 452 | shutil.copyfile(backup_db_file, main_db_file) |
| 453 | |
| 454 | # Remove the --wallet option and start. |
| 455 | del l1.daemon.opts['wallet'] |
| 456 | l1.start() |
| 457 | |
| 458 | # Should still see the funds. |
| 459 | assert(len(l1.rpc.listfunds()['outputs']) == 1) |
| 460 | |
| 461 | |
| 462 | @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Don't know how to swap dbs in Postgres") |