LCOV - code coverage report
Current view: top level - src/test - script_p2pkh_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 15 15 100.0 %
Date: 2026-06-25 07:23:43 Functions: 10 10 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2012-2015 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <script/script.h>
       6             : #include <test/util/setup_common.h>
       7             : 
       8             : #include <boost/test/unit_test.hpp>
       9             : 
      10         146 : BOOST_FIXTURE_TEST_SUITE(script_p2pkh_tests, BasicTestingSetup)
      11             : 
      12         149 : BOOST_AUTO_TEST_CASE(IsPayToPublicKeyHash)
      13             : {
      14             :     // Test CScript::IsPayToPublicKeyHash()
      15           1 :     uint160 dummy;
      16           1 :     CScript p2pkh;
      17           1 :     p2pkh << OP_DUP << OP_HASH160 << ToByteVector(dummy) << OP_EQUALVERIFY << OP_CHECKSIG;
      18           1 :     BOOST_CHECK(p2pkh.IsPayToPublicKeyHash());
      19             : 
      20             :     static const unsigned char direct[] = {
      21             :         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
      22             :     };
      23           1 :     BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToPublicKeyHash());
      24             : 
      25             :     static const unsigned char notp2pkh1[] = {
      26             :         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
      27             :     };
      28           1 :     BOOST_CHECK(!CScript(notp2pkh1, notp2pkh1+sizeof(notp2pkh1)).IsPayToPublicKeyHash());
      29             : 
      30             :     static const unsigned char p2sh[] = {
      31             :         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
      32             :     };
      33           1 :     BOOST_CHECK(!CScript(p2sh, p2sh+sizeof(p2sh)).IsPayToPublicKeyHash());
      34             : 
      35             :     static const unsigned char extra[] = {
      36             :         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
      37             :     };
      38           1 :     BOOST_CHECK(!CScript(extra, extra+sizeof(extra)).IsPayToPublicKeyHash());
      39             : 
      40             :     static const unsigned char missing[] = {
      41             :         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
      42             :     };
      43           1 :     BOOST_CHECK(!CScript(missing, missing+sizeof(missing)).IsPayToPublicKeyHash());
      44             : 
      45             :     static const unsigned char missing2[] = {
      46             :         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
      47             :     };
      48           1 :     BOOST_CHECK(!CScript(missing2, missing2+sizeof(missing2)).IsPayToPublicKeyHash());
      49             : 
      50             :     static const unsigned char tooshort[] = {
      51             :         OP_DUP, OP_HASH160, 2, 0,0, OP_EQUALVERIFY, OP_CHECKSIG
      52             :     };
      53           1 :     BOOST_CHECK(!CScript(tooshort, tooshort+sizeof(tooshort)).IsPayToPublicKeyHash());
      54             : 
      55           1 : }
      56             : 
      57         146 : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.16