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:
Diffstat (limited to 'src/selftest.cpp')
-rw-r--r--src/selftest.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 7d3a96e..343d9c5 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -1162,6 +1162,39 @@ public:
1162 1162
1163} // namespace 1163} // namespace
1164 1164
1165static bool CreateSQLiteWalletWithEmptyKey(const string& strPath)
1166{
1167 sqlite3* pdb = NULL;
1168 int ret = sqlite3_open_v2(strPath.c_str(), &pdb,
1169 SQLITE_OPEN_READWRITE |
1170 SQLITE_OPEN_CREATE |
1171 SQLITE_OPEN_FULLMUTEX,
1172 NULL);
1173 if (ret != SQLITE_OK || !pdb)
1174 {
1175 if (pdb)
1176 sqlite3_close(pdb);
1177 return false;
1178 }
1179
1180 char* pszErr = NULL;
1181 bool fOk =
1182 sqlite3_exec(pdb,
1183 "CREATE TABLE wallet_records ("
1184 "key BLOB PRIMARY KEY NOT NULL,"
1185 "value BLOB NOT NULL"
1186 ");",
1187 NULL, NULL, &pszErr) == SQLITE_OK &&
1188 sqlite3_exec(pdb,
1189 "INSERT INTO wallet_records(key, value) "
1190 "VALUES(x'', x'01');",
1191 NULL, NULL, &pszErr) == SQLITE_OK;
1192 if (pszErr)
1193 sqlite3_free(pszErr);
1194 sqlite3_close(pdb);
1195 return fOk;
1196}
1197
1165static int RunWalletSQLiteMigrationSelfTest() 1198static int RunWalletSQLiteMigrationSelfTest()
1166{ 1199{
1167 fflush(stdout); 1200 fflush(stdout);
@@ -1265,6 +1298,26 @@ static int RunWalletSQLiteMigrationSelfTest()
1265 "Refusing to overwrite existing wallet.dat"), 1298 "Refusing to overwrite existing wallet.dat"),
1266 "SQLite wallet restore refuses to overwrite wallet.dat") ? 0 : 1; 1299 "SQLite wallet restore refuses to overwrite wallet.dat") ? 0 : 1;
1267 1300
1301 string strBadSQLite = tmp + "/bad-empty-key.sqlite";
1302 nFail += Check(CreateSQLiteWalletWithEmptyKey(strBadSQLite),
1303 "bad SQLite export with an empty key can be created") ? 0 : 1;
1304 string strBadRestoreDir = tmp + "/bad-restore-wallet";
1305 nFail += Check(MakeDirLocal(strBadRestoreDir),
1306 "bad restore wallet directory can be created") ? 0 : 1;
1307 string strBadRestoreOut = tmp + "/sqlite-restore-bad.txt";
1308 vector<string> vBadRestoreArgs;
1309 vBadRestoreArgs.push_back("-datadir=" + strBadRestoreDir);
1310 vBadRestoreArgs.push_back("-nomanagedtor");
1311 vBadRestoreArgs.push_back("-nogui");
1312 vBadRestoreArgs.push_back("-walletsqliterestore=" + strBadSQLite);
1313 int nBadRestoreRet =
1314 RunBitflashChild(strExe, vBadRestoreArgs, NULL, &strBadRestoreOut);
1315 nFail += Check(nBadRestoreRet == 1 &&
1316 FileContainsText(strBadRestoreOut,
1317 "Cannot restore SQLite wallet export") &&
1318 !FileExists((strBadRestoreDir + "/wallet.dat").c_str()),
1319 "failed SQLite wallet restore removes incomplete wallet.dat") ? 0 : 1;
1320
1268 string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt"; 1321 string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt";
1269 int nOverwriteRet = 1322 int nOverwriteRet =
1270 RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut); 1323 RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut);