mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add STAccount unit tests (RIPD-994)
This commit is contained in:
committed by
Nik Bougalis
parent
fa05ded88e
commit
f63867e958
@@ -3046,6 +3046,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\tests\STAccount.test.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\tests\STAmount.test.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
|
||||
@@ -3741,6 +3741,9 @@
|
||||
<ClCompile Include="..\..\src\ripple\protocol\tests\RippleAddress.test.cpp">
|
||||
<Filter>ripple\protocol\tests</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\tests\STAccount.test.cpp">
|
||||
<Filter>ripple\protocol\tests</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\protocol\tests\STAmount.test.cpp">
|
||||
<Filter>ripple\protocol\tests</Filter>
|
||||
</ClCompile>
|
||||
|
||||
133
src/ripple/protocol/tests/STAccount.test.cpp
Normal file
133
src/ripple/protocol/tests/STAccount.test.cpp
Normal file
@@ -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 <BeastConfig.h>
|
||||
#include <ripple/protocol/STAccount.h>
|
||||
#include <beast/unit_test/suite.h>
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -71,6 +71,7 @@
|
||||
#include <ripple/protocol/tests/PublicKey_test.cpp>
|
||||
#include <ripple/protocol/tests/Quality.test.cpp>
|
||||
#include <ripple/protocol/tests/RippleAddress.test.cpp>
|
||||
#include <ripple/protocol/tests/STAccount.test.cpp>
|
||||
#include <ripple/protocol/tests/STAmount.test.cpp>
|
||||
#include <ripple/protocol/tests/STObject.test.cpp>
|
||||
#include <ripple/protocol/tests/STTx.test.cpp>
|
||||
|
||||
Reference in New Issue
Block a user