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.cpp74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index dc9936e..30bd28e 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -3076,6 +3076,76 @@ static int RunNetMessageSelfTest()
3076 return nFail == 0 ? 0 : 1; 3076 return nFail == 0 ? 0 : 1;
3077} 3077}
3078 3078
3079static int RunNetworkParamsSelfTest()
3080{
3081 fflush(stdout);
3082 printf("network-params self-test\n");
3083
3084 int nFail = 0;
3085 std::string strOldDataDir = strSetDataDir;
3086 try
3087 {
3088 SelectNetworkParams(false);
3089 nFail += Check(!IsTestNet(), "starts on mainnet after explicit selection") ? 0 : 1;
3090 nFail += Check(ntohs(GetDefaultPort()) == MAINNET_PORT,
3091 "mainnet default P2P port is 8433") ? 0 : 1;
3092 CAddress mainAddr("127.0.0.1");
3093 nFail += Check(mainAddr.port == htons(MAINNET_PORT),
3094 "mainnet address parsing uses the mainnet default port") ? 0 : 1;
3095 CMessageHeader mainHeader("ping", 0);
3096 char mainMagic[4];
3097 memcpy(mainMagic, mainHeader.pchMessageStart, sizeof(mainMagic));
3098
3099 SelectNetworkParams(true);
3100 nFail += Check(IsTestNet(), "testnet selection is sticky") ? 0 : 1;
3101 nFail += Check(ntohs(GetDefaultPort()) == TESTNET_PORT,
3102 "testnet default P2P port is 18433") ? 0 : 1;
3103 CAddress testAddr("127.0.0.1");
3104 nFail += Check(testAddr.port == htons(TESTNET_PORT),
3105 "testnet address parsing uses the testnet default port") ? 0 : 1;
3106 CMessageHeader testHeader("ping", 0);
3107 nFail += Check(memcmp(mainMagic, testHeader.pchMessageStart, sizeof(mainMagic)) != 0,
3108 "testnet message magic differs from mainnet") ? 0 : 1;
3109
3110 std::string tmp;
3111 if (!MakeTempDir(tmp))
3112 {
3113 nFail += Check(false, "creates a temporary data directory") ? 0 : 1;
3114 }
3115 else
3116 {
3117 strSetDataDir = tmp;
3118 SelectNetworkParams(false);
3119 std::string mainDir = GetAppDir();
3120 SelectNetworkParams(true);
3121 std::string testDir = GetAppDir();
3122 nFail += Check(mainDir == tmp,
3123 "mainnet uses the selected data directory") ? 0 : 1;
3124 nFail += Check(testDir == tmp + "/testnet",
3125 "testnet stores data below a testnet subdirectory") ? 0 : 1;
3126 RemoveTree(tmp);
3127 }
3128 }
3129 catch (const std::exception& e)
3130 {
3131 printf(" FAIL exception: %s\n", e.what());
3132 nFail++;
3133 }
3134 catch (...)
3135 {
3136 printf(" FAIL unknown exception\n");
3137 nFail++;
3138 }
3139
3140 strSetDataDir = strOldDataDir;
3141 SelectNetworkParams(false);
3142
3143 printf("%s (%d failure%s)\n", nFail == 0 ? "ALL TESTS PASSED" : "TESTS FAILED",
3144 nFail, nFail == 1 ? "" : "s");
3145 fflush(stdout);
3146 return nFail == 0 ? 0 : 1;
3147}
3148
3079static CBlock MakeSizedConsensusBlock(size_t nScriptBytes) 3149static CBlock MakeSizedConsensusBlock(size_t nScriptBytes)
3080{ 3150{
3081 CTransaction tx; 3151 CTransaction tx;
@@ -3517,6 +3587,8 @@ int RunSelfTest(const std::string& name)
3517 return RunWalletPortabilitySelfTest(); 3587 return RunWalletPortabilitySelfTest();
3518 if (name == "net-message") 3588 if (name == "net-message")
3519 return RunNetMessageSelfTest(); 3589 return RunNetMessageSelfTest();
3590 if (name == "network-params")
3591 return RunNetworkParamsSelfTest();
3520 if (name == "consensus-limits") 3592 if (name == "consensus-limits")
3521 return RunConsensusLimitsSelfTest(); 3593 return RunConsensusLimitsSelfTest();
3522 if (name == "pool-stratum") 3594 if (name == "pool-stratum")
@@ -3529,6 +3601,6 @@ int RunSelfTest(const std::string& name)
3529 return RunManagedTorSelfTest(); 3601 return RunManagedTorSelfTest();
3530 3602
3531 printf("Unknown self-test '%s'\n", name.c_str()); 3603 printf("Unknown self-test '%s'\n", name.c_str());
3532 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-storage-sanity, db-env-reopen, wallet-sqlite, wallet-sqlite-migration, wallet-crypto, wallet-encrypt, wallet-sqlite-encrypt, wallet-backend-default, wallet-convert, wallet-portability, net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy, managed-tor\n"); 3604 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-storage-sanity, db-env-reopen, wallet-sqlite, wallet-sqlite-migration, wallet-crypto, wallet-encrypt, wallet-sqlite-encrypt, wallet-backend-default, wallet-convert, wallet-portability, net-message, network-params, consensus-limits, pool-stratum, parse-money, socks5-proxy, managed-tor\n");
3533 return 1; 3605 return 1;
3534} 3606}