Commit graph

69 commits

Author SHA1 Message Date
Pieter Wuille 124d13a58c Merge test_random.h into test_bitcoin.h 2017-06-05 12:44:44 -07:00
Jorge Timón f2957ce6cd
Util: Create ArgsManager class...
- Introduce ArgsManager::GetArgs()
- Adapt util_tests.cpp to ArgsManager
2017-05-09 21:29:02 +02:00
practicalswift dbf30ff10f [trivial] Fix typos in comments 2017-03-21 19:49:08 +01:00
kobake 8e0720bdb9 Fix msvc compiler error C4146 (unary minus operator applied to unsigned type)
On msvc14, int literal '-2147483648' is invalid, because '2147483648' is unsigned type and cant't apply minus operator to unsigned type.
To define the int literal correctly, use '-2147483647 - 1' formula that is also used to define INT_MIN in limits.h.
2017-03-08 15:43:40 +09:00
MarcoFalke 4cfd57d2e3
Merge #9281: Refactor: Remove using namespace <xxx> from bench/ & test/ sources
73f4119 Refactoring: Removed using namespace <xxx> from bench/ and test/ source files. (Karl-Johan Alm)
2017-01-05 11:32:05 +01:00
Karl-Johan Alm 73f41190b9 Refactoring: Removed using namespace <xxx> from bench/ and test/ source files. 2017-01-02 20:35:23 +09:00
isle2983 27765b6403 Increment MIT Licence copyright header year on files modified in 2016
Edited via:

$ contrib/devtools/copyright_header.py update .
2016-12-31 11:01:21 -07:00
Matt Corallo 4cd373aea8 Un-expose mapArgs from utils.h 2016-12-24 11:29:33 -05:00
Matt Corallo 0cf86a6678 Introduce (and use) an IsArgSet accessor method 2016-12-23 21:30:16 -05:00
Matt Corallo 2b5f085ad1 Fix non-const mapMultiArgs[] access after init.
Swap mapMultiArgs for a const-reference to a _mapMultiArgs which is
only accessed in util.cpp
2016-12-23 21:30:15 -05:00
MarcoFalke fa8278e845 test: Fix test_random includes 2016-11-07 16:11:51 +01:00
Wladimir J. van der Laan 5eaaa83ac1 Kill insecure_random and associated global state
There are only a few uses of `insecure_random` outside the tests.
This PR replaces uses of insecure_random (and its accompanying global
state) in the core code with an FastRandomContext that is automatically
seeded on creation.

This is meant to be used for inner loops. The FastRandomContext
can be in the outer scope, or the class itself, then rand32() is used
inside the loop. Useful e.g. for pushing addresses in CNode or the fee
rounding, or randomization for coin selection.

As a context is created per purpose, thus it gets rid of
cross-thread unprotected shared usage of a single set of globals, this
should also get rid of the potential race conditions.

- I'd say TxMempool::check is not called enough to warrant using a special
  fast random context, this is switched to GetRand() (open for
  discussion...)

- The use of `insecure_rand` in ConnectThroughProxy has been replaced by
  an atomic integer counter. The only goal here is to have a different
  credentials pair for each connection to go on a different Tor circuit,
  it does not need to be random nor unpredictable.

- To avoid having a FastRandomContext on every CNode, the context is
  passed into PushAddress as appropriate.

