Skip to content

Commit fe5a70b

Browse files
author
MarcoFalke
committed
Merge #15099: tests: Use std::vector API for construction of test 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 #14752. Tree-SHA512: af82d447f0077259049f1da2d6f86a6c29723c6e17bd342e9a9ecf37b13bddff40643af95c8b3a3260765a5591713d31ca8a45a5a0c20a12c139aee53ea150da
2 parents f7e182a + 6b25f29 commit fe5a70b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/test/script_p2sh_tests.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,22 @@ BOOST_AUTO_TEST_CASE(is)
213213
BOOST_CHECK(p2sh.IsPayToScriptHash());
214214

215215
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
216-
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 };
217-
BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToScriptHash());
218-
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 };
219-
BOOST_CHECK(!CScript(pushdata1, pushdata1+sizeof(pushdata1)).IsPayToScriptHash());
220-
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 };
221-
BOOST_CHECK(!CScript(pushdata2, pushdata2+sizeof(pushdata2)).IsPayToScriptHash());
222-
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 };
223-
BOOST_CHECK(!CScript(pushdata4, pushdata4+sizeof(pushdata4)).IsPayToScriptHash());
216+
std::vector<unsigned char> direct = {OP_HASH160, 20};
217+
direct.insert(direct.end(), 20, 0);
218+
direct.push_back(OP_EQUAL);
219+
BOOST_CHECK(CScript(direct.begin(), direct.end()).IsPayToScriptHash());
220+
std::vector<unsigned char> pushdata1 = {OP_HASH160, OP_PUSHDATA1, 20};
221+
pushdata1.insert(pushdata1.end(), 20, 0);
222+
pushdata1.push_back(OP_EQUAL);
223+
BOOST_CHECK(!CScript(pushdata1.begin(), pushdata1.end()).IsPayToScriptHash());
224+
std::vector<unsigned char> pushdata2 = {OP_HASH160, 20, 0};
225+
pushdata2.insert(pushdata2.end(), 20, 0);
226+
pushdata2.push_back(OP_EQUAL);
227+
BOOST_CHECK(!CScript(pushdata2.begin(), pushdata2.end()).IsPayToScriptHash());
228+
std::vector<unsigned char> pushdata4 = {OP_HASH160, 20, 0, 0, 0};
229+
pushdata4.insert(pushdata4.end(), 20, 0);
230+
pushdata4.push_back(OP_EQUAL);
231+
BOOST_CHECK(!CScript(pushdata4.begin(), pushdata4.end()).IsPayToScriptHash());
224232

225233
CScript not_p2sh;
226234
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());

0 commit comments

Comments
 (0)