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/TER.h>
19#include <xrpl/protocol/TxFlags.h>
20#include <xrpl/protocol_autogen/ledger_entries/AccountRoot.h>
21#include <xrpl/protocol_autogen/transactions/Payment.h>
22#include <xrpl/protocol_autogen/transactions/SetRegularKey.h>
23#include <xrpl/protocol_autogen/transactions/SignerListSet.h>
24#include <xrpl/protocol_autogen/transactions/TicketCreate.h>
25#include <xrpl/protocol_autogen/transactions/TrustSet.h>
27#include <gtest/gtest.h>
28#include <helpers/Account.h>
29#include <helpers/IOU.h>
30#include <helpers/TxTest.h>
57 EXPECT_NE(sle,
nullptr);
59 EXPECT_EQ(accountRoot.
getFlags(), 0);
82 auto testFlags = [&alice, &aliceRegularKey, &env](
85 for (
std::uint32_t flag{1u}; flag < std::numeric_limits<std::uint32_t>::digits; ++flag)
87 if (flag == asfNoFreeze)
93 if (flag == asfAuthorizedNFTokenMinter)
101 if (flag == asfDisallowIncomingCheck || flag == asfDisallowIncomingPayChan ||
102 flag == asfDisallowIncomingNFTokenOffer || flag == asfDisallowIncomingTrustline)
108 if (flag == asfAllowTrustLineClawback)
114 if (flag == asfAllowTrustLineLocking)
143 EXPECT_EQ(nowFlags, origFlags);
205 EXPECT_EQ(nowFlags, origFlags);
289 for (
std::size_t len = maxLength - 1; len <= maxLength + 1; ++len)
293 EXPECT_EQ(domain2.
length(), len);
295 if (len <= maxLength)
350 using namespace std::string_literals;
369 "9633EC8AF54F16B5286DB1D7B519EF49EEFC050C0C8AC4384F1D88ACD1BFDF05";
371 EXPECT_TRUE(locatorHash.
parseHex(locator));
403 EXPECT_TRUE(emailHash.
parseHex(mh));
450 for (
auto const& r : testData)
452 auto const rateValue =
static_cast<std::uint32_t>(QUALITY_ONE * r.set);
463 EXPECT_EQ(r.get, 1.0);
573 entry[sfAccount] = bob.
id();
668 .build(alice.
pk(), alice.
sk())
677 EXPECT_FALSE(result.applied);
685 IOU const usd(
"USD", gw);
719 auto const amount = usd.amount(1);
740 EXPECT_EQ(env.
getBalance(alice.
id(), usd), usd.amount(10) - amountWithRate);
741 EXPECT_EQ(env.
getBalance(bob.
id(), usd), usd.amount(1));
778 ASSERT_NE(slePtr,
nullptr);
781 view.rawReplace(sleCopy);
784 auto const amount = usd.amount(1);
801 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)
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 ticket(AccountID const &id, std::uint32_t ticketSeq)
A ticket belonging to an account.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
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.
TEST(AccountSet, NullAccountSet)
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.
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)
std::enable_if_t< std::is_same_v< T, char >||std::is_same_v< T, unsigned char >, Slice > makeSlice(std::array< T, N > const &a)
Represents a transfer rate.
TER ter
The transaction engine result code.