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