20#include <test/jtx/Oracle.h>
22#include <xrpl/protocol/jss.h>
49 .fee =
static_cast<int>(env.
current()->fees().base.drops()),
56 env.
fund(env.
current()->fees().accountReserve(0), owner);
60 .fee =
static_cast<int>(env.
current()->fees().base.drops()),
67 env.
current()->fees().accountReserve(1) +
73 .fee =
static_cast<int>(env.
current()->fees().base.drops())});
74 BEAST_EXPECT(oracle.exists());
78 {
"XRP",
"EUR", 740, 1},
79 {
"XRP",
"GBP", 740, 1},
80 {
"XRP",
"CNY", 740, 1},
81 {
"XRP",
"CAD", 740, 1},
82 {
"XRP",
"AUD", 740, 1},
84 .fee =
static_cast<int>(env.
current()->fees().base.drops()),
91 static_cast<int>(env.
current()->fees().base.drops());
93 Oracle oracle(env, {.owner = owner, .fee = baseFee},
false);
103 .
series = {{
"XRP",
"USD", 740, 1}, {
"XRP",
"USD", 750, 1}},
110 {{
"XRP",
"USD", 740, 1}, {
"XRP",
"EUR", std::nullopt, 1}},
117 {{
"XRP",
"USD", 740, 1}, {
"XRP",
"USD", std::nullopt, 1}},
123 {{
"XRP",
"EUR", 740, 1}, {
"XRP",
"EUR", std::nullopt, 1}},
130 {{
"XRP",
"US1", 740, 1},
131 {
"XRP",
"US2", 750, 1},
132 {
"XRP",
"US3", 740, 1},
133 {
"XRP",
"US4", 750, 1},
134 {
"XRP",
"US5", 740, 1},
135 {
"XRP",
"US6", 750, 1},
136 {
"XRP",
"US7", 740, 1},
137 {
"XRP",
"US8", 750, 1},
138 {
"XRP",
"US9", 740, 1},
139 {
"XRP",
"U10", 750, 1},
140 {
"XRP",
"U11", 740, 1}},
151 static_cast<int>(env.current()->fees().base.drops());
158 .series = {{{
"XRP",
"USD", 740, 1}}},
163 {
"XRP",
"US1", 740, 1},
164 {
"XRP",
"US2", 750, 1},
165 {
"XRP",
"US3", 740, 1},
166 {
"XRP",
"US4", 750, 1},
167 {
"XRP",
"US5", 740, 1},
168 {
"XRP",
"US6", 750, 1},
169 {
"XRP",
"US7", 740, 1},
170 {
"XRP",
"US8", 750, 1},
171 {
"XRP",
"US9", 740, 1},
172 {
"XRP",
"U10", 750, 1},
181 static_cast<int>(env.
current()->fees().base.drops());
183 Oracle oracle(env, {.owner = owner, .fee = baseFee},
false);
188 .provider =
"provider",
193 .provider = std::nullopt,
201 .
fee =
static_cast<int>(env.
current()->fees().base.drops())});
202 BEAST_EXPECT(oracle.exists());
204 .
series = {{
"XRP",
"USD", 740, 1}},
205 .provider =
"provider1",
209 .
series = {{
"XRP",
"USD", 740, 1}},
210 .assetClass =
"currency1",
218 static_cast<int>(env.
current()->fees().base.drops());
220 Oracle oracle(env, {.owner = owner, .fee = baseFee},
false);
253 static_cast<int>(env.
current()->fees().base.drops());
257 Oracle oracle(env, {.owner = owner, .fee = baseFee});
258 BEAST_EXPECT(oracle.exists());
261 .series = {{
"XRP",
"USD", 740, 1}},
271 static_cast<int>(env.
current()->fees().base.drops());
272 auto closeTime = [&]() {
273 return duration_cast<seconds>(
274 env.
current()->info().closeTime.time_since_epoch() -
279 Oracle oracle(env, {.owner = owner, .fee = baseFee});
280 BEAST_EXPECT(oracle.exists());
284 .
series = {{
"XRP",
"USD", 740, 1}},
285 .lastUpdateTime =
static_cast<std::uint32_t>(closeTime() - 301),
290 .
series = {{
"XRP",
"USD", 740, 1}},
291 .lastUpdateTime =
static_cast<std::uint32_t>(closeTime() + 311),
296 BEAST_EXPECT(oracle.expectLastUpdateTime(
300 .
series = {{
"XRP",
"USD", 740, 1}},
306 .
series = {{
"XRP",
"USD", 740, 1}},
316 static_cast<int>(env.
current()->fees().base.drops());
318 Oracle oracle(env, {.owner = owner, .fee = baseFee});
319 BEAST_EXPECT(oracle.exists());
321 .
series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
326 .
series = {{
"XRP",
"USD", std::nullopt, std::nullopt}},
335 static_cast<int>(env.
current()->fees().base.drops());
340 .series = {{
"USD",
"USD", 740, 1}},
349 static_cast<int>(env.
current()->fees().base.drops());
363 static_cast<int>(env.
current()->fees().base.drops());
365 Oracle oracle(env, {.owner = owner, .fee = baseFee});
368 {{
"XRP",
"EUR", std::nullopt, std::nullopt},
369 {
"XRP",
"EUR", 740, 1}},
374 .
series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
380 .series = {{
"XRP",
"EUR", std::nullopt, std::nullopt}},
394 .fee =
static_cast<int>(env.
current()->fees().base.drops())});
409 static_cast<int>(env.
current()->fees().base.drops());
413 env, {.owner = owner, .series = series, .fee = baseFee});
414 BEAST_EXPECT(oracle.exists());
415 BEAST_EXPECT(
ownerCount(env, owner) == (count + adj));
416 BEAST_EXPECT(oracle.expectLastUpdateTime(946694810));
422 test(env, {{
"XRP",
"USD", 740, 1}}, 1);
430 {{
"XRP",
"USD", 740, 1},
431 {
"BTC",
"USD", 740, 1},
432 {
"ETH",
"USD", 740, 1},
433 {
"CAN",
"USD", 740, 1},
434 {
"YAN",
"USD", 740, 1},
435 {
"GBP",
"USD", 740, 1}},
443 static_cast<int>(env.
current()->fees().base.drops());
447 Oracle oracle(env, {.owner = owner, .fee = baseFee});
448 BEAST_EXPECT(oracle.exists());
451 .series = {{
"912810RR9",
"USD", 740, 1}},
465 static_cast<int>(env.
current()->fees().base.drops());
468 Oracle oracle(env, {.owner = owner, .fee = baseFee});
469 BEAST_EXPECT(oracle.exists());
511 static_cast<int>(env.
current()->fees().base.drops());
514 env, {.owner = owner, .series = series, .fee = baseFee});
516 BEAST_EXPECT(oracle.exists());
517 oracle.remove({.fee = baseFee});
518 BEAST_EXPECT(!oracle.exists());
519 BEAST_EXPECT(
ownerCount(env, owner) == (count - adj));
525 test(env, {{
"XRP",
"USD", 740, 1}}, 1);
534 {
"XRP",
"USD", 740, 1},
535 {
"BTC",
"USD", 740, 1},
536 {
"ETH",
"USD", 740, 1},
537 {
"CAN",
"USD", 740, 1},
538 {
"YAN",
"USD", 740, 1},
539 {
"GBP",
"USD", 740, 1},
548 static_cast<int>(env.
current()->fees().base.drops());
550 auto const alice =
Account(
"alice");
551 auto const acctDelFee{
drops(env.
current()->fees().increment)};
557 .series = {{
"XRP",
"USD", 740, 1}},
563 .series = {{
"XRP",
"EUR", 740, 1}},
566 BEAST_EXPECT(oracle.exists());
567 BEAST_EXPECT(oracle1.exists());
568 auto const index = env.
closed()->seq();
570 for (
int i = 0; i < 256; ++i)
574 BEAST_EXPECT(!oracle.exists());
575 BEAST_EXPECT(!oracle1.exists());
578 auto verifyLedgerData = [&](
auto const& field,
auto const& value) {
580 jvParams[field] = value;
581 jvParams[jss::binary] =
false;
582 jvParams[jss::type] = jss::oracle;
586 boost::lexical_cast<std::string>(jvParams));
587 BEAST_EXPECT(jrr[jss::result][jss::state].size() == 2);
589 verifyLedgerData(jss::ledger_index, index);
604 static_cast<int>(env.
current()->fees().base.drops());
607 Oracle oracle(env, {.owner = owner, .fee = baseFee});
608 BEAST_EXPECT(oracle.exists());
613 BEAST_EXPECT(oracle.expectPrice({{
"XRP",
"USD", 740, 2}}));
617 BEAST_EXPECT(
ownerCount(env, owner) == count);
622 BEAST_EXPECT(oracle.expectPrice(
623 {{
"XRP",
"USD", 0, 0}, {
"XRP",
"EUR", 700, 2}}));
625 BEAST_EXPECT(
ownerCount(env, owner) == count);
629 .
series = {{
"XRP",
"USD", 741, 2}, {
"XRP",
"EUR", 710, 2}},
631 BEAST_EXPECT(oracle.expectPrice(
632 {{
"XRP",
"USD", 741, 2}, {
"XRP",
"EUR", 710, 2}}));
634 BEAST_EXPECT(
ownerCount(env, owner) == count);
640 {
"BTC",
"USD", 741, 2},
641 {
"ETH",
"EUR", 710, 2},
642 {
"YAN",
"EUR", 710, 2},
643 {
"CAN",
"EUR", 710, 2},
647 BEAST_EXPECT(
ownerCount(env, owner) == count);
651 .series = {{
"BTC",
"USD", std::nullopt, std::nullopt}},
655 {{
"XRP",
"USD", 742, 2},
656 {
"XRP",
"EUR", 711, 2},
657 {
"ETH",
"EUR", std::nullopt, std::nullopt},
658 {
"YAN",
"EUR", std::nullopt, std::nullopt},
659 {
"CAN",
"EUR", std::nullopt, std::nullopt}},
661 BEAST_EXPECT(
oracle.expectPrice(
662 {{
"XRP",
"USD", 742, 2}, {
"XRP",
"EUR", 711, 2}}));
665 BEAST_EXPECT(
ownerCount(env, owner) == count);
672 static_cast<int>(env.current()->fees().base.drops());
674 env.current()->fees().accountReserve(1) +
675 env.current()->fees().base * 2,
677 Oracle
oracle(env, {.owner = owner, .fee = baseFee});
679 UpdateArg{.series = {{
"XRP",
"USD", 742, 2}}, .fee = baseFee});
686 testcase(
"Multisig");
688 Oracle::setFee(100'000);
690 Env env(*
this, features);
692 static_cast<int>(env.
current()->fees().base.drops());
700 env.
fund(
XRP(10'000), alice, becky, zelda, ed, bob);
708 env(signers(alice, 2, {{becky, 1}, {bogie, 1}, {ed, 2}}),
sig(alie));
711 int const signerListOwners{features[featureMultiSignReserve] ? 1 : 5};
726 BEAST_EXPECT(oracle.exists());
730 .
series = {{
"XRP",
"USD", 740, 1}},
735 .
series = {{
"XRP",
"USD", 740, 1}},
740 .
series = {{
"XRP",
"USD", 741, 1}},
741 .msig =
msig(becky, bogie),
743 BEAST_EXPECT(oracle.expectPrice({{
"XRP",
"USD", 741, 1}}));
745 env(signers(alice, jtx::none),
sig(alie));
747 env.require(
owners(alice, 1));
749 env(signers(alice, 2, {{zelda, 1}, {bob, 1}, {ed, 2}}), sig(alie));
752 oracle.set(UpdateArg{
753 .series = {{
"XRP",
"USD", 740, 1}},
754 .msig = msig(becky, bogie),
759 .series = {{
"XRP",
"USD", 7412, 2}},
760 .msig = msig(zelda, bob),
762 BEAST_EXPECT(
oracle.expectPrice({{
"XRP",
"USD", 7412, 2}}));
764 .series = {{
"XRP",
"USD", 74245, 3}},
767 BEAST_EXPECT(
oracle.expectPrice({{
"XRP",
"USD", 74245, 3}}));
771 {.msig = msig(bob), .fee = baseFee, .err = ter(tefBAD_QUORUM)});
773 {.msig = msig(becky),
775 .err = ter(tefBAD_SIGNATURE)});
776 oracle.remove({.msig = msig(ed), .fee = baseFee});
777 BEAST_EXPECT(!
oracle.exists());
783 testcase(
"Amendment");
788 Env env(*
this, features);
790 static_cast<int>(env.
current()->fees().base.drops());
799 Oracle oracle(env, {.owner = owner, .fee = baseFee},
false);
816 for (
auto const& features :
818 all - featureMultiSignReserve - featureExpandedSignerList,
819 all - featureExpandedSignerList})
820 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.