aboutsummaryrefslogtreecommitdiff
path: root/src/test/util_tests.cpp
AgeCommit message (Collapse)Author
2021-06-04util: Properly handle -noincludeconf on command lineMarcoFalke
This bug was introduced in commit fad0867d6ab9430070aa7d60bf7617a6508e0586. Unit test Co-Authored-By: Russell Yanofsky <russ@yanofsky.org>
2021-05-31scripted-diff: rename GetSystemTimeInSeconds to GetTimeSecondsfanquake
-BEGIN VERIFY SCRIPT- sed -i -e 's/GetSystemTimeInSeconds/GetTimeSeconds/g' $(git grep -l GetSystemTimeInSeconds src) -END VERIFY SCRIPT-
2021-05-24scripted-diff: Change `ArgsManager.GetDataDirPath()` to ↵Kiminuo
`ArgsManager.GetDataDirBase()` in tests -BEGIN VERIFY SCRIPT- git ls-files src/test/*_tests.cpp src/test/util/setup_common.cpp | xargs sed -i 's/.GetDataDirPath()/.GetDataDirBase()/g'; -END VERIFY SCRIPT-
2021-05-09test: ParseFixedPoint with 3 decimals for sat/vB fee ratesJon Atack
2021-04-18Change ClearDataDirPathCache() to ArgsManager.ClearPathCache().Kiminuo
2021-04-18scripted-diff: Modify unit tests to use the ArgsManager in the ↵Kiminuo
BasicTestingSetup class instead of implicitly relying on gArgs. -BEGIN VERIFY SCRIPT- git ls-files src/test/dbwrapper_tests.cpp src/test/denialofservice_tests.cpp src/test/flatfile_tests.cpp src/test/fs_tests.cpp src/test/settings_tests.cpp src/test/util_tests.cpp | xargs sed -i 's/GetDataDir()/m_args.GetDataDirPath()/g'; -END VERIFY SCRIPT-
2021-04-18Modify "util_datadir" unit test to not use gArgs.Kiminuo
2021-04-17Move GetDataDir(fNetSpecific) implementation to ArgsManager.Kiminuo
2021-04-13refactor: add [[noreturn]] attribute where applicablefanquake
2021-03-22Merge #21317: util: Make Assume() usable as unary expressionMarcoFalke
fa4cebadcffd9112da4b13c7cc7ccf21e2bee887 util: Make Assume() usable as unary expression (MarcoFalke) Pull request description: Assume shouldn't behave different at the call site depending on build flags. Currently compilation fails if it is used as expression. Fix that by using the lambda approach from `Assert()` without the `assert()`. ACKs for top commit: jnewbery: ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887 practicalswift: cr ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887: patch looks correct and commit hash starts with `fa` Tree-SHA512: 9ec9ac8d410cdaf5e4e28df571a89e3d23d38e05a7027bb726cae3da6e9314734277e5a218e9e090cc17e10db763da71052c229ad642077ca5824ee42022f3ed
2021-03-21test: remove duplicate assertions in util_testsJon Atack
Co-authored-by: Kiminuo <kiminuo@protonmail.com>
2021-03-19test: add ParseUInt16() test coverageJon Atack
2021-03-17Merge #21415: refactor: remove Optional & nulloptWladimir J. van der Laan
ebc4ab721b0371c0ef217c0f5bd7d42613e951e6 refactor: post Optional<> removal cleanups (fanquake) 57e980d13ca488031bde6ef197cf34d493d36796 scripted-diff: remove Optional & nullopt (fanquake) Pull request description: Same rationale & motivation as #21404, which turned out to be quite low in the number of potential conflicts. Lets see what the bot has to say here. ACKs for top commit: practicalswift: cr ACK ebc4ab721b0371c0ef217c0f5bd7d42613e951e6: patch looks correct jnewbery: utACK ebc4ab721b0371c0ef217c0f5bd7d42613e951e6 laanwj: Code review ACK ebc4ab721b0371c0ef217c0f5bd7d42613e951e6 Tree-SHA512: 550fbeef09b9d35ddefaa805d1755c18c8fd499c4b0f77ebfece8c20296a7abd1cf6c699e2261f92fe3552deeb7555ec2a2287ffe3ab9e98bb9f8612a4d43be3
2021-03-17refactor: post Optional<> removal cleanupsfanquake
2021-03-15refactor: reuse test string with embedded null char in util_testsJon Atack
2021-03-15test: add ParseUInt8() unit and fuzz test coverageJon Atack
2021-03-15scripted-diff: remove Optional & nulloptfanquake
-BEGIN VERIFY SCRIPT- git rm src/optional.h sed -i -e 's/Optional</std::optional</g' $(git grep -l 'Optional<' src) sed -i -e 's/{nullopt}/{std::nullopt}/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt;/ std::nullopt;/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt)/ std::nullopt)/g' $(git grep -l 'nullopt' src) sed -i -e 's/(nullopt)/(std::nullopt)/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt,/ std::nullopt,/g' $(git grep -l 'nullopt' src) sed -i -e 's/? nullopt :/? std::nullopt :/g' $(git grep -l 'nullopt' src) sed -i -e 's/: nullopt}/: std::nullopt}/g' $(git grep -l 'nullopt' src) sed -i -e '/optional.h \\/d' src/Makefile.am sed -i -e '/#include <optional.h>/d' src/test/fuzz/autofile.cpp src/test/fuzz/buffered_file.cpp src/test/fuzz/node_eviction.cpp sed -i -e 's/#include <optional.h>/#include <optional>/g' $(git grep -l '#include <optional.h>' src) -END VERIFY SCRIPT-
2021-03-11scripted-diff: remove MakeUnique<T>()fanquake
-BEGIN VERIFY SCRIPT- git rm src/util/memory.h sed -i -e 's/MakeUnique/std::make_unique/g' $(git grep -l MakeUnique src) sed -i -e '/#include <util\/memory.h>/d' $(git grep -l '#include <util/memory.h>' src) sed -i -e '/util\/memory.h \\/d' src/Makefile.am -END VERIFY SCRIPT-
2021-03-04util: Make Assume() usable as unary expressionMarcoFalke
2021-03-02util: Avoid invalid integer negation in FormatMoney: make FormatMoney(const ↵practicalswift
CAmount& n) well-defined also when n is std::numeric_limits<CAmount>::min()
2021-02-18Merge #19809: log: Prefix log messages with function name and source code ↵Wladimir J. van der Laan
location if -logsourcelocations is set b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 log: Prefix log messages with function name if -logsourcelocations is set (practicalswift) Pull request description: Prefix log messages with function name if `-logfunctionnames` is set. Yes, exactly like `-logthreadnames` but for function names instead of thread names :) This is a small developer ergonomics improvement: I've found this to be a cheap/simple way to correlate log output and originating function. For me it beats the ordinary cycle of 1.) try to figure out a regexp matching the static part of the dynamic log message, 2.) `git grep -E 'Using .* MiB out of .* requested for signature cache'`, 3.) `mcedit filename.cpp` (`openemacs filename.cpp` works too!) and 4.) search for log message and scroll up to find the function name :) Without any logging parameters: ``` $ src/bitcoind -regtest 2020-08-25T03:29:04Z Using RdRand as an additional entropy source 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z block tree size = 1 2020-08-25T03:29:04Z nBestHeight = 0 2020-08-25T03:29:04Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z 0 addresses found from DNS seeds ``` With `-logthreadnames` and `-logfunctionnames`: ``` $ src/bitcoind -regtest -logthreadnames -logfunctionnames 2020-08-25T03:29:04Z [init] [ReportHardwareRand] Using RdRand as an additional entropy source 2020-08-25T03:29:04Z [init] [InitSignatureCache] Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [InitScriptExecutionCache] Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [LoadChainTip] Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z [init] [AppInitMain] block tree size = 1 2020-08-25T03:29:04Z [init] [AppInitMain] nBestHeight = 0 2020-08-25T03:29:04Z [loadblk] [LoadMempool] Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z [dnsseed] [ThreadDNSAddressSeed] 0 addresses found from DNS seeds ``` ACKs for top commit: laanwj: Code review ACK b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 MarcoFalke: review ACK b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 🌃 Tree-SHA512: d100f5364630c323f31d275259864c597f7725e462d5f4bdedcc7033ea616d7fc0d16ef1b2af557e692f4deea73c6773ccfc681589e7bf6ba970b9ec169040c7
2021-02-04Introduce GetUniquePath(base) helper method to replace ↵Kiminuo
boost::filesystem::unique_path() which is not available in std::filesystem.
2021-01-15log: Prefix log messages with function name if -logsourcelocations is setpracticalswift
2021-01-05Merge #19846: build: enable unused member function diagnosticMarcoFalke
819d03b932134ee91df3b0fe98a481a331ce57bf refactor: took out unused member functions (Zero) ed69213c2b2a99023bdee5168614cb8b71990f5f build: enable unused member function diagnostic (Zero) Pull request description: This PR enables the `-Wunused-member-function` compiler diagnostic, as discussed in #19702. > **Notice**: The `unused-member-function` diagnostic is only available on clang. Therefore, clang should be used to test this PR. - [x] Include the `-Wunused-member-function`diagnostic in `./configure.ac`. (ed69213c2b2a99023bdee5168614cb8b71990f5f) - [x] Resolve the reported warnings. (819d03b932134ee91df3b0fe98a481a331ce57bf) Currently, enabling this flag no longer reports the following warnings: > **Note**: output from `make 2>&1 | grep "warning: unused member function" | sort | uniq -c` ``` 1 index/blockfilterindex.cpp:54:5: warning: unused member function 'DBHeightKey' [-Wunused-member-function] 2 script/bitcoinconsensus.cpp:50:9: warning: unused member function 'GetType' [-Wunused-member-function] 1 test/util_tests.cpp:1975:14: warning: unused member function 'operator=' [-Wunused-member-function] ``` All tests have passed locally (from `make check` & `src/test/test_bitcoin`). This PR closes #19702. ACKs for top commit: practicalswift: ACK 819d03b932134ee91df3b0fe98a481a331ce57bf - patch still looks correct :) MarcoFalke: ACK 819d03b932134ee91df3b0fe98a481a331ce57bf pox: Tested ACK 819d03b932134ee91df3b0fe98a481a331ce57bf with clang after `make clean`. No unused member function warnings. theStack: tested ACK 819d03b932134ee91df3b0fe98a481a331ce57bf Tree-SHA512: 5fdfbbb02b3dc618a90a874a5caa5e01e596fc1d14a209e75a6981f01b253f9bca0cfac8fdd758dd7151986609fb76571c3745124a29cfd4f8cbb8d82a07272e
2020-12-06Don't make "in" parameters look like "out"/"in-out" parameters: pass by ref ↵practicalswift
to const instead of ref to non-const
2020-12-01refactor: Improve use of explicit keywordFabian Jahr
2020-11-24test: Add testing of ParseInt/ParseUInt edge cases with leading +/-/0:spracticalswift
2020-11-20Merge #20223: build: Drop the leading 0 from the version numberMarcoFalke
8f7b93047581c67f2133cdb8c7845471de66c30f Drop the leading 0 from the version number (Andrew Chow) Pull request description: Removes the leading 0 from the version number. The minor version, which we had been using as the major version, is now the major version. The revision, which we had been using as the minor version, is now the minor version. The revision number is dropped. The build number is promoted to being part of the version number. This also avoids issues where it was accidentally not included in the version number. The CLIENT_VERSION remains the same format as previous as previously, as the Major version was 0 so it never actually got included in it. The user agent string formatter is updated to follow this new versioning. *** Honestly I'm just tired of all of the people asking for "1.0" that maybe this'll shut them up. Skip the whole 1.0 thing and go straight to version 22.0! Also, this means that the terminology we commonly use lines up with how the variables are named. So major versions are actually bumping the major version number, etc. ACKs for top commit: jnewbery: Code review ACK 8f7b930475 MarcoFalke: review ACK 8f7b93047581c67f2133cdb8c7845471de66c30f 🎻 Tree-SHA512: b5c3fae14d4c0a9c0ab3b1db7c949ecc0ac3537646306b13d98dd0efc17c489cdd16d43f0a24aaa28e9c4a92ea360500e05480a335b03f9fb308010cdd93a436
2020-11-20Merge #20000: test: fix creation of "std::string"s with \0sWladimir J. van der Laan
ecc6cf1a3b097b9b5b047282063a0b6779631b83 test: fix creation of std::string objects with \0s (Vasil Dimov) Pull request description: A string literal `"abc"` contains a terminating `\0`, so that is 4 bytes. There is no need to write `"abc\0"` unless two terminating `\0`s are necessary. `std::string` objects do not internally contain a terminating `\0`, so `std::string("abc")` creates a string with size 3 and is the same as `std::string("abc", 3)`. In `"\01"` the `01` part is interpreted as one number (1) and that is the same as `"\1"` which is a string like `{1, 0}` whereas `"\0z"` is a string like `{0, 'z', 0}`. To create a string like `{0, '1', 0}` one must use `"\0" "1"`. Adjust the tests accordingly. ACKs for top commit: laanwj: ACK ecc6cf1a3b097b9b5b047282063a0b6779631b83 practicalswift: ACK ecc6cf1a3b097b9b5b047282063a0b6779631b83 modulo happily green CI Tree-SHA512: 5eb489e8533a4199a9324b92f7280041552379731ebf7dfee169f70d5458e20e29b36f8bfaee6f201f48ab2b9d1d0fc4bdf8d6e4c58d6102f399cfbea54a219e
2020-11-18Drop the leading 0 from the version numberAndrew Chow
Removes the leading 0 from the version number. The minor version, which we had been using as the major version, is now the major version. The revision, which we had been using as the minor version, is now the minor version. The revision number is dropped. The build number is promoted to being part of the version number. This also avoids issues where it was accidentally not included in the version number. The CLIENT_VERSION remains the same format as previous as previously, the Major version was 0 so that was never a factor in CLIENT_VERSION.
2020-10-31test: fix creation of std::string objects with \0sVasil Dimov
A string literal `"abc"` contains a terminating `\0`, so that is 4 bytes. There is no need to write `"abc\0"` unless two terminating `\0`s are necessary. `std::string` objects do not internally contain a terminating `\0`, so `std::string("abc")` creates a string with size 3 and is the same as `std::string("abc", 3)`. In `"\01"` the `01` part is interpreted as one number (1) and that is the same as `"\1"` which is a string like `{1, 0}` whereas `"\0z"` is a string like `{0, 'z', 0}`. To create a string like `{0, '1', 0}` one must use `"\0" "1"`. Adjust the tests accordingly.
2020-10-27util: Add StripRedundantLastElementsOfPath functionHennadii Stepanov
Co-authored-by: saibato <saibato.naga@pm.me> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2020-09-22refactor: took out unused member functionsZero
Took out the following unused member functions: - 'DBHeightKey()' - 'GetType()' - 'operator='
2020-09-18test: signet network selection testsKarl-Johan Alm
2020-09-18add signet chain and accompanying parametersKarl-Johan Alm
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2020-08-14test: Fix 'make cov' with clangHennadii Stepanov
2020-08-06refactor: Make HexStr take a spanWladimir J. van der Laan
Make HexStr take a span of bytes, instead of an awkward pair of templated iterators.
2020-07-30Make Hash[160] consume range-like objectsPieter Wuille
2020-07-30Make CHash256 and CHash160 consume SpansPieter Wuille
2020-07-23Merge #15935: Add <datadir>/settings.json persistent settings storageMarcoFalke
9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 Add <datadir>/settings.json persistent settings storage. (Russell Yanofsky) eb682c5700e7a9176d0104d470b83ff9aa3589e8 util: Add ReadSettings and WriteSettings functions (Russell Yanofsky) Pull request description: Persistent settings are used in followup PRs #15936 to unify gui settings between bitcoin-qt and bitcoind, and #15937 to add a load_on_startup flag to the loadwallet RPC and maintain a dynamic list of wallets that should be loaded on startup that also can be shared between bitcoind and bitcoin-qt. ACKs for top commit: MarcoFalke: Approach re-ACK 9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 🌾 jnewbery: utACK 9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 Tree-SHA512: 39fcc6051717117c9141e934de1d0d3f739484be4685cdf97d54de967c8c816502b4fd0de12114433beaa5c5b7060c810fd8ae4e2b3ce7c371eb729ac01ba2e1
2020-07-11util: Make Assert work with any valueMarcoFalke
2020-07-11Add <datadir>/settings.json persistent settings storage.Russell Yanofsky
Persistent settings are used in followup PRs #15936 to unify gui settings between bitcoin-qt and bitcoind, and #15937 to add a load_on_startup flag to the loadwallet RPC and maintain a dynamic list of wallets that should be loaded on startup that also can be shared between bitcoind and bitcoin-qt.
2020-05-12Simplify usage of Span in several placesPieter Wuille
2020-05-08test: Fix outstanding -Wsign-compare errorsBen Woosley
2020-04-16scripted-diff: Sort test includesMarcoFalke
-BEGIN VERIFY SCRIPT- # Mark all lines with #includes sed -i --regexp-extended -e 's/(#include <.*>)/\1 /g' $(git grep -l '#include' ./src/bench/ ./src/test ./src/wallet/test/) # Sort all marked lines git diff -U0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v -END VERIFY SCRIPT-
2020-03-26Merge #18270: util: Fail to parse whitespace-only strings in ParseMoney(...) ↵MarcoFalke
(instead of parsing as zero) 100213c5c29ebd7bd50aa885e54594ae10bf87a4 util: Fail to parse space-only strings in ParseMoney(...) (instead of parsing as zero) (practicalswift) Pull request description: Fail to parse whitespace-only strings in `ParseMoney(...)` (instead of parsing as `0`). This is a follow-up to #18225 ("util: Fail to parse empty string in `ParseMoney`") which made `ParseMoney("")` fail instead of parsing as `0`. Context: https://github.com/bitcoin/bitcoin/pull/18225#issuecomment-592994765 Current non-test call sites: ``` $ git grep ParseMoney ":(exclude)src/test/" src/bitcoin-tx.cpp: if (!ParseMoney(strValue, value)) src/init.cpp: if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n)) src/init.cpp: if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) { src/init.cpp: if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) src/init.cpp: if (!ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n)) src/miner.cpp: if (gArgs.IsArgSet("-blockmintxfee") && ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) { src/util/moneystr.cpp:bool ParseMoney(const std::string& str, CAmount& nRet) src/util/moneystr.h:NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet); src/wallet/wallet.cpp: if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) { src/wallet/wallet.cpp: if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) { src/wallet/wallet.cpp: if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) { src/wallet/wallet.cpp: if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) { src/wallet/wallet.cpp: if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) { ``` ACKs for top commit: Empact: ACK https://github.com/bitcoin/bitcoin/pull/18270/commits/100213c5c29ebd7bd50aa885e54594ae10bf87a4 sipa: ACK 100213c5c29ebd7bd50aa885e54594ae10bf87a4 theStack: ACK https://github.com/bitcoin/bitcoin/commit/100213c5c29ebd7bd50aa885e54594ae10bf87a4 Tree-SHA512: cadfb1ac8276cf54736c3444705f2650e7a08023673aedc729fabe751ae80f6c490fc0945ee38dbfd02c95e4d9853d1e4c84f5d3c310f44eaf3585afec8a4c22
2020-03-14Replace std::to_string with locale-independent alternativeBen Woosley
2020-03-12util: Fail to parse space-only strings in ParseMoney(...) (instead of ↵practicalswift
parsing as zero)
2020-03-06Merge #16117: util: Replace boost sleep with std sleepfanquake
fae86c38bca5c960462e53975314a0749db5d17d util: Remove unused MilliSleep (MarcoFalke) fa9af06d91e9357e86863781746f0e78a509967e scripted-diff: Replace MilliSleep with UninterruptibleSleep (MarcoFalke) fa4620be782c2bf6b5ffddf4f671194fdd1536f3 util: Add UnintrruptibleSleep (MarcoFalke) Pull request description: We don't use the interruptible feature of boost's sleep anywhere, so replace it with the sleep in `std::thread` ACKs for top commit: ajtowns: ACK fae86c38bca5c960462e53975314a0749db5d17d quick code review practicalswift: ACK fae86c38bca5c960462e53975314a0749db5d17d -- patch looks correct sipa: Concept and code review ACK fae86c38bca5c960462e53975314a0749db5d17d fanquake: ACK fae86c38bca5c960462e53975314a0749db5d17d - note that an instance of `DHAVE_WORKING_BOOST_SLEEP_FOR` was missed in the [linter](https://github.com/bitcoin/bitcoin/blob/master/test/lint/extended-lint-cppcheck.sh#L69), but that can be cleaned up later. Tree-SHA512: 7c0f8eb197664b9f7d9fe6c472c77d384f11c797c913afc31de4b532e3b4fd9ea6dd174f92062ff9d1ec39b25e0900ca7c597435add87f0f2477d9557204848c
2020-02-29util: Fail to parse empty string in ParseMoneyMarcoFalke