aboutsummaryrefslogtreecommitdiff
path: root/src/test/rpc_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/rpc_tests.cpp
parentd11a58a2d39b90dfe27d3a696b3977b87d7c8113 (diff)
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Diffstat (limited to 'src/test/rpc_tests.cpp')
-rw-r--r--src/test/rpc_tests.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
new file mode 100644
index 0000000000..87462f765b
--- /dev/null
+++ b/src/test/rpc_tests.cpp
@@ -0,0 +1,74 @@
+#include <boost/test/unit_test.hpp>
+#include <boost/foreach.hpp>
+
+#include "base58.h"
+#include "util.h"
+#include "json/json_spirit_reader_template.h"
+#include "json/json_spirit_writer_template.h"
+#include "json/json_spirit_utils.h"
+
+using namespace std;
+using namespace json_spirit;
+
+typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
+extern map<string, rpcfn_type> mapCallTable;
+
+BOOST_AUTO_TEST_SUITE(rpc_tests)
+
+static Array
+createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL)
+{
+ Array result;
+ result.push_back(nRequired);
+ Array addresses;
+ if (address1) addresses.push_back(address1);
+ if (address2) addresses.push_back(address1);
+ result.push_back(addresses);
+ return result;
+}
+
+// This can be removed this when addmultisigaddress is enabled on main net:
+struct TestNetFixture
+{
+ TestNetFixture() { fTestNet = true; }
+ ~TestNetFixture() { fTestNet = false; }
+};
+
+BOOST_FIXTURE_TEST_CASE(rpc_addmultisig, TestNetFixture)
+{
+ rpcfn_type addmultisig = mapCallTable["addmultisigaddress"];
+
+ // old, 65-byte-long:
+ const char* address1Hex = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";
+ // new, compressed:
+ const char* address2Hex = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4";
+
+ Value v;
+ CBitcoinAddress address;
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, address1Hex), false), runtime_error);
+
+ BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
+
+ string short1(address1Hex, address1Hex+sizeof(address1Hex)-2); // last byte missing
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
+
+ string short2(address1Hex+2, address1Hex+sizeof(address1Hex)); // first byte missing
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
+}
+
+BOOST_AUTO_TEST_SUITE_END()