upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/selftest.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 81aa480..54249b1 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -783,8 +783,40 @@ public:
783 } 783 }
784}; 784};
785 785
786static const char* SELFTEST_MUTATE_WALLET_MARKER =
787 ".bitflash-selftest-wallet-mutate-ok";
788static const char* SELFTEST_MUTATE_WALLET_MARKER_TEXT =
789 "bitflash destructive wallet storage self-test\n";
790
791static string SelfTestMutationMarkerPath()
792{
793 return GetAppDir() + "/" + SELFTEST_MUTATE_WALLET_MARKER;
794}
795
796static bool WriteSelfTestMutationMarker(const string& strDir)
797{
798 string strPath = strDir + "/" + SELFTEST_MUTATE_WALLET_MARKER;
799 FILE* pf = fopen(strPath.c_str(), "wb");
800 if (!pf)
801 return false;
802 bool fOk = fwrite(SELFTEST_MUTATE_WALLET_MARKER_TEXT, 1,
803 strlen(SELFTEST_MUTATE_WALLET_MARKER_TEXT), pf) ==
804 strlen(SELFTEST_MUTATE_WALLET_MARKER_TEXT);
805 if (fclose(pf) != 0)
806 fOk = false;
807 return fOk;
808}
809
786int RunSelfTestMutateWallet(const std::string& name) 810int RunSelfTestMutateWallet(const std::string& name)
787{ 811{
812 if (!FileContainsText(SelfTestMutationMarkerPath(),
813 SELFTEST_MUTATE_WALLET_MARKER_TEXT))
814 {
815 fprintf(stderr, "Refusing destructive wallet storage mutation outside "
816 "a marked self-test datadir.\n");
817 return 1;
818 }
819
788 bool fOk = false; 820 bool fOk = false;
789 try 821 try
790 { 822 {
@@ -879,6 +911,23 @@ static int RunWalletStorageSanitySelfTest()
879 FileContainsText(strCreateOut, "Write these twelve words down"), 911 FileContainsText(strCreateOut, "Write these twelve words down"),
880 "scenario phrase wallet can be created") ? 0 : 1; 912 "scenario phrase wallet can be created") ? 0 : 1;
881 913
914 if (i == 0)
915 {
916 string strBlockedOut = tmp + "/" + scenarios[i].pszName + "-blocked-mutate.txt";
917 vector<string> vBlockedArgs;
918 vBlockedArgs.push_back("-datadir=" + strScenarioDir);
919 vBlockedArgs.push_back("-nomanagedtor");
920 vBlockedArgs.push_back("-nogui");
921 vBlockedArgs.push_back("-selftestmutatewallet=" + string(scenarios[i].pszName));
922 int nBlockedRet = RunBitflashChild(strExe, vBlockedArgs, NULL, &strBlockedOut);
923 nFail += Check(nBlockedRet != 0 &&
924 FileContainsText(strBlockedOut, "Refusing destructive wallet storage mutation"),
925 "wallet mutation helper is blocked without marker") ? 0 : 1;
926 }
927
928 nFail += Check(WriteSelfTestMutationMarker(strScenarioDir),
929 "scenario mutation marker can be written") ? 0 : 1;
930
882 string strMutateOut = tmp + "/" + scenarios[i].pszName + "-mutate.txt"; 931 string strMutateOut = tmp + "/" + scenarios[i].pszName + "-mutate.txt";
883 vector<string> vMutateArgs; 932 vector<string> vMutateArgs;
884 vMutateArgs.push_back("-datadir=" + strScenarioDir); 933 vMutateArgs.push_back("-datadir=" + strScenarioDir);