-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathTransaction_ordering_test.cpp
More file actions
138 lines (107 loc) · 3.82 KB
/
Transaction_ordering_test.cpp
File metadata and controls
138 lines (107 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <test/jtx.h>
#include <xrpl/core/JobQueue.h>
namespace xrpl {
namespace test {
struct Transaction_ordering_test : public beast::unit_test::suite
{
void
testCorrectOrder()
{
using namespace jtx;
testcase("Correct Order");
Env env(*this);
auto const alice = Account("alice");
env.fund(XRP(1000), noripple(alice));
auto const aliceSequence = env.seq(alice);
auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
auto const tx2 = env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
env(tx1);
env.close();
BEAST_EXPECT(env.seq(alice) == aliceSequence + 1);
env(tx2);
env.close();
BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
env.close();
{
auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
}
{
auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
}
}
void
testIncorrectOrder()
{
using namespace jtx;
testcase("Incorrect order");
Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
cfg->FORCE_MULTI_THREAD = false;
return cfg;
}));
auto const alice = Account("alice");
env.fund(XRP(1000), noripple(alice));
auto const aliceSequence = env.seq(alice);
auto const tx1 = env.jt(noop(alice), seq(aliceSequence));
auto const tx2 = env.jt(noop(alice), seq(aliceSequence + 1), last_ledger_seq(7));
env(tx2, ter(terPRE_SEQ));
BEAST_EXPECT(env.seq(alice) == aliceSequence);
env(tx1);
env.app().getJobQueue().rendezvous();
BEAST_EXPECT(env.seq(alice) == aliceSequence + 2);
env.close();
{
auto const result = env.rpc("tx", to_string(tx1.stx->getTransactionID()));
BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
}
{
auto const result = env.rpc("tx", to_string(tx2.stx->getTransactionID()));
BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
}
}
void
testIncorrectOrderMultipleIntermediaries()
{
using namespace jtx;
testcase("Incorrect order multiple intermediaries");
Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
cfg->FORCE_MULTI_THREAD = true;
return cfg;
}));
auto const alice = Account("alice");
env.fund(XRP(1000), noripple(alice));
auto const aliceSequence = env.seq(alice);
static constexpr auto kSIZE = 5;
std::vector<JTx> tx;
tx.reserve(kSIZE);
for (auto i = 0; i < kSIZE; ++i)
{
tx.emplace_back(env.jt(noop(alice), seq(aliceSequence + i), last_ledger_seq(7)));
}
for (auto i = 1; i < kSIZE; ++i)
{
env(tx[i], ter(terPRE_SEQ));
BEAST_EXPECT(env.seq(alice) == aliceSequence);
}
env(tx[0]);
env.app().getJobQueue().rendezvous();
BEAST_EXPECT(env.seq(alice) == aliceSequence + kSIZE);
env.close();
for (auto i = 0; i < kSIZE; ++i)
{
auto const result = env.rpc("tx", to_string(tx[i].stx->getTransactionID()));
BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS");
}
}
void
run() override
{
testCorrectOrder();
testIncorrectOrder();
testIncorrectOrderMultipleIntermediaries();
}
};
BEAST_DEFINE_TESTSUITE(Transaction_ordering, app, xrpl);
} // namespace test
} // namespace xrpl