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.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index dc9936e..2ada8f3 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -19,6 +19,7 @@
19#include "wallet_sqlite.h" 19#include "wallet_sqlite.h"
20 20
21extern int RunPoolStratumSelfTest(); 21extern int RunPoolStratumSelfTest();
22extern int RunPayoutLedgerSelfTest();
22 23
23// Test results go to the terminal, not to debug.log. 24// Test results go to the terminal, not to debug.log.
24// 25//
@@ -3023,6 +3024,13 @@ static int RunNetMessageSelfTest()
3023 int nFail = 0; 3024 int nFail = 0;
3024 try 3025 try
3025 { 3026 {
3027 // A peer that has not yet been kept waiting must not look like one that
3028 // has been waiting since the epoch. This is the whole bug: the stall
3029 // clock lives in CNode, so only the constructor can start it at zero.
3030 CNode opened(INVALID_SOCKET, CAddress("127.0.0.1"));
3031 nFail += Check(opened.nMsgWaitSince == 0 && opened.nMsgWaitSize == 0,
3032 "a new peer starts with its stall clock stopped") ? 0 : 1;
3033
3026 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1")); 3034 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1"));
3027 complete.nVersion = VERSION; 3035 complete.nVersion = VERSION;
3028 complete.vRecv << CMessageHeader("ping", 0); 3036 complete.vRecv << CMessageHeader("ping", 0);
@@ -3037,20 +3045,38 @@ static int RunNetMessageSelfTest()
3037 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1; 3045 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1;
3038 nFail += Check(partial.vRecv.size() == nPartialBefore, 3046 nFail += Check(partial.vRecv.size() == nPartialBefore,
3039 "an incomplete message keeps one header in the buffer") ? 0 : 1; 3047 "an incomplete message keeps one header in the buffer") ? 0 : 1;
3040 nFail += Check(partial.nIncompleteMessageStart != 0, 3048 nFail += Check(partial.nMsgWaitSince != 0,
3041 "an incomplete message starts a timeout clock") ? 0 : 1; 3049 "an incomplete message starts the stall clock") ? 0 : 1;
3050 nFail += Check(partial.nMsgWaitSize == 0,
3051 "the stall clock records how much payload had arrived") ? 0 : 1;
3042 nFail += Check(!partial.fDisconnect, 3052 nFail += Check(!partial.fDisconnect,
3043 "a fresh incomplete message does not disconnect immediately") ? 0 : 1; 3053 "a fresh incomplete message does not disconnect immediately") ? 0 : 1;
3044 3054
3055 // Still arriving, just slowly: more payload is here than when the clock
3056 // was started, so the clock restarts however old it was. Timing the
3057 // wait instead of the stall would drop this peer.
3058 CNode slow(INVALID_SOCKET, CAddress("127.0.0.1"));
3059 slow.nVersion = VERSION;
3060 slow.vRecv << CMessageHeader("block", 100);
3061 slow.vRecv.insert(slow.vRecv.end(), 50, '\0');
3062 slow.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
3063 slow.nMsgWaitSize = 10;
3064 ProcessMessages(&slow);
3065 nFail += Check(!slow.fDisconnect,
3066 "a peer still sending payload is not dropped") ? 0 : 1;
3067 nFail += Check(slow.nMsgWaitSize == 50,
3068 "progress restarts the stall clock") ? 0 : 1;
3069
3070 // Nothing more has arrived since the clock started, and the clock is
3071 // older than the limit.
3045 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1")); 3072 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1"));
3046 stale.nVersion = VERSION; 3073 stale.nVersion = VERSION;
3047 stale.vRecv << CMessageHeader("block", 100); 3074 stale.vRecv << CMessageHeader("block", 100);
3048 stale.nIncompleteMessageStart = GetTime() - BTF_INCOMPLETE_MESSAGE_TIMEOUT_SECS - 1; 3075 stale.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
3049 stale.nIncompleteMessageSize = 100; 3076 stale.nMsgWaitSize = 0;
3050 stale.strIncompleteMessageCommand = "block";
3051 ProcessMessages(&stale); 3077 ProcessMessages(&stale);
3052 nFail += Check(stale.fDisconnect, 3078 nFail += Check(stale.fDisconnect,
3053 "a stale incomplete message disconnects the peer") ? 0 : 1; 3079 "a stalled incomplete message disconnects the peer") ? 0 : 1;
3054 3080
3055 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1")); 3081 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1"));
3056 oversized.nVersion = VERSION; 3082 oversized.nVersion = VERSION;
@@ -3521,6 +3547,8 @@ int RunSelfTest(const std::string& name)
3521 return RunConsensusLimitsSelfTest(); 3547 return RunConsensusLimitsSelfTest();
3522 if (name == "pool-stratum") 3548 if (name == "pool-stratum")
3523 return RunPoolStratumSelfTest(); 3549 return RunPoolStratumSelfTest();
3550 if (name == "payout-ledger")
3551 return RunPayoutLedgerSelfTest();
3524 if (name == "parse-money") 3552 if (name == "parse-money")
3525 return RunParseMoneySelfTest(); 3553 return RunParseMoneySelfTest();
3526 if (name == "socks5-proxy") 3554 if (name == "socks5-proxy")
@@ -3529,6 +3557,6 @@ int RunSelfTest(const std::string& name)
3529 return RunManagedTorSelfTest(); 3557 return RunManagedTorSelfTest();
3530 3558
3531 printf("Unknown self-test '%s'\n", name.c_str()); 3559 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"); 3560 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, payout-ledger, parse-money, socks5-proxy, managed-tor\n");
3533 return 1; 3561 return 1;
3534} 3562}