1#include <xrpl/protocol_autogen/transactions/AccountSet.h>
3#include <xrpl/basics/Slice.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/helpers/DirectoryHelpers.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/KeyType.h>
10#include <xrpl/protocol/LedgerFormats.h>
11#include <xrpl/protocol/Quality.h>
12#include <xrpl/protocol/Rate.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STArray.h>
15#include <xrpl/protocol/STObject.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/SecretKey.h>
18#include <xrpl/protocol/SeqProxy.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/TxFlags.h>
21#include <xrpl/protocol_autogen/ledger_entries/AccountRoot.h>
22#include <xrpl/protocol_autogen/transactions/Payment.h>
23#include <xrpl/protocol_autogen/transactions/SetRegularKey.h>
24#include <xrpl/protocol_autogen/transactions/SignerListSet.h>
25#include <xrpl/protocol_autogen/transactions/TicketCreate.h>
26#include <xrpl/protocol_autogen/transactions/TrustSet.h>
28#include <gtest/gtest.h>
29#include <helpers/Account.h>
30#include <helpers/IOU.h>
31#include <helpers/TxTest.h>
58 EXPECT_NE(sle,
nullptr);
60 EXPECT_EQ(accountRoot.
getFlags(), 0);
83 auto testFlags = [&alice, &aliceRegularKey, &env](
86 for (
std::uint32_t flag{1u}; flag < std::numeric_limits<std::uint32_t>::digits; ++flag)
88 if (flag == asfNoFreeze)
94 if (flag == asfAuthorizedNFTokenMinter)
102 if (flag == asfDisallowIncomingCheck || flag == asfDisallowIncomingPayChan ||
103 flag == asfDisallowIncomingNFTokenOffer || flag == asfDisallowIncomingTrustline)
109 if (flag == asfAllowTrustLineClawback)
115 if (flag == asfAllowTrustLineLocking)
144 EXPECT_EQ(nowFlags, origFlags);
206 EXPECT_EQ(nowFlags, origFlags);
290 for (
std::size_t len = maxLength - 1; len <= maxLength + 1; ++len)
294 EXPECT_EQ(domain2.
length(), len);
296 if (len <= maxLength)
351 using namespace std::string_literals;
370 "9633EC8AF54F16B5286DB1D7B519EF49EEFC050C0C8AC4384F1D88ACD1BFDF05";
372 EXPECT_TRUE(locatorHash.
parseHex(locator));
404 EXPECT_TRUE(emailHash.
parseHex(mh));
451 for (
auto const& r : testData)
453 auto const rateValue =
static_cast<std::uint32_t>(QUALITY_ONE * r.set);
464 EXPECT_EQ(r.get, 1.0);
574 entry[sfAccount] = bob.
id();
675 .build(alice.
pk(), alice.
sk())
684 EXPECT_FALSE(result.applied);
692 IOU const usd(
"USD", gw);
726 auto const amount = usd.amount(1);
747 EXPECT_EQ(env.
getBalance(alice.
id(), usd), usd.amount(10) - amountWithRate);
748 EXPECT_EQ(env.
getBalance(bob.
id(), usd), usd.amount(1));
785 ASSERT_NE(slePtr,
nullptr);
788 view.rawReplace(sleCopy);
791 auto const amount = usd.amount(1);
808 EXPECT_EQ(env.
getBalance(alice.
id(), usd), usd.amount(10) - amountWithRate);
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
void push_back(STObject const &object)
void setFieldVL(SField const &field, Blob const &)
static STObject makeInnerObject(SField const &name)
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
An immutable linear range of bytes.
Ledger Entry: AccountRoot.
SF_UINT32::type::value_type getSequence() const
Get sfSequence (SoeRequired).
protocol_autogen::Optional< SF_VL::type::value_type > getDomain() const
Get sfDomain (SoeOptional).
bool hasWalletLocator() const
Check if sfWalletLocator is present.
bool hasAccountTxnID() const
Check if sfAccountTxnID is present.
bool hasDomain() const
Check if sfDomain is present.
bool hasEmailHash() const
Check if sfEmailHash is present.
protocol_autogen::Optional< SF_UINT32::type::value_type > getTransferRate() const
Get sfTransferRate (SoeOptional).
bool hasMessageKey() const
Check if sfMessageKey is present.
bool hasTransferRate() const
Check if sfTransferRate is present.
protocol_autogen::Optional< SF_UINT128::type::value_type > getEmailHash() const
Get sfEmailHash (SoeOptional).
SF_UINT32::type::value_type getOwnerCount() const
Get sfOwnerCount (SoeRequired).
protocol_autogen::Optional< SF_VL::type::value_type > getMessageKey() const
Get sfMessageKey (SoeOptional).
protocol_autogen::Optional< SF_UINT256::type::value_type > getWalletLocator() const
Get sfWalletLocator (SoeOptional).
bool isFlag(std::uint32_t f) const
Check if a specific flag is set.
std::uint32_t getFlags() const
Get the flags field (sfFlags).
A lightweight transaction testing harness.
void createAccount(Account const &account, XRPAmount xrp, uint32_t accountFlags=0)
Create a new account in the ledger.
OpenView & getOpenLedger()
Get the current open ledger view.
ReadView const & getClosedLedger() const
Get the closed (base) ledger view.
void close()
Close the current ledger.
STAmount getBalance(AccountID const &account, IOU const &iou) const
Get the balance of an IOU for an account.
ledger_entries::AccountRoot getAccountRoot(AccountID const &id) const
Get the account root object from the current open ledger.
TxResult submit(T &&builder, Account const &signer)
Submit a transaction from a builder.
Immutable cryptographic account descriptor.
SecretKey const & sk() const
Return the secret key.
PublicKey const & pk() const
Return the public key.
AccountID id() const
Returns the Account ID.
Converts to IOU Issue or STAmount.
Builder for AccountSet transactions.
AccountSetBuilder & setMessageKey(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfMessageKey (SoeOptional).
AccountSetBuilder & setSetFlag(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfSetFlag (SoeOptional).
AccountSetBuilder & setTransferRate(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfTransferRate (SoeOptional).
AccountSetBuilder & setEmailHash(std::decay_t< typename SF_UINT128::type::value_type > const &value)
Transaction-specific field setters.
AccountSetBuilder & setClearFlag(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfClearFlag (SoeOptional).
AccountSetBuilder & setDomain(std::decay_t< typename SF_VL::type::value_type > const &value)
Set sfDomain (SoeOptional).
AccountSetBuilder & setWalletLocator(std::decay_t< typename SF_UINT256::type::value_type > const &value)
Set sfWalletLocator (SoeOptional).
Builder for Payment transactions.
PaymentBuilder & setSendMax(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfSendMax (SoeOptional).
Builder for SetRegularKey transactions.
SetRegularKeyBuilder & setRegularKey(std::decay_t< typename SF_ACCOUNT::type::value_type > const &value)
Transaction-specific field setters.
Builder for SignerListSet transactions.
SignerListSetBuilder & setSignerEntries(STArray const &value)
Set sfSignerEntries (SoeOptional).
Builder for TicketCreate transactions.
Derived & setFee(STAmount const &value)
Set the transaction fee.
Derived & setFlags(std::uint32_t const &value)
Set transaction flags.
Derived & setTicketSequence(std::uint32_t const &value)
Set the ticket sequence to use for this transaction.
Derived & setSequence(std::uint32_t const &value)
Set the sequence number.
Builder for TrustSet transactions.
TrustSetBuilder & setLimitAmount(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Transaction-specific field setters.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Keylet account(AccountID const &id) noexcept
AccountID root.
XrpT const XRP
Converts to XRP Issue or STAmount.
json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
constexpr XRPAmount
Convert XRP to drops (integral types).
constexpr std::uint32_t asfToLsf(std::uint32_t asf)
Convert AccountSet flag (asf) to LedgerState flag (lsf).
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,...
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Slice makeSlice(std::array< T, N > const &a)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TERSubset< CanCvtToTER > TER
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
Represents a transfer rate.
TER ter
The transaction engine result code.