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
This commit is contained in:
commit
fe5a70b9fe
1 changed files with 16 additions and 8 deletions
|
@ -213,14 +213,22 @@ BOOST_AUTO_TEST_CASE(is)
|
||||||
BOOST_CHECK(p2sh.IsPayToScriptHash());
|
BOOST_CHECK(p2sh.IsPayToScriptHash());
|
||||||
|
|
||||||
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
|
// 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 };
|
std::vector<unsigned char> direct = {OP_HASH160, 20};
|
||||||
BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToScriptHash());
|
direct.insert(direct.end(), 20, 0);
|
||||||
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 };
|
direct.push_back(OP_EQUAL);
|
||||||
BOOST_CHECK(!CScript(pushdata1, pushdata1+sizeof(pushdata1)).IsPayToScriptHash());
|
BOOST_CHECK(CScript(direct.begin(), direct.end()).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 };
|
std::vector<unsigned char> pushdata1 = {OP_HASH160, OP_PUSHDATA1, 20};
|
||||||
BOOST_CHECK(!CScript(pushdata2, pushdata2+sizeof(pushdata2)).IsPayToScriptHash());
|
pushdata1.insert(pushdata1.end(), 20, 0);
|
||||||
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 };
|
pushdata1.push_back(OP_EQUAL);
|
||||||
BOOST_CHECK(!CScript(pushdata4, pushdata4+sizeof(pushdata4)).IsPayToScriptHash());
|
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;
|
CScript not_p2sh;
|
||||||
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
||||||
|
|
Loading…
Reference in a new issue