-
Notifications
You must be signed in to change notification settings - Fork 37.8k
tests: Unit tests for IsPayToWitnessScriptHash and IsWitnessProgram #14752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6473702
to
54c648d
Compare
|
||
BOOST_AUTO_TEST_CASE(IsPayToWitnessScriptHash_Valid) | ||
{ | ||
uint256 dummy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something but the two BOOST_CHECK
s here seem to be testing IsPayToWitnessScriptHash()
on identical CScript
s. If the intention is to test that the two ways of constructing a CScript
yield the same CScript
, perhaps that should be in another test case in another file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason why I added the second version here is because that code is used later for constructing the "invalid" ones as well (basically so that we would likely notice if the construction itself is wrong and the other tests invalid). But if you thank that it is clear enough that those scripts are constructed in the right way, then I'm happy to drop either of the two tests in this test case.
wit << OP_16 << program; | ||
BOOST_CHECK(IsExpectedWitnessProgram(wit, 16, program)); | ||
|
||
program.resize(32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little unclear why the construction of the CScript
here is different from the other two CHECK
s in the same test, does this change in construction test the correctness of IsExpectedWitnessProgram
in any way? As in, what advantages does this have over:
wit.clear();
program.resize(30);
wit << OP_5 << program;
BOOST_CHECK(IsExpectedWitnessProgram(wit, 5, program));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this for the same reason as with the other comment above - to make sure that code constructing a script "this way" yields a valid witness program as well, while very similar code in later tests with slight modifications yields an invalid program. Again I'm happy to remove that one if everyone else thinks this is clear anyway.
54c648d
to
5072c40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK on adding tests for those uncovered branches.
Could also add coverage to |
That test already exists, in |
3c8e3a6 Strip name prefix for IsWitnessProgram. (Daniel Kraft) 729d587 Unit tests for IsWitnessProgram and IsP2WSH. (Daniel Kraft) Pull request description: This fixes an issue with names and native segwit scripts (bech32 addresses). `CScript::IsWitnessProgram` did not strip name prefixes, which meant that names at bech32 addresses were anyone-can-spend even after segwit activation - but the transaction had to be included in a block, since the transaction would be rejected by a non-mandatory rule from the mempool. P2SH-Segwit is already working as expected. With this fix, names should work well together with segwit in all variants. This also includes tests to verify that, including (but not limited to) the situations described in #258. Note that this is in theory a consensus change, but it is safe to commit because segwit is not yet active for Namecoin. This includes a cherry-pick from bitcoin/bitcoin#14752, to create a place for the new name/segwit unit tests. Tree-SHA512: 01ec39dfcb2b167d3393dfa403c924ba9b71052eb5c93ff817f71b11ecad1ff3f78fefe6d97fa5bf7b53b16a905008707662ca35e5f80d88e9056ffedf23af36
3c36a8e
to
4cf6e7c
Compare
…est data 6b25f29 Use std::vector API for construction of test data. (Daniel Kraft) Pull request description: For constructing test scripts, use `std::vector` and, in particular, `std::vector::insert` to insert 20 zero bytes rather than listing the full array of bytes explicitly. This makes the code easier to read and makes it immediately obvious what the structure of the data is, without having to count the zeros to understand it. Of course, that is a matter of taste - so if you disagree that the change makes the code easier to read, let me know. This has been split out of bitcoin#14752. Tree-SHA512: af82d447f0077259049f1da2d6f86a6c29723c6e17bd342e9a9ecf37b13bddff40643af95c8b3a3260765a5591713d31ca8a45a5a0c20a12c139aee53ea150da
4cf6e7c
to
a1cb474
Compare
Rebased and updated the code for the recent refactoring of the testing setup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK a1cb474 on Ubuntu 20.04. Takes 0.4s to run.
a1cb474
to
b6b64d4
Compare
…est data 6b25f29 Use std::vector API for construction of test data. (Daniel Kraft) Pull request description: For constructing test scripts, use `std::vector` and, in particular, `std::vector::insert` to insert 20 zero bytes rather than listing the full array of bytes explicitly. This makes the code easier to read and makes it immediately obvious what the structure of the data is, without having to count the zeros to understand it. Of course, that is a matter of taste - so if you disagree that the change makes the code easier to read, let me know. This has been split out of bitcoin#14752. Tree-SHA512: af82d447f0077259049f1da2d6f86a6c29723c6e17bd342e9a9ecf37b13bddff40643af95c8b3a3260765a5591713d31ca8a45a5a0c20a12c139aee53ea150da
…est data 6b25f29 Use std::vector API for construction of test data. (Daniel Kraft) Pull request description: For constructing test scripts, use `std::vector` and, in particular, `std::vector::insert` to insert 20 zero bytes rather than listing the full array of bytes explicitly. This makes the code easier to read and makes it immediately obvious what the structure of the data is, without having to count the zeros to understand it. Of course, that is a matter of taste - so if you disagree that the change makes the code easier to read, let me know. This has been split out of bitcoin#14752. Tree-SHA512: af82d447f0077259049f1da2d6f86a6c29723c6e17bd342e9a9ecf37b13bddff40643af95c8b3a3260765a5591713d31ca8a45a5a0c20a12c139aee53ea150da
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
The new unit test file script_segwit_tests.cpp contains some basic unit tests for CScript::IsPayToWitnessScriptHash and CScript::IsWitnessProgram.
b6b64d4
to
bce9aaf
Compare
Rebased |
cc @dongcarl Do you still have concerns about this? |
tACK bce9aaf ( I have look thoroughly at every unit test of bce9aaf. Lines 210 to 216 in bce9aaf
and Lines 218 to 234 in bce9aaf
I've tweaked values locally of both functions.
For
Tests fail accordingly. |
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
BOOST_FIXTURE_TEST_SUITE(script_segwit_tests, BasicTestingSetup) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think you need any setup. BOOST_AUTO_TEST_SUITE(script_segwit_tests)
should work fine for pure utility tests.
…nd IsWitnessProgram bce9aaf Unit tests for IsWitnessProgram and IsP2WSH. (Daniel Kraft) Pull request description: This adds basic unit tests for `CScript::IsPayToWitnessScriptHash` and `CScript::IsWitnessProgram`, similar to the existing tests for `CScript::IsPayToScriptHash`. These tests are probably not super important given the other existing tests for segwit related code, but may be useful in catching some errors early. This implements bitcoin#14737. ACKs for top commit: aureleoules: tACK bce9aaf (`make check)`. Tree-SHA512: 3cff5efc4ac53079289c72bfba8b1937bc103baadd32bb1fba41e78017f65f9cca17678c3202ad0711eae42b351d4132d9ed9b4e2dc07d138298691a09c4e822
This adds basic unit tests for
CScript::IsPayToWitnessScriptHash
andCScript::IsWitnessProgram
, similar to the existing tests forCScript::IsPayToScriptHash
. These tests are probably not super important given the other existing tests for segwit related code, but may be useful in catching some errors early.This implements #14737.