Unit test for free trust lines (RIPD-911)

This commit is contained in:
Brad Chase
2016-10-20 13:39:20 -04:00
parent 795ee8bb5e
commit b8cae2dfaf
5 changed files with 78 additions and 1 deletions

1
.gitignore vendored
View File

@@ -93,3 +93,4 @@ Builds/VisualStudio2015/*.sdf
# MSVC
*.pdb
.vs/

View File

@@ -4386,6 +4386,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\SetTrust_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\SHAMapStore_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -5193,6 +5193,9 @@
<ClCompile Include="..\..\src\test\app\SetRegularKey_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\SetTrust_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\SHAMapStore_test.cpp">
<Filter>test\app</Filter>
</ClCompile>

View File

@@ -0,0 +1,68 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2016 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 <ripple/test/jtx.h>
namespace ripple {
namespace test {
class SetTrust_test : public beast::unit_test::suite
{
public:
void testFreeTrustlines()
{
testcase("Allow 2 free trust lines before requiring reserve");
using namespace jtx;
Env env(*this);
auto const gwA = Account{ "gatewayA" };
auto const gwB = Account{ "gatewayB" };
auto const gwC = Account{ "gatewayC" };
auto const alice = Account{ "alice" };
auto const txFee = env.current()->fees().base;
auto const baseReserve = env.current()->fees().accountReserve(0);
auto const threelineReserve = env.current()->fees().accountReserve(3);
env.fund(XRP(10000), gwA, gwB, gwC);
// Fund alice with ...
env.fund(baseReserve /* enough to hold an account */
+ drops(3*txFee) /* and to pay for 3 transactions */, alice);
env(trust(alice, gwA["USD"](100)), require(lines(alice,1)));
env(trust(alice, gwB["USD"](100)), require(lines(alice,2)));
// Alice does not have enough for the third trust line
env(trust(alice, gwC["USD"](100)), ter(tecNO_LINE_INSUF_RESERVE), require(lines(alice,2)));
// Fund Alice additional amount to cover
env(pay(env.master, alice, STAmount{ threelineReserve - baseReserve }));
env(trust(alice, gwC["USD"](100)), require(lines(alice,3)));
}
void run()
{
testFreeTrustlines();
}
};
BEAST_DEFINE_TESTSUITE(SetTrust, app, ripple);
} // test
} // ripple

View File

@@ -40,3 +40,4 @@
#include <test/app/Transaction_ordering_test.cpp>
#include <test/app/TxQ_test.cpp>
#include <test/app/ValidatorList_test.cpp>
#include <test/app/SetTrust_test.cpp>