1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/envconfig.h>
6#include <test/jtx/escrow.h>
7#include <test/jtx/fee.h>
8#include <test/jtx/ter.h>
10#include <xrpld/core/Config.h>
12#include <xrpl/basics/strHex.h>
13#include <xrpl/beast/unit_test/suite.h>
14#include <xrpl/config/Constants.h>
15#include <xrpl/core/StartUpType.h>
16#include <xrpl/protocol/Feature.h>
17#include <xrpl/protocol/Fees.h>
18#include <xrpl/protocol/Indexes.h>
19#include <xrpl/protocol/Protocol.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/SeqProxy.h>
22#include <xrpl/protocol/TER.h>
23#include <xrpl/protocol/XRPAmount.h>
54 static std::string const kPreamble =
"0061736D01000000";
56 hex.append((bytes * 2) - kPreamble.
size(),
'A');
65 return env.
current()->fees().base * 10 + bytecodeHex.
size() / 2 * 5;
81 for (
auto i = env.
current()->seq(); i <= 257; ++i)
89 return env.
current()->fees().base +
108 Env env(*
this, features - featureSmartEscrow);
109 env.
fund(
XRP(5000), alice, carol);
140 env.
fund(
XRP(5000), alice, carol);
145 std::string const longBytecode =
"00112233445566778899AA";
159 env.
fund(
XRP(5000), alice, carol);
177 env.
fund(
XRP(5000), alice, carol);
199 Env env(*
this, features);
201 env.
fund(
XRP(5000), alice, carol);
216 Env env(*
this, features);
218 env.
fund(
XRP(5000), alice, carol);
243 env.
fund(
XRP(5000), alice, carol);
332 testcase(
"EscrowCreate fee and reserve");
343 Env env(*
this, features);
344 env.
fund(
XRP(5000), alice, carol);
350 BEAST_EXPECT(fee == env.
current()->fees().base * 10 + 5'000);
359 auto const seq = env.
seq(alice);
369 if (BEAST_EXPECT(sle))
371 BEAST_EXPECT(sle->isFieldPresent(sfBytecode));
372 BEAST_EXPECT(
strHex(sle->getFieldVL(sfBytecode)) == bytecode);
373 BEAST_EXPECT(
strHex(sle->getFieldVL(sfData)) ==
"00112233");
380 Env env(*
this, features);
381 env.
fund(
XRP(5000), alice, carol);
385 for (
auto const size : {
400 expectedOwnerCount += (
size + 499) / 500;
410 Env env(*
this, features);
413 env.
fund(
XRP(300), alice, carol);
437 Env env(*
this, features);
445 auto const amount =
XRP(1'000);
446 auto const fees = env.
current()->fees();
450 STAmount{fees.accountReserve(1, 1) + amount.value().xrp() + fee},
noripple(dave));
453 STAmount{fees.accountReserve(2, 1) + amount.value().xrp() + fee},
noripple(erin));
484 Env env(*
this, features - featureSmartEscrow);
485 env.
fund(
XRP(5000), alice, carol);
496 env.
fund(
XRP(5000), alice, carol);
502 auto const seq = env.
seq(alice);
509 auto const gas = 1'001;
518 Env env(*
this, features);
519 env.
fund(
XRP(5000), alice, carol);
529 Env env(*
this, features);
530 env.
fund(
XRP(5000), alice, carol);
541 env.
fund(
XRP(5000), alice, carol);
545 auto const seq = env.
seq(alice);
552 auto const gas = 1'000;
563 testcase(
"EscrowFinish Bytecode and Gas must agree");
571 Env env(*
this, features);
575 for (
auto i = env.
current()->seq(); i <= 257; ++i)
578 env.
fund(
XRP(5000), alice, carol);
581 auto const seq = env.
seq(alice);
595 auto const plainSeq = env.
seq(alice);
601 auto const gas = 100;
623 cfg->fees.gasPrice = 1'000'000;
629 for (
auto i = env.
current()->seq(); i <= 257; ++i)
632 env.
fund(
XRP(5000), alice, carol);
635 auto const seq = env.
seq(alice);
644 auto const gas = 996'433;
646 BEAST_EXPECT(fee.drops() > gas);
648 BEAST_EXPECT(fee == env.
current()->fees().base + gas);
670 env.
fund(
XRP(5000), alice, carol);
673 auto const seq = env.
seq(alice);
679 BEAST_EXPECT(env.
current()->fees().gasPrice == 1);
681 auto const base = env.
current()->fees().base;
693 testcase(
"EscrowFinish has no WASM engine");
701 Env env(*
this, features);
702 env.
fund(
XRP(5000), alice, carol);
706 auto const seq = env.
seq(alice);
716 auto const gas = 1'000;
738 testcase(
"EscrowFinish releases the reserve");
748 Env env(*
this, features - featureSponsor - fixCleanup3_4_0);
749 env.
fund(
XRP(5000), alice, carol);
752 auto const seq = env.
seq(alice);
TestcaseT testcase
Memberspace for declaring test cases.
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Immutable cryptographic account descriptor.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
SLE::const_pointer le(Account const &account) const
Return an account root.
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
NetClock::time_point now()
Returns the current network time.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
HexBlobField< sfData > Data
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
HexBlobField< sfBytecode > Bytecode
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
std::array< std::uint8_t, 39 > const kCb1
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t microDropsPerDrop
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::size_t kMaxWasmDataLength
Maximum length of a Data field in Escrow object that can be updated by WASM code.
@ tefBYTECODE_NOT_INCLUDED
@ tecINSUFFICIENT_RESERVE
constexpr std::uint32_t kMaxGasLimit
Hard protocol bounds on the Feature Extension fee settings.
static constexpr auto kGasLimit
static constexpr auto kBytecodeSizeLimit
static constexpr auto kGasPrice
static constexpr auto kVoting
Smart Escrow's Bytecode, Data and Gas fields.
void testCreateFeeAndReserve(FeatureBitset features)
void testFinishWithoutEngine(FeatureBitset features)
void testFinishReleasesReserve(FeatureBitset features)
static std::string bytecodeOfSize(std::size_t bytes)
static XRPAmount createFeeFor(jtx::Env const &env, std::string const &bytecodeHex)
void testFinishPreflight(FeatureBitset features)
static void closePastFlagLedger(jtx::Env &env)
void testFinishBytecodePairing(FeatureBitset features)
void run() override
Runs the suite.
static std::unique_ptr< Config > votingFor(std::string const &key, std::uint32_t value)
void testCreatePreflight(FeatureBitset features)
static XRPAmount finishFeeFor(jtx::Env const &env, std::uint64_t gas)
void testFinishFee(FeatureBitset features)
void testWithFeats(FeatureBitset features)