forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtils.h
More file actions
151 lines (124 loc) · 4.87 KB
/
Copy pathTestUtils.h
File metadata and controls
151 lines (124 loc) · 4.87 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
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2016 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#pragma once
#include "bucket/HotArchiveBucketList.h"
#include "bucket/LiveBucketList.h"
#include "invariant/InvariantDoesNotHold.h"
#include "invariant/InvariantManagerImpl.h"
#include "ledger/LedgerManagerImpl.h"
#include "main/ApplicationImpl.h"
#include "util/ProtocolVersion.h"
#include <type_traits>
namespace stellar
{
class LoopbackPeerConnection;
class Simulation;
namespace testutil
{
void crankSome(VirtualClock& clock);
void crankFor(VirtualClock& clock, VirtualClock::duration duration);
void crankUntil(Application::pointer app,
std::function<bool()> const& predicate,
VirtualClock::duration timeout);
void crankUntil(Application& app, std::function<bool()> const& predicate,
VirtualClock::duration timeout);
void shutdownWorkScheduler(Application& app);
std::vector<Asset> getInvalidAssets(SecretKey const& issuer);
int32_t computeMultiplier(LedgerEntry const& le);
bool isTestApplicationProtocolVersionSupported(Config const& cfg);
void validateTestApplicationProtocolVersion(Config const& cfg);
template <class BucketT> class BucketListDepthModifier
{
BUCKET_TYPE_ASSERT(BucketT);
uint32_t const mPrevDepth;
public:
BucketListDepthModifier(uint32_t newDepth);
~BucketListDepthModifier();
};
inline BucketMetadata
testBucketMetadata(uint32_t protocolVersion)
{
BucketMetadata meta;
meta.ledgerVersion = protocolVersion;
if (protocolVersionStartsFrom(
protocolVersion,
HotArchiveBucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
{
meta.ext.v(1);
meta.ext.bucketListType() = BucketListType::LIVE;
}
return meta;
}
}
class TestInvariantManager : public InvariantManagerImpl
{
public:
TestInvariantManager(Application& app);
private:
virtual void
handleInvariantFailure(bool isStrict,
std::string const& message) const override;
};
class TestApplication : public ApplicationImpl
{
public:
TestApplication(VirtualClock& clock, Config const& cfg);
private:
std::unique_ptr<InvariantManager> createInvariantManager() override;
};
template <typename T = TestApplication, typename... Args,
typename = typename std::enable_if<
std::is_base_of<TestApplication, T>::value>::type>
std::shared_ptr<T>
createTestApplication(VirtualClock& clock, Config const& cfg, Args&&... args,
bool newDB = true, bool startApp = true)
{
testutil::validateTestApplicationProtocolVersion(cfg);
Config c2(cfg);
c2.adjust();
auto app = Application::create<T, Args...>(
clock, c2, std::forward<Args>(args)..., newDB);
if (startApp)
{
app->start();
}
return app;
}
TimePoint getTestDate(int day, int month, int year);
std::tm getTestDateTime(int day, int month, int year, int hour, int minute,
int second);
VirtualClock::system_time_point genesis(int minute, int second);
// Assigns values to the SorobanNetworkConfig fields that are suitable for
// most of the unit tests.
void setSorobanNetworkConfigForTest(
SorobanNetworkConfig& cfg,
std::optional<uint32_t> ledgerVersion = std::nullopt);
// Override Soroban network config defaults with generous settings suitable
// for most of the unit tests (unless the test is meant to exercise the
// configuration limits).
void overrideSorobanNetworkConfigForTest(Application& app);
// Runs loadgen to arm all nodes in simulation for the given upgrade. If
// applyUpgrade == true, close ledgers until the upgrade has been applied.
// Otherwise just arm the nodes without closing the ledger containing the
// upgrade.
void
upgradeSorobanNetworkConfig(std::function<void(SorobanNetworkConfig&)> modifyFn,
std::shared_ptr<Simulation> simulation,
bool applyUpgrade = true);
std::pair<SorobanNetworkConfig, UpgradeType> prepareSorobanNetworkConfigUpgrade(
Application& app, std::function<void(SorobanNetworkConfig&)> modifyFn);
void
modifySorobanNetworkConfig(Application& app,
std::function<void(SorobanNetworkConfig&)> modifyFn);
bool appProtocolVersionStartsFrom(Application& app,
ProtocolVersion fromVersion);
// Large enough fee to cover most of the Soroban transactions.
constexpr uint32_t DEFAULT_TEST_RESOURCE_FEE = 1'000'000;
void generateTransactions(Application& app,
std::filesystem::path const& outputFile,
uint32_t numTransactions, uint32_t accounts,
uint32_t offset);
bool isSorobanProtocolLinked(Config const& cfg,
ProtocolVersion protocolVersion);
}