1 // Copyright (c) 2012-2013 The Bitcoin Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
11 #include <boost/foreach.hpp>
12 #include <boost/test/unit_test.hpp>
17 static std::vector
<unsigned char>
18 Serialize(const CScript
& s
)
20 std::vector
<unsigned char> sSerialized(s
);
24 BOOST_AUTO_TEST_SUITE(sigopcount_tests
)
26 BOOST_AUTO_TEST_CASE(GetSigOpCount
)
28 // Test CScript::GetSigOpCount()
30 BOOST_CHECK_EQUAL(s1
.GetSigOpCount(false), 0U);
31 BOOST_CHECK_EQUAL(s1
.GetSigOpCount(true), 0U);
34 s1
<< OP_1
<< dummy
<< dummy
<< OP_2
<< OP_CHECKMULTISIG
;
35 BOOST_CHECK_EQUAL(s1
.GetSigOpCount(true), 2U);
36 s1
<< OP_IF
<< OP_CHECKSIG
<< OP_ENDIF
;
37 BOOST_CHECK_EQUAL(s1
.GetSigOpCount(true), 3U);
38 BOOST_CHECK_EQUAL(s1
.GetSigOpCount(false), 21U);
41 p2sh
.SetDestination(s1
.GetID());
43 scriptSig
<< OP_0
<< Serialize(s1
);
44 BOOST_CHECK_EQUAL(p2sh
.GetSigOpCount(scriptSig
), 3U);
46 std::vector
<CPubKey
> keys
;
47 for (int i
= 0; i
< 3; i
++)
51 keys
.push_back(k
.GetPubKey());
54 s2
.SetMultisig(1, keys
);
55 BOOST_CHECK_EQUAL(s2
.GetSigOpCount(true), 3U);
56 BOOST_CHECK_EQUAL(s2
.GetSigOpCount(false), 20U);
58 p2sh
.SetDestination(s2
.GetID());
59 BOOST_CHECK_EQUAL(p2sh
.GetSigOpCount(true), 0U);
60 BOOST_CHECK_EQUAL(p2sh
.GetSigOpCount(false), 0U);
62 scriptSig2
<< OP_1
<< dummy
<< dummy
<< Serialize(s2
);
63 BOOST_CHECK_EQUAL(p2sh
.GetSigOpCount(scriptSig2
), 3U);
66 BOOST_AUTO_TEST_SUITE_END()