Add test for transaction_entry request (RIPD-1401):

Test transaction_entry request. Remove unreachable redundant ledger
lookup check. Fix check for request against the current ledger
(disallowed).
This commit is contained in:
Mike Ellery
2017-02-13 07:45:03 -08:00
committed by seelabs
parent f1377d5d30
commit 4b0a0b0b85
5 changed files with 187 additions and 24 deletions

View File

@@ -4899,6 +4899,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\rpc\TransactionEntry_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\server\ServerStatus_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -5574,6 +5574,9 @@
<ClCompile Include="..\..\src\test\rpc\Subscribe_test.cpp">
<Filter>test\rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\rpc\TransactionEntry_test.cpp">
<Filter>test\rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\server\ServerStatus_test.cpp">
<Filter>test\server</Filter>
</ClCompile>

View File

@@ -35,18 +35,17 @@ namespace ripple {
// means any ledger.
Json::Value doTransactionEntry (RPC::Context& context)
{
std::shared_ptr <ReadView const> lpLedger;
std::shared_ptr<ReadView const> lpLedger;
Json::Value jvResult = RPC::lookupLedger (lpLedger, context);
if (!lpLedger)
if(! lpLedger)
return jvResult;
if (!context.params.isMember (jss::tx_hash))
if(! context.params.isMember (jss::tx_hash))
{
jvResult[jss::error] = "fieldNotFoundTransaction";
jvResult[jss::error] = "fieldNotFoundTransaction";
}
else if (!context.params.isMember (jss::ledger_hash)
&& !context.params.isMember (jss::ledger_index))
else if(jvResult.get(jss::ledger_hash, Json::nullValue).isNull())
{
// We don't work on ledger current.
@@ -60,28 +59,19 @@ Json::Value doTransactionEntry (RPC::Context& context)
// routine, returning success or failure.
uTransID.SetHex (context.params[jss::tx_hash].asString ());
if (!lpLedger)
auto tx = lpLedger->txRead (uTransID);
if(! tx.first)
{
jvResult[jss::error] = "ledgerNotFound";
jvResult[jss::error] = "transactionNotFound";
}
else
{
TxMeta::pointer tmTrans;
auto tx = lpLedger->txRead (uTransID);
if (!tx.first)
{
jvResult[jss::error] = "transactionNotFound";
}
else
{
jvResult[jss::tx_json] = tx.first->getJson (0);
if (tx.second)
jvResult[jss::metadata] = tx.second->getJson (0);
// 'accounts'
// 'engine_...'
// 'ledger_...'
}
jvResult[jss::tx_json] = tx.first->getJson (0);
if (tx.second)
jvResult[jss::metadata] = tx.second->getJson (0);
// 'accounts'
// 'engine_...'
// 'ledger_...'
}
}

View File

@@ -0,0 +1,165 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2017 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.h>
#include <test/jtx/Env.h>
#include <ripple/protocol/JsonFields.h>
namespace ripple {
class TransactionEntry_test : public beast::unit_test::suite
{
void
testBadInput()
{
testcase("Invalid request params");
using namespace test::jtx;
Env env {*this};
{
//no params
auto const result = env.client()
.invoke("transaction_entry", {})[jss::result];
BEAST_EXPECT(result[jss::error] == "fieldNotFoundTransaction");
BEAST_EXPECT(result[jss::status] == "error");
}
{
Json::Value params {Json::objectValue};
params[jss::ledger] = 20;
auto const result = env.client()
.invoke("transaction_entry", params)[jss::result];
BEAST_EXPECT(result[jss::error] == "lgrNotFound");
BEAST_EXPECT(result[jss::status] == "error");
}
{
Json::Value params {Json::objectValue};
params[jss::ledger] = "current";
params[jss::tx_hash] = "DEADBEEF";
auto const result = env.client()
.invoke("transaction_entry", params)[jss::result];
BEAST_EXPECT(result[jss::error] == "notYetImplemented");
BEAST_EXPECT(result[jss::status] == "error");
}
{
Json::Value params {Json::objectValue};
params[jss::ledger] = "closed";
params[jss::tx_hash] = "DEADBEEF";
auto const result = env.client()
.invoke("transaction_entry", params)[jss::result];
BEAST_EXPECT(! result[jss::ledger_hash].asString().empty());
BEAST_EXPECT(result[jss::error] == "transactionNotFound");
BEAST_EXPECT(result[jss::status] == "error");
}
}
void testRequest()
{
testcase("Basic request");
using namespace test::jtx;
Env env {*this};
auto check_tx = [this, &env]
(int index, std::string txhash, std::string type = "")
{
Json::Value resIndex, resHash;
// first request using ledger_index to lookup
{
Json::Value params {Json::objectValue};
params[jss::ledger_index] = index;
params[jss::tx_hash] = txhash;
resIndex = env.client()
.invoke("transaction_entry", params)[jss::result];
if(! BEAST_EXPECTS(resIndex.isMember(jss::tx_json), txhash))
return;
BEAST_EXPECT(resIndex[jss::tx_json][jss::hash] == txhash);
if(! type.empty())
BEAST_EXPECTS(
resIndex[jss::tx_json][jss::TransactionType] == type,
txhash + " is " +
resIndex[jss::tx_json][jss::TransactionType].asString());
}
// second request using ledger_hash to lookup and verify
// both responses match
{
Json::Value params {Json::objectValue};
params[jss::ledger_hash] = resIndex[jss::ledger_hash];
params[jss::tx_hash] = txhash;
resHash = env.client()
.invoke("transaction_entry", params)[jss::result];
BEAST_EXPECT(resHash == resIndex);
}
};
Account A1 {"A1"};
Account A2 {"A2"};
env.fund(XRP(10000), A1);
auto fund_1_tx =
boost::lexical_cast<std::string>(env.tx()->getTransactionID());
env.fund(XRP(10000), A2);
auto fund_2_tx =
boost::lexical_cast<std::string>(env.tx()->getTransactionID());
env.close();
// these are actually AccountSet txs because fund does two txs and
// env.tx only reports the last one
check_tx(env.closed()->seq(), fund_1_tx);
check_tx(env.closed()->seq(), fund_2_tx);
env.trust(A2["USD"](1000), A1);
// the trust tx is actually a payment since the trust method
// refunds fees with a payment after TrustSet..so just ignore the type
// in the check below
auto trust_tx =
boost::lexical_cast<std::string>(env.tx()->getTransactionID());
env(pay(A2, A1, A2["USD"](5)));
auto pay_tx =
boost::lexical_cast<std::string>(env.tx()->getTransactionID());
env.close();
check_tx(env.closed()->seq(), trust_tx);
check_tx(env.closed()->seq(), pay_tx, "Payment");
env(offer(A2, XRP(100), A2["USD"](1)));
auto offer_tx =
boost::lexical_cast<std::string>(env.tx()->getTransactionID());
env.close();
check_tx(env.closed()->seq(), offer_tx, "OfferCreate");
}
public:
void run ()
{
testBadInput();
testRequest();
}
};
BEAST_DEFINE_TESTSUITE (TransactionEntry, rpc, ripple);
} // ripple

View File

@@ -38,3 +38,4 @@
#include <test/rpc/ServerInfo_test.cpp>
#include <test/rpc/Status_test.cpp>
#include <test/rpc/Subscribe_test.cpp>
#include <test/rpc/TransactionEntry_test.cpp>