From 5b09dc731fd578d697dc703852a268df0f1cbb41 Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 22 Aug 2016 17:50:04 -0400 Subject: [PATCH] Add jtx cpp test for noripple flag (RIPD-1259): - Set and clear noripple flag - DefaultRipple on account - Set noripple on trustline with -ve balance - Pairwise noripple --- Builds/VisualStudio2015/RippleD.vcxproj | 4 + .../VisualStudio2015/RippleD.vcxproj.filters | 3 + src/test/rpc/NoRipple_test.cpp | 226 ++++++++++++++++++ src/unity/rpc_test_unity.cpp | 1 + 4 files changed, 234 insertions(+) create mode 100644 src/test/rpc/NoRipple_test.cpp diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 0a6f1dadd7..71c065f7f7 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -4732,6 +4732,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 7733837e9b..c7f958424b 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -5424,6 +5424,9 @@ test\rpc + + test\rpc + test\rpc diff --git a/src/test/rpc/NoRipple_test.cpp b/src/test/rpc/NoRipple_test.cpp new file mode 100644 index 0000000000..437ad4bce0 --- /dev/null +++ b/src/test/rpc/NoRipple_test.cpp @@ -0,0 +1,226 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 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 +#include + +namespace ripple { + +namespace test { + +class NoRipple_test : public beast::unit_test::suite +{ +public: + void + testSetAndClear() + { + testcase("Set and clear noripple"); + + using namespace jtx; + Env env(*this); + + auto const gw = Account("gateway"); + auto const alice = Account("alice"); + + env.fund(XRP(10000), gw, alice); + + auto const USD = gw["USD"]; + + Json::Value account_gw; + account_gw[jss::account] = gw.human(); + Json::Value account_alice; + account_alice[jss::account] = alice.human(); + + for (auto SetOrClear : {true,false}) + { + // Create a trust line with no-ripple flag setting + env( trust(gw, USD(100), alice, SetOrClear ? tfSetNoRipple + : tfClearNoRipple)); + env.close(); + + // Check no-ripple flag on sender 'gateway' + auto lines = env.rpc("json", "account_lines", to_string(account_gw)); + auto const& gline0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(gline0[jss::no_ripple].asBool() == SetOrClear); + + // Check no-ripple peer flag on destination 'alice' + lines = env.rpc("json", "account_lines", to_string(account_alice)); + auto const& aline0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(aline0[jss::no_ripple_peer].asBool() == SetOrClear); + } + } + + void + testNegativeBalance() + { + testcase("Set noripple on a line with negative balance"); + + using namespace jtx; + Env env(*this); + + auto const gw = Account("gateway"); + auto const alice = Account("alice"); + auto const bob = Account("bob"); + auto const carol = Account("carol"); + + env.fund(XRP(10000), gw, alice, bob, carol); + + env.trust(alice["USD"](100), bob); + env.trust(bob["USD"](100), carol); + env.close(); + + env(pay(alice, carol, carol["USD"](50)), path(bob)); + + env(trust(alice, bob["USD"](100), bob, tfSetNoRipple)); + env(trust(bob, carol["USD"](100), carol, tfSetNoRipple)); + env.close(); + + Json::Value params; + params[jss::source_account] = alice.human(); + params[jss::destination_account] = carol.human(); + params[jss::destination_amount] = [] { + Json::Value dest_amt; + dest_amt[jss::currency] = "USD"; + dest_amt[jss::value] = "1"; + dest_amt[jss::issuer] = Account("carol").human(); + return dest_amt; + }(); + + auto const resp = env.rpc("json", "ripple_path_find", to_string(params)); + BEAST_EXPECT(resp[jss::result][jss::alternatives].size()==1); + + Json::Value account_alice; + account_alice[jss::account] = alice.human(); + auto const res = env.rpc("json", "account_lines", to_string(account_alice)); + auto const& lines = res[jss::result][jss::lines]; + BEAST_EXPECT(lines.size() == 1); + BEAST_EXPECT(!lines[0u].isMember(jss::no_ripple)); + } + + void + testPairwise() + { + testcase("pairwise NoRipple"); + + using namespace jtx; + Env env(*this); + + auto const alice = Account("alice"); + auto const bob = Account("bob"); + auto const carol = Account("carol"); + + env.fund(XRP(10000), alice, bob, carol); + + env(trust(bob, alice["USD"](100))); + env(trust(carol, bob["USD"](100))); + + env(trust(bob, alice["USD"](100), alice, tfSetNoRipple)); + env(trust(bob, carol["USD"](100), carol, tfSetNoRipple)); + env.close(); + + Json::Value params; + params[jss::source_account] = alice.human(); + params[jss::destination_account] = carol.human(); + params[jss::destination_amount] = [] { + Json::Value dest_amt; + dest_amt[jss::currency] = "USD"; + dest_amt[jss::value] = "1"; + dest_amt[jss::issuer] = Account("carol").human(); + return dest_amt; + }(); + + auto const resp = env.rpc("json", "ripple_path_find", to_string(params)); + BEAST_EXPECT(resp[jss::result][jss::alternatives].size() == 0); + + env(pay(alice, carol, bob["USD"](50)), ter(tecPATH_DRY)); + } + + void + testDefaultRipple() + { + testcase("Set default ripple on an account and check new trustlines"); + + using namespace jtx; + Env env(*this); + + auto const gw = Account("gateway"); + auto const alice = Account("alice"); + auto const bob = Account("bob"); + + env.fund(XRP(10000), gw, noripple(alice, bob)); + + env(fset(bob, asfDefaultRipple)); + + auto const USD = gw["USD"]; + + env(trust(gw, USD(100), alice, 0)); + env(trust(gw, USD(100), bob, 0)); + + { + Json::Value params; + params[jss::account] = gw.human(); + params[jss::peer] = alice.human(); + + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == true); + } + { + Json::Value params; + params[jss::account] = alice.human(); + params[jss::peer] = gw.human(); + + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == true); + } + { + Json::Value params; + params[jss::account] = gw.human(); + params[jss::peer] = bob.human(); + + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == false); + } + { + Json::Value params; + params[jss::account] = bob.human(); + params[jss::peer] = gw.human(); + + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == false); + } + } + + void run () + { + testSetAndClear(); + testNegativeBalance(); + testPairwise(); + testDefaultRipple(); + } +}; + +BEAST_DEFINE_TESTSUITE(NoRipple,app,ripple); + +} // RPC +} // ripple + diff --git a/src/unity/rpc_test_unity.cpp b/src/unity/rpc_test_unity.cpp index 2134635f69..d71dcc0dde 100644 --- a/src/unity/rpc_test_unity.cpp +++ b/src/unity/rpc_test_unity.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include