]> Git Repo - VerusCoin.git/blame - src/test/sigopcount_tests.cpp
Merge pull request #5360
[VerusCoin.git] / src / test / sigopcount_tests.cpp
CommitLineData
3fc68461 1// Copyright (c) 2012-2013 The Bitcoin Core developers
78253fcb 2// Distributed under the MIT software license, see the accompanying
3fc68461 3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
51ed9ec9 4
d2e74c55 5#include "pubkey.h"
922e8e29 6#include "key.h"
cbd22a50 7#include "script/script.h"
0be990ba 8#include "script/standard.h"
51ed9ec9 9#include "uint256.h"
92fd887f 10#include "test/test_bitcoin.h"
51ed9ec9
BD
11
12#include <vector>
13
14#include <boost/foreach.hpp>
15#include <boost/test/unit_test.hpp>
922e8e29
GA
16
17using namespace std;
18
19// Helpers:
20static std::vector<unsigned char>
21Serialize(const CScript& s)
22{
23 std::vector<unsigned char> sSerialized(s);
24 return sSerialized;
25}
26
92fd887f 27BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup)
922e8e29
GA
28
29BOOST_AUTO_TEST_CASE(GetSigOpCount)
30{
31 // Test CScript::GetSigOpCount()
32 CScript s1;
87b9931b
GA
33 BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
34 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
922e8e29 35
4f152496 36 uint160 dummy;
e9ca4280 37 s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG;
87b9931b 38 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
922e8e29 39 s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
87b9931b
GA
40 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
41 BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U);
922e8e29 42
066e2a14 43 CScript p2sh = GetScriptForDestination(CScriptID(s1));
922e8e29
GA
44 CScript scriptSig;
45 scriptSig << OP_0 << Serialize(s1);
87b9931b 46 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U);
922e8e29 47
dfa23b94 48 std::vector<CPubKey> keys;
922e8e29
GA
49 for (int i = 0; i < 3; i++)
50 {
51 CKey k;
0d56f11a 52 k.MakeNewKey(true);
dfa23b94 53 keys.push_back(k.GetPubKey());
922e8e29 54 }
0be990ba 55 CScript s2 = GetScriptForMultisig(1, keys);
87b9931b
GA
56 BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U);
57 BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U);
922e8e29 58
066e2a14 59 p2sh = GetScriptForDestination(CScriptID(s2));
87b9931b
GA
60 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
61 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
922e8e29 62 CScript scriptSig2;
e9ca4280 63 scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << Serialize(s2);
87b9931b 64 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
922e8e29
GA
65}
66
67BOOST_AUTO_TEST_SUITE_END()
This page took 0.128181 seconds and 4 git commands to generate.