aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-01-05 00:53:11 +0100
committerMarcoFalke <falke.marco@gmail.com>2019-01-05 00:53:13 +0100
commitfe5a70b9fefa0548f497a749746f53f3d7fd0ebb (patch)
tree1f6dea0c91c8baf4079517800f10156ef74377f3
parentf7e182a973ed66b4c11dc6239e57016655503b4c (diff)
parent6b25f29a91867e1cd081777bc9fb6338f0c0e739 (diff)
downloadbitcoin-fe5a70b9fefa0548f497a749746f53f3d7fd0ebb.tar.xz
Merge #15099: tests: Use std::vector API for construction of test data
6b25f29a91 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 #14752. Tree-SHA512: af82d447f0077259049f1da2d6f86a6c29723c6e17bd342e9a9ecf37b13bddff40643af95c8b3a3260765a5591713d31ca8a45a5a0c20a12c139aee53ea150da
-rw-r--r--src/test/script_p2sh_tests.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp
index 1556b2f667..3a2a11ef98 100644
--- a/src/test/script_p2sh_tests.cpp
+++ b/src/test/script_p2sh_tests.cpp
@@ -213,14 +213,22 @@ BOOST_AUTO_TEST_CASE(is)
BOOST_CHECK(p2sh.IsPayToScriptHash());
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
- static const unsigned char direct[] = { OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
- BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToScriptHash());
- static const unsigned char pushdata1[] = { OP_HASH160, OP_PUSHDATA1, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
- BOOST_CHECK(!CScript(pushdata1, pushdata1+sizeof(pushdata1)).IsPayToScriptHash());
- static const unsigned char pushdata2[] = { OP_HASH160, OP_PUSHDATA2, 20,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
- BOOST_CHECK(!CScript(pushdata2, pushdata2+sizeof(pushdata2)).IsPayToScriptHash());
- static const unsigned char pushdata4[] = { OP_HASH160, OP_PUSHDATA4, 20,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
- BOOST_CHECK(!CScript(pushdata4, pushdata4+sizeof(pushdata4)).IsPayToScriptHash());
+ std::vector<unsigned char> direct = {OP_HASH160, 20};
+ direct.insert(direct.end(), 20, 0);
+ direct.push_back(OP_EQUAL);
+ BOOST_CHECK(CScript(direct.begin(), direct.end()).IsPayToScriptHash());
+ std::vector<unsigned char> pushdata1 = {OP_HASH160, OP_PUSHDATA1, 20};
+ pushdata1.insert(pushdata1.end(), 20, 0);
+ pushdata1.push_back(OP_EQUAL);
+ BOOST_CHECK(!CScript(pushdata1.begin(), pushdata1.end()).IsPayToScriptHash());
+ std::vector<unsigned char> pushdata2 = {OP_HASH160, 20, 0};
+ pushdata2.insert(pushdata2.end(), 20, 0);
+ pushdata2.push_back(OP_EQUAL);
+ BOOST_CHECK(!CScript(pushdata2.begin(), pushdata2.end()).IsPayToScriptHash());
+ std::vector<unsigned char> pushdata4 = {OP_HASH160, 20, 0, 0, 0};
+ pushdata4.insert(pushdata4.end(), 20, 0);
+ pushdata4.push_back(OP_EQUAL);
+ BOOST_CHECK(!CScript(pushdata4.begin(), pushdata4.end()).IsPayToScriptHash());
CScript not_p2sh;
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());