18 #include <ripple/app/tx/apply.h>
19 #include <ripple/basics/StringUtilities.h>
20 #include <ripple/json/json_reader.h>
21 #include <ripple/protocol/Feature.h>
22 #include <ripple/protocol/jss.h>
24 #include <test/jtx/envconfig.h>
38 auto const USD = gw[
"USD"];
39 env.
fund(
XRP(10000),
"alice", gw);
41 env(offer(
"alice", USD(20),
XRP(10)),
43 { "OfferSequence" : 4 }
51 testcase(
"Account balance < fee destroys correct amount of XRP");
59 auto closed = std::make_shared<Ledger>(
65 BEAST_EXPECT(closed->info().drops == expectedDrops);
67 auto const aliceXRP = 400;
68 auto const aliceAmount =
XRP(aliceXRP);
70 auto next = std::make_shared<Ledger>(
74 auto const jt = env.
jt(
pay(env.
master,
"alice", aliceAmount));
80 BEAST_EXPECT(result.second);
84 expectedDrops -= next->fees().base;
85 BEAST_EXPECT(next->info().drops == expectedDrops);
91 BEAST_EXPECT(
balance == aliceAmount);
97 auto const jt = env.
jt(
noop(
"alice"),
fee(expectedDrops),
seq(2));
104 BEAST_EXPECT(result.second);
116 BEAST_EXPECT(next->info().drops == expectedDrops);
122 testcase(
"Signing with a secp256r1 key should fail gracefully");
127 auto test256r1key = [&env](
Account const& acct) {
128 auto const baseFee = env.
current()->fees().base;
132 JTx jt = env.
jt(jsonNoop);
138 "045d02995ec24988d9a2ae06a3733aa35ba0741e87527"
139 "ed12909b60bd458052c944b24cbf5893c3e5be321774e"
140 "5082e11c034b765861d0effbde87423f8476bb2c";
143 jt.
jv[
"SigningPubKey"] = secp256r1PubKey;
146 auto secp256r1Sig = std::make_unique<STTx>(*(jt.
stx));
147 auto pubKeyBlob =
strUnHex(secp256r1PubKey);
150 jt.
stx.reset(secp256r1Sig.release());
158 env.
fund(
XRP(10000), alice, becky);
167 testcase(
"Autofilled fee should use the escalated fee");
170 cfg->section(
"transaction_queue")
171 .
set(
"minimum_txn_in_ledger_standalone",
"3");
176 auto const alice =
Account(
"alice");
181 params[jss::fee_mult_max] = 5000;
186 for (
int i = 0; i < 5; ++i)
191 if (BEAST_EXPECT(tx))
193 BEAST_EXPECT(tx->getAccountID(
sfAccount) == alice.id());
195 auto const fee = tx->getFieldAmount(
sfFee);
196 BEAST_EXPECT(
fee ==
drops(expectedFees[i]));
204 testcase(
"Fee escalation shouldn't allocate extreme memory");
207 using namespace std::chrono_literals;
210 auto& s = cfg->section(
"transaction_queue");
211 s.set(
"minimum_txn_in_ledger_standalone",
"4294967295");
212 s.set(
"minimum_txn_in_ledger",
"4294967295");
213 s.set(
"target_txn_in_ledger",
"4294967295");
214 s.set(
"normal_consensus_increase_percent",
"4294967295");
222 auto const start = clock_type::now();
224 BEAST_EXPECT(clock_type::now() - start < 1s);
231 using boost::asio::buffer;
232 testcase(
"jsonInvalid");
235 R
"json({"command":"path_find","id":19,"subcommand":"create","source_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_amount":"1000000","source_currencies":[{"currency":"0000000000000000000000000000000000000000"},{"currency":"0000000000000000000000005553440000000000"},{"currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004555520000000000"},{"currency":"0000000000000000000000004554480000000000"},{"currency":"0000000000000000000000004A50590000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"000000000000000000000000434E590000000000"},{"currency":"0000000000000000000000004742490000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004341440000000000"}]})json";
243 buffer(request.data() + 1024, request.length() - 1024));
Json::Value noop(Account const &account)
The null transaction.
virtual Family & getNodeFamily()=0
const XRP_t XRP
Converts to XRP Issue or STAmount.
constexpr XRPAmount dropsPerXRP
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
std::pair< TER, bool > apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Set the expected result code for a JTx The test will fail if the code doesn't match.
void apply(TxsRawView &to) const
Apply changes.
Match the number of items in the account's owner directory.
Writable ledger view that accumulates state and tx changes.
const SF_VL sfSigningPubKey
std::shared_ptr< STTx const > stx
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Check a set of conditions.
const beast::Journal journal
virtual TimeKeeper & timeKeeper()=0
Unserialize a JSON document into a Value.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
void testFeeEscalationExtremeConfig()
@ objectValue
object value (collection of name/value pairs).
Keylet account(AccountID const &id) noexcept
AccountID root.
virtual Config & config()=0
Execution context for applying a JSON transaction.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
virtual time_point closeTime() const =0
Returns the close time, in network time.
Set the regular signature on a JTx.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
A transaction testing environment wrapper.
@ ttACCOUNT_SET
This transaction type adjusts various account settings.
Set the sequence number on a JTx.
void testFeeEscalationAutofill()
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
const create_genesis_t create_genesis
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
void testLowBalanceDestroy()
const SF_AMOUNT sfBalance
Immutable cryptographic account descriptor.
const SF_ACCOUNT sfAccount
void memoize(Account const &account)
Associate AccountID with account.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
A transaction testing environment.
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)