xrpld
Loading...
Searching...
No Matches
acctdelete.cpp
1#include <test/jtx/acctdelete.h>
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5
6#include <xrpl/beast/unit_test/suite.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/jss.h>
10
11#include <cstdint>
12
13namespace xrpl::test::jtx {
14
15// Delete account. If successful transfer remaining XRP to dest.
16json::Value
17acctdelete(jtx::Account const& account, jtx::Account const& dest)
18{
19 json::Value jv;
20 jv[sfAccount.jsonName] = account.human();
21 jv[sfDestination.jsonName] = dest.human();
22 jv[sfTransactionType.jsonName] = jss::AccountDelete;
23 return jv;
24}
25
26// Close the ledger until the ledger sequence is large enough to close
27// the account. If margin is specified, close the ledger so `margin`
28// more closes are needed
29void
31{
32 using namespace jtx;
33 auto openLedgerSeq = [](jtx::Env& env) -> std::uint32_t { return env.current()->seq(); };
34
35 int const delta = [&]() -> int {
36 if (env.seq(acc) + 255 > openLedgerSeq(env))
37 return env.seq(acc) - openLedgerSeq(env) + 255 - margin;
38 return 0;
39 }();
40 env.test.BEAST_EXPECT(margin == 0 || delta >= 0);
41 for (int i = 0; i < delta; ++i)
42 env.close();
43 env.test.BEAST_EXPECT(openLedgerSeq(env) == env.seq(acc) + 255 - margin);
44}
45
46} // namespace xrpl::test::jtx
Represents a JSON value.
Definition json_value.h:130
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
std::string const & human() const
Returns the human readable public key.
Definition jtx/Account.h:92
A transaction testing environment.
Definition Env.h:143
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:275
beast::unit_test::Suite & test
Definition Env.h:145
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:353
json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
void incLgrSeqForAccDel(jtx::Env &env, jtx::Account const &acc, std::uint32_t margin=0)