Commit Graph

142 Commits

Author SHA1 Message Date
Pieter Wuille 92f1f8b319 Split off key_io_tests from base58_tests 2018-02-19 18:55:21 -08:00
Wladimir J. van der Laan 20166f8a44
Merge #11748: [Tests] Adding unit tests for GetDifficulty in blockchain.cpp.
3e1ee31 [Tests] Adding unit tests for GetDifficulty in blockchain.cpp. (sean)

Pull request description:

  blockchain.cpp has low unit test coverage. This commit is intended
  to start improving its code coverage to reasonable levels. One or more
  follow up commits will complete the task that this commit is starting
  (though the usefulness of this commit is not dependent upon later
  commits).

  Note that these tests were not written based upon a specification of how
  GetDifficulty *should* work, but rather how it actually *does* work. As
  a result, if there are any bugs in the current GetDifficulty
  implementation, these unit tests serve to lock them in rather than
  expose them.

  -- Why has blockchain.cpp been modified if this is a unit testing change?

  Since the existing GetDifficulty function relies on a global variable,
  chainActive, it was not suitable for unit testing purposes. Both the
  existing GetDifficulty function and the unit tests now call through to
  a new, more modular version of GetDifficulty that can work on any chain,
  not just chainActive.

  -- Why does blockchain_tests.cpp directly include blockchain.cpp instead
  of blockchain.h?

  While the new GetDifficulty function's signature is arguably better than
  the old one's, it still isn't great, and doesn't seem to warrant inclusion
  as part of the blockchain.h API, especially since only test code is
  directly using it. If a better way of exposing the new GetDifficulty
  function to unit tests exists, please mention it and the commit will be
  updated accordingly.

  -- Why is the test fixture named blockchain_difficulty_tests rather than
  blockchain_tests?

  The Bitcoin Core policy for naming unit test files is to match the the
  file under test ("blockchain" becomes "blockchain_tests"). While this
  commit complies with that, blockchain.cpp is a massive file, such that
  having all of the unit tests in one file will tend towards disorder.
  Since there will be a lot more tests added to this file, the intention
  is to divide up different types of tests into different test fixtures
  within the same file.

Tree-SHA512: a7dda9c2a9414d4819b4d2911f5637891dc19cecbecfc1463846161d2a78793151927a5ab911c69a5d3013f7668e75a1d78a65667cb9d83910cda439cbe84d62
2017-12-23 11:22:18 +01:00
John Newbery 2862b562cc [tests] remove redundant univalue_tests.cpp 2017-12-12 12:45:53 -05:00
sean 3e1ee31043 [Tests] Adding unit tests for GetDifficulty in blockchain.cpp.
blockchain.cpp has low unit test coverage. This commit is intended
to start improving its code coverage to reasonable levels. One or more
follow up commits will complete the task that this commit is starting
(though the usefulness of this commit is not dependent upon later
commits).

Note that these tests were not written based upon a specification of how
GetDifficulty *should* work, but rather how it actually *does* work. As
a result, if there are any bugs in the current GetDifficulty
implementation, these unit tests serve to lock them in rather than
expose them.

-- Why has blockchain.cpp been modified if this is a unit testing change?

Since the existing GetDifficulty function relies on a global variable,
chainActive, it was not suitable for unit testing purposes. Both the
existing GetDifficulty function and the unit tests now call through to
a new, more modular version of GetDifficulty that can work on any chain,
not just chainActive.

-- Why does blockchain_tests.cpp directly include blockchain.cpp instead
of blockchain.h?

While the new GetDifficulty function's signature is arguably better than
the old one's, it still isn't great, and doesn't seem to warrant inclusion
as part of the blockchain.h API, especially since only test code is
directly using it. If a better way of exposing the new GetDifficulty
function to unit tests exists, please mention it and the commit will be
updated accordingly.

-- Why is the test fixture named blockchain_difficulty_tests rather than
blockchain_tests?

