diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index 617125c02e..f7b39c2273 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -2,6 +2,7 @@ #include "SerializedTransaction.h" #include +#include #include "Application.h" #include "Log.h" @@ -109,6 +110,20 @@ void SerializedTransaction::sign(const NewcoinAddress& naAccountPrivate) setFieldVL(sfTxnSignature, signature); } +bool SerializedTransaction::checkSign() const +{ + try + { + NewcoinAddress n; + n.setAccountPublic(getFieldVL(sfSigningPubKey)); + return checkSign(n); + } + catch (...) + { + return false; + } +} + bool SerializedTransaction::checkSign(const NewcoinAddress& naAccountPublic) const { try @@ -166,4 +181,40 @@ std::string SerializedTransaction::getSQL(Serializer rawTxn, uint32 inLedger, ch } +BOOST_AUTO_TEST_SUITE(SerializedTransactionTS) + +BOOST_AUTO_TEST_CASE( STrans_test ) +{ + NewcoinAddress seed; + seed.setSeedRandom(); + NewcoinAddress generator = NewcoinAddress::createGeneratorPublic(seed); + NewcoinAddress publicAcct = NewcoinAddress::createAccountPublic(generator, 1); + NewcoinAddress privateAcct = NewcoinAddress::createAccountPrivate(generator, seed, 1); + + SerializedTransaction j(ttCLAIM); + j.setSourceAccount(publicAcct); + j.setSigningPubKey(publicAcct); + j.setFieldVL(sfPublicKey, publicAcct.getAccountPublic()); + j.sign(privateAcct); + + if (!j.checkSign()) BOOST_FAIL("Transaction fails signature test"); + + Serializer rawTxn; + j.add(rawTxn); + SerializerIterator sit(rawTxn); + SerializedTransaction copy(sit); + if (copy != j) + { + Log(lsFATAL) << j.getJson(0); + Log(lsFATAL) << copy.getJson(0); + BOOST_FAIL("Transaction fails serialize/deserialize test"); + } + Log(lsFATAL) << j.getJson(0); + std::auto_ptr new_obj = STObject::parseJson(j.getJson(0), sfGeneric); + if (new_obj.get() == NULL) BOOST_FAIL("Unable to build object from json"); + Log(lsINFO) << new_obj->getJson(0); +} + +BOOST_AUTO_TEST_SUITE_END(); + // vim:ts=4 diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 0d9f59e529..a2089f2240 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -63,6 +63,7 @@ public: void sign(const NewcoinAddress& naAccountPrivate); bool checkSign(const NewcoinAddress& naAccountPublic) const; + bool checkSign() const; // SQL Functions static std::string getSQLValueHeader();