LCOV - code coverage report
Current view: top level - src/test - sigopcount_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 32 32 100.0 %
Date: 2025-02-23 09:33:43 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2012-2013 The Bitcoin Core developers
       2             : // Copyright (c) 2017-2020 The PIVX Core developers
       3             : // Distributed under the MIT/X11 software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #include "pubkey.h"
       7             : #include "key.h"
       8             : #include "script/script.h"
       9             : #include "script/standard.h"
      10             : #include "uint256.h"
      11             : #include "test_pivx.h"
      12             : 
      13             : #include <vector>
      14             : 
      15             : #include <boost/test/unit_test.hpp>
      16             : 
      17             : 
      18             : // Helpers:
      19             : static std::vector<unsigned char>
      20           2 : Serialize(const CScript& s)
      21             : {
      22           6 :     std::vector<unsigned char> sSerialized(s.begin(), s.end());
      23           2 :     return sSerialized;
      24             : }
      25             : 
      26             : BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup)
      27             : 
      28           2 : BOOST_AUTO_TEST_CASE(GetSigOpCount)
      29             : {
      30             :     // Test CScript::GetSigOpCount()
      31           1 :     CScript s1;
      32           1 :     BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
      33           1 :     BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
      34             : 
      35           1 :     uint160 dummy;
      36           2 :     s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG;
      37           1 :     BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
      38           1 :     s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
      39           1 :     BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
      40           1 :     BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U);
      41             : 
      42           2 :     CScript p2sh = GetScriptForDestination(CScriptID(s1));
      43           2 :     CScript scriptSig;
      44           1 :     scriptSig << OP_0 << Serialize(s1);
      45           1 :     BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U);
      46             : 
      47           2 :     std::vector<CPubKey> keys;
      48           4 :     for (int i = 0; i < 3; i++)
      49             :     {
      50           6 :         CKey k;
      51           3 :         k.MakeNewKey(true);
      52           6 :         keys.push_back(k.GetPubKey());
      53             :     }
      54           2 :     CScript s2 = GetScriptForMultisig(1, keys);
      55           1 :     BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U);
      56           1 :     BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U);
      57             : 
      58           1 :     p2sh = GetScriptForDestination(CScriptID(s2));
      59           1 :     BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
      60           1 :     BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
      61           2 :     CScript scriptSig2;
      62           3 :     scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << Serialize(s2);
      63           1 :     BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
      64           1 : }
      65             : 
      66             : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.14