From ea02919a0ccdbbbbb6cde5c5c8a29bfeedf31241 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Sat, 17 Jun 2023 00:15:32 +0000 Subject: [PATCH] fix test env autofill --- src/test/jtx/Env.h | 36 ++++++++++++++++++++++++++++++++---- src/test/jtx/impl/Env.cpp | 33 ++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 61b2c410a..d80e29cde 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -445,6 +445,18 @@ public: return jt; } + /** Create a JTx from parameters. */ + template + JTx + jt(JsonValue&& jv, Account account, FN const&... fN) + { + JTx jt(std::forward(jv)); + invoke(jt, fN...); + acct_autofill(jt, account); + jt.stx = st(jt); + return jt; + } + /** Create a JTx from parameters. */ template JTx @@ -452,7 +464,7 @@ public: { JTx jt(std::forward(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(jv), fN...); } + + /** Apply funclets and submit. */ + /** @{ */ + template + void + apply(JsonValue&& jv, Account const& account = {}, FN const&... fN) + { + submit(jt(std::forward(jv), account, fN...)); + } + + template + void + operator()(JsonValue&& jv, Account const& account, FN const&... fN) + { + apply(std::forward(jv), account, fN...); + } /** @} */ /** Return the TER for the last JTx. */ @@ -662,10 +690,10 @@ protected: std::unordered_map 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); diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 38dfb340c..a11ff5a2e 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -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&) {