20#include <xrpl/beast/unit_test/suite.h>
21#include <xrpl/protocol/Feature.h>
22#include <xrpl/protocol/Indexes.h>
23#include <xrpl/protocol/Issue.h>
24#include <xrpl/protocol/SField.h>
25#include <xrpl/protocol/STXChainBridge.h>
26#include <xrpl/protocol/Serializer.h>
27#include <xrpl/protocol/TER.h>
28#include <xrpl/protocol/XChainAttestations.h>
31#include <test/jtx/Env.h>
32#include <test/jtx/attester.h>
33#include <test/jtx/multisign.h>
34#include <test/jtx/xchain_bridge.h>
66 :
env_(s,
std::move(config), features,
std::move(logs), thresh)
91 template <
class Arg,
class... Args>
99 template <
class JsonValue,
class... FN>
101 tx(JsonValue&& jv, FN
const&... fN)
103 env_(std::forward<JsonValue>(jv), fN...);
107 template <
class... FN>
111 for (
auto const& jv : jvv)
137 return env_.
current()->fees().accountReserve(count);
161 if ((*r)[sfXChainBridge] == b)
174 return (*
bridge(jvb))[sfXChainAccountClaimCount];
180 return (*
bridge(jvb))[sfXChainClaimID];
216 this->
fund(xrp_funds, s.account);
231 this->
fund(xrp_funds, ra);
234 this->
fund(xrp_funds, s.account);
284 :
from_(env, from_acct)
290 for (
size_t i = 0; i < num_payees; ++i)
322 [&](
const balance& b) { return b.diff() == reward; });
336 bool check_payer =
true)
404 bool exceptionPresent =
false;
407 exceptionPresent =
false;
412 exceptionPresent =
true;
415 BEAST_EXPECT(!exceptionPresent);
419 exceptionPresent =
false;
420 jBridge[
"Extra"] = 1;
425 exceptionPresent =
true;
428 BEAST_EXPECT(exceptionPresent);
603 testcase(
"Bridge create constraints");
604 XEnv env(*
this,
true);
608 auto AUSD = A[
"USD"];
609 auto BUSD = B[
"USD"];
610 auto CUSD = C[
"USD"];
611 auto GUSD =
scGw[
"USD"];
612 auto AEUR = A[
"EUR"];
613 auto BEUR = B[
"EUR"];
614 auto CEUR = C[
"EUR"];
615 auto GEUR =
scGw[
"EUR"];
625 env.
fund(
XRP(10000), a1, a2, a3, a4, a5, a6);
648 auto const goodBridge1 =
bridge(A, GUSD, B, BUSD);
649 auto const goodBridge2 =
bridge(A, BUSD, C, CUSD);
667 .
tx(
pay(B, C, BUSD(1000)))
669 auto const aBalanceStart = env.
balance(A, BUSD);
670 auto const cBalanceStart = env.
balance(C, BUSD);
672 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(0));
673 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50));
675 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(60));
676 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50 - 60));
680 BEAST_EXPECT((*env.
bridge(goodBridge1))[sfSignatureReward] ==
XRP(33));
682 BEAST_EXPECT((*env.
bridge(goodBridge2))[sfSignatureReward] ==
XRP(44));
732 "Locking chain is IOU(locking chain door)",
733 [&](
auto& env,
bool) {
738 "Locking chain is IOU(issuing chain door funded on locking "
740 [&](
auto& env,
bool shouldFund) {
747 "Locking chain is IOU(issuing chain door account unfunded "
749 [&](
auto& env,
bool) {
754 "Locking chain is IOU(bob funded on locking chain)",
755 [&](
auto& env,
bool) {
760 "Locking chain is IOU(bob unfunded on locking chain)",
761 [&](
auto& env,
bool) {
772 "Issuing chain is IOU(issuing chain door account)",
773 [&](
auto& env,
bool) {
778 "Issuing chain is IOU(locking chain door funded on issuing "
780 [&](
auto& env,
bool shouldFund) {
787 "Issuing chain is IOU(locking chain door unfunded on "
789 [&](
auto& env,
bool) {
794 "Issuing chain is IOU(bob funded on issuing chain)",
795 [&](
auto& env,
bool) {
800 "Issuing chain is IOU(bob unfunded on issuing chain)",
801 [&](
auto& env,
bool) {
806 "Issuing chain is XRP and issuing chain door account is "
807 "not the root account",
808 [&](
auto& env,
bool) {
813 "Issuing chain is XRP and issuing chain door account is "
815 [&](
auto& env,
bool) {
866 auto testcase = [&](
auto const& lc,
auto const& ic) {
868 XEnv scEnv(*
this,
true);
870 lc.second(mcEnv,
true);
871 lc.second(scEnv,
false);
873 ic.second(mcEnv,
false);
874 ic.second(scEnv,
true);
876 auto const& expected = expected_result[test_result.
size()];
893 auto apply_ics = [&](
auto const& lc,
auto const& ics) {
895 [&](
auto const&... ic) { (
testcase(lc, ic), ...); }, ics);
898 std::apply([&](
auto const&... lc) { (apply_ics(lc, ics), ...); }, lcs);
900#if GENERATE_MTX_OUTPUT
905 std::cout <<
"Markdown output for matrix test: " << fname <<
"\n";
911 if (std::get<2>(tup))
920 auto output_table = [&](
auto print_res) {
926 res +=
"| `issuing ->` | ";
928 [&](
auto const&... ic) {
929 ((res += ic.first, res +=
" | "), ...);
936 [&](
auto const&... ic) {
937 (((void)ic.first, res +=
":---: | "), ...);
942 auto output = [&](
auto const& lc,
auto const& ic) {
943 res += print_res(test_result[test_idx]);
948 auto output_ics = [&](
auto const& lc,
auto const& ics) {
953 [&](
auto const&... ic) { (output(lc, ic), ...); }, ics);
958 [&](
auto const&... lc) { (output_ics(lc, ics), ...); }, lcs);
966 std::cout <<
"ter output for matrix test: " << ter_fname <<
"\n";
969 for (
auto& t : test_result)
1030 for (
auto withClaim : {
false,
true})
1033 XEnv scEnv(*
this,
true);
1044 auto const amt =
XRP(1000);
1085 for (
auto withClaim : {
false,
true})
1088 XEnv scEnv(*
this,
true);
1099 auto const amt =
XRP(1000);
1148 for (
auto withClaim : {
false,
true})
1151 XEnv scEnv(*
this,
true);
1162 auto const amt =
XRP(1000);
1287 using namespace jtx;
1304 XEnv xenv(*
this,
true);
1312 BEAST_EXPECT(scAlice_bal.
diff() == -tx_fee);
1377 using namespace jtx;
1392 auto const amt =
XRP(1000);
1400 BEAST_EXPECT(alice_bal.
diff() == -(claim_cost + tx_fee));
1513 using namespace jtx;
1529 for (
auto withClaim : {
true})
1532 XEnv scEnv(*
this,
true);
1546 auto const amt =
XRP(1000);
1598 for (
auto withClaim : {
false,
true})
1601 XEnv scEnv(*
this,
true);
1605 constexpr int numSigners = 4;
1610 for (
int i = 0; i < numSigners; ++i)
1612 using namespace std::literals;
1630 auto const amt =
XRP(1000);
1673 for (
auto withClaim : {
false,
true})
1676 XEnv scEnv(*
this,
true);
1680 constexpr int numSigners = 4;
1685 for (
int i = 0; i < numSigners; ++i)
1687 using namespace std::literals;
1707 auto const amt =
XRP(1000);
1751 for (
auto withClaim : {
false,
true})
1754 XEnv scEnv(*
this,
true);
1758 constexpr int numSigners = 4;
1763 for (
int i = 0; i < numSigners; ++i)
1765 using namespace std::literals;
1784 auto const amt =
XRP(1000);
1826 for (
auto withClaim : {
false,
true})
1829 XEnv scEnv(*
this,
true);
1833 constexpr int numSigners = 4;
1838 for (
int i = 0; i < numSigners; ++i)
1840 using namespace std::literals;
1859 auto const amt =
XRP(1000);
1909 XEnv scEnv(*
this,
true);
1910 auto const amt =
XRP(1000);
1911 auto const amt_plus_reward = amt +
reward;
1931 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
1951 BEAST_EXPECT(attester.
diff() == -multiTtxFee(6));
1971 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
1989 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2005 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2007 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2027 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2043 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2044 BEAST_EXPECT(attester.
diff() == -tx_fee);
2059 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2060 BEAST_EXPECT(attester.
diff() == -tx_fee);
2072 XEnv scEnv(*
this,
true);
2074 auto const amt = res0 -
XRP(1);
2075 auto const amt_plus_reward = amt +
reward;
2088 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2089 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2109 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2118 XEnv scEnv(*
this,
true);
2120 auto const amt =
XRP(111);
2121 auto const amt_plus_reward = amt +
reward;
2134 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2135 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2156 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2157 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2158 BEAST_EXPECT(alice.
diff() == amt);
2165 XEnv scEnv(*
this,
true);
2167 auto const amt =
XRP(1000);
2168 auto const amt_plus_reward = amt +
reward;
2181 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2182 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2205 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2216 XEnv scEnv(*
this,
true);
2217 auto const amt =
XRP(1000);
2218 auto const amt_plus_reward = amt +
reward;
2240 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
2251 auto const bad_amt =
XRP(10);
2262 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 1),
"claim id 1 created");
2263 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 2),
"claim id 2 created");
2264 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 3),
"claim id 3 created");
2298 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 deleted");
2299 BEAST_EXPECTS(scEnv.
claimCount(
jvb) == 1,
"scuAlice created");
2308 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 2),
"claim id 2 deleted");
2309 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 not added");
2317 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 3),
"claim id 3 deleted");
2328 BEAST_EXPECT(attester.
diff() == -multiTtxFee(txCount));
2341 XEnv scEnv(*
this,
true);
2363 XEnv scEnv(*
this,
true);
2386 using namespace jtx;
2388 testcase(
"Add Non Batch Claim Attestation");
2392 XEnv scEnv(*
this,
true);
2406 auto const amt =
XRP(1000);
2409 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2411 for (
int i = 0; i <
signers.size(); ++i)
2424 TER const expectedTER =
2432 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2435 dstStartBalance + amt == scEnv.
env_.
balance(dst));
2437 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2458 XEnv scEnv(*
this,
true);
2459 auto const amt =
XRP(1000);
2475 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2509 att[sfAttestationSignerAccount.getJsonName()] =
2516 auto const unfundedSigner1 =
2518 auto const unfundedSigner2 =
2530 att[sfAttestationSignerAccount.getJsonName()] =
2531 unfundedSigner2.account.human();
2534 att[sfAttestationSignerAccount.getJsonName()] =
2535 unfundedSigner1.
account.human();
2552 tempSignerList.
front());
2553 att[sfAttestationSignerAccount.getJsonName()] =
2601 att.removeMember(sfAttestationSignerAccount.getJsonName());
2603 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2604 att[sfAttestationSignerAccount.getJsonName()] =
2607 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2615 using namespace jtx;
2617 testcase(
"Add Non Batch Account Create Attestation");
2620 XEnv scEnv(*
this,
true);
2628 mcEnv.
fund(funds, a);
2629 mcEnv.
fund(funds, doorA);
2644 xrp_b.initBridge(mcEnv, scEnv);
2646 auto const amt =
XRP(777);
2647 auto const amt_plus_reward = amt + xrp_b.reward;
2649 Balance bal_doorA(mcEnv, doorA);
2654 a, xrp_b.jvb, ua, amt, xrp_b.reward))
2657 BEAST_EXPECT(bal_doorA.
diff() == amt_plus_reward);
2658 BEAST_EXPECT(bal_a.
diff() == -(amt_plus_reward + tx_fee));
2661 for (
int i = 0; i <
signers.size(); ++i)
2674 TER const expectedTER = i < xrp_b.quorum
2679 if (i + 1 < xrp_b.quorum)
2680 BEAST_EXPECT(!scEnv.
env_.
le(ua));
2682 BEAST_EXPECT(scEnv.
env_.
le(ua));
2684 BEAST_EXPECT(scEnv.
env_.
le(ua));
2690 using namespace jtx;
2701 for (
auto withClaim : {
false,
true})
2704 XEnv scEnv(*
this,
true);
2715 auto const amt =
XRP(1000);
2755 for (
auto withClaim : {
false,
true})
2758 XEnv scEnv(*
this,
true);
2770 auto const amt =
XRP(1000);
2805 for (
auto withClaim : {
false,
true})
2808 XEnv scEnv(*
this,
true);
2821 auto const amt =
XRP(1000);
2854 for (
auto withClaim : {
false,
true})
2857 XEnv scEnv(*
this,
true);
2873 auto const amt =
XRP(1000);
2912 for (
auto withClaim : {
false,
true})
2915 XEnv scEnv(*
this,
true);
2926 auto const amt =
XRP(1000);
2963 for (
auto withClaim : {
false,
true})
2966 XEnv scEnv(*
this,
true);
2977 auto const amt =
XRP(1000);
3022 for (
auto withClaim : {
false,
true})
3025 XEnv scEnv(*
this,
true);
3036 auto const amt =
XRP(1000);
3062 for (
auto withClaim : {
false,
true})
3065 XEnv scEnv(*
this,
true);
3076 auto const amt =
XRP(1000);
3083 auto tooFew =
quorum - 1;
3113 for (
auto withClaim : {
false,
true})
3116 XEnv scEnv(*
this,
true);
3127 auto const amt =
XRP(1000);
3167 for (
auto withClaim : {
true})
3170 XEnv scEnv(*
this,
true);
3181 auto const amt =
XRP(1000);
3223 for (
auto withClaim : {
true})
3226 XEnv scEnv(*
this,
true);
3237 auto const amt =
XRP(1000);
3279 for (
auto withClaim : {
false,
true})
3282 XEnv scEnv(*
this,
true);
3295 auto const amt =
XRP(1000);
3346 scEnv.
tx(txns.back());
3363 for (
auto withClaim : {
false,
true})
3366 XEnv scEnv(*
this,
true);
3381 auto const amt =
XRP(1000);
3417 for (
auto withClaim : {
false,
true})
3420 XEnv scEnv(*
this,
true);
3432 auto const amt =
XRP(1000);
3460 scEnv.
tx(txns.back()).
close();
3476 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3480 scEnv.
tx(txns.back()).
close();
3493 scEnv.
tx(txns.back()).
close();
3494 BEAST_EXPECT(scBob_bal.
diff() == amt);
3500 for (
auto withClaim : {
false,
true})
3503 XEnv scEnv(*
this,
true);
3515 auto const amt =
XRP(1000);
3543 scEnv.
tx(txns.back()).
close();
3558 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3562 scEnv.
tx(txns.back()).
close();
3576 scEnv.
tx(txns.back()).
close();
3577 BEAST_EXPECT(scBob_bal.
diff() == amt);
3587 XEnv scEnv(*
this,
true);
3599 auto const amt =
XRP(1000);
3624 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3629 for (
auto withClaim : {
true})
3632 XEnv scEnv(*
this,
true);
3643 auto const amt =
XRP(1000);
3682 for (
auto withClaim : {
false,
true})
3685 XEnv scEnv(*
this,
true);
3696 auto const amt =
XRP(1000);
3729 claim_cost += tx_fee;
3734 scAlice_bal.
diff() == -claim_cost);
3740 for (
auto withClaim : {
false,
true})
3743 XEnv scEnv(*
this,
true);
3754 auto const amt =
XRP(1000);
3786 claim_cost += tx_fee;
3799 for (
auto withClaim : {
false,
true})
3802 XEnv scEnv(*
this,
true);
3807 alt_payees.back() =
Account(
"inexistent");
3816 auto const amt =
XRP(1000);
3854 for (
auto withClaim : {
false,
true})
3857 XEnv scEnv(*
this,
true);
3869 auto const amt =
XRP(1000);
3874 Balance last_signer(scEnv, unpaid);
3946 using namespace jtx;
3953 XEnv scEnv(*
this,
true);
3955 auto const amt =
XRP(111);
3956 auto const amt_plus_reward = amt +
reward;
4000 BEAST_EXPECT(carol.
diff() == -tx_fee);
4087 BEAST_EXPECT(door.
diff() == -tx_fee);
4111 using namespace jtx;
4134 auto const minAccountCreate =
XRP(20);
4161 using namespace jtx;
4163 testcase(
"Bridge Delete Door Account");
4165 auto const acctDelFee{
4176 for (
size_t i = 0; i < 256; ++i)
4188 XEnv scEnv(*
this,
true);
4197 for (
size_t i = 0; i < 256; ++i)
4211 using namespace jtx;
4216 XEnv scEnv(*
this,
true);
4219 auto const amt =
XRP(1000);
4237 auto k = jvAtt[
"PublicKey"].asString();
4239 jvAtt[
"PublicKey"] = k;
4246 XEnv scEnv(*
this,
true);
4249 auto const amt =
XRP(1000);
4250 auto const rewardAmt =
XRP(1);
4267 auto k = jvAtt[
"PublicKey"].asString();
4269 jvAtt[
"PublicKey"] = k;
4370 for (
auto const& c : claims)
4384 size_t num_successful = 0;
4385 for (
auto const& c : claims)
4396 return num_successful;
4402 bool callback_called;
4409 callback_called =
false;
4417 auto& create_claims =
4418 claims.create_claims[c.claim_count];
4419 auto num_attns = create_claims.size();
4423 i,
bridge, create_claims);
4425 assert(claims.create_claims[c.claim_count].empty());
4430 if (c.num_create_attn_sent >=
bridge->quorum)
4432 callback_called =
true;
4433 c.create_callbacks[c.claim_count](c.signers);
4435 c.num_create_attn_sent = 0;
4439 }
while (callback_called);
4464 it->second.expectedDiff +=
4502 for (
auto const& [acct, state] :
accounts)
4503 if (!state.verify(
env, acct))
4596 return static_cast<T&
>(*this).a2b() ?
st_->a_ :
st_->b_;
4602 return static_cast<T&
>(*this).a2b() ?
st_->b_ :
st_->a_;
4698 if (counters.create_callbacks.size() <
cr.
claim_id)
4699 counters.create_callbacks.resize(
cr.
claim_id);
4702 auto num_attestors =
signers.size();
4708 assert(
cr.
claim_id - 1 == counters.claim_count);
4722 counters.create_callbacks[
cr.
claim_id - 1] = std::move(complete_cb);
4953 bool verify_balances =
true)
4955 using namespace jtx;
4965 auto vis = [&](
auto& sm) {
4966 uint32_t rnd = distrib(gen);
4967 return sm.advance(time, rnd);
4969 auto& [t, sm] = *it;
4977 st->sendAttestations();
4983 if (verify_balances)
4985 BEAST_EXPECT(st->verify());
4993 using namespace jtx;
4995 testcase(
"Bridge usage simulation");
4998 XEnv scEnv(*
this,
true);
5000 auto st = std::make_shared<ChainStateTracker>(mcEnv, scEnv);
5004 Account doorXRPLocking(
"doorXRPLocking"),
5005 doorUSDLocking(
"doorUSDLocking"), doorUSDIssuing(
"doorUSDIssuing");
5007 constexpr size_t num_acct = 10;
5008 auto a = [&doorXRPLocking, &doorUSDLocking, &doorUSDIssuing]() {
5009 using namespace std::literals;
5012 for (
int i = 0; i < num_acct; ++i)
5017 doorXRPLocking = result.
back();
5019 doorUSDLocking = result.
back();
5021 doorUSDIssuing = result.
back();
5025 for (
auto& acct : a)
5029 mcEnv.
fund(amt, acct);
5030 scEnv.
fund(amt, acct);
5032 Account USDLocking{
"USDLocking"};
5033 IOU usdLocking{USDLocking[
"USD"]};
5034 IOU usdIssuing{doorUSDIssuing[
"USD"]};
5036 mcEnv.
fund(
XRP(100000), USDLocking);
5038 mcEnv.
tx(
trust(doorUSDLocking, usdLocking(100000)));
5040 mcEnv.
tx(
pay(USDLocking, doorUSDLocking, usdLocking(50000)));
5042 for (
int i = 0; i < a.size(); ++i)
5047 mcEnv.
tx(
trust(acct, usdLocking(100000)));
5048 scEnv.
tx(
trust(acct, usdIssuing(100000)));
5053 st->init(s.account);
5058 constexpr size_t num_ua = 20;
5060 using namespace std::literals;
5063 for (
int i = 0; i < num_ua; ++i)
5071 auto initBridge = [&mcEnv, &scEnv, &st](
BridgeDef& bd) {
5072 bd.initBridge(mcEnv, scEnv);
5073 st->a_.spendFee(bd.doorA, 2);
5074 st->b_.spendFee(bd.doorB, 2);
5112 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
true});
5113 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
true});
5118 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
false});
5119 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
false});
5126 xfer(1, st, xrp_b, {a[1], a[1], a[1],
XRP(1),
true});
5127 xfer(2, st, xrp_b, {a[0], a[0], a[1],
XRP(3),
false});
5128 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(5),
false});
5130 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(9),
true});
5135 xfer(0, st, usd_b, {a[0], a[1], a[2], usdLocking(3),
true});
5140 xfer(0, st, usd_b, {a[0], a[0], a[1], usdLocking(6),
true});
5141 xfer(1, st, usd_b, {a[0], a[0], a[1], usdIssuing(8),
false});
5142 xfer(1, st, usd_b, {a[1], a[1], a[1], usdLocking(1),
true});
5143 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(3),
false});
5144 xfer(2, st, usd_b, {a[1], a[1], a[1], usdIssuing(5),
false});
5145 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(7),
false});
5146 xfer(2, st, usd_b, {a[1], a[1], a[1], usdLocking(9),
true});
5151 xfer(0, st, xrp_b, {a[0], a[0], a[0],
XRP(1),
true});
5152 xfer(0, st, usd_b, {a[1], a[3], a[3], usdIssuing(3),
false});
5153 xfer(0, st, usd_b, {a[3], a[2], a[1], usdIssuing(5),
false});
5155 xfer(1, st, xrp_b, {a[0], a[0], a[0],
XRP(4),
false});
5156 xfer(1, st, xrp_b, {a[1], a[1], a[0],
XRP(8),
true});
5157 xfer(1, st, usd_b, {a[4], a[1], a[1], usdLocking(7),
true});
5159 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(7),
true});
5160 xfer(3, st, xrp_b, {a[0], a[4], a[3],
XRP(2),
false});
5161 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(9),
true});
5162 xfer(3, st, usd_b, {a[3], a[1], a[1], usdIssuing(11),
false});
5167 ac(0, st, xrp_b, {a[0], ua[1],
XRP(301), xrp_b.reward,
true});
5168 ac(0, st, xrp_b, {a[1], ua[2],
XRP(302), xrp_b.reward,
true});
5169 ac(1, st, xrp_b, {a[0], ua[3],
XRP(303), xrp_b.reward,
true});
5170 ac(2, st, xrp_b, {a[1], ua[4],
XRP(304), xrp_b.reward,
true});
5171 ac(3, st, xrp_b, {a[0], ua[5],
XRP(305), xrp_b.reward,
true});
5172 ac(4, st, xrp_b, {a[1], ua[6],
XRP(306), xrp_b.reward,
true});
5173 ac(6, st, xrp_b, {a[0], ua[7],
XRP(307), xrp_b.reward,
true});
5174 ac(7, st, xrp_b, {a[2], ua[8],
XRP(308), xrp_b.reward,
true});
5175 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5176 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5177 ac(10, st, xrp_b, {a[0], ua[10],
XRP(310), xrp_b.reward,
true});
5178 ac(12, st, xrp_b, {a[0], ua[11],
XRP(311), xrp_b.reward,
true});
5179 ac(12, st, xrp_b, {a[3], ua[12],
XRP(312), xrp_b.reward,
true});
5180 ac(12, st, xrp_b, {a[4], ua[13],
XRP(313), xrp_b.reward,
true});
5181 ac(12, st, xrp_b, {a[3], ua[14],
XRP(314), xrp_b.reward,
true});
5182 ac(12, st, xrp_b, {a[6], ua[15],
XRP(315), xrp_b.reward,
true});
5183 ac(13, st, xrp_b, {a[7], ua[16],
XRP(316), xrp_b.reward,
true});
5184 ac(15, st, xrp_b, {a[3], ua[17],
XRP(317), xrp_b.reward,
true});
5196BEAST_DEFINE_TESTSUITE(XChainSim, app,
ripple);
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
virtual Config & config()=0
std::unordered_set< uint256, beast::uhash<> > features
A currency issued by an account.
Issue const & issue() const
static constexpr TERSubset fromInt(int from)
std::shared_ptr< ChainStateTracker > st_
const BridgeDef & bridge_
ChainStateTrack & srcState()
jtx::Account const & srcDoor()
SmBase(const std::shared_ptr< ChainStateTracker > &chainstate, const BridgeDef &bridge)
jtx::Account const & dstDoor()
ChainStateTrack & destState()
SmCreateAccount(const std::shared_ptr< ChainStateTracker > &chainstate, const BridgeDef &bridge, AccountCreate create)
uint32_t issue_account_create()
SmState advance(uint64_t time, uint32_t rnd)
void attest(uint64_t time, uint32_t rnd)
void distribute_reward(ChainStateTrack &st)
SmState advance(uint64_t time, uint32_t rnd)
SmTransfer(const std::shared_ptr< ChainStateTracker > &chainstate, const BridgeDef &bridge, Transfer xfer)
bool attest(uint64_t time, uint32_t rnd)
uint32_t create_claim_id()
Immutable cryptographic account descriptor.
static Account const master
The master account.
A transaction testing environment.
TER ter() const
Return the TER for the last JTx.
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.
void enableFeature(uint256 const feature)
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
void memoize(Account const &account)
Associate AccountID with account.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Converts to IOU Issue or STAmount.
Set the expected result code for a JTx The test will fail if the code doesn't match.
T emplace_back(T... args)
Severity
Severity level / threshold of a Journal message.
Keylet xChainClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Keylet bridge(STXChainBridge const &bridge, STXChainBridge::ChainType chainType)
Keylet xChainCreateAccountClaimID(STXChainBridge const &bridge, std::uint64_t seq)
constexpr std::size_t UT_XCHAIN_DEFAULT_QUORUM
Json::Value create_account_attestation(jtx::Account const &submittingAccount, Json::Value const &jvBridge, jtx::Account const &sendingAccount, jtx::AnyAmount const &sendingAmount, jtx::AnyAmount const &rewardAmount, jtx::Account const &rewardAccount, bool wasLockingChainSend, std::uint64_t createCount, jtx::Account const &dst, jtx::signer const &signer)
JValueVec claim_attestations(jtx::Account const &submittingAccount, Json::Value const &jvBridge, jtx::Account const &sendingAccount, jtx::AnyAmount const &sendingAmount, std::vector< jtx::Account > const &rewardAccounts, bool wasLockingChainSend, std::uint64_t claimID, std::optional< jtx::Account > const &dst, std::vector< jtx::signer > const &signers, std::size_t const numAtts, std::size_t const fromIdx)
Json::Value bridge_create(Account const &acc, Json::Value const &bridge, STAmount const &reward, std::optional< STAmount > const &minAccountCreate)
Json::Value claim_attestation(jtx::Account const &submittingAccount, Json::Value const &jvBridge, jtx::Account const &sendingAccount, jtx::AnyAmount const &sendingAmount, jtx::Account const &rewardAccount, bool wasLockingChainSend, std::uint64_t claimID, std::optional< jtx::Account > const &dst, jtx::signer const &signer)
Json::Value bridge(Account const &lockingChainDoor, Issue const &lockingChainIssue, Account const &issuingChainDoor, Issue const &issuingChainIssue)
Json::Value regkey(Account const &account, disabled_t)
Disable the regular key.
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
std::vector< Json::Value > JValueVec
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value sidechain_xchain_account_create(Account const &acc, Json::Value const &bridge, Account const &dst, AnyAmount const &amt, AnyAmount const &reward)
Json::Value xchain_claim(Account const &acc, Json::Value const &bridge, std::uint32_t claimID, AnyAmount const &amt, Account const &dst)
constexpr std::size_t UT_XCHAIN_DEFAULT_NUM_SIGNERS
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Json::Value xchain_create_claim_id(Account const &acc, Json::Value const &bridge, STAmount const &reward, Account const &otherChainSource)
Json::Value bridge_modify(Account const &acc, Json::Value const &bridge, std::optional< STAmount > const &reward, std::optional< STAmount > const &minAccountCreate)
Json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount, NetClock::duration const &settleDelay, PublicKey const &pk, std::optional< NetClock::time_point > const &cancelAfter, std::optional< std::uint32_t > const &dstTag)
Json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
Json::Value xchain_commit(Account const &acc, Json::Value const &bridge, std::uint32_t claimID, AnyAmount const &amt, std::optional< Account > const &dst)
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.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
STAmount divide(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t asfRequireDest
STAmount multiply(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t tfFillOrKill
@ current
This was a new validation and was added.
constexpr std::uint32_t asfDisableMaster
std::string transToken(TER code)
constexpr std::uint32_t tfClearAccountCreateAmount
@ tecXCHAIN_INSUFF_CREATE_AMOUNT
@ tecXCHAIN_CREATE_ACCOUNT_DISABLED
@ tecXCHAIN_CLAIM_NO_QUORUM
@ tecXCHAIN_ACCOUNT_CREATE_PAST
@ tecXCHAIN_REWARD_MISMATCH
@ tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR
@ tecXCHAIN_NO_SIGNERS_LIST
@ tecINSUFFICIENT_RESERVE
@ temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT
@ temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT
@ temXCHAIN_EQUAL_DOOR_ACCOUNTS
@ temXCHAIN_BRIDGE_NONDOOR_OWNER
@ temXCHAIN_BRIDGE_BAD_ISSUES
bool payees_received(STAmount const &reward) const
std::vector< balance > reward_accounts
BalanceTransfer(T &env, jtx::Account const &from_acct, jtx::Account const &to_acct, jtx::Account const &payor, jtx::Account const *payees, size_t num_payees, bool withClaim)
bool check_most_balances(STAmount const &amt, STAmount const &reward)
BalanceTransfer(T &env, jtx::Account const &from_acct, jtx::Account const &to_acct, jtx::Account const &payor, std::vector< jtx::Account > const &payees, bool withClaim)
bool has_happened(STAmount const &amt, STAmount const &reward, bool check_payer=true)
Balance(T &env, jtx::Account const &account)
jtx::Account const & account_
STAmount minAccountCreate
void initBridge(ENV &mcEnv, ENV &scEnv)
std::vector< jtx::signer > const & signers
std::shared_ptr< SLE const > bridge(Json::Value const &jvb)
SEnv(T &s, std::unique_ptr< Config > config, FeatureBitset features, std::unique_ptr< Logs > logs=nullptr, beast::severities::Severity thresh=beast::severities::kError)
SEnv & enableFeature(uint256 const feature)
std::uint64_t claimCount(Json::Value const &jvb)
std::shared_ptr< SLE const > account(jtx::Account const &account)
SEnv & multiTx(jtx::JValueVec &&jvv, FN const &... fN)
std::shared_ptr< SLE const > caClaimID(Json::Value const &jvb, std::uint64_t seq)
std::uint64_t claimID(Json::Value const &jvb)
std::shared_ptr< SLE const > claimID(Json::Value const &jvb, std::uint64_t seq)
SEnv & tx(JsonValue &&jv, FN const &... fN)
XRPAmount reserve(std::uint32_t count)
STAmount balance(jtx::Account const &account) const
SEnv & disableFeature(uint256 const feature)
STAmount balance(jtx::Account const &account, Issue const &issue) const
SEnv & fund(STAmount const &amount, Arg const &arg, Args const &... args)
std::array< bool, num_signers > attested
void init(ENV &env, jtx::Account const &acct)
bool verify(ENV &env, jtx::Account const &acct) const
std::vector< complete_cb > create_callbacks
std::vector< size_t > signers
uint32_t num_create_attn_sent
CreateClaimMap create_claims
SignersAttns signers_attns
void spend(jtx::Account const &acct, STAmount amt, std::uint64_t times=1)
void transfer(jtx::Account const &from, jtx::Account const &to, STAmount amt)
ChainStateTrack(ENV &env)
uint32_t sendCreateAttestations(size_t signer_idx, BridgeID bridge, CreateClaimVec &claims)
void spendFee(jtx::Account const &acct, size_t times=1)
std::map< BridgeID, BridgeCounters > counters
void init(jtx::Account const &acct)
void sendAttestations(size_t signer_idx, BridgeID bridge, ClaimVec &claims)
void receive(jtx::Account const &acct, STAmount amt, std::uint64_t divisor=1)
std::map< jtx::Account, AccountStateTrack > accounts
void init(jtx::Account const &acct)
ChainStateTracker(ENV &a_env, ENV &b_env)
std::array< bool, num_signers > attested
BridgeDef const * BridgeID
void testXChainSimulation()
void ac(uint64_t time, const std::shared_ptr< ChainStateTracker > &chainstate, BridgeDef const &bridge, AccountCreate ac)
void xfer(uint64_t time, const std::shared_ptr< ChainStateTracker > &chainstate, BridgeDef const &bridge, Transfer transfer)
void run() override
Runs the suite.
static constexpr size_t num_signers
void runSimulation(std::shared_ptr< ChainStateTracker > const &st, bool verify_balances=true)
void testXChainDeleteDoor()
void run() override
Runs the suite.
void testXChainBridgeExtraFields()
void testXChainAddAccountCreateNonBatchAttestation()
XRPAmount reserve(std::uint32_t count)
void testXChainBridgeCreateConstraints()
void testXChainAddAttestation()
void testXChainAddClaimNonBatchAttestation()
void testXChainModifyBridge()
void testXChainCreateAccount()
void testXChainCreateClaimID()
void testXChainCreateBridgeMatrix()
void testXChainCreateBridge()
void testFeeDipsIntoReserve()
XEnv(T &s, bool side=false)
STAmount const & value() const
JValueVec att_create_acct_vec(std::uint64_t createCount, jtx::AnyAmount const &amt, jtx::Account const &dst, std::size_t const numAtts, std::size_t const fromIdx=0)
std::uint32_t const quorum
const STAmount tiny_reward_remainder
std::vector< signer > const alt_signers
Json::Value create_bridge(Account const &acc, Json::Value const &bridge=Json::nullValue, STAmount const &_reward=XRP(1), std::optional< STAmount > const &minAccountCreate=std::nullopt)
const STAmount tiny_reward
const STAmount tiny_reward_split
STAmount const split_reward_everyone
std::vector< Account > const payees
FeatureBitset const features
std::vector< signer > const signers
STAmount const split_reward_quorum
Set the sequence number on a JTx.
A signer in a SignerList.