2016-03-08 20:47:12 +01:00
|
|
|
// Copyright (c) 2012-2015 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <script/script.h>
|
2022-02-25 18:19:25 +01:00
|
|
|
#include <test/util/setup_common.h>
|
2016-03-08 20:47:12 +01:00
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2020-07-07 18:27:55 +02:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(script_p2pkh_tests, BasicTestingSetup)
|
2016-03-08 20:47:12 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(IsPayToPublicKeyHash)
|
|
|
|
{
|
|
|
|
// Test CScript::IsPayToPublicKeyHash()
|
|
|
|
uint160 dummy;
|
|
|
|
CScript p2pkh;
|
|
|
|
p2pkh << OP_DUP << OP_HASH160 << ToByteVector(dummy) << OP_EQUALVERIFY << OP_CHECKSIG;
|
|
|
|
BOOST_CHECK(p2pkh.IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char direct[] = {
|
|
|
|
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG
|
|
|
|
};
|
|
|
|
BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char notp2pkh1[] = {
|
|
|
|
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
|
|
|
|
};
|
|
|
|
BOOST_CHECK(!CScript(notp2pkh1, notp2pkh1+sizeof(notp2pkh1)).IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char p2sh[] = {
|
|
|
|
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(p2sh, p2sh+sizeof(p2sh)).IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char extra[] = {
|
|
|
|
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
|
|
|
|
};
|
|
|
|
BOOST_CHECK(!CScript(extra, extra+sizeof(extra)).IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char missing[] = {
|
|
|
|
OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_RETURN
|
|
|
|
};
|
|
|
|
BOOST_CHECK(!CScript(missing, missing+sizeof(missing)).IsPayToPublicKeyHash());
|
|
|
|
|
|
|
|
static const unsigned char missing2[] = {
|
|
|
|
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
|
|
};
|
2018-06-29 00:23:25 +02:00
|
|
|
BOOST_CHECK(!CScript(missing2, missing2+sizeof(missing2)).IsPayToPublicKeyHash());
|
2016-03-08 20:47:12 +01:00
|
|
|
|
|
|
|
static const unsigned char tooshort[] = {
|
|
|
|
OP_DUP, OP_HASH160, 2, 0,0, OP_EQUALVERIFY, OP_CHECKSIG
|
|
|
|
};
|
2018-06-29 00:23:25 +02:00
|
|
|
BOOST_CHECK(!CScript(tooshort, tooshort+sizeof(tooshort)).IsPayToPublicKeyHash());
|
2016-03-08 20:47:12 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|