Skip to content

Commit

Permalink
add NetworkID support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jul 23, 2024
1 parent a0c472f commit b3ec935
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/test/rpc/Simulate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ namespace test {

class Simulate_test : public beast::unit_test::suite
{
std::unique_ptr<Config>
makeNetworkConfig(uint32_t networkID)
{
using namespace jtx;
return envconfig([&](std::unique_ptr<Config> cfg) {
cfg->NETWORK_ID = networkID;
return cfg;
});
}

void
checkBasicReturnValidity(
Json::Value& result,
Expand Down Expand Up @@ -411,17 +421,32 @@ class Simulate_test : public beast::unit_test::suite
void
testTransactionNonTecFailure()
{
testcase("Transaction non-tec failure");
testcase("Transaction non-tec failure + NetworkID autofill");

using namespace jtx;
Env env(*this);
// also check NetworkID
test::jtx::Env env{*this, makeNetworkConfig(1025)};
Account const alice("alice");

{
std::function<void(Json::Value, Json::Value&)> testSimulation =
[&](Json::Value resp, Json::Value& tx) {
auto result = resp[jss::result];
checkBasicReturnValidity(result, tx);
Json::Value tx_json;
if (result.isMember(jss::tx_json))
{
tx_json = result[jss::tx_json];
}
else
{
auto unHexed =
strUnHex(result[jss::tx_blob].asString());
SerialIter sitTrans(makeSlice(*unHexed));
tx_json = STObject(std::ref(sitTrans), sfGeneric)
.getJson(JsonOptions::none);
}
BEAST_EXPECT(tx_json.get(jss::NetworkID, -1) == 1025);

BEAST_EXPECT(result[jss::engine_result] == "temBAD_AMOUNT");
BEAST_EXPECT(result[jss::engine_result_code] == -298);
Expand Down
5 changes: 5 additions & 0 deletions src/xrpld/rpc/handlers/Simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ autofillTx(Json::Value& tx_json, RPC::JsonContext& context)
? 0
: context.app.getTxQ().nextQueuableSeq(sle).value();
}
if (!tx_json.isMember(jss::NetworkID) &&
context.app.config().NETWORK_ID > 1024)
{
tx_json[jss::NetworkID] = context.app.config().NETWORK_ID;
}

return std::nullopt;
}
Expand Down

0 comments on commit b3ec935

Please sign in to comment.