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 3c93927..9f7106f 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -15,6 +15,7 @@
15#include "walletcmd.h" 15#include "walletcmd.h"
16 16
17extern int RunPoolStratumSelfTest(); 17extern int RunPoolStratumSelfTest();
18extern int RunPayoutLedgerSelfTest();
18 19
19// Test results go to the terminal, not to debug.log. 20// Test results go to the terminal, not to debug.log.
20// 21//
@@ -1139,6 +1140,13 @@ static int RunNetMessageSelfTest()
1139 int nFail = 0; 1140 int nFail = 0;
1140 try 1141 try
1141 { 1142 {
1143 // A peer that has not yet been kept waiting must not look like one that
1144 // has been waiting since the epoch. This is the whole bug: the stall
1145 // clock lives in CNode, so only the constructor can start it at zero.
1146 CNode opened(INVALID_SOCKET, CAddress("127.0.0.1"));
1147 nFail += Check(opened.nMsgWaitSince == 0 && opened.nMsgWaitSize == 0,
1148 "a new peer starts with its stall clock stopped") ? 0 : 1;
1149
1142 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1")); 1150 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1"));
1143 complete.nVersion = VERSION; 1151 complete.nVersion = VERSION;
1144 complete.vRecv << CMessageHeader("ping", 0); 1152 complete.vRecv << CMessageHeader("ping", 0);
@@ -1153,20 +1161,38 @@ static int RunNetMessageSelfTest()
1153 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1; 1161 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1;
1154 nFail += Check(partial.vRecv.size() == nPartialBefore, 1162 nFail += Check(partial.vRecv.size() == nPartialBefore,
1155 "an incomplete message keeps one header in the buffer") ? 0 : 1; 1163 "an incomplete message keeps one header in the buffer") ? 0 : 1;
1156 nFail += Check(partial.nIncompleteMessageStart != 0, 1164 nFail += Check(partial.nMsgWaitSince != 0,
1157 "an incomplete message starts a timeout clock") ? 0 : 1; 1165 "an incomplete message starts the stall clock") ? 0 : 1;
1166 nFail += Check(partial.nMsgWaitSize == 0,
1167 "the stall clock records how much payload had arrived") ? 0 : 1;
1158 nFail += Check(!partial.fDisconnect, 1168 nFail += Check(!partial.fDisconnect,
1159 "a fresh incomplete message does not disconnect immediately") ? 0 : 1; 1169 "a fresh incomplete message does not disconnect immediately") ? 0 : 1;
1160 1170
1171 // Still arriving, just slowly: more payload is here than when the clock
1172 // was started, so the clock restarts however old it was. Timing the
1173 // wait instead of the stall would drop this peer.
1174 CNode slow(INVALID_SOCKET, CAddress("127.0.0.1"));
1175 slow.nVersion = VERSION;
1176 slow.vRecv << CMessageHeader("block", 100);
1177 slow.vRecv.insert(slow.vRecv.end(), 50, '\0');
1178 slow.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
1179 slow.nMsgWaitSize = 10;
1180 ProcessMessages(&slow);
1181 nFail += Check(!slow.fDisconnect,
1182 "a peer still sending payload is not dropped") ? 0 : 1;
1183 nFail += Check(slow.nMsgWaitSize == 50,
1184 "progress restarts the stall clock") ? 0 : 1;
1185
1186 // Nothing more has arrived since the clock started, and the clock is
1187 // older than the limit.
1161 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1")); 1188 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1"));
1162 stale.nVersion = VERSION; 1189 stale.nVersion = VERSION;
1163 stale.vRecv << CMessageHeader("block", 100); 1190 stale.vRecv << CMessageHeader("block", 100);
1164 stale.nIncompleteMessageStart = GetTime() - BTF_INCOMPLETE_MESSAGE_TIMEOUT_SECS - 1; 1191 stale.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
1165 stale.nIncompleteMessageSize = 100; 1192 stale.nMsgWaitSize = 0;
1166 stale.strIncompleteMessageCommand = "block";
1167 ProcessMessages(&stale); 1193 ProcessMessages(&stale);
1168 nFail += Check(stale.fDisconnect, 1194 nFail += Check(stale.fDisconnect,
1169 "a stale incomplete message disconnects the peer") ? 0 : 1; 1195 "a stalled incomplete message disconnects the peer") ? 0 : 1;
1170 1196
1171 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1")); 1197 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1"));
1172 oversized.nVersion = VERSION; 1198 oversized.nVersion = VERSION;
@@ -1621,6 +1647,8 @@ int RunSelfTest(const std::string& name)
1621 return RunConsensusLimitsSelfTest(); 1647 return RunConsensusLimitsSelfTest();
1622 if (name == "pool-stratum") 1648 if (name == "pool-stratum")
1623 return RunPoolStratumSelfTest(); 1649 return RunPoolStratumSelfTest();
1650 if (name == "payout-ledger")
1651 return RunPayoutLedgerSelfTest();
1624 if (name == "parse-money") 1652 if (name == "parse-money")
1625 return RunParseMoneySelfTest(); 1653 return RunParseMoneySelfTest();
1626 if (name == "socks5-proxy") 1654 if (name == "socks5-proxy")
@@ -1629,6 +1657,6 @@ int RunSelfTest(const std::string& name)
1629 return RunManagedTorSelfTest(); 1657 return RunManagedTorSelfTest();
1630 1658
1631 printf("Unknown self-test '%s'\n", name.c_str()); 1659 printf("Unknown self-test '%s'\n", name.c_str());
1632 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt, net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy, managed-tor\n"); 1660 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt, net-message, consensus-limits, pool-stratum, payout-ledger, parse-money, socks5-proxy, managed-tor\n");
1633 return 1; 1661 return 1;
1634} 1662}