Skip to content

Commit 6b25f29

Browse files
committed
Use std::vector API for construction of test data.
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.
1 parent d71d0d7 commit 6b25f29

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)