bitcoin-tx: Accept input via stdin. Add input handling to tests.
[bitcoinplatinum.git] / src / test / sigopcount_tests.cpp
blob722f14a9897943800a57692f47a11c225afed20f
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.
5 #include "key.h"
6 #include "script.h"
7 #include "uint256.h"
9 #include <vector>
11 #include <boost/foreach.hpp>
12 #include <boost/test/unit_test.hpp>
14 using namespace std;
16 // Helpers:
17 static std::vector<unsigned char>
18 Serialize(const CScript& s)
20 std::vector<unsigned char> sSerialized(s);
21 return sSerialized;
24 BOOST_AUTO_TEST_SUITE(sigopcount_tests)
26 BOOST_AUTO_TEST_CASE(GetSigOpCount)
28 // Test CScript::GetSigOpCount()
29 CScript s1;
30 BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
31 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
33 uint160 dummy;
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);
40 CScript p2sh;
41 p2sh.SetDestination(s1.GetID());
42 CScript scriptSig;
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++)
49 CKey k;
50 k.MakeNewKey(true);
51 keys.push_back(k.GetPubKey());
53 CScript s2;
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);
61 CScript scriptSig2;
62 scriptSig2 << OP_1 << dummy << dummy << Serialize(s2);
63 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
66 BOOST_AUTO_TEST_SUITE_END()