21#include <test/jtx/Env.h>
22#include <test/jtx/attester.h>
23#include <test/jtx/multisign.h>
24#include <test/jtx/xchain_bridge.h>
26#include <xrpl/beast/unit_test/suite.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/Issue.h>
30#include <xrpl/protocol/SField.h>
31#include <xrpl/protocol/STXChainBridge.h>
32#include <xrpl/protocol/Serializer.h>
33#include <xrpl/protocol/TER.h>
34#include <xrpl/protocol/XChainAttestations.h>
63 :
env_(s,
std::move(config), features,
std::move(logs), thresh)
88 template <
class Arg,
class... Args>
96 template <
class JsonValue,
class... FN>
98 tx(JsonValue&& jv, FN
const&... fN)
104 template <
class... FN>
108 for (
auto const& jv : jvv)
134 return env_.
current()->fees().accountReserve(count);
158 if ((*r)[sfXChainBridge] == b)
171 return (*
bridge(jvb))[sfXChainAccountClaimCount];
177 return (*
bridge(jvb))[sfXChainClaimID];
213 this->
fund(xrp_funds, s.account);
228 this->
fund(xrp_funds, ra);
231 this->
fund(xrp_funds, s.account);
281 :
from_(env, from_acct)
287 for (
size_t i = 0; i < num_payees; ++i)
319 [&](
balance const& b) { return b.diff() == reward; });
333 bool check_payer =
true)
401 bool exceptionPresent =
false;
404 exceptionPresent =
false;
409 exceptionPresent =
true;
412 BEAST_EXPECT(!exceptionPresent);
416 exceptionPresent =
false;
417 jBridge[
"Extra"] = 1;
422 exceptionPresent =
true;
425 BEAST_EXPECT(exceptionPresent);
600 testcase(
"Bridge create constraints");
601 XEnv env(*
this,
true);
605 auto AUSD = A[
"USD"];
606 auto BUSD = B[
"USD"];
607 auto CUSD = C[
"USD"];
608 auto GUSD =
scGw[
"USD"];
609 auto AEUR = A[
"EUR"];
610 auto BEUR = B[
"EUR"];
611 auto CEUR = C[
"EUR"];
612 auto GEUR =
scGw[
"EUR"];
622 env.
fund(
XRP(10000), a1, a2, a3, a4, a5, a6);
645 auto const goodBridge1 =
bridge(A, GUSD, B, BUSD);
646 auto const goodBridge2 =
bridge(A, BUSD, C, CUSD);
664 .
tx(
pay(B, C, BUSD(1000)))
666 auto const aBalanceStart = env.
balance(A, BUSD);
667 auto const cBalanceStart = env.
balance(C, BUSD);
669 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(0));
670 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50));
672 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(60));
673 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50 - 60));
677 BEAST_EXPECT((*env.
bridge(goodBridge1))[sfSignatureReward] ==
XRP(33));
679 BEAST_EXPECT((*env.
bridge(goodBridge2))[sfSignatureReward] ==
XRP(44));
729 "Locking chain is IOU(locking chain door)",
730 [&](
auto& env,
bool) {
735 "Locking chain is IOU(issuing chain door funded on locking "
737 [&](
auto& env,
bool shouldFund) {
744 "Locking chain is IOU(issuing chain door account unfunded "
746 [&](
auto& env,
bool) {
751 "Locking chain is IOU(bob funded on locking chain)",
752 [&](
auto& env,
bool) {
757 "Locking chain is IOU(bob unfunded on locking chain)",
758 [&](
auto& env,
bool) {
769 "Issuing chain is IOU(issuing chain door account)",
770 [&](
auto& env,
bool) {
775 "Issuing chain is IOU(locking chain door funded on issuing "
777 [&](
auto& env,
bool shouldFund) {
784 "Issuing chain is IOU(locking chain door unfunded on "
786 [&](
auto& env,
bool) {
791 "Issuing chain is IOU(bob funded on issuing chain)",
792 [&](
auto& env,
bool) {
797 "Issuing chain is IOU(bob unfunded on issuing chain)",
798 [&](
auto& env,
bool) {
803 "Issuing chain is XRP and issuing chain door account is "
804 "not the root account",
805 [&](
auto& env,
bool) {
810 "Issuing chain is XRP and issuing chain door account is "
812 [&](
auto& env,
bool) {
863 auto testcase = [&](
auto const& lc,
auto const& ic) {
865 XEnv scEnv(*
this,
true);
867 lc.second(mcEnv,
true);
868 lc.second(scEnv,
false);
870 ic.second(mcEnv,
false);
871 ic.second(scEnv,
true);
873 auto const& expected = expected_result[test_result.
size()];
890 auto apply_ics = [&](
auto const& lc,
auto const& ics) {
892 [&](
auto const&... ic) { (
testcase(lc, ic), ...); }, ics);
895 std::apply([&](
auto const&... lc) { (apply_ics(lc, ics), ...); }, lcs);
897#if GENERATE_MTX_OUTPUT
902 std::cout <<
"Markdown output for matrix test: " << fname <<
"\n";
917 auto output_table = [&](
auto print_res) {
923 res +=
"| `issuing ->` | ";
925 [&](
auto const&... ic) {
926 ((res += ic.first, res +=
" | "), ...);
933 [&](
auto const&... ic) {
934 (((void)ic.first, res +=
":---: | "), ...);
939 auto output = [&](
auto const& lc,
auto const& ic) {
940 res += print_res(test_result[test_idx]);
945 auto output_ics = [&](
auto const& lc,
auto const& ics) {
950 [&](
auto const&... ic) { (output(lc, ic), ...); }, ics);
955 [&](
auto const&... lc) { (output_ics(lc, ics), ...); }, lcs);
963 std::cout <<
"ter output for matrix test: " << ter_fname <<
"\n";
966 for (
auto& t : test_result)
1027 for (
auto withClaim : {
false,
true})
1030 XEnv scEnv(*
this,
true);
1041 auto const amt =
XRP(1000);
1082 for (
auto withClaim : {
false,
true})
1085 XEnv scEnv(*
this,
true);
1096 auto const amt =
XRP(1000);
1145 for (
auto withClaim : {
false,
true})
1148 XEnv scEnv(*
this,
true);
1159 auto const amt =
XRP(1000);
1284 using namespace jtx;
1301 XEnv xenv(*
this,
true);
1309 BEAST_EXPECT(scAlice_bal.
diff() == -tx_fee);
1374 using namespace jtx;
1389 auto const amt =
XRP(1000);
1397 BEAST_EXPECT(alice_bal.
diff() == -(claim_cost + tx_fee));
1510 using namespace jtx;
1526 for (
auto withClaim : {
true})
1529 XEnv scEnv(*
this,
true);
1543 auto const amt =
XRP(1000);
1595 for (
auto withClaim : {
false,
true})
1598 XEnv scEnv(*
this,
true);
1602 constexpr int numSigners = 4;
1607 for (
int i = 0; i < numSigners; ++i)
1627 auto const amt =
XRP(1000);
1670 for (
auto withClaim : {
false,
true})
1673 XEnv scEnv(*
this,
true);
1677 constexpr int numSigners = 4;
1682 for (
int i = 0; i < numSigners; ++i)
1704 auto const amt =
XRP(1000);
1748 for (
auto withClaim : {
false,
true})
1751 XEnv scEnv(*
this,
true);
1755 constexpr int numSigners = 4;
1760 for (
int i = 0; i < numSigners; ++i)
1781 auto const amt =
XRP(1000);
1823 for (
auto withClaim : {
false,
true})
1826 XEnv scEnv(*
this,
true);
1830 constexpr int numSigners = 4;
1835 for (
int i = 0; i < numSigners; ++i)
1856 auto const amt =
XRP(1000);
1906 XEnv scEnv(*
this,
true);
1907 auto const amt =
XRP(1000);
1908 auto const amt_plus_reward = amt +
reward;
1928 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
1948 BEAST_EXPECT(attester.
diff() == -multiTtxFee(6));
1968 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
1986 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2002 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2004 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2024 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2040 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2041 BEAST_EXPECT(attester.
diff() == -tx_fee);
2056 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2057 BEAST_EXPECT(attester.
diff() == -tx_fee);
2069 XEnv scEnv(*
this,
true);
2071 auto const amt = res0 -
XRP(1);
2072 auto const amt_plus_reward = amt +
reward;
2085 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2086 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2106 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2115 XEnv scEnv(*
this,
true);
2117 auto const amt =
XRP(111);
2118 auto const amt_plus_reward = amt +
reward;
2131 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2132 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2153 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2154 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2155 BEAST_EXPECT(alice.
diff() == amt);
2162 XEnv scEnv(*
this,
true);
2164 auto const amt =
XRP(1000);
2165 auto const amt_plus_reward = amt +
reward;
2178 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2179 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2202 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2213 XEnv scEnv(*
this,
true);
2214 auto const amt =
XRP(1000);
2215 auto const amt_plus_reward = amt +
reward;
2237 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
2248 auto const bad_amt =
XRP(10);
2259 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 1),
"claim id 1 created");
2260 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 2),
"claim id 2 created");
2261 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 3),
"claim id 3 created");
2295 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 deleted");
2296 BEAST_EXPECTS(scEnv.
claimCount(
jvb) == 1,
"scuAlice created");
2305 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 2),
"claim id 2 deleted");
2306 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 not added");
2314 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 3),
"claim id 3 deleted");
2325 BEAST_EXPECT(attester.
diff() == -multiTtxFee(txCount));
2338 XEnv scEnv(*
this,
true);
2360 XEnv scEnv(*
this,
true);
2383 using namespace jtx;
2385 testcase(
"Add Non Batch Claim Attestation");
2389 XEnv scEnv(*
this,
true);
2403 auto const amt =
XRP(1000);
2406 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2408 for (
int i = 0; i <
signers.size(); ++i)
2421 TER const expectedTER =
2429 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2432 dstStartBalance + amt == scEnv.
env_.
balance(dst));
2434 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2455 XEnv scEnv(*
this,
true);
2456 auto const amt =
XRP(1000);
2472 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2506 att[sfAttestationSignerAccount.getJsonName()] =
2513 auto const unfundedSigner1 =
2515 auto const unfundedSigner2 =
2527 att[sfAttestationSignerAccount.getJsonName()] =
2528 unfundedSigner2.account.human();
2531 att[sfAttestationSignerAccount.getJsonName()] =
2532 unfundedSigner1.
account.human();
2549 tempSignerList.
front());
2550 att[sfAttestationSignerAccount.getJsonName()] =
2599 att.removeMember(sfAttestationSignerAccount.getJsonName());
2601 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2602 att[sfAttestationSignerAccount.getJsonName()] =
2605 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2613 using namespace jtx;
2615 testcase(
"Add Non Batch Account Create Attestation");
2618 XEnv scEnv(*
this,
true);
2626 mcEnv.
fund(funds, a);
2627 mcEnv.
fund(funds, doorA);
2642 xrp_b.initBridge(mcEnv, scEnv);
2644 auto const amt =
XRP(777);
2645 auto const amt_plus_reward = amt + xrp_b.reward;
2647 Balance bal_doorA(mcEnv, doorA);
2652 a, xrp_b.jvb, ua, amt, xrp_b.reward))
2655 BEAST_EXPECT(bal_doorA.
diff() == amt_plus_reward);
2656 BEAST_EXPECT(bal_a.
diff() == -(amt_plus_reward + tx_fee));
2659 for (
int i = 0; i <
signers.size(); ++i)
2672 TER const expectedTER = i < xrp_b.quorum
2677 if (i + 1 < xrp_b.quorum)
2678 BEAST_EXPECT(!scEnv.
env_.
le(ua));
2680 BEAST_EXPECT(scEnv.
env_.
le(ua));
2682 BEAST_EXPECT(scEnv.
env_.
le(ua));
2688 using namespace jtx;
2699 for (
auto withClaim : {
false,
true})
2702 XEnv scEnv(*
this,
true);
2713 auto const amt =
XRP(1000);
2753 for (
auto withClaim : {
false,
true})
2756 XEnv scEnv(*
this,
true);
2768 auto const amt =
XRP(1000);
2803 for (
auto withClaim : {
false,
true})
2806 XEnv scEnv(*
this,
true);
2819 auto const amt =
XRP(1000);
2852 for (
auto withClaim : {
false,
true})
2855 XEnv scEnv(*
this,
true);
2871 auto const amt =
XRP(1000);
2910 for (
auto withClaim : {
false,
true})
2913 XEnv scEnv(*
this,
true);
2924 auto const amt =
XRP(1000);
2961 for (
auto withClaim : {
false,
true})
2964 XEnv scEnv(*
this,
true);
2975 auto const amt =
XRP(1000);
3020 for (
auto withClaim : {
false,
true})
3023 XEnv scEnv(*
this,
true);
3034 auto const amt =
XRP(1000);
3060 for (
auto withClaim : {
false,
true})
3063 XEnv scEnv(*
this,
true);
3074 auto const amt =
XRP(1000);
3081 auto tooFew =
quorum - 1;
3111 for (
auto withClaim : {
false,
true})
3114 XEnv scEnv(*
this,
true);
3125 auto const amt =
XRP(1000);
3165 for (
auto withClaim : {
true})
3168 XEnv scEnv(*
this,
true);
3179 auto const amt =
XRP(1000);
3221 for (
auto withClaim : {
true})
3224 XEnv scEnv(*
this,
true);
3235 auto const amt =
XRP(1000);
3277 for (
auto withClaim : {
false,
true})
3280 XEnv scEnv(*
this,
true);
3293 auto const amt =
XRP(1000);
3344 scEnv.
tx(txns.back());
3361 for (
auto withClaim : {
false,
true})
3364 XEnv scEnv(*
this,
true);
3379 auto const amt =
XRP(1000);
3415 for (
auto withClaim : {
false,
true})
3418 XEnv scEnv(*
this,
true);
3430 auto const amt =
XRP(1000);
3458 scEnv.
tx(txns.back()).
close();
3474 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3478 scEnv.
tx(txns.back()).
close();
3491 scEnv.
tx(txns.back()).
close();
3492 BEAST_EXPECT(scBob_bal.
diff() == amt);
3498 for (
auto withClaim : {
false,
true})
3501 XEnv scEnv(*
this,
true);
3513 auto const amt =
XRP(1000);
3541 scEnv.
tx(txns.back()).
close();
3556 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3560 scEnv.
tx(txns.back()).
close();
3574 scEnv.
tx(txns.back()).
close();
3575 BEAST_EXPECT(scBob_bal.
diff() == amt);
3585 XEnv scEnv(*
this,
true);
3597 auto const amt =
XRP(1000);
3622 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3627 for (
auto withClaim : {
true})
3630 XEnv scEnv(*
this,
true);
3641 auto const amt =
XRP(1000);
3680 for (
auto withClaim : {
false,
true})
3683 XEnv scEnv(*
this,
true);
3694 auto const amt =
XRP(1000);
3727 claim_cost += tx_fee;
3732 scAlice_bal.
diff() == -claim_cost);
3738 for (
auto withClaim : {
false,
true})
3741 XEnv scEnv(*
this,
true);
3752 auto const amt =
XRP(1000);
3784 claim_cost += tx_fee;
3797 for (
auto withClaim : {
false,
true})
3800 XEnv scEnv(*
this,
true);
3805 alt_payees.back() =
Account(
"inexistent");
3814 auto const amt =
XRP(1000);
3852 for (
auto withClaim : {
false,
true})
3855 XEnv scEnv(*
this,
true);
3867 auto const amt =
XRP(1000);
3872 Balance last_signer(scEnv, unpaid);
3944 using namespace jtx;
3951 XEnv scEnv(*
this,
true);
3953 auto const amt =
XRP(111);
3954 auto const amt_plus_reward = amt +
reward;
3998 BEAST_EXPECT(carol.
diff() == -tx_fee);
4085 BEAST_EXPECT(door.
diff() == -tx_fee);
4109 using namespace jtx;
4132 auto const minAccountCreate =
XRP(20);
4159 using namespace jtx;
4161 testcase(
"Bridge Delete Door Account");
4163 auto const acctDelFee{
4174 for (
size_t i = 0; i < 256; ++i)
4186 XEnv scEnv(*
this,
true);
4195 for (
size_t i = 0; i < 256; ++i)
4209 using namespace jtx;
4214 XEnv scEnv(*
this,
true);
4217 auto const amt =
XRP(1000);
4235 auto k = jvAtt[
"PublicKey"].asString();
4237 jvAtt[
"PublicKey"] = k;
4244 XEnv scEnv(*
this,
true);
4247 auto const amt =
XRP(1000);
4248 auto const rewardAmt =
XRP(1);
4265 auto k = jvAtt[
"PublicKey"].asString();
4267 jvAtt[
"PublicKey"] = k;
4368 for (
auto const& c : claims)
4382 size_t num_successful = 0;
4383 for (
auto const& c : claims)
4394 return num_successful;
4400 bool callback_called;
4407 callback_called =
false;
4415 auto& create_claims =
4416 claims.create_claims[c.claim_count];
4417 auto num_attns = create_claims.size();
4421 i,
bridge, create_claims);
4423 assert(claims.create_claims[c.claim_count].empty());
4428 if (c.num_create_attn_sent >=
bridge->quorum)
4430 callback_called =
true;
4431 c.create_callbacks[c.claim_count](c.signers);
4433 c.num_create_attn_sent = 0;
4437 }
while (callback_called);
4462 it->second.expectedDiff +=
4500 for (
auto const& [acct, state] :
accounts)
4501 if (!state.verify(
env, acct))
4594 return static_cast<T&
>(*this).a2b() ?
st_->a_ :
st_->b_;
4600 return static_cast<T&
>(*this).a2b() ?
st_->b_ :
st_->a_;
4696 if (counters.create_callbacks.size() <
cr.
claim_id)
4697 counters.create_callbacks.resize(
cr.
claim_id);
4700 auto num_attestors =
signers.size();
4706 assert(
cr.
claim_id - 1 == counters.claim_count);
4720 counters.create_callbacks[
cr.
claim_id - 1] = std::move(complete_cb);
4951 bool verify_balances =
true)
4953 using namespace jtx;
4963 auto vis = [&](
auto& sm) {
4965 return sm.advance(time, rnd);
4967 auto& [t, sm] = *it;
4975 st->sendAttestations();
4981 if (verify_balances)
4983 BEAST_EXPECT(st->verify());
4991 using namespace jtx;
4993 testcase(
"Bridge usage simulation");
4996 XEnv scEnv(*
this,
true);
5002 Account doorXRPLocking(
"doorXRPLocking"),
5003 doorUSDLocking(
"doorUSDLocking"), doorUSDIssuing(
"doorUSDIssuing");
5005 constexpr size_t num_acct = 10;
5006 auto a = [&doorXRPLocking, &doorUSDLocking, &doorUSDIssuing]() {
5010 for (
int i = 0; i < num_acct; ++i)
5015 doorXRPLocking = result.
back();
5017 doorUSDLocking = result.
back();
5019 doorUSDIssuing = result.
back();
5023 for (
auto& acct : a)
5027 mcEnv.
fund(amt, acct);
5028 scEnv.
fund(amt, acct);
5030 Account USDLocking{
"USDLocking"};
5031 IOU usdLocking{USDLocking[
"USD"]};
5032 IOU usdIssuing{doorUSDIssuing[
"USD"]};
5034 mcEnv.
fund(
XRP(100000), USDLocking);
5036 mcEnv.
tx(
trust(doorUSDLocking, usdLocking(100000)));
5038 mcEnv.
tx(
pay(USDLocking, doorUSDLocking, usdLocking(50000)));
5040 for (
int i = 0; i < a.size(); ++i)
5045 mcEnv.
tx(
trust(acct, usdLocking(100000)));
5046 scEnv.
tx(
trust(acct, usdIssuing(100000)));
5051 st->init(s.account);
5056 constexpr size_t num_ua = 20;
5061 for (
int i = 0; i < num_ua; ++i)
5069 auto initBridge = [&mcEnv, &scEnv, &st](
BridgeDef& bd) {
5070 bd.initBridge(mcEnv, scEnv);
5071 st->a_.spendFee(bd.doorA, 2);
5072 st->b_.spendFee(bd.doorB, 2);
5110 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
true});
5111 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
true});
5116 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
false});
5117 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
false});
5124 xfer(1, st, xrp_b, {a[1], a[1], a[1],
XRP(1),
true});
5125 xfer(2, st, xrp_b, {a[0], a[0], a[1],
XRP(3),
false});
5126 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(5),
false});
5128 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(9),
true});
5133 xfer(0, st, usd_b, {a[0], a[1], a[2], usdLocking(3),
true});
5138 xfer(0, st, usd_b, {a[0], a[0], a[1], usdLocking(6),
true});
5139 xfer(1, st, usd_b, {a[0], a[0], a[1], usdIssuing(8),
false});
5140 xfer(1, st, usd_b, {a[1], a[1], a[1], usdLocking(1),
true});
5141 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(3),
false});
5142 xfer(2, st, usd_b, {a[1], a[1], a[1], usdIssuing(5),
false});
5143 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(7),
false});
5144 xfer(2, st, usd_b, {a[1], a[1], a[1], usdLocking(9),
true});
5149 xfer(0, st, xrp_b, {a[0], a[0], a[0],
XRP(1),
true});
5150 xfer(0, st, usd_b, {a[1], a[3], a[3], usdIssuing(3),
false});
5151 xfer(0, st, usd_b, {a[3], a[2], a[1], usdIssuing(5),
false});
5153 xfer(1, st, xrp_b, {a[0], a[0], a[0],
XRP(4),
false});
5154 xfer(1, st, xrp_b, {a[1], a[1], a[0],
XRP(8),
true});
5155 xfer(1, st, usd_b, {a[4], a[1], a[1], usdLocking(7),
true});
5157 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(7),
true});
5158 xfer(3, st, xrp_b, {a[0], a[4], a[3],
XRP(2),
false});
5159 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(9),
true});
5160 xfer(3, st, usd_b, {a[3], a[1], a[1], usdIssuing(11),
false});
5165 ac(0, st, xrp_b, {a[0], ua[1],
XRP(301), xrp_b.reward,
true});
5166 ac(0, st, xrp_b, {a[1], ua[2],
XRP(302), xrp_b.reward,
true});
5167 ac(1, st, xrp_b, {a[0], ua[3],
XRP(303), xrp_b.reward,
true});
5168 ac(2, st, xrp_b, {a[1], ua[4],
XRP(304), xrp_b.reward,
true});
5169 ac(3, st, xrp_b, {a[0], ua[5],
XRP(305), xrp_b.reward,
true});
5170 ac(4, st, xrp_b, {a[1], ua[6],
XRP(306), xrp_b.reward,
true});
5171 ac(6, st, xrp_b, {a[0], ua[7],
XRP(307), xrp_b.reward,
true});
5172 ac(7, st, xrp_b, {a[2], ua[8],
XRP(308), xrp_b.reward,
true});
5173 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5174 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5175 ac(10, st, xrp_b, {a[0], ua[10],
XRP(310), xrp_b.reward,
true});
5176 ac(12, st, xrp_b, {a[0], ua[11],
XRP(311), xrp_b.reward,
true});
5177 ac(12, st, xrp_b, {a[3], ua[12],
XRP(312), xrp_b.reward,
true});
5178 ac(12, st, xrp_b, {a[4], ua[13],
XRP(313), xrp_b.reward,
true});
5179 ac(12, st, xrp_b, {a[3], ua[14],
XRP(314), xrp_b.reward,
true});
5180 ac(12, st, xrp_b, {a[6], ua[15],
XRP(315), xrp_b.reward,
true});
5181 ac(13, st, xrp_b, {a[7], ua[16],
XRP(316), xrp_b.reward,
true});
5182 ac(15, st, xrp_b, {a[3], ua[17],
XRP(317), xrp_b.reward,
true});
5194BEAST_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_
SmBase(std::shared_ptr< ChainStateTracker > const &chainstate, BridgeDef const &bridge)
BridgeDef const & bridge_
ChainStateTrack & srcState()
jtx::Account const & srcDoor()
jtx::Account const & dstDoor()
ChainStateTrack & destState()
uint32_t issue_account_create()
SmCreateAccount(std::shared_ptr< ChainStateTracker > const &chainstate, BridgeDef const &bridge, AccountCreate create)
SmState advance(uint64_t time, uint32_t rnd)
void attest(uint64_t time, uint32_t rnd)
void distribute_reward(ChainStateTrack &st)
SmTransfer(std::shared_ptr< ChainStateTracker > const &chainstate, BridgeDef const &bridge, Transfer xfer)
SmState advance(uint64_t time, uint32_t rnd)
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
FeatureBitset testable_amendments()
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.
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, std::shared_ptr< ChainStateTracker > const &chainstate, BridgeDef const &bridge, AccountCreate ac)
void xfer(uint64_t time, std::shared_ptr< ChainStateTracker > const &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
STAmount const tiny_reward_split
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)
STAmount const tiny_reward
std::uint32_t const quorum
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)
STAmount const split_reward_everyone
STAmount const tiny_reward_remainder
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.