Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance AccountTx unit test #2977

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,7 @@ else ()
src/test/jtx/impl/WSClient.cpp
src/test/jtx/impl/amount.cpp
src/test/jtx/impl/balance.cpp
src/test/jtx/impl/check.cpp
src/test/jtx/impl/delivermin.cpp
src/test/jtx/impl/deposit.cpp
src/test/jtx/impl/envconfig.cpp
Expand Down
69 changes: 0 additions & 69 deletions src/test/app/Check_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,79 +20,10 @@
#include <test/jtx.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include <ripple/protocol/TxFlags.h>

namespace ripple {

// For the time being Checks seem pretty much self contained. So the
// functions that operate on jtx are defined here, locally. If they are
// needed by other unit tests they could put in another file.
namespace test {
namespace jtx {
namespace check {

// Create a check.
Json::Value
create (jtx::Account const& account,
jtx::Account const& dest, STAmount const& sendMax)
{
Json::Value jv;
jv[sfAccount.jsonName] = account.human();
jv[sfSendMax.jsonName] = sendMax.getJson(JsonOptions::none);
jv[sfDestination.jsonName] = dest.human();
jv[sfTransactionType.jsonName] = jss::CheckCreate;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

// Type used to specify DeliverMin for cashing a check.
struct DeliverMin
{
STAmount value;
explicit DeliverMin (STAmount const& deliverMin)
: value (deliverMin) { }
};

// Cash a check.
Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, STAmount const& amount)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfAmount.jsonName] = amount.getJson(JsonOptions::none);
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCash;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, DeliverMin const& atLeast)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfDeliverMin.jsonName] = atLeast.value.getJson(JsonOptions::none);
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCash;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

// Cancel a check.
Json::Value
cancel (jtx::Account const& dest, uint256 const& checkId)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCancel;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

} // namespace check

/** Set Expiration on a JTx. */
class expiration
Expand Down
1 change: 1 addition & 0 deletions src/test/jtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <test/jtx/Account.h>
#include <test/jtx/amount.h>
#include <test/jtx/balance.h>
#include <test/jtx/check.h>
#include <test/jtx/delivermin.h>
#include <test/jtx/deposit.h>
#include <test/jtx/Env.h>
Expand Down
71 changes: 71 additions & 0 deletions src/test/jtx/check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2019 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.
*/
//==============================================================================

#ifndef RIPPLE_TEST_JTX_CHECK_H_INCLUDED
#define RIPPLE_TEST_JTX_CHECK_H_INCLUDED

#include <test/jtx/Env.h>
#include <test/jtx/Account.h>
#include <test/jtx/owners.h>

namespace ripple {
namespace test {
namespace jtx {

/** Check operations. */
namespace check {

/** Create a check. */
Json::Value
create (jtx::Account const& account,
jtx::Account const& dest, STAmount const& sendMax);

/** Cash a check requiring that a specific amount be delivered. */
Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, STAmount const& amount);

/** Type used to specify DeliverMin for cashing a check. */
struct DeliverMin
{
STAmount value;
explicit DeliverMin (STAmount const& deliverMin)
: value (deliverMin) { }
};

/** Cash a check requiring that at least a minimum amount be delivered. */
Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, DeliverMin const& atLeast);

/** Cancel a check. */
Json::Value
cancel (jtx::Account const& dest, uint256 const& checkId);

} // check

/** Match the number of checks on the account. */
using checks = owner_count<ltCHECK>;

} // jtx

} // test
} // ripple

#endif
88 changes: 88 additions & 0 deletions src/test/jtx/impl/check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2019 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 <test/jtx/check.h>
#include <ripple/protocol/jss.h>
#include <ripple/protocol/TxFlags.h>

namespace ripple {
namespace test {
namespace jtx {

namespace check {

// Create a check.
Json::Value
create (jtx::Account const& account,
jtx::Account const& dest, STAmount const& sendMax)
{
Json::Value jv;
jv[sfAccount.jsonName] = account.human();
jv[sfSendMax.jsonName] = sendMax.getJson(JsonOptions::none);
jv[sfDestination.jsonName] = dest.human();
jv[sfTransactionType.jsonName] = jss::CheckCreate;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

// Cash a check requiring that a specific amount be delivered.
Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, STAmount const& amount)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfAmount.jsonName] = amount.getJson(JsonOptions::none);
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCash;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

// Cash a check requiring that at least a minimum amount be delivered.
Json::Value
cash (jtx::Account const& dest,
uint256 const& checkId, DeliverMin const& atLeast)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfDeliverMin.jsonName] = atLeast.value.getJson(JsonOptions::none);
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCash;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

// Cancel a check.
Json::Value
cancel (jtx::Account const& dest, uint256 const& checkId)
{
Json::Value jv;
jv[sfAccount.jsonName] = dest.human();
jv[sfCheckID.jsonName] = to_string (checkId);
jv[sfTransactionType.jsonName] = jss::CheckCancel;
jv[sfFlags.jsonName] = tfUniversal;
return jv;
}

} // check

} // jtx
} // test
} // ripple
15 changes: 3 additions & 12 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,9 @@ class AccountObjects_test : public beast::unit_test::suite
BEAST_EXPECT (state[sfBalance.jsonName][jss::value].asInt() == -5);
BEAST_EXPECT (state[sfHighLimit.jsonName][jss::value].asUInt() == 1000);
}
{
// gw writes a check for USD(10) to alice.
Json::Value jvCheck;
jvCheck[sfAccount.jsonName] = gw.human();
jvCheck[sfSendMax.jsonName] =
USD(10).value().getJson(JsonOptions::none);
jvCheck[sfDestination.jsonName] = alice.human();
jvCheck[sfTransactionType.jsonName] = jss::CheckCreate;
jvCheck[sfFlags.jsonName] = tfUniversal;
env (jvCheck);
env.close();
}
// gw writes a check for USD(10) to alice.
env (check::create (gw, alice, USD(10)));
env.close();
{
// Find the check.
Json::Value const resp = acct_objs (gw, jss::check);
Expand Down