upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-17 11:12:40 -0300
committerNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-17 11:12:40 -0300
commit6c23bc3b0bb1643c5c287dfc9160cb5a8cdc37b6 (patch)
tree477fbbee48b3311393cd1f5c794a8e5dafa1ec18
parent8e91ff3a57a085663312a6e1821ec4cb1c152144 (diff)
tests: prove typed SQLite wallets load
-rw-r--r--src/selftest.cpp66
1 files changed, 66 insertions, 0 deletions
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)
1268 return true; 1268 return true;
1269} 1269}
1270 1270
1271static bool CreateTypedSQLiteWallet(const string& strPath)
1272{
1273 string strError;
1274 CWalletDBSQLite db;
1275 CKey key;
1276 key.MakeNewKey();
1277
1278 vector<unsigned char> vchPubKey = key.GetPubKey();
1279 CPrivKey vchPrivKey = key.GetPrivKey();
1280 string strAddress = PubKeyToAddress(vchPubKey);
1281
1282 if (!db.Open(strPath, strError))
1283 return false;
1284 if (!db.BeginTransaction(strError))
1285 return false;
1286 if (!db.WriteTypedRecord(make_pair(string("key"), vchPubKey),
1287 vchPrivKey, strError, false))
1288 return false;
1289 if (!db.WriteTypedRecord(string("defaultkey"), vchPubKey, strError))
1290 return false;
1291 if (!db.WriteTypedRecord(make_pair(string("name"), strAddress),
1292 string("Typed SQLite Address"), strError))
1293 return false;
1294 if (!db.CommitTransaction(strError))
1295 return false;
1296 if (!db.Checkpoint(strError))
1297 return false;
1298 return true;
1299}
1300
1271static int RunWalletSQLiteMigrationSelfTest() 1301static int RunWalletSQLiteMigrationSelfTest()
1272{ 1302{
1273 fflush(stdout); 1303 fflush(stdout);
@@ -1362,6 +1392,42 @@ static int RunWalletSQLiteMigrationSelfTest()
1362 "SQLite wallet loaded: read-only staging backend"), 1392 "SQLite wallet loaded: read-only staging backend"),
1363 "SQLite wallet export loads through the runtime startup path") ? 0 : 1; 1393 "SQLite wallet export loads through the runtime startup path") ? 0 : 1;
1364 1394
1395 string strTypedSQLite = tmp + "/typed-wallet.sqlite";
1396 nFail += Check(CreateTypedSQLiteWallet(strTypedSQLite),
1397 "typed SQLite wallet can be created without Berkeley DB") ? 0 : 1;
1398
1399 string strTypedLoadCheckOut = tmp + "/sqlite-typed-loadcheck.txt";
1400 vector<string> vTypedLoadCheckArgs;
1401 vTypedLoadCheckArgs.push_back("-datadir=" + strWalletDir);
1402 vTypedLoadCheckArgs.push_back("-nomanagedtor");
1403 vTypedLoadCheckArgs.push_back("-nogui");
1404 vTypedLoadCheckArgs.push_back("-walletsqliteloadcheck=" + strTypedSQLite);
1405 int nTypedLoadCheckRet =
1406 RunBitflashChild(strExe, vTypedLoadCheckArgs, NULL,
1407 &strTypedLoadCheckOut);
1408 nFail += Check(nTypedLoadCheckRet == 0 &&
1409 FileContainsText(strTypedLoadCheckOut,
1410 "load check: ok"),
1411 "typed SQLite wallet passes the loader compatibility check") ? 0 : 1;
1412
1413 string strTypedRuntimeDir = tmp + "/typed-runtime-wallet";
1414 nFail += Check(MakeDirLocal(strTypedRuntimeDir),
1415 "typed SQLite runtime directory can be created") ? 0 : 1;
1416 string strTypedRuntimeOut = tmp + "/sqlite-typed-runtime.txt";
1417 vector<string> vTypedRuntimeArgs;
1418 vTypedRuntimeArgs.push_back("-datadir=" + strTypedRuntimeDir);
1419 vTypedRuntimeArgs.push_back("-nomanagedtor");
1420 vTypedRuntimeArgs.push_back("-nogui");
1421 vTypedRuntimeArgs.push_back("-walletsqlite=" + strTypedSQLite);
1422 int nTypedRuntimeRet =
1423 RunBitflashChild(strExe, vTypedRuntimeArgs, NULL,
1424 &strTypedRuntimeOut);
1425 nFail += Check(nTypedRuntimeRet == 0 &&
1426 FileContainsText(strTypedRuntimeOut,
1427 "SQLite wallet loaded: read-only staging backend") &&
1428 !FileExists((strTypedRuntimeDir + "/wallet.dat").c_str()),
1429 "typed SQLite wallet loads through runtime without creating wallet.dat") ? 0 : 1;
1430
1365 string strRestoredDir = tmp + "/restored-wallet"; 1431 string strRestoredDir = tmp + "/restored-wallet";
1366 nFail += Check(MakeDirLocal(strRestoredDir), 1432 nFail += Check(MakeDirLocal(strRestoredDir),
1367 "restored wallet directory can be created") ? 0 : 1; 1433 "restored wallet directory can be created") ? 0 : 1;