Skip to content

Commit 3a55ce1

Browse files
ximinezseelabs
authored andcommitted
Add more 'sign' tests:
fix XRPLF#229
1 parent d67d248 commit 3a55ce1

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/test/rpc/JSONRPC_test.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,76 @@ class JSONRPC_test : public beast::unit_test::suite
21602160
BEAST_EXPECT(RPC::contains_error(result));
21612161
}
21622162

2163+
{
2164+
// 10: Call "sign" with nothing in the open ledger
2165+
Json::Value toSign;
2166+
toSign[jss::tx_json] = noop(env.master);
2167+
toSign[jss::secret] = "masterpassphrase";
2168+
auto rpcResult = env.rpc("json", "sign", to_string(toSign));
2169+
auto result = rpcResult[jss::result];
2170+
2171+
BEAST_EXPECT(! RPC::contains_error(result));
2172+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Fee) &&
2173+
result[jss::tx_json][jss::Fee] == "10");
2174+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Sequence) &&
2175+
result[jss::tx_json][jss::Sequence].isConvertibleTo(
2176+
Json::ValueType::uintValue));
2177+
}
2178+
2179+
{
2180+
// 11: Call "sign" with enough transactions in the open ledger
2181+
// to escalate the fee.
2182+
for (;;)
2183+
{
2184+
auto metrics = env.app().getTxQ().getMetrics(*env.current());
2185+
if (!BEAST_EXPECT(metrics))
2186+
break;
2187+
if (metrics->expFeeLevel > metrics->minFeeLevel)
2188+
break;
2189+
env(noop(env.master));
2190+
}
2191+
2192+
Json::Value toSign;
2193+
toSign[jss::tx_json] = noop(env.master);
2194+
toSign[jss::secret] = "masterpassphrase";
2195+
toSign[jss::fee_mult_max] = 900;
2196+
auto rpcResult = env.rpc("json", "sign", to_string(toSign));
2197+
auto result = rpcResult[jss::result];
2198+
2199+
BEAST_EXPECT(! RPC::contains_error(result));
2200+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Fee) &&
2201+
result[jss::tx_json][jss::Fee] == "8889");
2202+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Sequence) &&
2203+
result[jss::tx_json][jss::Sequence].isConvertibleTo(
2204+
Json::ValueType::uintValue));
2205+
2206+
env.close();
2207+
}
2208+
2209+
{
2210+
// 12: Call "sign" with higher server load
2211+
{
2212+
auto& feeTrack = env.app().getFeeTrack();
2213+
BEAST_EXPECT(feeTrack.getLoadFactor() == 256);
2214+
for (int i = 0; i < 8; ++i)
2215+
feeTrack.raiseLocalFee();
2216+
BEAST_EXPECT(feeTrack.getLoadFactor() == 1220);
2217+
}
2218+
2219+
Json::Value toSign;
2220+
toSign[jss::tx_json] = noop(env.master);
2221+
toSign[jss::secret] = "masterpassphrase";
2222+
auto rpcResult = env.rpc("json", "sign", to_string(toSign));
2223+
auto result = rpcResult[jss::result];
2224+
2225+
BEAST_EXPECT(! RPC::contains_error(result));
2226+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Fee) &&
2227+
result[jss::tx_json][jss::Fee] == "47");
2228+
BEAST_EXPECT(result[jss::tx_json].isMember(jss::Sequence) &&
2229+
result[jss::tx_json][jss::Sequence].isConvertibleTo(
2230+
Json::ValueType::uintValue));
2231+
}
2232+
21632233
}
21642234

21652235
// A function that can be called as though it would process a transaction.

0 commit comments

Comments
 (0)