diff options
Diffstat (limited to 'src/selftest.cpp')
| -rw-r--r-- | src/selftest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp index 408dd41..4ba90c3 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp | |||
| @@ -1134,6 +1134,8 @@ static int RunWalletSQLiteSelfTest() | |||
| 1134 | return nFail == 0 ? 0 : 1; | 1134 | return nFail == 0 ? 0 : 1; |
| 1135 | } | 1135 | } |
| 1136 | 1136 | ||
| 1137 | namespace { | ||
| 1138 | |||
| 1137 | class CWalletRecordMapVisitor : public CWalletRecordVisitor | 1139 | class CWalletRecordMapVisitor : public CWalletRecordVisitor |
| 1138 | { | 1140 | { |
| 1139 | public: | 1141 | public: |
| @@ -1158,6 +1160,8 @@ public: | |||
| 1158 | } | 1160 | } |
| 1159 | }; | 1161 | }; |
| 1160 | 1162 | ||
| 1163 | } // namespace | ||
| 1164 | |||
| 1161 | static int RunWalletSQLiteMigrationSelfTest() | 1165 | static int RunWalletSQLiteMigrationSelfTest() |
| 1162 | { | 1166 | { |
| 1163 | fflush(stdout); | 1167 | fflush(stdout); |
| @@ -1215,6 +1219,17 @@ static int RunWalletSQLiteMigrationSelfTest() | |||
| 1215 | FileContainsText(strExportOut, "SQLite wallet export written"), | 1219 | FileContainsText(strExportOut, "SQLite wallet export written"), |
| 1216 | "wallet.dat can be exported to SQLite") ? 0 : 1; | 1220 | "wallet.dat can be exported to SQLite") ? 0 : 1; |
| 1217 | 1221 | ||
| 1222 | string strVerifyOut = tmp + "/sqlite-verify.txt"; | ||
| 1223 | vector<string> vVerifyArgs; | ||
| 1224 | vVerifyArgs.push_back("-datadir=" + strWalletDir); | ||
| 1225 | vVerifyArgs.push_back("-nomanagedtor"); | ||
| 1226 | vVerifyArgs.push_back("-nogui"); | ||
| 1227 | vVerifyArgs.push_back("-walletsqliteverify=" + strSQLite); | ||
| 1228 | int nVerifyRet = RunBitflashChild(strExe, vVerifyArgs, NULL, &strVerifyOut); | ||
| 1229 | nFail += Check(nVerifyRet == 0 && | ||
| 1230 | FileContainsText(strVerifyOut, "verification: ok"), | ||
| 1231 | "SQLite wallet export verifies against wallet.dat") ? 0 : 1; | ||
| 1232 | |||
| 1218 | string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt"; | 1233 | string strOverwriteOut = tmp + "/sqlite-export-overwrite.txt"; |
| 1219 | int nOverwriteRet = | 1234 | int nOverwriteRet = |
| 1220 | RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut); | 1235 | RunBitflashChild(strExe, vExportArgs, NULL, &strOverwriteOut); |
| @@ -1265,6 +1280,32 @@ static int RunWalletSQLiteMigrationSelfTest() | |||
| 1265 | nFail += Check(db.ScanRecords(sqliteVisitor, strError) && | 1280 | nFail += Check(db.ScanRecords(sqliteVisitor, strError) && |
| 1266 | mapSQLite == mapBDB, | 1281 | mapSQLite == mapBDB, |
| 1267 | "SQLite wallet scanner streams every exported record byte-for-byte") ? 0 : 1; | 1282 | "SQLite wallet scanner streams every exported record byte-for-byte") ? 0 : 1; |
| 1283 | |||
| 1284 | db.Close(); | ||
| 1285 | CWalletDBSQLite dbCorrupt; | ||
| 1286 | vector<unsigned char> vchBadValue; | ||
| 1287 | vchBadValue.push_back(0xba); | ||
| 1288 | vchBadValue.push_back(0xad); | ||
| 1289 | nFail += Check(!mapBDB.empty() && | ||
| 1290 | dbCorrupt.Open(strSQLite, strError) && | ||
| 1291 | dbCorrupt.BeginTransaction(strError) && | ||
| 1292 | dbCorrupt.WriteRecord(mapBDB.begin()->first, | ||
| 1293 | vchBadValue, | ||
| 1294 | strError) && | ||
| 1295 | dbCorrupt.CommitTransaction(strError) && | ||
| 1296 | dbCorrupt.Checkpoint(strError), | ||
| 1297 | "SQLite export can be deliberately corrupted for verifier test") ? 0 : 1; | ||
| 1298 | dbCorrupt.Close(); | ||
| 1299 | |||
| 1300 | string strVerifyBadOut = tmp + "/sqlite-verify-bad.txt"; | ||
| 1301 | int nVerifyBadRet = | ||
| 1302 | RunBitflashChild(strExe, vVerifyArgs, NULL, &strVerifyBadOut); | ||
| 1303 | nFail += Check(nVerifyBadRet == 2 && | ||
| 1304 | FileContainsText(strVerifyBadOut, | ||
| 1305 | "record value mismatches: 1") && | ||
| 1306 | FileContainsText(strVerifyBadOut, | ||
| 1307 | "verification: failed"), | ||
| 1308 | "SQLite wallet verifier detects a mismatched record value") ? 0 : 1; | ||
| 1268 | } | 1309 | } |
| 1269 | catch (const std::exception& e) | 1310 | catch (const std::exception& e) |
| 1270 | { | 1311 | { |