Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[POC] Introducing property based testing to Core #8469
Conversation
fanquake
commented on an outdated diff
Aug 8, 2016
| @@ -0,0 +1,21 @@ | ||
| +package=rapidcheck | ||
| + | ||
| +$(package)_version:1.0 | ||
| + | ||
| +$(package)_download_path:https://github.com/Christewart/rapidcheck/releases/download/1.0 | ||
| + | ||
| +$(package)_file_name:rapidcheck-1.0.tar.gz |
fanquake
Contributor
|
fanquake
commented on an outdated diff
Aug 8, 2016
fanquake
commented on an outdated diff
Aug 8, 2016
fanquake
commented on an outdated diff
Aug 8, 2016
| @@ -508,7 +508,7 @@ if test x$TARGET_OS = xdarwin; then | ||
| AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"]) | ||
| fi | ||
| -AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h]) | ||
| +AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h ]) |
|
|
|
This needs a rebase/conflicts fixed. |
fanquake
commented on an outdated diff
Aug 8, 2016
fanquake
and 1 other
commented on an outdated diff
Aug 8, 2016
| @@ -0,0 +1,21 @@ | ||
| +package=rapidcheck | ||
| + | ||
| +$(package)_version:1.0 | ||
| + | ||
| +$(package)_download_path:https://github.com/Christewart/rapidcheck/releases/download/1.0 | ||
| + | ||
| +$(package)_file_name:rapidcheck-1.0.tar.gz | ||
| + | ||
| +$(package)_sha256_hash:c228dc21ec24618bfb6afa31d622d1f4ea71168f04ee499e1ffcfc63cd5833f4 | ||
| + |
Christewart
Contributor
|
|
I think this approach of testing is interesting and may render useful
for bitcoin. The user guide
https://github.com/emil-e/rapidcheck/blob/master/doc/user_guide.md
mentions that the API is not finalized, so it may be better to
integrate it via a subtree (maybe in /test)?
|
|
I think this is useful. I'm not very familiar with property based testing, but this seems to be something that would make sense for consensus and security critical projects. Some thoughts:
If others also agree to take this into master, we should probably have a first logical slice of property based tests (maybe serialization). Needs rebase. |
jonasschnelli
added Feature Tests and removed Feature
labels
Aug 8, 2016
|
@theuni Can you help here to decide if using depends is fine or a subtree would be cleaner? (I prefer a subtree per my above comment, but I am not familiar with the build system. Input is appreciated) |
|
I would probably need help with the build code to get it production ready. I plan to keep on adding properties to this pull request though when time permits. I'm going to try and get around implementing fanquake's comments and figure out how to do the |
MarcoFalke
and 1 other
commented on an outdated diff
Aug 19, 2016
| @@ -0,0 +1,21 @@ | ||
| +package=rapidcheck | ||
| + | ||
| +$(package)_version:1.0 | ||
| + | ||
| +$(package)_download_path:https://github.com/Christewart/rapidcheck/releases/download/1.0 |
MarcoFalke
Member
|
MarcoFalke
and 1 other
commented on an outdated diff
Aug 24, 2016
| @@ -0,0 +1,21 @@ | ||
| +package=rapidcheck | ||
| + | ||
| +$(package)_version=1.0 | ||
| + | ||
| +$(package)_download_path=https://github.com/Christewart/rapidcheck/releases/download/1.0 | ||
| + | ||
| +$(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
| + | ||
| +$(package)_sha256_hash=c228dc21ec24618bfb6afa31d622d1f4ea71168f04ee499e1ffcfc63cd5833f4 |
MarcoFalke
Member
|
Christewart
and 1 other
commented on an outdated diff
Aug 26, 2016
| $(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
| - | ||
| -$(package)_sha256_hash=c228dc21ec24618bfb6afa31d622d1f4ea71168f04ee499e1ffcfc63cd5833f4 | ||
| - | ||
| -define $(package)_preprocess_cmds | ||
| - mkdir build | ||
| -endef | ||
| +$(package)_sha256_hash=78cdb8d0185b602e32e66f4e5d1a6ceec1f801dd9641b8a9456c386b1eaaf0e5 |
MarcoFalke
Member
|
|
@Christewart Do you need help to address the feedback from @jonasschnelli? |
|
@MarcoFalke Yeah I'm not really sure how to get that done |
| + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||
| + ss << tx; | ||
| + deserialize_type t; | ||
| + CTransaction tx2(t,ss); |
|
I like this kind of testing-- testing invariants on random test cases--, and we use it extensively in libsecp256k1. It's one of the answers to my irritation with the way many of the unit tests in Bitcoin core have worked in the past: hard-coding the exact behavior. Meaning that if you change anything, the tests all fail and you're left wondering if you broke something important or if the test was just mandating the behavior you were fixing. In either case, updating the test is often more work than the change. Taking a dependency for it seems unfortunate; but I'm not qualified to judge if it does snazzy things that make generating cases easy. I have had bad experience with test frameworks in the past which had very high overhead making test cases that should have taken seconds take minutes, resulting in less testing. I see in this one that it uses a excessively slow PRNG based on skein, which makes me a bit dubious-- but if thats the only problem it would be easy to fix if we forked it (by replacing it with xorshift128+ or likewise). |
|
It should also be noted that they way the test are currently written they tie in the boost testing framework, if we add rapidcheck as a dependency and decide to remove boost, which #8670 suggests, we will have to rewrite these test cases to be independent of boost. In terms of speed, you would know more than I would about choosing PRNG. Rapidcheck currently defaults to running 100 test cases against every property you have specified. You can configure this property to be higher or lower depending on the situation. I think it would make sense to configure this to lower value for local development, and a higher value for travis builds to try and exhaustively test our invariants. You can read more about configuration of rapidcheck here. @jonasschnelli 's comment above was interesting I thought, I'm not super familiar with C++ build systems but only including the rapidcheck dependency if the flag I think the long term value add here is having a library of generators (for various protocol data structures) that we can use to test new protocol changes. I'm going to be adding some properties about creating tx types in the coming weeks. To get an idea of what I'm looking to add, you can look at some of the generators I have created in bitcoin-s. |
Christewart
referenced
this pull request
Mar 12, 2017
Merged
Fix mem access violation merkleblock #9980
Christewart
added some commits
Jun 19, 2016
|
Hmm, looks like travis is failing to build rapidcheck here? Are you interested in rebasing and potentially fixing it? |
|
It appears there is a bug with gcc 4.8 that causes a problems with lambdas and parameter packs: |
sipa
added a commit
that referenced
this pull request
Jul 17, 2017
|
|
sipa |
fee0d80
|
Christewart commentedAug 6, 2016
This pull request is a proof of concept for introducting property based testing into Bitcoin Core
This has been very useful for a Bitcoin library I've been working on and thought it would be worthwhile to develop a POC for Bitcoin Core. The property based library I am using for C++ is called rapidcheck. Here are the docs.
This pull request currently contains two properties, one testing
CKeygeneration and the other testing serialization symmetry forCKeyandCBitcoinSecret. These are rather trivial properties, but useful for illustrating the power of property based testing if there was a bug inside of Core.I want to solicit some feedback from developers if this is something that would actually be merged into Core. Eventually we could have a large library of generators that would allow us to quickly prototype, test, and reason about the behavior of new code added to Core. Here is an example of a library of generators (in Scala) that could give you a little more of an idea of what I am talking about.
Thoughts?