There remains an insecure_random for test usage in `test_random.h`.
2016-10-17 13:08:35 +02:00
MarcoFalke fa1cf9e7b8 [test] Remove unused code 2016-08-24 20:21:31 +02:00
Wladimir J. van der Laan e012f3cea0 util: Add ParseUInt32 and ParseUInt64
Add error and range-checking parsers for unsigned 32 and 64 bit numbers.
The 32-bit variant is required for parsing sequence numbers from the
command line in `bitcoin-tx` (see #8164 for discussion). I've thrown in
the 64-bit variant as a bonus, as I'm sure it will be needed at some
point.

Also adds tests, and updates `developer-notes.md`.
2016-06-08 10:28:51 +02:00
MarcoFalke fa3a81af18 [tests] Extend util_ParseMoney test case 2016-03-14 15:49:33 +01:00
Wladimir J. van der Laan f31b6b8995 test: test leading space for ParseHex
BerkeleyDB dump files have key and value lines indented.
The salvage code passes these to ParseHex as-is.
Check this in the tests (should just pass with current code).
2016-02-15 17:14:30 +01:00
Luke Dashjr a68bb9f5e7 Merge branch 'master' into single_prodname 2016-02-03 05:41:13 +00:00
Luke Dashjr cc2095ecae Rewrite FormatParagraph to handle newlines within input strings correctly 2016-02-03 05:38:43 +00:00
MarcoFalke fa24439ff3 Bump copyright headers to 2015 2015-12-13 18:08:39 +01:00
MarcoFalke 43edd515e5 SanitizeString: Allow hypen char 2015-09-23 12:06:00 +02:00
MarcoFalke 1c1b1b315f [uacomment] Sanitize per BIP-0014
* SanitizeString() can be requested to be more strict
* Throw error when SanitizeString() changes uacomments
* Fix tests
2015-09-16 15:23:29 +02:00
Wladimir J. van der Laan 9cc91523db rpc: Accept scientific notation for monetary amounts in JSON
Add a function `ParseFixedPoint` that parses numbers according
to the JSON number specification and returns a 64-bit integer.

Then this in `AmountFromValue`, rather than `ParseMoney`.

Also add lots of tests (thanks to @jonasschnelli for some of them).

Fixes issue #6297.
2015-07-10 15:43:26 +02:00
Wladimir J. van der Laan 643114f539
Merge pull request #6239
7d8ffac Changes necessary now that zero values accepted in AmountFromValue (Wladimir J. van der Laan)
a04bdef Get rid of fPlus argument to FormatMoney (Wladimir J. van der Laan)
4b4b9a8 Don't go through double in AmountFromValue and ValueFromAmount (Wladimir J. van der Laan)
2015-06-09 18:38:33 +02:00
Jonas Schnelli c946ebed5e fix util_tests.cpp clang warnings
was introduced with #6121
2015-06-06 10:12:12 +02:00
Wladimir J. van der Laan a04bdefbeb Get rid of fPlus argument to FormatMoney
It's never used with any other value than false, the default.
2015-06-06 09:30:41 +02:00
Wladimir J. van der Laan 7e98a3c642 util: Add ParseInt64 and ParseDouble functions
Strict parsing functions for other numeric types.

- ParseInt64 analogous to ParseInt32, but for 64-bit values.
- ParseDouble for doubles.
- Make all three Parse* functions more strict (e.g. reject whitespace on
  the inside)

Also add tests.
2015-06-04 13:18:46 +02:00
Wladimir J. van der Laan 92fd887fd4 tests: add a BasicTestingSetup and apply to all tests
Make sure that chainparams and logging is properly initialized. Doing
this for every test may be overkill, but this initialization is so
simple that that does not matter.

This should fix the travis issues.
2015-03-12 09:45:22 +01:00
Cory Fields 7f991e364e c++11: These look like user-defined literals.
Add a space to keep the compiler happy
2015-02-03 23:31:00 -05:00
Michael Ford 78253fcbad Remove references to X11 licence 2014-12-16 15:56:50 +08:00
Pavel Janík a26bf478ea Add a new test for FormatParagraph (string longer than the default width). 2014-12-06 22:49:07 +01:00
Luke Dashjr d227011184 MOVEONLY: core/ -> primitives/ 2014-12-03 10:52:58 +00:00
Cory Fields 71697f97d3 Separate protocol versioning from clientversion 2014-10-29 00:24:40 -04:00
jtimon 4a3587d8db MOVEONLY: Separate CTransaction and dependencies from core 2014-10-27 13:54:37 +01:00
Cory Fields 5f4bcf6b14 boost: drop boost dependency in version.cpp.
Also add a test to verify.
2014-10-15 15:13:20 -04:00
Mark Friedenbach a372168e77 Use a typedef for monetary values 2014-09-26 15:42:04 -07:00
Wladimir J. van der Laan ad49c256c3 Split up util.cpp/h
Split up util.cpp/h into:

- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)

