fix test env autofill

This commit is contained in:
Denis Angell
2023-06-17 00:15:32 +00:00
parent de03278927
commit ea02919a0c
2 changed files with 58 additions and 11 deletions

View File

@@ -445,6 +445,18 @@ public:
return jt;
}
/** Create a JTx from parameters. */
template <class JsonValue, class... FN>
JTx
jt(JsonValue&& jv, Account account, FN const&... fN)
{
JTx jt(std::forward<JsonValue>(jv));
invoke(jt, fN...);
acct_autofill(jt, account);
jt.stx = st(jt);
return jt;
}
/** Create a JTx from parameters. */
template <class JsonValue, class Account, class... FN>
JTx
@@ -452,7 +464,7 @@ public:
{
JTx jt(std::forward<JsonValue>(jv));
invoke(jt, fN...);
nofill_sig(jt, account);
autofill_sig(jt, account);
jt.stx = st(jt);
return jt;
}
@@ -518,6 +530,22 @@ public:
{
apply(std::forward<JsonValue>(jv), fN...);
}
/** Apply funclets and submit. */
/** @{ */
template <class JsonValue, class Account, class... FN>
void
apply(JsonValue&& jv, Account const& account = {}, FN const&... fN)
{
submit(jt(std::forward<JsonValue>(jv), account, fN...));
}
template <class JsonValue, class Account, class... FN>
void
operator()(JsonValue&& jv, Account const& account, FN const&... fN)
{
apply(std::forward<JsonValue>(jv), account, fN...);
}
/** @} */
/** Return the TER for the last JTx. */
@@ -662,10 +690,10 @@ protected:
std::unordered_map<std::string, std::string> const& headers = {});
void
autofill_sig(JTx& jt);
autofill_sig(JTx& jt, Account const& account);
void
nofill_sig(JTx& jt, Account account);
virtual void
acct_autofill(JTx& jt, Account const& account);
virtual void
autofill(JTx& jt);

View File

@@ -402,14 +402,14 @@ Env::txid() const
}
void
Env::autofill_sig(JTx& jt)
Env::autofill_sig(JTx& jt, Account const& account)
{
auto& jv = jt.jv;
if (jt.signer)
return jt.signer(*this, jt);
if (!jt.fill_sig)
return;
auto const account = lookup(jv[jss::Account].asString());
if (!app().checkSigs())
{
jv[jss::SigningPubKey] = strHex(account.pk().slice());
@@ -425,10 +425,28 @@ Env::autofill_sig(JTx& jt)
}
void
Env::nofill_sig(JTx& jt, Account account)
Env::acct_autofill(JTx& jt, Account const& account)
{
auto& jv = jt.jv;
jtx::sign(jv, account);
if (jt.fill_fee)
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
{
autofill_sig(jt, account);
}
catch (parse_error const&)
{
test.log << "parse failed:\n" << pretty(jv) << std::endl;
Rethrow();
}
}
void
@@ -439,15 +457,16 @@ 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
{
autofill_sig(jt);
auto const account = lookup(jv[jss::Account].asString());
autofill_sig(jt, account);
}
catch (parse_error const&)
{