rippled
Loading...
Searching...
No Matches
acctdelete.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2019 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/Env.h>
21#include <test/jtx/acctdelete.h>
22
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26namespace test {
27namespace jtx {
28
29// Delete account. If successful transfer remaining XRP to dest.
31acctdelete(jtx::Account const& account, jtx::Account const& dest)
32{
33 Json::Value jv;
34 jv[sfAccount.jsonName] = account.human();
35 jv[sfDestination.jsonName] = dest.human();
36 jv[sfTransactionType.jsonName] = jss::AccountDelete;
37 return jv;
38}
39
40// Close the ledger until the ledger sequence is large enough to close
41// the account. If margin is specified, close the ledger so `margin`
42// more closes are needed
43void
45{
46 using namespace jtx;
47 auto openLedgerSeq = [](jtx::Env& env) -> std::uint32_t {
48 return env.current()->seq();
49 };
50
51 int const delta = [&]() -> int {
52 if (env.seq(acc) + 255 > openLedgerSeq(env))
53 return env.seq(acc) - openLedgerSeq(env) + 255 - margin;
54 return 0;
55 }();
56 env.test.BEAST_EXPECT(margin == 0 || delta >= 0);
57 for (int i = 0; i < delta; ++i)
58 env.close();
59 env.test.BEAST_EXPECT(openLedgerSeq(env) == env.seq(acc) + 255 - margin);
60}
61
62} // namespace jtx
63} // namespace test
64} // namespace ripple
Represents a JSON value.
Definition: json_value.h:149
Immutable cryptographic account descriptor.
Definition: Account.h:39
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:114
A transaction testing environment.
Definition: Env.h:121
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition: Env.cpp:254
beast::unit_test::suite & test
Definition: Env.h:123
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:331
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:117
void incLgrSeqForAccDel(jtx::Env &env, jtx::Account const &acc, std::uint32_t margin=0)
Definition: acctdelete.cpp:44
Json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
Definition: acctdelete.cpp:31
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25