20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/misc/NetworkOPs.h>
22 #include <ripple/app/misc/TxQ.h>
23 #include <ripple/basics/Slice.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/consensus/LedgerTiming.h>
26 #include <ripple/json/to_string.h>
27 #include <ripple/net/HTTPClient.h>
28 #include <ripple/net/RPCCall.h>
29 #include <ripple/protocol/ErrorCodes.h>
30 #include <ripple/protocol/Feature.h>
31 #include <ripple/protocol/HashPrefix.h>
32 #include <ripple/protocol/Indexes.h>
33 #include <ripple/protocol/LedgerFormats.h>
34 #include <ripple/protocol/Serializer.h>
35 #include <ripple/protocol/SystemParameters.h>
36 #include <ripple/protocol/TER.h>
37 #include <ripple/protocol/TxFlags.h>
38 #include <ripple/protocol/UintTypes.h>
39 #include <ripple/protocol/jss.h>
41 #include <test/jtx/Env.h>
42 #include <test/jtx/JSONRPCClient.h>
43 #include <test/jtx/balance.h>
44 #include <test/jtx/fee.h>
45 #include <test/jtx/flags.h>
46 #include <test/jtx/pay.h>
47 #include <test/jtx/require.h>
48 #include <test/jtx/seq.h>
49 #include <test/jtx/sig.h>
50 #include <test/jtx/trust.h>
51 #include <test/jtx/utility.h>
60 beast::unit_test::suite& suite,
73 logs = std::make_unique<SuiteLogs>(suite);
76 std::make_unique<SuiteJournalSink>(
"Debug",
kFatal, suite));
78 auto timeKeeper_ = std::make_unique<ManualTimeKeeper>();
83 std::move(config), std::move(logs), std::move(timeKeeper_));
87 Throw<std::runtime_error>(
"Env::AppBundle: setup failed");
126 using namespace std::chrono_literals;
128 closeTime +=
closed()->info().closeTimeResolution - 1s;
136 auto resp =
rpc(
"ledger_accept");
137 if (resp[
"result"][
"status"] !=
std::string(
"success"))
140 if (resp.isMember(
"error_what"))
141 reason = resp[
"error_what"].asString();
142 else if (resp.isMember(
"error_message"))
143 reason = resp[
"error_message"].asString();
144 else if (resp.isMember(
"error"))
145 reason = resp[
"error"].asString();
147 JLOG(
journal.
error()) <<
"Env::close() failed: " << reason;
158 map_.emplace(account.id(), account);
164 auto const iter =
map_.find(
id);
165 if (iter ==
map_.end())
167 std::cout <<
"Unknown account: " <<
id <<
"\n";
168 Throw<std::runtime_error>(
"Env::lookup:: unknown account ID");
176 auto const account = parseBase58<AccountID>(base58ID);
178 Throw<std::runtime_error>(
"Env::lookup: invalid account ID");
185 auto const sle =
le(account);
188 return {sle->getFieldAmount(
sfBalance),
""};
198 return {
STAmount(issue, 0), account.name()};
199 auto amount = sle->getFieldAmount(
sfBalance);
200 amount.setIssuer(issue.
account);
201 if (account.id() > issue.
account)
209 auto const sle =
le(account);
211 Throw<std::runtime_error>(
"missing account root");
231 if (setDefaultRipple)
261 auto const start =
balance(account);
280 jr[jss::result].
isMember(jss::engine_result_code))
316 auto const& passphrase = account.name();
322 auto const jv = boost::lexical_cast<std::string>(
jt.
jv);
323 jr =
rpc(
"submit", passphrase, jv);
334 params[jss::secret] = passphrase;
336 params[jss::tx_json] =
jt.
jv;
337 jr =
client().invoke(
"submit", params);
395 auto const account =
lookup(jv[jss::Account].asString());
396 if (!
app().checkSigs())
398 jv[jss::SigningPubKey] =
strHex(account.pk().slice());
400 jv[jss::TxnSignature] =
"00";
403 auto const ar =
le(account);
virtual bool setup(boost::program_options::variables_map const &options)=0
std::string const & name() const
Return the name.
void autofill_sig(JTx &jt)
const XRP_t XRP
Converts to XRP Issue or STAmount.
A pair of SHAMap key and LedgerEntryType.
virtual void start(bool withTimers)=0
A currency issued by an account.
std::unordered_map< AccountID, Account > map_
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
std::unique_ptr< AbstractClient > client
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
void require(Args const &... args)
Check a set of requirements.
void apply(JsonValue &&jv, FN const &... fN)
Apply funclets and submit.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
const SF_UINT32 sfSequence
const SF_ACCOUNT sfRegularKey
void enableFeature(uint256 const feature)
ManualTimeKeeper * timeKeeper
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
std::shared_ptr< STTx const > stx
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
void fill_seq(Json::Value &jv, ReadView const &view)
Set the sequence number automatically.
virtual void signalStop(std::string msg="")=0
std::string transToken(TER code)
const beast::Journal journal
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpc_version)
Returns a client using JSON-RPC over HTTP/S.
A namespace for easy access to logging severity values.
void sign_and_submit(JTx const &jt, Json::Value params=Json::nullValue)
Use the submit RPC command with a provided JTx object.
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
bool isNull() const
isNull() tests to see if this field is null.
void sign(Json::Value &jv, Account const &account)
Sign automatically.
TER ter() const
Return the TER for the last JTx.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
beast::Journal debugLog()
Returns a debug journal.
virtual NetworkOPs & getOPs()=0
static const autofill_t autofill
std::shared_ptr< STTx const > st(JTx const &jt)
Create a STTx from a JTx The framework requires that JSON is valid.
static std::pair< TER, bool > parseResult(Json::Value const &jr)
Gets the TER result and didApply flag from a RPC Json result object.
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
virtual LedgerMaster & getLedgerMaster()=0
Keylet account(AccountID const &id) noexcept
AccountID root.
void Rethrow()
Rethrow the exception currently being handled.
void postconditions(JTx const &jt, TER ter, bool didApply)
Check expected postconditions of JTx submission.
virtual Config & config()=0
Execution context for applying a JSON transaction.
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
void fill_fee(Json::Value &jv, ReadView const &view)
Set the fee automatically.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
virtual JobQueue & getJobQueue()=0
virtual void submit(JTx const &jt)
Submit an existing JTx.
Slice slice() const noexcept
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
bool isXRP(AccountID const &c)
bool isMember(const char *key) const
Return true if the object has a member named key.
Set the regular signature on a JTx.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
beast::unit_test::suite & test
std::function< void(Env &, JTx &)> signer
void rendezvous()
Block until no jobs running.
std::string transHuman(TER code)
Set the sequence number on a JTx.
std::shared_ptr< Ledger const > getClosedLedger()
beast::severities::Severity threshold() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
std::unordered_set< uint256, beast::uhash<> > features
virtual void autofill(JTx &jt)
Json::Value do_rpc(std::vector< std::string > const &args, std::unordered_map< std::string, std::string > const &headers={})
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
bool close()
Close and advance the ledger.
Severity
Severity level / threshold of a Journal message.
static constexpr TERSubset fromInt(int from)
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
constexpr std::uint32_t asfDefaultRipple
std::pair< int, Json::Value > rpcClient(std::vector< std::string > const &args, Config const &config, Logs &logs, std::unordered_map< std::string, std::string > const &headers)
Internal invocation of RPC client.
std::unique_ptr< Application > owned
const SF_AMOUNT sfBalance
virtual std::uint32_t acceptLedger(std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)=0
Accepts the current transaction tree, return the new ledger's sequence.
Match clear account flags.
void disableFeature(uint256 const feature)
Immutable cryptographic account descriptor.
std::string strHex(FwdIt begin, FwdIt end)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
STObject parse(Json::Value const &jv)
Convert JSON to STObject.
void memoize(Account const &account)
Associate AccountID with account.
static void initializeSSLContext(Config const &config, beast::Journal j)
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
std::unique_ptr< Application > make_Application(std::unique_ptr< Config > config, std::unique_ptr< Logs > logs, std::unique_ptr< TimeKeeper > timeKeeper)
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
std::string asString() const
Returns the unquoted string value.