aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/base58_tests.cpp10
-rw-r--r--src/test/rpc_tests.cpp31
-rw-r--r--src/test/script_tests.cpp4
-rw-r--r--src/test/serialize_tests.cpp48
-rw-r--r--src/test/transaction_tests.cpp4
5 files changed, 88 insertions, 9 deletions
diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp
index c435becc61..05675685bd 100644
--- a/src/test/base58_tests.cpp
+++ b/src/test/base58_tests.cpp
@@ -20,7 +20,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- std::string strTest = write_string(tv, raw_utf8);
+ std::string strTest = write_string(tv, false);
if (test.size() < 2) // Allow for extra stuff (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- std::string strTest = write_string(tv, raw_utf8);
+ std::string strTest = write_string(tv, false);
if (test.size() < 2) // Allow for extra stuff (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
@@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- std::string strTest = write_string(tv, raw_utf8);
+ std::string strTest = write_string(tv, false);
if (test.size() < 3) // Allow for extra stuff (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- std::string strTest = write_string(tv, raw_utf8);
+ std::string strTest = write_string(tv, false);
if (test.size() < 3) // Allow for extra stuff (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
@@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- std::string strTest = write_string(tv, raw_utf8);
+ std::string strTest = write_string(tv, false);
if (test.size() < 1) // Allow for extra stuff (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 35eabed0e2..25849054eb 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -168,4 +168,35 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true);
}
+BOOST_AUTO_TEST_CASE(rpc_format_monetary_values)
+{
+ BOOST_CHECK(write_string(ValueFromAmount(0LL), false) == "0.00000000");
+ BOOST_CHECK(write_string(ValueFromAmount(1LL), false) == "0.00000001");
+ BOOST_CHECK(write_string(ValueFromAmount(17622195LL), false) == "0.17622195");
+ BOOST_CHECK(write_string(ValueFromAmount(50000000LL), false) == "0.50000000");
+ BOOST_CHECK(write_string(ValueFromAmount(89898989LL), false) == "0.89898989");
+ BOOST_CHECK(write_string(ValueFromAmount(100000000LL), false) == "1.00000000");
+ BOOST_CHECK(write_string(ValueFromAmount(2099999999999990LL), false) == "20999999.99999990");
+ BOOST_CHECK(write_string(ValueFromAmount(2099999999999999LL), false) == "20999999.99999999");
+}
+
+static Value ValueFromString(const std::string &str)
+{
+ Value value;
+ BOOST_CHECK(read_string(str, value));
+ return value;
+}
+
+BOOST_AUTO_TEST_CASE(rpc_parse_monetary_values)
+{
+ BOOST_CHECK(AmountFromValue(ValueFromString("0.00000001")) == 1LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("0.17622195")) == 17622195LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("0.5")) == 50000000LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("0.50000000")) == 50000000LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("0.89898989")) == 89898989LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("1.00000000")) == 100000000LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("20999999.9999999")) == 2099999999999990LL);
+ BOOST_CHECK(AmountFromValue(ValueFromString("20999999.99999999")) == 2099999999999999LL);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 079cc49f60..32be914414 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- string strTest = write_string(tv, raw_utf8);
+ string strTest = write_string(tv, false);
if (test.size() < 2) // Allow size > 2; extra stuff ignored (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
@@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(script_invalid)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- string strTest = write_string(tv, raw_utf8);
+ string strTest = write_string(tv, false);
if (test.size() < 2) // Allow size > 2; extra stuff ignored (useful for comments)
{
BOOST_ERROR("Bad test: " << strTest);
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
index 50139df09e..7e193c88ce 100644
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -102,4 +102,52 @@ BOOST_AUTO_TEST_CASE(noncanonical)
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
}
+BOOST_AUTO_TEST_CASE(insert_delete)
+{
+ // Test inserting/deleting bytes.
+ CDataStream ss(SER_DISK, 0);
+ BOOST_CHECK_EQUAL(ss.size(), 0);
+
+ ss.write("\x00\x01\x02\xff", 4);
+ BOOST_CHECK_EQUAL(ss.size(), 4);
+
+ char c = (char)11;
+
+ // Inserting at beginning/end/middle:
+ ss.insert(ss.begin(), c);
+ BOOST_CHECK_EQUAL(ss.size(), 5);
+ BOOST_CHECK_EQUAL(ss[0], c);
+ BOOST_CHECK_EQUAL(ss[1], 0);
+
+ ss.insert(ss.end(), c);
+ BOOST_CHECK_EQUAL(ss.size(), 6);
+ BOOST_CHECK_EQUAL(ss[4], (char)0xff);
+ BOOST_CHECK_EQUAL(ss[5], c);
+
+ ss.insert(ss.begin()+2, c);
+ BOOST_CHECK_EQUAL(ss.size(), 7);
+ BOOST_CHECK_EQUAL(ss[2], c);
+
+ // Delete at beginning/end/middle
+ ss.erase(ss.begin());
+ BOOST_CHECK_EQUAL(ss.size(), 6);
+ BOOST_CHECK_EQUAL(ss[0], 0);
+
+ ss.erase(ss.begin()+ss.size()-1);
+ BOOST_CHECK_EQUAL(ss.size(), 5);
+ BOOST_CHECK_EQUAL(ss[4], (char)0xff);
+
+ ss.erase(ss.begin()+1);
+ BOOST_CHECK_EQUAL(ss.size(), 4);
+ BOOST_CHECK_EQUAL(ss[0], 0);
+ BOOST_CHECK_EQUAL(ss[1], 1);
+ BOOST_CHECK_EQUAL(ss[2], 2);
+ BOOST_CHECK_EQUAL(ss[3], (char)0xff);
+
+ // Make sure GetAndClear does the right thing:
+ CSerializeData d;
+ ss.GetAndClear(d);
+ BOOST_CHECK_EQUAL(ss.size(), 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index c6bc2e8aa1..bd999caa14 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- string strTest = write_string(tv, raw_utf8);
+ string strTest = write_string(tv, false);
if (test[0].type() == array_type)
{
if (test.size() != 3 || test[1].type() != str_type || test[2].type() != bool_type)
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
- string strTest = write_string(tv, raw_utf8);
+ string strTest = write_string(tv, false);
if (test[0].type() == array_type)
{
if (test.size() != 3 || test[1].type() != str_type || test[2].type() != bool_type)