Skip to content

Commit 968b033

Browse files
committed
test: Env unit test RPC errors return a unique result: (#4877)
* telENV_RPC_FAILED is a new code, reserved exclusively for unit tests when RPC fails unexpectedly. This will make those types of errors distinct and easier to test for when expect and/or diagnose when not.
1 parent 8a2f6be commit 968b033

File tree

9 files changed

+34
-13
lines changed

9 files changed

+34
-13
lines changed

src/ripple/protocol/TER.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ enum TELcodes : TERUnderlyingType {
6464
telCAN_NOT_QUEUE_FULL,
6565
telWRONG_NETWORK,
6666
telREQUIRES_NETWORK_ID,
67-
telNETWORK_ID_MAKES_TX_NON_CANONICAL
67+
telNETWORK_ID_MAKES_TX_NON_CANONICAL,
68+
telENV_RPC_FAILED
6869
};
6970

7071
//------------------------------------------------------------------------------

src/ripple/protocol/impl/TER.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ transResults()
154154
MAKE_ERROR(telWRONG_NETWORK, "Transaction specifies a Network ID that differs from that of the local node."),
155155
MAKE_ERROR(telREQUIRES_NETWORK_ID, "Transactions submitted to this node/network must include a correct NetworkID field."),
156156
MAKE_ERROR(telNETWORK_ID_MAKES_TX_NON_CANONICAL, "Transactions submitted to this node/network must NOT include a NetworkID field."),
157+
MAKE_ERROR(telENV_RPC_FAILED, "Unit test RPC failure."),
157158

158159
MAKE_ERROR(temMALFORMED, "Malformed transaction."),
159160
MAKE_ERROR(temBAD_AMM_TOKENS, "Malformed: Invalid LPTokens."),

src/test/app/MultiSign_test.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ class MultiSign_test : public beast::unit_test::suite
247247

248248
// Duplicate signers should fail.
249249
aliceSeq = env.seq(alice);
250-
env(noop(alice), msig(demon, demon), fee(3 * baseFee), ter(temINVALID));
250+
env(noop(alice),
251+
msig(demon, demon),
252+
fee(3 * baseFee),
253+
ter(telENV_RPC_FAILED));
251254
env.close();
252255
BEAST_EXPECT(env.seq(alice) == aliceSeq);
253256

@@ -358,7 +361,7 @@ class MultiSign_test : public beast::unit_test::suite
358361
msig phantoms{bogie, demon};
359362
std::reverse(phantoms.signers.begin(), phantoms.signers.end());
360363
std::uint32_t const aliceSeq = env.seq(alice);
361-
env(noop(alice), phantoms, ter(temINVALID));
364+
env(noop(alice), phantoms, ter(telENV_RPC_FAILED));
362365
env.close();
363366
BEAST_EXPECT(env.seq(alice) == aliceSeq);
364367
}
@@ -1634,7 +1637,10 @@ class MultiSign_test : public beast::unit_test::suite
16341637

16351638
// Duplicate signers should fail.
16361639
aliceSeq = env.seq(alice);
1637-
env(noop(alice), msig(demon, demon), fee(3 * baseFee), ter(temINVALID));
1640+
env(noop(alice),
1641+
msig(demon, demon),
1642+
fee(3 * baseFee),
1643+
ter(telENV_RPC_FAILED));
16381644
env.close();
16391645
BEAST_EXPECT(env.seq(alice) == aliceSeq);
16401646

src/test/app/Regression_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct Regression_test : public beast::unit_test::suite
149149
secp256r1Sig->setFieldVL(sfSigningPubKey, *pubKeyBlob);
150150
jt.stx.reset(secp256r1Sig.release());
151151

152-
env(jt, ter(temINVALID));
152+
env(jt, ter(telENV_RPC_FAILED));
153153
};
154154

155155
Account const alice{"alice", KeyType::secp256k1};

src/test/app/ValidatorSite_test.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ class ValidatorSite_test : public beast::unit_test::suite
239239

240240
std::vector<std::string> uris;
241241
for (auto const& u : servers)
242+
{
243+
log << "Testing " << u.uri << std::endl;
242244
uris.push_back(u.uri);
245+
}
243246
sites->load(uris);
244247
sites->start();
245248
sites->join();

src/test/jtx/Env_test.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,9 @@ class Env_test : public beast::unit_test::suite
747747
// Force the factor low enough to fail
748748
params[jss::fee_mult_max] = 1;
749749
params[jss::fee_div_max] = 2;
750-
// RPC errors result in temINVALID
751-
envs(noop(alice), fee(none), seq(none), ter(temINVALID))(params);
750+
// RPC errors result in telENV_RPC_FAILED
751+
envs(noop(alice), fee(none), seq(none), ter(telENV_RPC_FAILED))(
752+
params);
752753

