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.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index a1efaa0..9fa0938 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -1051,6 +1051,8 @@ static int RunWalletSQLiteSelfTest()
1051 int nFail = 0; 1051 int nFail = 0;
1052 string strPath = tmp + "/wallet.sqlite"; 1052 string strPath = tmp + "/wallet.sqlite";
1053 string strError; 1053 string strError;
1054 string strOldRuntimeDataDir;
1055 bool fRestoreRuntimeDataDir = false;
1054 1056
1055 try 1057 try
1056 { 1058 {
@@ -1166,14 +1168,88 @@ static int RunWalletSQLiteSelfTest()
1166 vchTypedPubKey == vchPubKey, 1168 vchTypedPubKey == vchPubKey,
1167 "SQLite wallet reads a typed defaultkey record") ? 0 : 1; 1169 "SQLite wallet reads a typed defaultkey record") ? 0 : 1;
1168 } 1170 }
1171
1172 {
1173 string strRuntimePath = tmp + "/runtime-wallet.sqlite";
1174 string strRuntimeDir = tmp + "/runtime-datadir";
1175 nFail += Check(MakeDirLocal(strRuntimeDir),
1176 "SQLite runtime datadir can be created") ? 0 : 1;
1177
1178 {
1179 CWalletDBSQLite db;
1180 nFail += Check(db.Open(strRuntimePath, strError),
1181 "SQLite runtime wallet file can be created") ? 0 : 1;
1182 }
1183
1184 string strOldDataDir = strSetDataDir;
1185 strSetDataDir = strRuntimeDir;
1186 strOldRuntimeDataDir = strOldDataDir;
1187 fRestoreRuntimeDataDir = true;
1188 bool fRuntimeOpened = WalletSQLiteRuntimeOpen(strRuntimePath, strError);
1189 nFail += Check(fRuntimeOpened,
1190 "SQLite runtime wallet can be activated") ? 0 : 1;
1191
1192 if (fRuntimeOpened)
1193 {
1194 CKey key;
1195 key.MakeNewKey();
1196 vector<unsigned char> vchRuntimePubKey = key.GetPubKey();
1197 CPrivKey vchRuntimePrivKey = key.GetPrivKey();
1198 string strRuntimeAddress = PubKeyToAddress(vchRuntimePubKey);
1199
1200 nFail += Check(CWalletDB().WriteSetting("runtime-sqlite-setting",
1201 (int64)909090) &&
1202 CWalletDB().WriteDefaultKey(vchRuntimePubKey) &&
1203 CWalletDB().WriteKey(vchRuntimePubKey,
1204 vchRuntimePrivKey) &&
1205 CWalletDB().WriteName(strRuntimeAddress,
1206 "SQLite Runtime Address"),
1207 "CWalletDB writes route to active SQLite runtime") ? 0 : 1;
1208
1209 int64 nRuntimeSetting = 0;
1210 vector<unsigned char> vchRuntimeDefaultKey;
1211 CPrivKey vchRuntimeReadPrivKey;
1212 string strRuntimeName;
1213 nFail += Check(CWalletDB("r").ReadSetting("runtime-sqlite-setting",
1214 nRuntimeSetting) &&
1215 nRuntimeSetting == 909090 &&
1216 CWalletDB("r").ReadDefaultKey(vchRuntimeDefaultKey) &&
1217 vchRuntimeDefaultKey == vchRuntimePubKey &&
1218 CWalletDB("r").ReadKey(vchRuntimePubKey,
1219 vchRuntimeReadPrivKey) &&
1220 vchRuntimeReadPrivKey == vchRuntimePrivKey &&
1221 CWalletDB("r").ReadName(strRuntimeAddress,
1222 strRuntimeName) &&
1223 strRuntimeName == "SQLite Runtime Address",
1224 "CWalletDB reads route to active SQLite runtime") ? 0 : 1;
1225
1226 nFail += Check(CWalletDB().EraseName(strRuntimeAddress) &&
1227 !CWalletDB("r").ReadName(strRuntimeAddress,
1228 strRuntimeName),
1229 "CWalletDB erases route to active SQLite runtime") ? 0 : 1;
1230
1231 nFail += Check(!FileExists((strRuntimeDir + "/wallet.dat").c_str()),
1232 "active SQLite runtime does not create wallet.dat") ? 0 : 1;
1233 }
1234
1235 WalletSQLiteRuntimeClose();
1236 strSetDataDir = strOldDataDir;
1237 fRestoreRuntimeDataDir = false;
1238 }
1169 } 1239 }
1170 catch (const std::exception& e) 1240 catch (const std::exception& e)
1171 { 1241 {
1242 WalletSQLiteRuntimeClose();
1243 if (fRestoreRuntimeDataDir)
1244 strSetDataDir = strOldRuntimeDataDir;
1172 printf(" FAIL exception: %s\n", e.what()); 1245 printf(" FAIL exception: %s\n", e.what());
1173 nFail++; 1246 nFail++;
1174 } 1247 }
1175 catch (...) 1248 catch (...)
1176 { 1249 {
1250 WalletSQLiteRuntimeClose();
1251 if (fRestoreRuntimeDataDir)
1252 strSetDataDir = strOldRuntimeDataDir;
1177 printf(" FAIL unknown exception\n"); 1253 printf(" FAIL unknown exception\n");
1178 nFail++; 1254 nFail++;
1179 } 1255 }