The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).

Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-26 13:25:22 +02:00
Wladimir J. van der Laan d1e26d4e71 Move CMedianFilter to timedata.cpp
Now that we no longer use the median filter to keep track of
the number of blocks of peers, that's the only place it is used.
2014-08-26 13:25:20 +02:00
Philip Kaufmann 6354935c48 move rand functions from util to new random.h/.cpp 2014-07-09 09:42:19 +02:00
Wladimir J. van der Laan 97789d374c util: Add function FormatParagraph to format paragraph to fixed-width
This is to be used for the `-version` and `-help` messages.
2014-06-11 14:27:09 +02:00
Wladimir J. van der Laan 3e8ac6af9a
Replace non-threadsafe gmtime and setlocale
Make DateTimeStrFormat use boost::posix_time.

Also re-enable the util_DateTimeStrFormat tests, as they are no
longer platform specific.
2014-05-23 15:23:11 +02:00
Wladimir J. van der Laan c3ad56f4e0
Merge pull request #4138
783b182 Remove dummy PRIszX macros for formatting (Wladimir J. van der Laan)
2014-05-12 14:01:48 +02:00
Wladimir J. van der Laan fdbd7075ca Remove unused function WildcardMatch
No longer necessary after implementing netmask-based matching.
Also remove a longer-unused function `skipspaces`.
2014-05-09 16:45:57 +02:00
Wladimir J. van der Laan 0d4ea1cf8a util: add parseint32 function with strict error reporting
None of the current integer parsing functions in util
check whether the result is valid and fits in the range
of the type. This is required for less sloppy error reporting.
2014-05-09 16:45:56 +02:00
Wladimir J. van der Laan 783b182c8f Remove dummy PRIszX macros for formatting
Size specifiers are no longer needed now that we use typesafe tinyformat
for string formatting, instead of the system's sprintf.

No functional changes.

This continues the work in #3735.
2014-05-06 15:29:16 +02:00
Wladimir J. van der Laan 3fc6846181 Add licenses for tests and test data
- Add license headers to source files (years based on commit dates)
  in `src/test` as well as `qa`
- Add `README.md` to `src/test/data` specifying MIT license

Fixes #3848
2014-03-18 10:20:55 +01:00
Wladimir J. van der Laan f48742c2bf Get rid of C99 PRI?64 usage in source files
Amend to d5f1e72. It turns out that BerkelyDB was including inttypes.h
indirectly, so we cannot fix this with just macros.

Trivial commit: apply the following script to all .cpp and .h files:

    # Middle
    sed -i 's/"PRIx64"/x/g' "$1"
    sed -i 's/"PRIu64"/u/g' "$1"
    sed -i 's/"PRId64"/d/g' "$1"
    # Initial
    sed -i 's/PRIx64"/"x/g' "$1"
    sed -i 's/PRIu64"/"u/g' "$1"
    sed -i 's/PRId64"/"d/g' "$1"
    # Trailing
    sed -i 's/"PRIx64/x"/g' "$1"
    sed -i 's/"PRIu64/u"/g' "$1"
    sed -i 's/"PRId64/d"/g' "$1"

After this commit, `git grep` for PRI.64 should turn up nothing except
the defines in util.h.
2014-02-24 09:08:56 +01:00
Wladimir J. van der Laan eaafa23cbd Add test for GetTime()
Test for mingw/wine issue #3494, where the upper word of time(NULL)
return value gets clobbered.
2014-01-09 11:35:38 +01:00
Wladimir J. van der Laan c82788efff tests: add testcases for strprintf 2013-11-13 17:02:27 +01:00
Brandon Dahler 51ed9ec971 Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
2013-11-10 09:36:28 -06:00
Gavin Andresen 42656ea2e5 Make RPC password resistant to timing attacks
Fixes issue#2838; this is a tweaked version of pull#2845 that
should not leak the length of the password and is more generic,
in case we run into other situations where we need
timing-attack-resistant comparisons.
2013-08-08 19:58:57 +10:00