diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index dd78d653ab..5dac8331b7 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -3046,6 +3046,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index df06558c44..4d725047ac 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -3741,6 +3741,9 @@ ripple\protocol\tests + + ripple\protocol\tests + ripple\protocol\tests diff --git a/src/ripple/protocol/tests/STAccount.test.cpp b/src/ripple/protocol/tests/STAccount.test.cpp new file mode 100644 index 0000000000..fe1d1f4f0d --- /dev/null +++ b/src/ripple/protocol/tests/STAccount.test.cpp @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2015 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include + +namespace ripple { + +struct STAccount_test : public beast::unit_test::suite +{ + void + testSTAccount() + { + { + // Test default constructor. + STAccount const defaultAcct; + expect (defaultAcct.getSType() == STI_ACCOUNT); + expect (defaultAcct.getText() == ""); + expect (defaultAcct.isDefault() == true); + expect (defaultAcct.value() == AccountID {}); + expect (! defaultAcct.isValueH160()); + { +#ifdef NDEBUG // Qualified because the serialization asserts in a debug build. + Serializer s; + defaultAcct.add (s); // Asserts in debug build + expect (s.size() == 1); + expect (s.getHex() == "00"); + SerialIter sit (s.slice ()); + STAccount const deserializedDefault (sit, sfAccount); + expect (deserializedDefault.isEquivalent (defaultAcct)); + expect (! deserializedDefault.isValueH160()); +#endif // NDEBUG + } + { + // Construct a deserialized default STAccount. + Serializer s; + s.addVL (nullptr, 0); + SerialIter sit (s.slice ()); + STAccount const deserializedDefault (sit, sfAccount); + expect (deserializedDefault.isEquivalent (defaultAcct)); + expect (! deserializedDefault.isValueH160()); + } + + // Test constructor from SField. + STAccount const sfAcct {sfAccount}; + expect (sfAcct.getSType() == STI_ACCOUNT); + expect (sfAcct.getText() == ""); + expect (sfAcct.isDefault()); + expect (sfAcct.value() == AccountID {}); + expect (! sfAcct.isValueH160()); + expect (sfAcct.isEquivalent (defaultAcct)); + { + Serializer s; + sfAcct.add (s); + expect (s.size() == 1); + expect (s.getHex() == "00"); + SerialIter sit (s.slice ()); + STAccount const deserializedSf (sit, sfAccount); + expect (deserializedSf.isEquivalent(sfAcct)); + expect (! deserializedSf.isValueH160()); + } + + // Test constructor from SField and AccountID. + STAccount const zeroAcct {sfAccount, AccountID{}}; + expect (zeroAcct.getText() == "rrrrrrrrrrrrrrrrrrrrrhoLvTp"); + expect (! zeroAcct.isDefault()); + expect (zeroAcct.value() == AccountID {0}); + expect (zeroAcct.isValueH160()); + expect (! zeroAcct.isEquivalent (defaultAcct)); + expect (! zeroAcct.isEquivalent (sfAcct)); + { + Serializer s; + zeroAcct.add (s); + expect (s.size() == 21); + expect (s.getHex() == + "140000000000000000000000000000000000000000"); + SerialIter sit (s.slice ()); + STAccount const deserializedZero (sit, sfAccount); + expect (deserializedZero.isEquivalent (zeroAcct)); + expect (deserializedZero.isValueH160()); + } + { + // Construct from a VL that is not exactly 160 bits. + Serializer s; + const std::uint8_t bits128[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + s.addVL (bits128, sizeof (bits128)); + SerialIter sit (s.slice ()); + STAccount const deserializedBadSize (sit, sfAccount); + expect (! deserializedBadSize.isValueH160()); + } + + // Interestingly, equal values but different types are equivalent! + STAccount const regKey {sfRegularKey, AccountID{}}; + expect (regKey.isEquivalent (zeroAcct)); + + // Test assignment. + STAccount assignAcct; + expect (assignAcct.isEquivalent (defaultAcct)); + expect (assignAcct.isDefault()); + assignAcct = AccountID{}; + expect (! assignAcct.isEquivalent (defaultAcct)); + expect (assignAcct.isEquivalent (zeroAcct)); + expect (! assignAcct.isDefault()); + } + } + + void + run() override + { + testSTAccount(); + } +}; + +BEAST_DEFINE_TESTSUITE(STAccount,protocol,ripple); + +} diff --git a/src/ripple/unity/protocol.cpp b/src/ripple/unity/protocol.cpp index 15fac6e004..8b148e2e88 100644 --- a/src/ripple/unity/protocol.cpp +++ b/src/ripple/unity/protocol.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include