From 6c23bc3b0bb1643c5c287dfc9160cb5a8cdc37b6 Mon Sep 17 00:00:00 2001 From: Nsable-sh Date: Mon, 17 Aug 2026 11:12:40 -0300 Subject: tests: prove typed SQLite wallets load --- src/selftest.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/selftest.cpp') diff --git a/src/selftest.cpp b/src/selftest.cpp index 4b1e733..a1efaa0 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp @@ -1268,6 +1268,36 @@ static bool CreateSQLiteWalletWithFutureMinVersion(const string& strPath) return true; } +static bool CreateTypedSQLiteWallet(const string& strPath) +{ + string strError; + CWalletDBSQLite db; + CKey key; + key.MakeNewKey(); + + vector vchPubKey = key.GetPubKey(); + CPrivKey vchPrivKey = key.GetPrivKey(); + string strAddress = PubKeyToAddress(vchPubKey); + + if (!db.Open(strPath, strError)) + return false; + if (!db.BeginTransaction(strError)) + return false; + if (!db.WriteTypedRecord(make_pair(string("key"), vchPubKey), + vchPrivKey, strError, false)) + return false; + if (!db.WriteTypedRecord(string("defaultkey"), vchPubKey, strError)) + return false; + if (!db.WriteTypedRecord(make_pair(string("name"), strAddress), + string("Typed SQLite Address"), strError)) + return false; + if (!db.CommitTransaction(strError)) + return false; + if (!db.Checkpoint(strError)) + return false; + return true; +} + static int RunWalletSQLiteMigrationSelfTest() { fflush(stdout); @@ -1362,6 +1392,42 @@ static int RunWalletSQLiteMigrationSelfTest() "SQLite wallet loaded: read-only staging backend"), "SQLite wallet export loads through the runtime startup path") ? 0 : 1; + string strTypedSQLite = tmp + "/typed-wallet.sqlite"; + nFail += Check(CreateTypedSQLiteWallet(strTypedSQLite), + "typed SQLite wallet can be created without Berkeley DB") ? 0 : 1; + + string strTypedLoadCheckOut = tmp + "/sqlite-typed-loadcheck.txt"; + vector vTypedLoadCheckArgs; + vTypedLoadCheckArgs.push_back("-datadir=" + strWalletDir); + vTypedLoadCheckArgs.push_back("-nomanagedtor"); + vTypedLoadCheckArgs.push_back("-nogui"); + vTypedLoadCheckArgs.push_back("-walletsqliteloadcheck=" + strTypedSQLite); + int nTypedLoadCheckRet = + RunBitflashChild(strExe, vTypedLoadCheckArgs, NULL, + &strTypedLoadCheckOut); + nFail += Check(nTypedLoadCheckRet == 0 && + FileContainsText(strTypedLoadCheckOut, + "load check: ok"), + "typed SQLite wallet passes the loader compatibility check") ? 0 : 1; + + string strTypedRuntimeDir = tmp + "/typed-runtime-wallet"; + nFail += Check(MakeDirLocal(strTypedRuntimeDir), + "typed SQLite runtime directory can be created") ? 0 : 1; + string strTypedRuntimeOut = tmp + "/sqlite-typed-runtime.txt"; + vector vTypedRuntimeArgs; + vTypedRuntimeArgs.push_back("-datadir=" + strTypedRuntimeDir); + vTypedRuntimeArgs.push_back("-nomanagedtor"); + vTypedRuntimeArgs.push_back("-nogui"); + vTypedRuntimeArgs.push_back("-walletsqlite=" + strTypedSQLite); + int nTypedRuntimeRet = + RunBitflashChild(strExe, vTypedRuntimeArgs, NULL, + &strTypedRuntimeOut); + nFail += Check(nTypedRuntimeRet == 0 && + FileContainsText(strTypedRuntimeOut, + "SQLite wallet loaded: read-only staging backend") && + !FileExists((strTypedRuntimeDir + "/wallet.dat").c_str()), + "typed SQLite wallet loads through runtime without creating wallet.dat") ? 0 : 1; + string strRestoredDir = tmp + "/restored-wallet"; nFail += Check(MakeDirLocal(strRestoredDir), "restored wallet directory can be created") ? 0 : 1; -- cgit v1.2.3