rippled
Loading...
Searching...
No Matches
Transaction_ordering_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted, provided that the above
7 copyright notice and this permission notice appear in all copies.
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16//==============================================================================
17
18#include <test/jtx.h>
19
20#include <xrpld/core/JobQueue.h>
21
22namespace ripple {
23namespace test {
24
26{
27 void
29 {
30 using namespace jtx;
31 testcase("Correct Order");
32
33 Env env(*this);
34 auto const alice = Account("alice");
35 env.fund(XRP(1000), noripple(alice));
36
37 auto const aliceSequence = env.seq(alice);
38
39 auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
40 auto const tx2 =
41 env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
42
43 env(tx1);
44 env.close();
45 BEAST_EXPECT(env.seq(alice) == aliceSequence + 1);
46 env(tx2);
47 env.close();
48 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
49
50 env.close();
51
52 {
53 auto const result =
54 env.rpc("tx", to_string(tx1.stx->getTransactionID()));
55 BEAST_EXPECT(
56 result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
57 }
58 {
59 auto const result =
60 env.rpc("tx", to_string(tx2.stx->getTransactionID()));
61 BEAST_EXPECT(
62 result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
63 }
64 }
65
66 void
68 {
69 using namespace jtx;
70
71 testcase("Incorrect order");
72
73 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
74 cfg->FORCE_MULTI_THREAD = false;
75 return cfg;
76 }));
77
78 auto const alice = Account("alice");
79 env.fund(XRP(1000), noripple(alice));
80
81 auto const aliceSequence = env.seq(alice);
82
83 auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
84 auto const tx2 =
85 env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
86
87 env(tx2, ter(terPRE_SEQ));
88 BEAST_EXPECT(env.seq(alice) == aliceSequence);
89 env(tx1);
90 env.app().getJobQueue().rendezvous();
91 BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
92
93 env.close();
94
95 {
96 auto const result =
97 env.rpc("tx", to_string(tx1.stx->getTransactionID()));
98 BEAST_EXPECT(
99 result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
100 }
101 {
102 auto const result =
103 env.rpc("tx", to_string(tx2.stx->getTransactionID()));
104 BEAST_EXPECT(
105 result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
106 }
107 }
108
109 void
111 {
112 using namespace jtx;
113
114 testcase("Incorrect order multiple intermediaries");
115
116 Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
117 cfg->FORCE_MULTI_THREAD = true;
118 return cfg;
119 }));
120
121 auto const alice = Account("alice");
122 env.fund(XRP(1000), noripple(alice));
123
124 auto const aliceSequence = env.seq(alice);
125
127 for (auto i = 0; i < 5; ++i)
128 {
129 tx.emplace_back(env.jt(
130 noop(alice), seq(aliceSequence + i), last_ledger_seq(7)));
131 }
132
133 for (auto i = 1; i < 5; ++i)
134 {
135 env(tx[i], ter(terPRE_SEQ));
136 BEAST_EXPECT(env.seq(alice) == aliceSequence);
137 }
138
139 env(tx[0]);
140 env.app().getJobQueue().rendezvous();
141 BEAST_EXPECT(env.seq(alice) == aliceSequence + 5);
142
143 env.close();
144
145 for (auto i = 0; i < 5; ++i)
146 {
147 auto const result =
148 env.rpc("tx", to_string(tx[i].stx->getTransactionID()));
149 BEAST_EXPECT(
150 result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
151 }
152 }
153
154 void
161};
162
163BEAST_DEFINE_TESTSUITE(Transaction_ordering, app, ripple);
164
165} // namespace test
166} // namespace ripple
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
virtual JobQueue & getJobQueue()=0
void rendezvous()
Block until no jobs running.
Definition JobQueue.cpp:273
Immutable cryptographic account descriptor.
Definition Account.h:39
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:269
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:122
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:508
Application & app()
Definition Env.h:261
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:791
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:290
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:35
T emplace_back(T... args)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:54
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:111
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
@ terPRE_SEQ
Definition TER.h:221
Set the sequence number on a JTx.
Definition seq.h:34