xrpld
Loading...
Searching...
No Matches
Transaction_ordering_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/envconfig.h>
6#include <test/jtx/last_ledger_sequence.h>
7#include <test/jtx/noop.h>
8#include <test/jtx/seq.h>
9#include <test/jtx/ter.h>
10
11#include <xrpld/core/Config.h>
12
13#include <xrpl/basics/base_uint.h>
14#include <xrpl/beast/unit_test/suite.h>
15#include <xrpl/core/JobQueue.h>
16#include <xrpl/protocol/TER.h>
17
18#include <memory>
19#include <vector>
20
21namespace xrpl::test {
22
24{
25 void
27 {
28 using namespace jtx;
29 testcase("Correct Order");
30
31 Env env(*this);
32 auto const alice = Account("alice");
33 env.fund(XRP(1000), noripple(alice));
34
35 auto const aliceSequence = env.seq(alice);
36
37 auto const tx1 = env.jt(noop(alice), Seq(aliceSequence));
38 auto const tx2 = env.jt(noop(alice), Seq(aliceSequence + 1), LastLedgerSeq(7));
39
40 env(tx1);
41 env.close();
42 BEAST_EXPECT(env.seq(alice) == aliceSequence + 1);
43 env(tx2);
44 env.close();
45 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
46
47 env.close();
48
49 {
50 auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
51 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
52 }
53 {
54 auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
55 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
56 }
57 }
58
59 void
61 {
62 using namespace jtx;
63
64 testcase("Incorrect order");
65
66 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
67 cfg->forceMultiThread = false;
68 return cfg;
69 }));
70
71 auto const alice = Account("alice");
72 env.fund(XRP(1000), noripple(alice));
73
74 auto const aliceSequence = env.seq(alice);
75
76 auto const tx1 = env.jt(noop(alice), Seq(aliceSequence));
77 auto const tx2 = env.jt(noop(alice), Seq(aliceSequence + 1), LastLedgerSeq(7));
78
79 env(tx2, Ter(terPRE_SEQ));
80 BEAST_EXPECT(env.seq(alice) == aliceSequence);
81 env(tx1);
82 env.app().getJobQueue().rendezvous();
83 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
84
85 env.close();
86
87 {
88 auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
89 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
90 }
91 {
92 auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
93 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
94 }
95 }
96
97 void
99 {
100 using namespace jtx;
101
102 testcase("Incorrect order multiple intermediaries");
103
104 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
105 cfg->forceMultiThread = true;
106 return cfg;
107 }));
108
109 auto const alice = Account("alice");
110 env.fund(XRP(1000), noripple(alice));
111
112 auto const aliceSequence = env.seq(alice);
113 static constexpr auto kSize = 5;
114
116 tx.reserve(kSize);
117 for (auto i = 0; i < kSize; ++i)
118 {
119 tx.emplace_back(env.jt(noop(alice), Seq(aliceSequence + i), LastLedgerSeq(7)));
120 }
121
122 for (auto i = 1; i < kSize; ++i)
123 {
124 env(tx[i], Ter(terPRE_SEQ));
125 BEAST_EXPECT(env.seq(alice) == aliceSequence);
126 }
127
128 env(tx[0]);
129 env.app().getJobQueue().rendezvous();
130 BEAST_EXPECT(env.seq(alice) == aliceSequence + kSize);
131
132 env.close();
133
134 for (auto i = 0; i < kSize; ++i)
135 {
136 auto const result = env.rpc("tx", to_string(tx[i].stx->getTransactionID()));
137 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
138 }
139 }
140
141 void
148};
149
150BEAST_DEFINE_TESTSUITE(Transaction_ordering, app, xrpl);
151
152} // namespace xrpl::test
A testsuite class.
Definition suite.h:50
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
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
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:275
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:864
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:566
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:13
T emplace_back(T... args)
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
json::Value noop(Account const &account)
The null transaction.
Definition noop.h:9
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
Definition Env.h:70
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:28
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terPRE_SEQ
Definition TER.h:213
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
T reserve(T... args)
Set the sequence number on a JTx.
Definition seq.h:12