]>
Commit | Line | Data |
---|---|---|
922e8e29 GA |
1 | #include <vector> |
2 | #include <boost/test/unit_test.hpp> | |
3 | #include <boost/foreach.hpp> | |
4 | ||
5 | #include "script.h" | |
6 | #include "key.h" | |
7 | ||
8 | using namespace std; | |
9 | ||
10 | // Helpers: | |
11 | static std::vector<unsigned char> | |
12 | Serialize(const CScript& s) | |
13 | { | |
14 | std::vector<unsigned char> sSerialized(s); | |
15 | return sSerialized; | |
16 | } | |
17 | ||
18 | BOOST_AUTO_TEST_SUITE(sigopcount_tests) | |
19 | ||
20 | BOOST_AUTO_TEST_CASE(GetSigOpCount) | |
21 | { | |
22 | // Test CScript::GetSigOpCount() | |
23 | CScript s1; | |
24 | BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0); | |
25 | BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0); | |
26 | ||
27 | uint160 dummy; | |
28 | s1 << OP_1 << dummy << dummy << OP_2 << OP_CHECKMULTISIG; | |
29 | BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2); | |
30 | s1 << OP_IF << OP_CHECKSIG << OP_ENDIF; | |
31 | BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3); | |
32 | BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21); | |
33 | ||
34 | CScript p2sh; | |
35 | p2sh.SetPayToScriptHash(s1); | |
36 | CScript scriptSig; | |
37 | scriptSig << OP_0 << Serialize(s1); | |
38 | BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3); | |
39 | ||
40 | std::vector<CKey> keys; | |
41 | for (int i = 0; i < 3; i++) | |
42 | { | |
43 | CKey k; | |
0d56f11a | 44 | k.MakeNewKey(true); |
922e8e29 GA |
45 | keys.push_back(k); |
46 | } | |
47 | CScript s2; | |
48 | s2.SetMultisig(1, keys); | |
49 | BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3); | |
50 | BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20); | |
51 | ||
52 | p2sh.SetPayToScriptHash(s2); | |
53 | BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0); | |
54 | BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0); | |
55 | CScript scriptSig2; | |
56 | scriptSig2 << OP_1 << dummy << dummy << Serialize(s2); | |
57 | BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3); | |
58 | } | |
59 | ||
60 | BOOST_AUTO_TEST_SUITE_END() |