The Bitcoin Core policy for naming unit test files is to match the the
file under test ("blockchain" becomes "blockchain_tests"). While this
commit complies with that, blockchain.cpp is a massive file, such that
having all of the unit tests in one file will tend towards disorder.
Since there will be a lot more tests added to this file, the intention
is to divide up different types of tests into different test fixtures
within the same file.
2017-11-22 15:48:14 -08:00
James O'Beirne 65e91f5edf [tests] Test that mempool rejects coinbase transactions 2017-11-18 00:48:34 -08:00
Wladimir J. van der Laan 0c715214dd build: Remove -I for everything but project root
Remove -I from build system for everything but the project root,
and built-in dependencies.
2017-11-16 08:23:02 +13:00
MarcoFalke b4a509a3f8
Merge #11433: qa: Restore bitcoin-util-test py2 compatibility
fafff1220 qa: Restore bitcoin-util-test py2 compatibility (MarcoFalke)

Pull request description:

  Currently `./configure && make check` will look for python3, then python2. As long as we support python2 (and use it as fallback), `make check` should run fine with both python2 and python3.

  Fixes #11352 by @Zenitur

Tree-SHA512: a335ebdd224328d6f924fe52a9b97de196926476c9ee04ce3280743ea93bcae355eb2d5d4bed4050c01b2e904105595eac7db2eaa9307207581caa0a98ebcc0b
2017-10-03 21:25:00 +02:00
MarcoFalke dbc4ae0396
Merge #11293: Deduplicate CMerkleBlock construction code, add test coverage
46ce223d1 Add tests for CMerkleBlock usage with txids specified (James O'Beirne)
5ab586f90 Consolidate CMerkleBlock constructor into a single method (James O'Beirne)

Pull request description:

  What started as a simple task to add test coverage ended up giving way to a light refactoring. This consolidates the mostly-identical `CMerkleBlock` constructors into one (using C++11 constructor delegation) and adds coverage for the by-txids construction case.

  ### Before

  ![selection_006](https://user-images.githubusercontent.com/73197/30242104-0f381fe4-9545-11e7-9617-83b87fce0456.png)

  ### After

  ![selection_008](https://user-images.githubusercontent.com/73197/30242107-1425dfaa-9545-11e7-9e6b-2c3432517dd1.png)

Tree-SHA512: eed84ed3e8bfc43473077b575c8252759a857e37275e4b36ca7cc2c17a65895e5f494bfd9d4aeab09fc6e98fc6a9c641ac7ecc0ddbeefe01a9e4308e7909e529
2017-10-03 14:27:39 +02:00
MarcoFalke fafff1220c qa: Restore bitcoin-util-test py2 compatibility 2017-10-01 11:22:07 +02:00
Pieter Wuille 8fd2267053 Import Bech32 C++ reference code & tests
This includes a reformatted version of the Bech32 reference code
(see https://github.com/sipa/bech32/tree/master/ref/c%2B%2B), with
extra documentation.
2017-09-28 16:02:16 -07:00
Jim Posen d7afe2d157 [script] Unit tests for script/standard functions 2017-09-21 12:24:20 -07:00
James O'Beirne 46ce223d15 Add tests for CMerkleBlock usage with txids specified 2017-09-20 20:36:10 -07:00
MeshCollider d1138e3620 Remove redundant testutil files 2017-09-05 15:02:17 +12:00
Jonas Schnelli 32c9710c50
Fix test_bitcoin circular dependency issue 2017-07-17 17:42:21 +02:00
Wladimir J. van der Laan a4fe07714d
Merge #10544: Update to LevelDB 1.20
3ee3d04 Add extra LevelDB source to Makefile (MarcoFalke)
2424989 leveldb: enable runtime-detected crc32 instructions (Cory Fields)
cf44e4c Squashed 'src/leveldb/' changes from a31c8aa40..196962ff0 (Pieter Wuille)

Tree-SHA512: 19ade77e3f6265507b3ab7b9aa5150d378aa0751e24ac7a61567b0f720a566cedc6c3d3336da17a3bd2b5d068ee86600d96a15228f78bd20ccf98c8fc9041a91
2017-06-13 19:48:13 +02:00
Cory Fields 2424989e4f leveldb: enable runtime-detected crc32 instructions 2017-06-09 19:25:36 -07:00
Pieter Wuille e801084dec
Merge #10321: Use FastRandomContext for all tests
e94584858 scripted-diff: Use new naming style for insecure_rand* functions (Pieter Wuille)
2fcd9cc86 scripted-diff: Use randbits/bool instead of randrange where possible (Pieter Wuille)
2ada67852 Use randbits instead of ad-hoc emulation in prevector tests (Pieter Wuille)
5f0b04eed Replace rand() & ((1 << N) - 1) with randbits(N) (Pieter Wuille)
3ecabae36 Replace more rand() % NUM by randranges (Pieter Wuille)
efee1db21 scripted-diff: use insecure_rand256/randrange more (Pieter Wuille)
1119927df Add various insecure_rand wrappers for tests (Pieter Wuille)
124d13a58 Merge test_random.h into test_bitcoin.h (Pieter Wuille)
90620d66c scripted-diff: Rename cuckoo tests' local rand context (Pieter Wuille)
37e864eb9 Add FastRandomContext::rand256() and ::randbytes() (Pieter Wuille)

Tree-SHA512: d09705a3ec718ae792f7d66a75401903ba7b9c9d3fc36669d6e3b9242f0194738106be26baefc8a8e3fa6df7c9a35978c71c0c430278a028b331df23a3ea3070
2017-06-07 15:12:14 -07:00
MarcoFalke 75e898c094
Merge #10331: Share config between util and functional tests
8ad5bde Merge bctest.py into bitcoin-util-test.py (John Newbery)
95836c5 Use shared config file for functional and util tests (John Newbery)
89fcd35 Use an .ini config file for environment vars in bitcoin-util-test.py (John Newbery)
e9265df Change help_text in bitcoin-util-test.py to a docstring. (John Newbery)
ce58e93 Change bitcoin-util-test.py to use Python3 (John Newbery)

Tree-SHA512: 66dab0b4a8546aee0dfaef134a165f1447aff4c0ec335754bbc7d9e55909721c62f09cdbf4b22d02ac1fcd5a9b66780f91e1cc4d8687fae7288cc9072a23a78f
2017-06-06 23:55:24 +02:00
Pieter Wuille 124d13a58c Merge test_random.h into test_bitcoin.h 2017-06-05 12:44:44 -07:00
Jack Grigg 29f3c20078
torcontrol: Add unit tests for Tor reply parsers 2017-05-16 18:22:07 +12:00
John Newbery ce58e93ec0 Change bitcoin-util-test.py to use Python3 2017-05-03 14:14:04 -04:00
Wladimir J. van der Laan 342b9bc390
Merge #9792: FastRandomContext improvements and switch to ChaCha20
4fd2d2f Add a FastRandomContext::randrange and use it (Pieter Wuille)
1632922 Switch FastRandomContext to ChaCha20 (Pieter Wuille)
e04326f Add ChaCha20 (Pieter Wuille)
663fbae FastRandom benchmark (Pieter Wuille)
c21cbe6 Introduce FastRandomContext::randbool() (Pieter Wuille)

Tree-SHA512: 7fff61e3f6d6dc6ac846ca643d877b377db609646dd401a0e8f50b052c6b9bcd2f5fc34de6bbf28f04afd1724f6279ee163ead5f37d724fb782a00239f35db1d
2017-04-24 14:28:49 +02:00
John Newbery 7fd50c3b70 allow libevent logging to be updated during runtime 2017-04-10 17:05:59 -04:00
Pieter Wuille 16329224e7 Switch FastRandomContext to ChaCha20 2017-03-29 11:26:08 -07:00
John Newbery 63d66ba20a Move src/test/bitcoin-util-test.py to test/util/bitcoin-util-test.py 2017-03-20 10:40:31 -04:00
Jonas Schnelli b9f930b383
Merge #9974: Add basic Qt wallet test
9576b01 Enable xvfb in travis to allow running test_bitcoin-qt (Russell Yanofsky)
9e6817e Add new test_bitcoin-qt static library dependencies (Russell Yanofsky)
2754ef1 Add simple qt wallet test sending a transaction (Russell Yanofsky)
b61b34c Add braces to if statements in Qt test_main (Russell Yanofsky)
cc9503c Make qt test compatible with TestChain100Setup framework (Russell Yanofsky)
91e3035 Make test_bitcoin.cpp compatible with Qt Test framework (Russell Yanofsky)

Tree-SHA512: da491181848b8c39138e997ae5ff2df0b16eef2d9cdd0a965229b1a28d4fa862d5f1ef314a1736e5050e88858f329124d15c689659fc6e50fefde769ba24e523
2017-03-17 14:31:22 +01:00
Wladimir J. van der Laan 2c781fb920
Merge #9497: CCheckQueue Unit Tests
96c7f2c Add CheckQueue Tests (Jeremy Rubin)
e207342 Fix CCheckQueue IsIdle (potential) race condition and remove dangerous constructors. (Jeremy Rubin)

Tree-SHA512: 5989743ad0f8b08998335e7ca9256e168fa319053f91b9dece9dbb134885bef7753b567b591acc7135785f23d19799ed7e6375917f59fe0178d389e961633d62
2017-03-14 12:23:41 +01:00
Russell Yanofsky 91e303595b Make test_bitcoin.cpp compatible with Qt Test framework
Move Boost.Test main function and global overrides to a new test_bitcoin_main.cpp file.
2017-03-10 15:47:41 -05:00
Wladimir J. van der Laan 224e6eb089 util: Specific GetOSRandom for Linux/FreeBSD/OpenBSD
These are available in sandboxes without access to files or
devices. Also [they are safer and more straightforward](https://en.wikipedia.org/wiki/Entropy-supplying_system_calls)
to use than `/dev/urandom` as reading from a file has quite a few edge
cases:

- Linux: `getrandom(buf, buflen, 0)`. [getrandom(2)](http://man7.org/linux/man-pages/man2/getrandom.2.html)
  was introduced in version 3.17 of the Linux kernel.
- OpenBSD: `getentropy(buf, buflen)`. The [getentropy(2)](http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2)
  function appeared in OpenBSD 5.6.
- FreeBSD and NetBSD: `sysctl(KERN_ARND)`. Not sure when this was added
  but it has existed for quite a while.

Alternatives:

- Linux has sysctl `CTL_KERN` / `KERN_RANDOM` / `RANDOM_UUID`
  which gives 16 bytes of randomness. This may be available
  on older kernels, however [sysctl is deprecated on Linux](https://lwn.net/Articles/605392/)
  and even removed in some distros so we shouldn't use it.

Add tests for `GetOSRand()`:

- Test that no error happens (otherwise `RandFailure()` which aborts)
- Test that all 32 bytes are overwritten (initialize with zeros, try multiple times)

Discussion:

- When to use these? Currently they are always used when available.
  Another option would be to use them only when `/dev/urandom` is not
  available. But this would mean these code paths receive less testing,
  and I'm not sure there is any reason to prefer `/dev/urandom`.

Closes: #9676
2017-02-21 20:57:34 +01:00
Jeremy Rubin 96c7f2c345 Add CheckQueue Tests 2017-02-16 01:37:53 -05:00
MarcoFalke 02e5308c1b
Merge #9525: test: Include tx data in EXTRA_DIST
fa29736 test: Include tx data in EXTRA_DIST (MarcoFalke)
2017-01-12 13:41:32 +01:00
MarcoFalke fa2973678e test: Include tx data in EXTRA_DIST 2017-01-12 13:13:07 +01:00
Wladimir J. van der Laan cfe41d7a60
Merge #9387: [Refactor] RAII of libevent stuff using unique ptrs with deleters
05a55a6 Added EVENT_CFLAGS to test makefile to explicitly include libevent headers. (Karl-Johan Alm)
280a559 Added some simple tests for the RAII-style events. (Karl-Johan Alm)
7f7f102 Switched bitcoin-cli.cpp to use RAII unique pointers with deleters. (Karl-Johan Alm)
e5534d2 Added std::unique_ptr<> wrappers with deleters for libevent modules. (Karl-Johan Alm)
2017-01-05 11:11:17 +01:00
Karl-Johan Alm 05a55a639b Added EVENT_CFLAGS to test makefile to explicitly include libevent headers. 2017-01-04 18:16:55 +09:00
MarcoFalke fa558be2c1 test: Include tx data in EXTRA_DIST 2016-12-27 19:16:17 +01:00
Wladimir J. van der Laan 8dfe9fcb90
Merge #9376: Remove unused test files and references
9cb6624 Fix testfile reference (BtcDrak)
23208ac Remove unused test files and references (BtcDrak)
2016-12-21 09:26:11 +01:00
Karl-Johan Alm 280a5599eb Added some simple tests for the RAII-style events. 2016-12-21 16:49:21 +09:00
BtcDrak 9cb66248dc
Fix testfile reference 2016-12-20 19:49:02 +00:00
BtcDrak 23208ac81b
Remove unused test files and references 2016-12-19 07:43:12 +00:00
Karl-Johan Alm 815f4148b2 Uses built-in byte swap if available (Apple) and if bswap_XX is undefined.
Defers to pre-defined version if found (e.g. protobuf). For protobuf case, the definitions are identical and thus include order should not affect results.
2016-12-17 12:27:00 +09:00
Wladimir J. van der Laan 5bc209c73f
Merge #9172: Resurrect pstratem's "Simple fuzzing framework"
8b15434 doc: Add bare-bones documentation for fuzzing (Wladimir J. van der Laan)
a4153e2 Simple fuzzing framework (Patrick Strateman)
2016-12-15 16:57:06 +01:00
Patrick Strateman a4153e20ec Simple fuzzing framework 2016-12-15 13:29:03 +01:00
Pieter Wuille b83264d9c7
Merge #8895: Better SigCache Implementation
67dac4e Add unit tests for the CuckooCache (Jeremy Rubin)
c9e69fb Add CuckooCache implementation and replace the sigcache map_type with it (Jeremy Rubin)
2016-12-14 18:14:02 -08:00
Jeremy Rubin 67dac4e193 Add unit tests for the CuckooCache
SQUASHME: Update Tests for other SQUASHMEs
2016-12-14 16:02:22 -05:00
Luke Dashjr b74ff5cf0c Bugfix: Correctly replace generated headers and fail cleanly
Also removes generation of headers for *.raw files in test_bitcoin (none exist anymore)
2016-11-12 07:16:28 +00:00
MarcoFalke fa8278e845 test: Fix test_random includes 2016-11-07 16:11:51 +01:00
Gregory Maxwell 2082b5574c Remove GetTotalBlocksEstimate and checkpoint tests that test nothing.
GetTotalBlocksEstimate is no longer used and it was the only thing
 the checkpoint tests were testing.

Since checkpoints are on their way out it makes more sense to remove
 the test file than to cook up a new pointless test.
2016-11-02 01:49:45 +00:00
Luke Dashjr f4dffdd6bf Add MIT license to Makefiles 2016-09-21 22:35:12 +00:00
Patrick Strateman 9578333ec4 Remove rpc_wallet_tests.cpp 2016-08-07 19:30:20 -07:00
Wladimir J. van der Laan 042c323922
Merge #8275: Remove bad chain alert partition check
ab8be98 Remove bad chain alert partition check (BtcDrak)
2016-07-06 07:35:54 +02:00