rippled
Loading...
Searching...
No Matches
Transaction_ordering_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/core/JobQueue.h>
4
5namespace xrpl {
6namespace test {
7
9{
10 void
12 {
13 using namespace jtx;
14 testcase("Correct Order");
15
16 Env env(*this);
17 auto const alice = Account("alice");
18 env.fund(XRP(1000), noripple(alice));
19
20 auto const aliceSequence = env.seq(alice);
21
22 auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
23 auto const tx2 = env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
24
25 env(tx1);
26 env.close();
27 BEAST_EXPECT(env.seq(alice) == aliceSequence + 1);
28 env(tx2);
29 env.close();
30 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
31
32 env.close();
33
34 {
35 auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
36 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
37 }
38 {
39 auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
40 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
41 }
42 }
43
44 void
46 {
47 using namespace jtx;
48
49 testcase("Incorrect order");
50
51 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
52 cfg->FORCE_MULTI_THREAD = false;
53 return cfg;
54 }));
55
56 auto const alice = Account("alice");
57 env.fund(XRP(1000), noripple(alice));
58
59 auto const aliceSequence = env.seq(alice);
60
61 auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
62 auto const tx2 = env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
63
64 env(tx2, ter(terPRE_SEQ));
65 BEAST_EXPECT(env.seq(alice) == aliceSequence);
66 env(tx1);
67 env.app().getJobQueue().rendezvous();
68 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
69
70 env.close();
71
72 {
73 auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
74 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
75 }
76 {
77 auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
78 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
79 }
80 }
81
82 void
84 {
85 using namespace jtx;
86
87 testcase("Incorrect order multiple intermediaries");
88
89 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
90 cfg->FORCE_MULTI_THREAD = true;
91 return cfg;
92 }));
93
94 auto const alice = Account("alice");
95 env.fund(XRP(1000), noripple(alice));
96
97 auto const aliceSequence = env.seq(alice);
98
100 for (auto i = 0; i < 5; ++i)
101 {
102 tx.emplace_back(env.jt(noop(alice), seq(aliceSequence + i), last_ledger_seq(7)));
103 }
104
105 for (auto i = 1; i < 5; ++i)
106 {
107 env(tx[i], ter(terPRE_SEQ));
108 BEAST_EXPECT(env.seq(alice) == aliceSequence);
109 }
110
111 env(tx[0]);
112 env.app().getJobQueue().rendezvous();
113 BEAST_EXPECT(env.seq(alice) == aliceSequence + 5);
114
115 env.close();
116
117 for (auto i = 0; i < 5; ++i)
118 {
119 auto const result = env.rpc("tx", to_string(tx[i].stx->getTransactionID()));
120 BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
121 }
122 }
123
124 void
131};
132
133BEAST_DEFINE_TESTSUITE(Transaction_ordering, app, xrpl);
134
135} // namespace test
136} // namespace xrpl
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:148
void rendezvous()
Block until no jobs running.
Definition JobQueue.cpp:229
virtual JobQueue & getJobQueue()=0
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:98
Application & app()
Definition Env.h:230
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:97
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:260
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:239
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:473
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:749
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:16
T emplace_back(T... args)
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:90
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ terPRE_SEQ
Definition TER.h:202
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
Set the sequence number on a JTx.
Definition seq.h:15