mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
add autofill + refactor (#54)
This commit is contained in:
@@ -47,9 +47,7 @@ public:
|
||||
void
|
||||
testNetworkID()
|
||||
{
|
||||
testcase(
|
||||
"Require txn NetworkID to be specified (or not) depending on the "
|
||||
"network ID of the node");
|
||||
testcase("network_id");
|
||||
using namespace jtx;
|
||||
|
||||
auto const alice = Account{"alice"};
|
||||
@@ -67,14 +65,9 @@ public:
|
||||
jv[jss::Destination] = alice.human();
|
||||
jv[jss::TransactionType] = "Payment";
|
||||
jv[jss::Amount] = "10000000000";
|
||||
if (env.app().config().NETWORK_ID > 1024)
|
||||
jv[jss::NetworkID] =
|
||||
std::to_string(env.app().config().NETWORK_ID);
|
||||
|
||||
env(jv, fee(1000), sig(env.master));
|
||||
}
|
||||
|
||||
// run tx
|
||||
env(jv, fee(1000), ter(expectedOutcome));
|
||||
env.close();
|
||||
};
|
||||
@@ -127,11 +120,25 @@ public:
|
||||
test::jtx::Env env{*this, makeNetworkConfig(1025)};
|
||||
BEAST_EXPECT(env.app().config().NETWORK_ID == 1025);
|
||||
|
||||
// try to submit a txn without network id, this should not work
|
||||
{
|
||||
env.fund(XRP(200), alice);
|
||||
// try to submit a txn without network id, this should not work
|
||||
Json::Value jvn;
|
||||
jvn[jss::Account] = alice.human();
|
||||
jvn[jss::TransactionType] = jss::AccountSet;
|
||||
jvn[jss::Fee] = to_string(env.current()->fees().base);
|
||||
jvn[jss::Sequence] = env.seq(alice);
|
||||
jvn[jss::LastLedgerSequence] = env.current()->info().seq + 2;
|
||||
auto jt = env.jtnofill(jvn);
|
||||
Serializer s;
|
||||
jt.stx->add(s);
|
||||
BEAST_EXPECT(env.rpc("submit", strHex(s.slice()))[jss::result][jss::engine_result] == "telREQUIRES_NETWORK_ID");
|
||||
env.close();
|
||||
}
|
||||
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::TransactionType] = jss::AccountSet;
|
||||
runTx(env, jv, telREQUIRES_NETWORK_ID);
|
||||
|
||||
// try to submit with wrong network id
|
||||
jv[jss::NetworkID] = 0;
|
||||
|
||||
@@ -445,6 +445,18 @@ public:
|
||||
return jt;
|
||||
}
|
||||
|
||||
/** Create a JTx from parameters. */
|
||||
template <class JsonValue, class... FN>
|
||||
JTx
|
||||
jtnofill(JsonValue&& jv, FN const&... fN)
|
||||
{
|
||||
JTx jt(std::forward<JsonValue>(jv));
|
||||
invoke(jt, fN...);
|
||||
autofill_sig(jt);
|
||||
jt.stx = st(jt);
|
||||
return jt;
|
||||
}
|
||||
|
||||
/** Create JSON from parameters.
|
||||
This will apply funclets and autofill.
|
||||
*/
|
||||
|
||||
@@ -432,6 +432,11 @@ Env::autofill(JTx& jt)
|
||||
jtx::fill_fee(jv, *current());
|
||||
if (jt.fill_seq)
|
||||
jtx::fill_seq(jv, *current());
|
||||
|
||||
uint32_t networkID = app().config().NETWORK_ID;
|
||||
if (!jv.isMember(jss::NetworkID) && networkID > 1024)
|
||||
jv[jss::NetworkID] = std::to_string(networkID);
|
||||
|
||||
// Must come last
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user