]> Git Repo - VerusCoin.git/blame_incremental - src/test/sigopcount_tests.cpp
Merge pull request #5360
[VerusCoin.git] / src / test / sigopcount_tests.cpp
... / ...
CommitLineData
1// Copyright (c) 2012-2013 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 "pubkey.h"
6#include "key.h"
7#include "script/script.h"
8#include "script/standard.h"
9#include "uint256.h"
10#include "test/test_bitcoin.h"
11
12#include <vector>
13
14#include <boost/foreach.hpp>
15#include <boost/test/unit_test.hpp>
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
27BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup)
28
29BOOST_AUTO_TEST_CASE(GetSigOpCount)
30{
31 // Test CScript::GetSigOpCount()
32 CScript s1;
33 BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
34 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
35
36 uint160 dummy;
37 s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG;
38 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
39 s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
40 BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
41 BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U);
42
43 CScript p2sh = GetScriptForDestination(CScriptID(s1));
44 CScript scriptSig;
45 scriptSig << OP_0 << Serialize(s1);
46 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U);
47
48 std::vector<CPubKey> keys;
49 for (int i = 0; i < 3; i++)
50 {
51 CKey k;
52 k.MakeNewKey(true);
53 keys.push_back(k.GetPubKey());
54 }
55 CScript s2 = GetScriptForMultisig(1, keys);
56 BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U);
57 BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U);
58
59 p2sh = GetScriptForDestination(CScriptID(s2));
60 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
61 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
62 CScript scriptSig2;
63 scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << Serialize(s2);
64 BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
65}
66
67BOOST_AUTO_TEST_SUITE_END()
This page took 0.022373 seconds and 4 git commands to generate.