diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-14 12:28:55 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-14 12:28:55 -0300 |
| commit | 23d5c397c35a5c4dad6e3fe170aefdfa2fd00580 (patch) | |
| tree | fe47d412af57bc2a8cd47f6d726b224addfeebe9 | |
| parent | 94cda9794f302ca7b5e8b6f192c98ddcb3d4a12e (diff) | |
tests: guard destructive wallet mutation helper
| -rw-r--r-- | src/selftest.cpp | 49 |
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 | ||
| 786 | static const char* SELFTEST_MUTATE_WALLET_MARKER = | ||
| 787 | ".bitflash-selftest-wallet-mutate-ok"; | ||
| 788 | static const char* SELFTEST_MUTATE_WALLET_MARKER_TEXT = | ||
| 789 | "bitflash destructive wallet storage self-test\n"; | ||
| 790 | |||
| 791 | static string SelfTestMutationMarkerPath() | ||
| 792 | { | ||
| 793 | return GetAppDir() + "/" + SELFTEST_MUTATE_WALLET_MARKER; | ||
| 794 | } | ||
| 795 | |||
| 796 | static 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 | |||
| 786 | int RunSelfTestMutateWallet(const std::string& name) | 810 | int 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); |