mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -166,8 +166,6 @@ STAmount::STAmount(SField::ref n, const Json::Value& v)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw std::runtime_error("invalid amount type");
|
throw std::runtime_error("invalid amount type");
|
||||||
|
|
||||||
cLog(lsTRACE) << "Parsed: " << this->getJson(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string STAmount::createHumanCurrency(const uint160& uCurrency)
|
std::string STAmount::createHumanCurrency(const uint160& uCurrency)
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
|
|
||||||
// Functions to add CKey support for deterministic EC keys
|
// Functions to add CKey support for deterministic EC keys
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "Serializer.h"
|
#include "Serializer.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
// <-- seed
|
// <-- seed
|
||||||
uint128 CKey::PassPhraseToKey(const std::string& passPhrase)
|
uint128 CKey::PassPhraseToKey(const std::string& passPhrase)
|
||||||
@@ -304,4 +307,34 @@ EC_KEY* CKey::GeneratePrivateDeterministicKey(const NewcoinAddress& pubGen, cons
|
|||||||
return pkey;
|
return pkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(DeterministicKeys_test)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(DeterminsticKeys_test1)
|
||||||
|
{
|
||||||
|
Log(lsDEBUG) << "Beginning deterministic key test";
|
||||||
|
|
||||||
|
uint128 seed1, seed2;
|
||||||
|
seed1.SetHex("71ED064155FFADFA38782C5E0158CB26");
|
||||||
|
seed2.SetHex("CF0C3BE4485961858C4198515AE5B965");
|
||||||
|
CKey root1(seed1), root2(seed2);
|
||||||
|
|
||||||
|
uint256 priv1, priv2;
|
||||||
|
root1.GetPrivateKeyU(priv1);
|
||||||
|
root2.GetPrivateKeyU(priv2);
|
||||||
|
|
||||||
|
if (priv1.GetHex() != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8")
|
||||||
|
BOOST_FAIL("Incorrect private key for generator");
|
||||||
|
if (priv2.GetHex() != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B")
|
||||||
|
BOOST_FAIL("Incorrect private key for generator");
|
||||||
|
|
||||||
|
NewcoinAddress nSeed;
|
||||||
|
nSeed.setSeed(seed1);
|
||||||
|
if (nSeed.humanSeed() != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn")
|
||||||
|
BOOST_FAIL("Incorrect human seed");
|
||||||
|
if (nSeed.humanSeed1751() != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH")
|
||||||
|
BOOST_FAIL("Incorrect 1751 seed");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END();
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ bool STObject::setType(const std::vector<SOElement::ptr> &type)
|
|||||||
{
|
{
|
||||||
if (elem->flags != SOE_OPTIONAL)
|
if (elem->flags != SOE_OPTIONAL)
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "setType !valid missing " << elem->e_field.fieldName;
|
cLog(lsWARNING) << "setType( " << getFName().getName() << ") invalid missing "
|
||||||
|
<< elem->e_field.fieldName;
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
newData.push_back(makeNonPresentObject(elem->e_field));
|
newData.push_back(makeNonPresentObject(elem->e_field));
|
||||||
@@ -178,7 +179,8 @@ bool STObject::setType(const std::vector<SOElement::ptr> &type)
|
|||||||
{
|
{
|
||||||
if (!t.getFName().isDiscardable())
|
if (!t.getFName().isDiscardable())
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "setType !valid leftover: " << t.getFName().getName();
|
cLog(lsWARNING) << "setType( " << getFName().getName() << ") invalid leftover "
|
||||||
|
<< t.getFName().getName();
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -792,6 +794,42 @@ Json::Value STObject::getJson(int options) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STObject::operator==(const STObject& obj) const
|
||||||
|
{ // This is not particularly efficient, and only compares data elements with binary representations
|
||||||
|
int matches = 0;
|
||||||
|
BOOST_FOREACH(const SerializedType& t, mData)
|
||||||
|
if ((t.getSType() != STI_NOTPRESENT) && t.getFName().isBinary())
|
||||||
|
{ // each present field must have a matching field
|
||||||
|
bool match = false;
|
||||||
|
BOOST_FOREACH(const SerializedType& t2, obj.mData)
|
||||||
|
if (t.getFName() == t2.getFName())
|
||||||
|
{
|
||||||
|
if (t2 != t)
|
||||||
|
return false;
|
||||||
|
match = true;
|
||||||
|
++matches;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!match)
|
||||||
|
{
|
||||||
|
Log(lsTRACE) << "STObject::operator==: no match for " << t.getFName().getName();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fields = 0;
|
||||||
|
BOOST_FOREACH(const SerializedType& t2, obj.mData)
|
||||||
|
if ((t2.getSType() != STI_NOTPRESENT) && t2.getFName().isBinary())
|
||||||
|
++fields;
|
||||||
|
|
||||||
|
if (fields != matches)
|
||||||
|
{
|
||||||
|
Log(lsTRACE) << "STObject::operator==: " << fields << " fields, " << matches << " matches";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value STVector256::getJson(int options) const
|
Json::Value STVector256::getJson(int options) const
|
||||||
{
|
{
|
||||||
Json::Value ret(Json::arrayValue);
|
Json::Value ret(Json::arrayValue);
|
||||||
@@ -1246,7 +1284,6 @@ BOOST_AUTO_TEST_CASE( FieldManipulation_test )
|
|||||||
if (object1.getFieldVL(sfTestVL) != j) BOOST_FAIL("STObject error");
|
if (object1.getFieldVL(sfTestVL) != j) BOOST_FAIL("STObject error");
|
||||||
if (object3.getFieldVL(sfTestVL) != j) BOOST_FAIL("STObject error");
|
if (object3.getFieldVL(sfTestVL) != j) BOOST_FAIL("STObject error");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END();
|
BOOST_AUTO_TEST_SUITE_END();
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ public:
|
|||||||
{ return makeDefaultObject(STI_NOTPRESENT, name); }
|
{ return makeDefaultObject(STI_NOTPRESENT, name); }
|
||||||
static std::auto_ptr<SerializedType> makeDefaultObject(SField::ref name)
|
static std::auto_ptr<SerializedType> makeDefaultObject(SField::ref name)
|
||||||
{ return makeDefaultObject(name.fieldType, name); }
|
{ return makeDefaultObject(name.fieldType, name); }
|
||||||
|
|
||||||
|
bool operator==(const STObject& o) const;
|
||||||
|
bool operator!=(const STObject& o) const { return ! (*this == o); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class STArray : public SerializedType
|
class STArray : public SerializedType
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ SerializedTransaction::SerializedTransaction(const STObject& object) : STObject(
|
|||||||
throw std::runtime_error("invalid transaction type");
|
throw std::runtime_error("invalid transaction type");
|
||||||
if (!setType(mFormat->elements))
|
if (!setType(mFormat->elements))
|
||||||
{
|
{
|
||||||
assert(false);
|
|
||||||
throw std::runtime_error("transaction not valid");
|
throw std::runtime_error("transaction not valid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,10 +223,15 @@ BOOST_AUTO_TEST_CASE( STrans_test )
|
|||||||
Log(lsFATAL) << copy.getJson(0);
|
Log(lsFATAL) << copy.getJson(0);
|
||||||
BOOST_FAIL("Transaction fails serialize/deserialize test");
|
BOOST_FAIL("Transaction fails serialize/deserialize test");
|
||||||
}
|
}
|
||||||
Log(lsINFO) << "ORIG: " << j.getJson(0);
|
|
||||||
std::auto_ptr<STObject> new_obj = STObject::parseJson(j.getJson(0), sfGeneric);
|
std::auto_ptr<STObject> new_obj = STObject::parseJson(j.getJson(0), sfGeneric);
|
||||||
if (new_obj.get() == NULL) BOOST_FAIL("Unable to build object from json");
|
if (new_obj.get() == NULL) BOOST_FAIL("Unable to build object from json");
|
||||||
|
|
||||||
|
if (STObject(j) != *new_obj)
|
||||||
|
{
|
||||||
|
Log(lsINFO) << "ORIG: " << j.getJson(0);
|
||||||
Log(lsINFO) << "BUILT " << new_obj->getJson(0);
|
Log(lsINFO) << "BUILT " << new_obj->getJson(0);
|
||||||
|
BOOST_FAIL("Built a different transaction");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END();
|
BOOST_AUTO_TEST_SUITE_END();
|
||||||
|
|||||||
Reference in New Issue
Block a user