20#include <test/jtx/Oracle.h>
21#include <xrpl/protocol/jss.h>
51 env.
fund(env.
current()->fees().accountReserve(0), owner);
59 env.
current()->fees().accountReserve(1) +
62 Oracle oracle(env, {.owner = owner});
63 BEAST_EXPECT(oracle.exists());
67 {
"XRP",
"EUR", 740, 1},
68 {
"XRP",
"GBP", 740, 1},
69 {
"XRP",
"CNY", 740, 1},
70 {
"XRP",
"CAD", 740, 1},
71 {
"XRP",
"AUD", 740, 1},
79 Oracle oracle(env, {.owner = owner},
false);
87 .
series = {{
"XRP",
"USD", 740, 1}, {
"XRP",
"USD", 750, 1}},
93 {{
"XRP",
"USD", 740, 1}, {
"XRP",
"EUR", std::nullopt, 1}},
99 {{
"XRP",
"USD", 740, 1}, {
"XRP",
"USD", std::nullopt, 1}},
104 {{
"XRP",
"EUR", 740, 1}, {
"XRP",
"EUR", std::nullopt, 1}},
110 {{
"XRP",
"US1", 740, 1},
111 {
"XRP",
"US2", 750, 1},
112 {
"XRP",
"US3", 740, 1},
113 {
"XRP",
"US4", 750, 1},
114 {
"XRP",
"US5", 740, 1},
115 {
"XRP",
"US6", 750, 1},
116 {
"XRP",
"US7", 740, 1},
117 {
"XRP",
"US8", 750, 1},
118 {
"XRP",
"US9", 740, 1},
119 {
"XRP",
"U10", 750, 1},
120 {
"XRP",
"U11", 740, 1}},
133 .
owner = owner, .series = {{{
"XRP",
"USD", 740, 1}}}});
137 {
"XRP",
"US1", 740, 1},
138 {
"XRP",
"US2", 750, 1},
139 {
"XRP",
"US3", 740, 1},
140 {
"XRP",
"US4", 750, 1},
141 {
"XRP",
"US5", 740, 1},
142 {
"XRP",
"US6", 750, 1},
143 {
"XRP",
"US7", 740, 1},
144 {
"XRP",
"US8", 750, 1},
145 {
"XRP",
"US9", 740, 1},
146 {
"XRP",
"U10", 750, 1},
154 Oracle oracle(env, {.owner = owner},
false);
159 .provider =
"provider",
163 .provider = std::nullopt,
170 BEAST_EXPECT(oracle.exists());
172 .
series = {{
"XRP",
"USD", 740, 1}},
173 .provider =
"provider1",
176 .
series = {{
"XRP",
"USD", 740, 1}},
177 .assetClass =
"currency1",
184 Oracle oracle(env, {.owner = owner},
false);
212 Oracle oracle(env, {.owner = owner});
213 BEAST_EXPECT(oracle.exists());
216 .series = {{
"XRP",
"USD", 740, 1}},
224 auto closeTime = [&]() {
225 return duration_cast<seconds>(
226 env.
current()->info().closeTime.time_since_epoch() -
231 Oracle oracle(env, {.owner = owner});
232 BEAST_EXPECT(oracle.exists());
236 .
series = {{
"XRP",
"USD", 740, 1}},
237 .lastUpdateTime =
static_cast<std::uint32_t>(closeTime() - 301),
241 .
series = {{
"XRP",
"USD", 740, 1}},
242 .lastUpdateTime =
static_cast<std::uint32_t>(closeTime() + 311),
245 BEAST_EXPECT(oracle.expectLastUpdateTime(
249 .
series = {{
"XRP",
"USD", 740, 1}},
254 .
series = {{
"XRP",
"USD", 740, 1}},
263 Oracle oracle(env, {.owner = owner});
264 BEAST_EXPECT(oracle.exists());
266 .
series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
270 .
series = {{
"XRP",
"USD", std::nullopt, std::nullopt}},
281 .series = {{
"USD",
"USD", 740, 1}},
300 Oracle oracle(env, {.owner = owner});
303 {{
"XRP",
"EUR", std::nullopt, std::nullopt},
304 {
"XRP",
"EUR", 740, 1}},
308 .
series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
313 .series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
323 Oracle oracle1(env, {.owner = owner});
339 Oracle oracle(env, {.owner = owner, .series = series});
340 BEAST_EXPECT(oracle.exists());
341 BEAST_EXPECT(
ownerCount(env, owner) == (count + adj));
342 BEAST_EXPECT(oracle.expectLastUpdateTime(946694810));
348 test(env, {{
"XRP",
"USD", 740, 1}}, 1);
356 {{
"XRP",
"USD", 740, 1},
357 {
"BTC",
"USD", 740, 1},
358 {
"ETH",
"USD", 740, 1},
359 {
"CAN",
"USD", 740, 1},
360 {
"YAN",
"USD", 740, 1},
361 {
"GBP",
"USD", 740, 1}},
371 Oracle oracle(env, {.owner = owner});
372 BEAST_EXPECT(oracle.exists());
374 .
owner =
some, .series = {{
"912810RR9",
"USD", 740, 1}}});
388 Oracle oracle(env, {.owner = owner});
389 BEAST_EXPECT(oracle.exists());
423 Oracle oracle(env, {.owner = owner, .series = series});
425 BEAST_EXPECT(oracle.exists());
427 BEAST_EXPECT(!oracle.exists());
428 BEAST_EXPECT(
ownerCount(env, owner) == (count - adj));
434 test(env, {{
"XRP",
"USD", 740, 1}}, 1);
443 {
"XRP",
"USD", 740, 1},
444 {
"BTC",
"USD", 740, 1},
445 {
"ETH",
"USD", 740, 1},
446 {
"CAN",
"USD", 740, 1},
447 {
"YAN",
"USD", 740, 1},
448 {
"GBP",
"USD", 740, 1},
456 auto const alice =
Account(
"alice");
457 auto const acctDelFee{
drops(env.
current()->fees().increment)};
461 env, {.owner = owner, .series = {{
"XRP",
"USD", 740, 1}}});
466 .series = {{
"XRP",
"EUR", 740, 1}}});
468 BEAST_EXPECT(oracle.exists());
469 BEAST_EXPECT(oracle1.exists());
470 auto const index = env.
closed()->seq();
472 for (
int i = 0; i < 256; ++i)
476 BEAST_EXPECT(!oracle.exists());
477 BEAST_EXPECT(!oracle1.exists());
480 auto verifyLedgerData = [&](
auto const& field,
auto const& value) {
482 jvParams[field] = value;
483 jvParams[jss::binary] =
false;
484 jvParams[jss::type] = jss::oracle;
488 boost::lexical_cast<std::string>(jvParams));
489 BEAST_EXPECT(jrr[jss::result][jss::state].size() == 2);
491 verifyLedgerData(jss::ledger_index, index);
507 Oracle oracle(env, {.owner = owner});
508 BEAST_EXPECT(oracle.exists());
512 BEAST_EXPECT(oracle.expectPrice({{
"XRP",
"USD", 740, 2}}));
516 BEAST_EXPECT(
ownerCount(env, owner) == count);
520 BEAST_EXPECT(oracle.expectPrice(
521 {{
"XRP",
"USD", 0, 0}, {
"XRP",
"EUR", 700, 2}}));
523 BEAST_EXPECT(
ownerCount(env, owner) == count);
527 .
series = {{
"XRP",
"USD", 741, 2}, {
"XRP",
"EUR", 710, 2}}});
528 BEAST_EXPECT(oracle.expectPrice(
529 {{
"XRP",
"USD", 741, 2}, {
"XRP",
"EUR", 710, 2}}));
531 BEAST_EXPECT(
ownerCount(env, owner) == count);
536 {
"BTC",
"USD", 741, 2},
537 {
"ETH",
"EUR", 710, 2},
538 {
"YAN",
"EUR", 710, 2},
539 {
"CAN",
"EUR", 710, 2},
542 BEAST_EXPECT(
ownerCount(env, owner) == count);
546 .series = {{
"BTC",
"USD", std::nullopt, std::nullopt}}});
549 {
"XRP",
"USD", 742, 2},
550 {
"XRP",
"EUR", 711, 2},
551 {
"ETH",
"EUR", std::nullopt, std::nullopt},
552 {
"YAN",
"EUR", std::nullopt, std::nullopt},
553 {
"CAN",
"EUR", std::nullopt, std::nullopt}}});
554 BEAST_EXPECT(
oracle.expectPrice(
555 {{
"XRP",
"USD", 742, 2}, {
"XRP",
"EUR", 711, 2}}));
558 BEAST_EXPECT(
ownerCount(env, owner) == count);
565 env.current()->fees().accountReserve(1) +
566 env.current()->fees().base * 2,
568 Oracle
oracle(env, {.owner = owner});
569 oracle.set(UpdateArg{.series = {{
"XRP",
"USD", 742, 2}}});
576 testcase(
"Multisig");
578 Oracle::setFee(100'000);
580 Env env(*
this, features);
587 env.
fund(
XRP(10'000), alice, becky, zelda, ed, bob);
595 env(signers(alice, 2, {{becky, 1}, {bogie, 1}, {ed, 2}}),
sig(alie));
598 int const signerListOwners{features[featureMultiSignReserve] ? 1 : 5};
609 BEAST_EXPECT(oracle.exists());
613 .
series = {{
"XRP",
"USD", 740, 1}},
617 .
series = {{
"XRP",
"USD", 740, 1}},
621 .
series = {{
"XRP",
"USD", 741, 1}}, .msig =
msig(becky, bogie)});
622 BEAST_EXPECT(oracle.expectPrice({{
"XRP",
"USD", 741, 1}}));
624 env(signers(alice, jtx::none),
sig(alie));
626 env.require(
owners(alice, 1));
628 env(signers(alice, 2, {{zelda, 1}, {bob, 1}, {ed, 2}}), sig(alie));
631 oracle.set(UpdateArg{
632 .series = {{
"XRP",
"USD", 740, 1}},
633 .msig = msig(becky, bogie),
637 .series = {{
"XRP",
"USD", 7412, 2}}, .msig = msig(zelda, bob)});
638 BEAST_EXPECT(
oracle.expectPrice({{
"XRP",
"USD", 7412, 2}}));
640 UpdateArg{.series = {{
"XRP",
"USD", 74245, 3}}, .msig = msig(ed)});
641 BEAST_EXPECT(
oracle.expectPrice({{
"XRP",
"USD", 74245, 3}}));
644 oracle.remove({.msig = msig(bob), .err = ter(tefBAD_QUORUM)});
645 oracle.remove({.msig = msig(becky), .err = ter(tefBAD_SIGNATURE)});
646 oracle.remove({.msig = msig(ed)});
647 BEAST_EXPECT(!
oracle.exists());
653 testcase(
"Amendment");
658 Env env(*
this, features);
666 Oracle oracle(env, {.owner = owner},
false);
683 for (
auto const& features :
685 all - featureMultiSignReserve - featureExpandedSignerList,
686 all - featureExpandedSignerList})
687 testMultisig(features);
testcase_t testcase
Memberspace for declaring test cases.
Immutable cryptographic account descriptor.
A transaction testing environment.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
void memoize(Account const &account)
Associate AccountID with account.
Set a multisignature on a JTx.
Oracle class facilitates unit-testing of the Price Oracle feature.
Match the number of items in the account's owner directory.
Set the regular signature on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
static constexpr std::chrono::seconds testStartTime
std::uint32_t ownerCount(Env const &env, Account const &account)
Json::Value regkey(Account const &account, disabled_t)
Disable the regular key.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::size_t constexpr maxPriceScale
The maximum price scaling factor.
constexpr std::uint32_t const tfSellNFToken
constexpr std::uint32_t asfDisableMaster
@ invalid
Timely, but invalid signature.
@ tecINSUFFICIENT_RESERVE
@ tecTOKEN_PAIR_NOT_FOUND
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
std::string to_string(base_uint< Bits, Tag > const &a)
std::optional< AnyValue > uri
std::optional< AnyValue > assetClass
std::optional< AccountID > owner
std::optional< jtx::msig > msig
std::optional< AnyValue > provider
void run() override
Runs the suite.
void testMultisig(FeatureBitset features)
std::optional< AnyValue > documentID
std::optional< AccountID > owner
Set the sequence number on a JTx.