aboutsummaryrefslogtreecommitdiff
path: root/src/test/sigopcount_tests.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-01-04 21:40:52 -0500
committerGavin Andresen <gavinandresen@gmail.com>2012-01-13 10:22:23 -0500
commit922e8e2929a2e78270868385aa46f96002fbcff3 (patch)
treed7c7d2b3fe89bc18b8d0f1137980b9db16db3ae8 /src/test/sigopcount_tests.cpp
parentd11a58a2d39b90dfe27d3a696b3977b87d7c8113 (diff)
downloadbitcoin-922e8e2929a2e78270868385aa46f96002fbcff3.tar.xz
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Diffstat (limited to 'src/test/sigopcount_tests.cpp')
-rw-r--r--src/test/sigopcount_tests.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp
new file mode 100644
index 0000000000..0b0a4a62d8
--- /dev/null
+++ b/src/test/sigopcount_tests.cpp
@@ -0,0 +1,60 @@
+#include <vector>
+#include <boost/test/unit_test.hpp>
+#include <boost/foreach.hpp>
+
+#include "script.h"
+#include "key.h"
+
+using namespace std;
+
+// Helpers:
+static std::vector<unsigned char>
+Serialize(const CScript& s)
+{
+ std::vector<unsigned char> sSerialized(s);
+ return sSerialized;
+}
+
+BOOST_AUTO_TEST_SUITE(sigopcount_tests)
+
+BOOST_AUTO_TEST_CASE(GetSigOpCount)
+{
+ // Test CScript::GetSigOpCount()
+ CScript s1;
+ BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0);
+ BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0);
+
+ uint160 dummy;
+ s1 << OP_1 << dummy << dummy << OP_2 << OP_CHECKMULTISIG;
+ BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2);
+ s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
+ BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3);
+ BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21);
+
+ CScript p2sh;
+ p2sh.SetPayToScriptHash(s1);
+ CScript scriptSig;
+ scriptSig << OP_0 << Serialize(s1);
+ BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3);
+
+ std::vector<CKey> keys;
+ for (int i = 0; i < 3; i++)
+ {
+ CKey k;
+ k.MakeNewKey();
+ keys.push_back(k);
+ }
+ CScript s2;
+ s2.SetMultisig(1, keys);
+ BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3);
+ BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20);
+
+ p2sh.SetPayToScriptHash(s2);
+ BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0);
+ BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0);
+ CScript scriptSig2;
+ scriptSig2 << OP_1 << dummy << dummy << Serialize(s2);
+ BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3);
+}
+
+BOOST_AUTO_TEST_SUITE_END()