upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/selftest.cpp
diff options
context:
space:
mode:
authorNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-14 17:44:09 -0300
committerNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-14 17:44:09 -0300
commit3e778dd6cc9045862e99503b5b9af80ec682826f (patch)
tree4a055fb61ea1c6fde9edc65c8ec7356baa8c9c07 /src/selftest.cpp
parent307d1a79d4f9bdecd3f834f9ab4987f46d16d177 (diff)
wallet: check SQLite exports against loader types
Diffstat (limited to 'src/selftest.cpp')
-rw-r--r--src/selftest.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 343d9c5..feb4076 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -1195,6 +1195,28 @@ static bool CreateSQLiteWalletWithEmptyKey(const string& strPath)
1195 return fOk; 1195 return fOk;
1196} 1196}
1197 1197
1198static bool CreateSQLiteWalletWithFutureMinVersion(const string& strPath)
1199{
1200 string strError;
1201 CWalletDBSQLite db;
1202 CDataStream ssKey(SER_DISK);
1203 ssKey << string("walletminversion");
1204 CDataStream ssValue(SER_DISK);
1205 ssValue << (WALLET_FORMAT_SUPPORTED + 1);
1206
1207 if (!db.Open(strPath, strError))
1208 return false;
1209 if (!db.BeginTransaction(strError))
1210 return false;
1211 if (!db.WriteRecord(DataStreamBytes(ssKey), DataStreamBytes(ssValue), strError))
1212 return false;
1213 if (!db.CommitTransaction(strError))
1214 return false;
1215 if (!db.Checkpoint(strError))
1216 return false;
1217 return true;
1218}
1219
1198static int RunWalletSQLiteMigrationSelfTest() 1220static int RunWalletSQLiteMigrationSelfTest()
1199{ 1221{
1200 fflush(stdout); 1222 fflush(stdout);
@@ -1263,6 +1285,19 @@ static int RunWalletSQLiteMigrationSelfTest()
1263 FileContainsText(strVerifyOut, "verification: ok"), 1285 FileContainsText(strVerifyOut, "verification: ok"),
1264 "SQLite wallet export verifies against wallet.dat") ? 0 : 1; 1286 "SQLite wallet export verifies against wallet.dat") ? 0 : 1;
1265 1287
1288 string strLoadCheckOut = tmp + "/sqlite-loadcheck.txt";
1289 vector<string> vLoadCheckArgs;
1290 vLoadCheckArgs.push_back("-datadir=" + strWalletDir);
1291 vLoadCheckArgs.push_back("-nomanagedtor");
1292 vLoadCheckArgs.push_back("-nogui");
1293 vLoadCheckArgs.push_back("-walletsqliteloadcheck=" + strSQLite);
1294 int nLoadCheckRet =
1295 RunBitflashChild(strExe, vLoadCheckArgs, NULL, &strLoadCheckOut);
1296 nFail += Check(nLoadCheckRet == 0 &&
1297 FileContainsText(strLoadCheckOut,
1298 "load check: ok"),
1299 "SQLite wallet export passes the loader compatibility check") ? 0 : 1;
1300
1266 string strRestoredDir = tmp + "/restored-wallet"; 1301 string strRestoredDir = tmp + "/restored-wallet";
1267 nFail += Check(MakeDirLocal(strRestoredDir), 1302 nFail += Check(MakeDirLocal(strRestoredDir),
1268 "restored wallet directory can be created") ? 0 : 1; 1303 "restored wallet directory can be created") ? 0 : 1;
@@ -1318,6 +1353,25 @@ static int RunWalletSQLiteMigrationSelfTest()
1318 !FileExists((strBadRestoreDir + "/wallet.dat").c_str()), 1353 !FileExists((strBadRestoreDir + "/wallet.dat").c_str()),
1319 "failed SQLite wallet restore removes incomplete wallet.dat") ? 0 : 1; 1354 "failed SQLite wallet restore removes incomplete wallet.dat") ? 0 : 1;
1320 1355
1356 string strFutureSQLite = tmp + "/future-wallet.sqlite";
1357 nFail += Check(CreateSQLiteWalletWithFutureMinVersion(strFutureSQLite),
1358 "SQLite export with a future wallet format can be created") ? 0 : 1;
1359 string strFutureLoadCheckOut = tmp + "/sqlite-loadcheck-future.txt";
1360 vector<string> vFutureLoadCheckArgs;
1361 vFutureLoadCheckArgs.push_back("-datadir=" + strWalletDir);
1362 vFutureLoadCheckArgs.push_back("-nomanagedtor");
1363 vFutureLoadCheckArgs.push_back("-nogui");
1364 vFutureLoadCheckArgs.push_back("-walletsqliteloadcheck=" + strFutureSQLite);
1365 int nFutureLoadCheckRet =
1366 RunBitflashChild(strExe, vFutureLoadCheckArgs, NULL,
1367 &strFutureLoadCheckOut);
1368 nFail += Check(nFutureLoadCheckRet == 2 &&
1369 FileContainsText(strFutureLoadCheckOut,
1370 "unsupported future wallet format") &&
1371 FileContainsText(strFutureLoadCheckOut,
1372 "load check: failed"),
1373 "SQLite wallet load check rejects future wallet formats") ? 0 : 1;
1374
1321 string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt"; 1375 string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt";
1322 int nOverwriteRet = 1376 int nOverwriteRet =
1323 RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut); 1377 RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut);