rippled
Loading...
Searching...
No Matches
src/test/jtx/Oracle.h
1#pragma once
2
3#include <test/jtx.h>
4
5#include <date/date.h>
6
7namespace xrpl {
8namespace test {
9namespace jtx {
10namespace oracle {
11
14
15// Special string value, which is converted to unquoted string in the string
16// passed to rpc.
17constexpr char const* NoneTag = "%None%";
18constexpr char const* UnquotedNone = "None";
19constexpr char const* NonePattern = "\"%None%\"";
20
22asUInt(AnyValue const& v);
23
24bool
26
27void
28toJson(Json::Value& jv, AnyValue const& v);
29
30void
31toJsonHex(Json::Value& jv, AnyValue const& v);
32
33// base asset, quote asset, price, scale
35 std::
37
38// Typical defaults for Create
55
56// Typical defaults for Update
72
83
84// Simulate testStartTime as 10'000s from Ripple epoch time to make
85// LastUpdateTime validation to work and to make unit-test consistent.
86// The value doesn't matter much, it has to be greater
87// than maxLastUpdateTimeDelta in order to pass LastUpdateTime
88// validation {close-maxLastUpdateTimeDelta,close+maxLastUpdateTimeDelta}.
90
95class Oracle
96{
97private:
98 // Global fee if not 0
99 static inline std::uint32_t fee = 0;
103
104private:
105 void
106 submit(
107 Json::Value const& jv,
110 std::optional<ter> const& err);
111
112public:
113 Oracle(Env& env, CreateArg const& arg, bool submit = true);
114
115 void
116 remove(RemoveArg const& arg);
117
118 void
119 set(CreateArg const& arg);
120 void
121 set(UpdateArg const& arg);
122
123 static Json::Value
125 Env& env,
126 std::optional<AnyValue> const& baseAsset,
127 std::optional<AnyValue> const& quoteAsset,
130 std::optional<AnyValue> const& timeThreshold = std::nullopt);
131
134 {
135 return documentID_;
136 }
137
138 [[nodiscard]] bool
139 exists() const
140 {
141 return exists(env_, owner_, documentID_);
142 }
143
144 [[nodiscard]] static bool
145 exists(Env& env, AccountID const& account, std::uint32_t documentID);
146
147 [[nodiscard]] bool
148 expectPrice(DataSeries const& prices) const;
149
150 [[nodiscard]] bool
151 expectLastUpdateTime(std::uint32_t lastUpdateTime) const;
152
153 static Json::Value
155 Env& env,
159
162 {
164 }
165
166 static void
168 {
169 fee = f;
170 }
171
173 operator<<(std::ostream& strm, Oracle const& oracle)
174 {
175 strm << oracle.ledgerEntry().toStyledString();
176 return strm;
177 }
178};
179
180} // namespace oracle
181} // namespace jtx
182} // namespace test
183} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A transaction testing environment.
Definition Env.h:122
Set the fee on a JTx.
Definition fee.h:17
Match set account flags.
Definition flags.h:108
Set a multisignature on a JTx.
Definition multisign.h:41
Oracle class facilitates unit-testing of the Price Oracle feature.
static Json::Value ledgerEntry(Env &env, std::optional< std::variant< AccountID, std::string > > const &account, std::optional< AnyValue > const &documentID, std::optional< std::string > const &index=std::nullopt)
Definition Oracle.cpp:302
static Json::Value aggregatePrice(Env &env, std::optional< AnyValue > const &baseAsset, std::optional< AnyValue > const &quoteAsset, std::optional< OraclesData > const &oracles=std::nullopt, std::optional< AnyValue > const &trim=std::nullopt, std::optional< AnyValue > const &timeThreshold=std::nullopt)
Definition Oracle.cpp:143
friend std::ostream & operator<<(std::ostream &strm, Oracle const &oracle)
void submit(Json::Value const &jv, std::optional< jtx::msig > const &msig, std::optional< jtx::seq > const &seq, std::optional< ter > const &err)
Definition Oracle.cpp:58
bool expectLastUpdateTime(std::uint32_t lastUpdateTime) const
Definition Oracle.cpp:136
bool expectPrice(DataSeries const &prices) const
Definition Oracle.cpp:110
static void setFee(std::uint32_t f)
Json::Value ledgerEntry(std::optional< std::string > const &index=std::nullopt) const
void remove(RemoveArg const &arg)
Definition Oracle.cpp:34
T is_same_v
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition Indexes.cpp:468
constexpr char const * NoneTag
std::uint32_t asUInt(AnyValue const &v)
Definition Oracle.cpp:380
constexpr char const * UnquotedNone
static constexpr std::chrono::seconds testStartTime
bool validDocumentID(AnyValue const &v)
Definition Oracle.cpp:388
constexpr char const * NonePattern
void toJsonHex(Json::Value &jv, AnyValue const &v)
Definition Oracle.cpp:356
void toJson(Json::Value &jv, AnyValue const &v)
Definition Oracle.cpp:350
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
Definition chrono.h:33
std::optional< AnyValue > documentID
std::optional< AnyValue > lastUpdateTime
std::optional< AnyValue > assetClass
std::optional< AnyValue > const & documentID
std::optional< ter > const & err
std::optional< AccountID > const & owner
std::optional< AnyValue > documentID
std::optional< AnyValue > lastUpdateTime
std::optional< AnyValue > assetClass
Set the sequence number on a JTx.
Definition seq.h:14