753754
auto tx = env.tx();
754755
BEAST_EXPECT(!tx);

src/test/jtx/impl/Env.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ Env::parseResult(Json::Value const& jr)
280280
jr[jss::result].isMember(jss::engine_result_code))
281281
ter = TER::fromInt(jr[jss::result][jss::engine_result_code].asInt());
282282
else
283-
ter = temINVALID;
283+
// Use an error code that is not used anywhere in the transaction engine
284+
// to distinguish this case.
285+
ter = telENV_RPC_FAILED;
284286
return std::make_pair(ter, isTesSuccess(ter) || isTecClaim(ter));
285287
}
286288

src/test/net/DatabaseDownloader_test.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class DatabaseDownloader_test : public beast::unit_test::suite
147147
// server to request from. Use the /textfile endpoint
148148
// to get a simple text file sent as response.
149149
auto server = createServer(env);
150+
log << "Downloading DB from " << server->local_endpoint() << std::endl;
150151

151152
ripple::test::detail::FileDirGuard const data{
152153
*this, "downloads", "data", "", false, false};
@@ -225,6 +226,8 @@ class DatabaseDownloader_test : public beast::unit_test::suite
225226
auto server = createServer(env);
226227
auto host = server->local_endpoint().address().to_string();
227228
auto port = std::to_string(server->local_endpoint().port());
229+
log << "Downloading DB from " << server->local_endpoint()
230+
<< std::endl;
228231
server->stop();
229232
BEAST_EXPECT(dl->download(
230233
host,
@@ -249,6 +252,8 @@ class DatabaseDownloader_test : public beast::unit_test::suite
249252
ripple::test::detail::FileDirGuard const datafile{
250253
*this, "downloads", "data", "", false, false};
251254
auto server = createServer(env, false);
255+
log << "Downloading DB from " << server->local_endpoint()
256+
<< std::endl;
252257
BEAST_EXPECT(dl->download(
253258
server->local_endpoint().address().to_string(),
254259
std::to_string(server->local_endpoint().port()),
@@ -272,6 +277,8 @@ class DatabaseDownloader_test : public beast::unit_test::suite
272277
ripple::test::detail::FileDirGuard const datafile{
273278
*this, "downloads", "data", "", false, false};
274279
auto server = createServer(env);
280+
log << "Downloading DB from " << server->local_endpoint()
281+
<< std::endl;
275282
BEAST_EXPECT(dl->download(
276283
server->local_endpoint().address().to_string(),
277284
std::to_string(server->local_endpoint().port()),

src/test/protocol/Memo_test.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Memo_test : public beast::unit_test::suite
5656
JTx memoSize = makeJtxWithMemo();
5757
memoSize.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
5858
[sfMemoData.jsonName] = std::string(2020, '0');
59-
env(memoSize, ter(temINVALID));
59+
env(memoSize, ter(telENV_RPC_FAILED));
6060

6161
// This memo is just barely small enough.
6262
memoSize.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
@@ -72,23 +72,23 @@ class Memo_test : public beast::unit_test::suite
7272
auto& m = mi[sfCreatedNode.jsonName]; // CreatedNode in Memos
7373
m[sfMemoData.jsonName] = "3030303030";
7474

75-
env(memoNonMemo, ter(temINVALID));
75+
env(memoNonMemo, ter(telENV_RPC_FAILED));
7676
}
7777
{
7878
// Put an invalid field in a Memo object.
7979
JTx memoExtra = makeJtxWithMemo();
8080
memoExtra
8181
.jv[sfMemos.jsonName][0u][sfMemo.jsonName][sfFlags.jsonName] =
8282
13;
83-
env(memoExtra, ter(temINVALID));
83+
env(memoExtra, ter(telENV_RPC_FAILED));
8484
}
8585
{
8686
// Put a character that is not allowed in a URL in a MemoType field.
8787
JTx memoBadChar = makeJtxWithMemo();
8888
memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
8989
[sfMemoType.jsonName] =
9090
strHex(std::string_view("ONE<INFINITY"));
91-
env(memoBadChar, ter(temINVALID));
91+
env(memoBadChar, ter(telENV_RPC_FAILED));
9292
}
9393
{
9494
// Put a character that is not allowed in a URL in a MemoData field.
@@ -105,7 +105,7 @@ class Memo_test : public beast::unit_test::suite
105105
memoBadChar.jv[sfMemos.jsonName][0u][sfMemo.jsonName]
106106
[sfMemoFormat.jsonName] =
107107
strHex(std::string_view("NoBraces{}InURL"));
108-
env(memoBadChar, ter(temINVALID));
108+
env(memoBadChar, ter(telENV_RPC_FAILED));
109109
}
110110
}
111111

0 commit comments

Comments
 (0)