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];
220 this->
fund(xrp_funds, s.account);
235 this->
fund(xrp_funds, ra);
238 this->
fund(xrp_funds, s.account);
288 :
from_(env, from_acct)
294 for (
size_t i = 0; i < num_payees; ++i)
326 [&](
const balance& b) { return b.diff() == reward; });
340 bool check_payer =
true)
408 bool exceptionPresent =
false;
411 exceptionPresent =
false;
416 exceptionPresent =
true;
419 BEAST_EXPECT(!exceptionPresent);
423 exceptionPresent =
false;
424 jBridge[
"Extra"] = 1;
429 exceptionPresent =
true;
432 BEAST_EXPECT(exceptionPresent);
607 testcase(
"Bridge create constraints");
608 XEnv env(*
this,
true);
612 auto AUSD = A[
"USD"];
613 auto BUSD = B[
"USD"];
614 auto CUSD = C[
"USD"];
615 auto GUSD =
scGw[
"USD"];
616 auto AEUR = A[
"EUR"];
617 auto BEUR = B[
"EUR"];
618 auto CEUR = C[
"EUR"];
619 auto GEUR =
scGw[
"EUR"];
629 env.
fund(
XRP(10000), a1, a2, a3, a4, a5, a6);
652 auto const goodBridge1 =
bridge(A, GUSD, B, BUSD);
653 auto const goodBridge2 =
bridge(A, BUSD, C, CUSD);
671 .
tx(
pay(B, C, BUSD(1000)))
673 auto const aBalanceStart = env.
balance(A, BUSD);
674 auto const cBalanceStart = env.
balance(C, BUSD);
676 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(0));
677 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50));
679 BEAST_EXPECT(env.
balance(A, BUSD) - aBalanceStart == BUSD(60));
680 BEAST_EXPECT(env.
balance(C, BUSD) - cBalanceStart == BUSD(-50 - 60));
684 BEAST_EXPECT((*env.
bridge(goodBridge1))[sfSignatureReward] ==
XRP(33));
686 BEAST_EXPECT((*env.
bridge(goodBridge2))[sfSignatureReward] ==
XRP(44));
736 "Locking chain is IOU(locking chain door)",
737 [&](
auto& env,
bool) {
742 "Locking chain is IOU(issuing chain door funded on locking "
744 [&](
auto& env,
bool shouldFund) {
751 "Locking chain is IOU(issuing chain door account unfunded "
753 [&](
auto& env,
bool) {
758 "Locking chain is IOU(bob funded on locking chain)",
759 [&](
auto& env,
bool) {
764 "Locking chain is IOU(bob unfunded on locking chain)",
765 [&](
auto& env,
bool) {
776 "Issuing chain is IOU(issuing chain door account)",
777 [&](
auto& env,
bool) {
782 "Issuing chain is IOU(locking chain door funded on issuing "
784 [&](
auto& env,
bool shouldFund) {
791 "Issuing chain is IOU(locking chain door unfunded on "
793 [&](
auto& env,
bool) {
798 "Issuing chain is IOU(bob funded on issuing chain)",
799 [&](
auto& env,
bool) {
804 "Issuing chain is IOU(bob unfunded on issuing chain)",
805 [&](
auto& env,
bool) {
810 "Issuing chain is XRP and issuing chain door account is "
811 "not the root account",
812 [&](
auto& env,
bool) {
817 "Issuing chain is XRP and issuing chain door account is "
819 [&](
auto& env,
bool) {
870 auto testcase = [&](
auto const& lc,
auto const& ic) {
872 XEnv scEnv(*
this,
true);
874 lc.second(mcEnv,
true);
875 lc.second(scEnv,
false);
877 ic.second(mcEnv,
false);
878 ic.second(scEnv,
true);
880 auto const& expected = expected_result[test_result.
size()];
897 auto apply_ics = [&](
auto const& lc,
auto const& ics) {
899 [&](
auto const&... ic) { (
testcase(lc, ic), ...); }, ics);
902 std::apply([&](
auto const&... lc) { (apply_ics(lc, ics), ...); }, lcs);
904#if GENERATE_MTX_OUTPUT
909 std::cout <<
"Markdown output for matrix test: " << fname <<
"\n";
915 if (std::get<2>(tup))
924 auto output_table = [&](
auto print_res) {
930 res +=
"| `issuing ->` | ";
932 [&](
auto const&... ic) {
933 ((res += ic.first, res +=
" | "), ...);
940 [&](
auto const&... ic) {
941 (((void)ic.first, res +=
":---: | "), ...);
946 auto output = [&](
auto const& lc,
auto const& ic) {
947 res += print_res(test_result[test_idx]);
952 auto output_ics = [&](
auto const& lc,
auto const& ics) {
957 [&](
auto const&... ic) { (output(lc, ic), ...); }, ics);
962 [&](
auto const&... lc) { (output_ics(lc, ics), ...); }, lcs);
970 std::cout <<
"ter output for matrix test: " << ter_fname <<
"\n";
973 for (
auto& t : test_result)
1034 for (
auto withClaim : {
false,
true})
1037 XEnv scEnv(*
this,
true);
1048 auto const amt =
XRP(1000);
1089 for (
auto withClaim : {
false,
true})
1092 XEnv scEnv(*
this,
true);
1103 auto const amt =
XRP(1000);
1152 for (
auto withClaim : {
false,
true})
1155 XEnv scEnv(*
this,
true);
1166 auto const amt =
XRP(1000);
1291 using namespace jtx;
1308 XEnv xenv(*
this,
true);
1316 BEAST_EXPECT(scAlice_bal.
diff() == -tx_fee);
1381 using namespace jtx;
1396 auto const amt =
XRP(1000);
1404 BEAST_EXPECT(alice_bal.
diff() == -(claim_cost + tx_fee));
1517 using namespace jtx;
1533 for (
auto withClaim : {
true})
1536 XEnv scEnv(*
this,
true);
1550 auto const amt =
XRP(1000);
1602 for (
auto withClaim : {
false,
true})
1605 XEnv scEnv(*
this,
true);
1609 constexpr int numSigners = 4;
1614 for (
int i = 0; i < numSigners; ++i)
1616 using namespace std::literals;
1634 auto const amt =
XRP(1000);
1677 for (
auto withClaim : {
false,
true})
1680 XEnv scEnv(*
this,
true);
1684 constexpr int numSigners = 4;
1689 for (
int i = 0; i < numSigners; ++i)
1691 using namespace std::literals;
1711 auto const amt =
XRP(1000);
1755 for (
auto withClaim : {
false,
true})
1758 XEnv scEnv(*
this,
true);
1762 constexpr int numSigners = 4;
1767 for (
int i = 0; i < numSigners; ++i)
1769 using namespace std::literals;
1788 auto const amt =
XRP(1000);
1830 for (
auto withClaim : {
false,
true})
1833 XEnv scEnv(*
this,
true);
1837 constexpr int numSigners = 4;
1842 for (
int i = 0; i < numSigners; ++i)
1844 using namespace std::literals;
1863 auto const amt =
XRP(1000);
1913 XEnv scEnv(*
this,
true);
1914 auto const amt =
XRP(1000);
1915 auto const amt_plus_reward = amt +
reward;
1935 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
1955 BEAST_EXPECT(attester.
diff() == -multiTtxFee(6));
1975 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
1993 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2009 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2011 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2031 BEAST_EXPECT(attester.
diff() == -multiTtxFee(3));
2047 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2048 BEAST_EXPECT(attester.
diff() == -tx_fee);
2063 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2064 BEAST_EXPECT(attester.
diff() == -tx_fee);
2076 XEnv scEnv(*
this,
true);
2078 auto const amt = res0 -
XRP(1);
2079 auto const amt_plus_reward = amt +
reward;
2092 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2093 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2113 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2122 XEnv scEnv(*
this,
true);
2124 auto const amt =
XRP(111);
2125 auto const amt_plus_reward = amt +
reward;
2138 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2139 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2160 BEAST_EXPECT(door.
diff() == -amt_plus_reward);
2161 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2162 BEAST_EXPECT(alice.
diff() == amt);
2169 XEnv scEnv(*
this,
true);
2171 auto const amt =
XRP(1000);
2172 auto const amt_plus_reward = amt +
reward;
2185 BEAST_EXPECT(door.
diff() == amt_plus_reward);
2186 BEAST_EXPECT(carol.
diff() == -(amt_plus_reward + tx_fee));
2209 BEAST_EXPECT(attester.
diff() == -multiTtxFee(4));
2220 XEnv scEnv(*
this,
true);
2221 auto const amt =
XRP(1000);
2222 auto const amt_plus_reward = amt +
reward;
2244 BEAST_EXPECT(carol.
diff() == -(amt +
reward + tx_fee));
2255 auto const bad_amt =
XRP(10);
2266 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 1),
"claim id 1 created");
2267 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 2),
"claim id 2 created");
2268 BEAST_EXPECTS(!!scEnv.
caClaimID(
jvb, 3),
"claim id 3 created");
2302 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 deleted");
2303 BEAST_EXPECTS(scEnv.
claimCount(
jvb) == 1,
"scuAlice created");
2312 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 2),
"claim id 2 deleted");
2313 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 1),
"claim id 1 not added");
2321 BEAST_EXPECTS(!scEnv.
caClaimID(
jvb, 3),
"claim id 3 deleted");
2332 BEAST_EXPECT(attester.
diff() == -multiTtxFee(txCount));
2345 XEnv scEnv(*
this,
true);
2367 XEnv scEnv(*
this,
true);
2390 using namespace jtx;
2392 testcase(
"Add Non Batch Claim Attestation");
2396 XEnv scEnv(*
this,
true);
2410 auto const amt =
XRP(1000);
2413 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2415 for (
int i = 0; i <
signers.size(); ++i)
2428 TER const expectedTER =
2436 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2439 dstStartBalance + amt == scEnv.
env_.
balance(dst));
2441 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2462 XEnv scEnv(*
this,
true);
2463 auto const amt =
XRP(1000);
2479 auto const dstStartBalance = scEnv.
env_.
balance(dst);
2513 att[sfAttestationSignerAccount.getJsonName()] =
2520 auto const unfundedSigner1 =
2522 auto const unfundedSigner2 =
2534 att[sfAttestationSignerAccount.getJsonName()] =
2535 unfundedSigner2.account.human();
2538 att[sfAttestationSignerAccount.getJsonName()] =
2539 unfundedSigner1.
account.human();
2556 tempSignerList.
front());
2557 att[sfAttestationSignerAccount.getJsonName()] =
2605 att.removeMember(sfAttestationSignerAccount.getJsonName());
2607 BEAST_EXPECT(dstStartBalance == scEnv.
env_.
balance(dst));
2608 att[sfAttestationSignerAccount.getJsonName()] =
2611 BEAST_EXPECT(dstStartBalance + amt == scEnv.
env_.
balance(dst));
2619 using namespace jtx;
2621 testcase(
"Add Non Batch Account Create Attestation");
2624 XEnv scEnv(*
this,
true);
2632 mcEnv.
fund(funds, a);
2633 mcEnv.
fund(funds, doorA);
2648 xrp_b.initBridge(mcEnv, scEnv);
2650 auto const amt =
XRP(777);
2651 auto const amt_plus_reward = amt + xrp_b.reward;
2653 Balance bal_doorA(mcEnv, doorA);
2658 a, xrp_b.jvb, ua, amt, xrp_b.reward))
2661 BEAST_EXPECT(bal_doorA.
diff() == amt_plus_reward);
2662 BEAST_EXPECT(bal_a.
diff() == -(amt_plus_reward + tx_fee));
2665 for (
int i = 0; i <
signers.size(); ++i)
2678 TER const expectedTER = i < xrp_b.quorum
2683 if (i + 1 < xrp_b.quorum)
2684 BEAST_EXPECT(!scEnv.
env_.
le(ua));
2686 BEAST_EXPECT(scEnv.
env_.
le(ua));
2688 BEAST_EXPECT(scEnv.
env_.
le(ua));
2694 using namespace jtx;
2705 for (
auto withClaim : {
false,
true})
2708 XEnv scEnv(*
this,
true);
2719 auto const amt =
XRP(1000);
2759 for (
auto withClaim : {
false,
true})
2762 XEnv scEnv(*
this,
true);
2774 auto const amt =
XRP(1000);
2809 for (
auto withClaim : {
false,
true})
2812 XEnv scEnv(*
this,
true);
2825 auto const amt =
XRP(1000);
2858 for (
auto withClaim : {
false,
true})
2861 XEnv scEnv(*
this,
true);
2877 auto const amt =
XRP(1000);
2916 for (
auto withClaim : {
false,
true})
2919 XEnv scEnv(*
this,
true);
2930 auto const amt =
XRP(1000);
2967 for (
auto withClaim : {
false,
true})
2970 XEnv scEnv(*
this,
true);
2981 auto const amt =
XRP(1000);
3026 for (
auto withClaim : {
false,
true})
3029 XEnv scEnv(*
this,
true);
3040 auto const amt =
XRP(1000);
3066 for (
auto withClaim : {
false,
true})
3069 XEnv scEnv(*
this,
true);
3080 auto const amt =
XRP(1000);
3087 auto tooFew =
quorum - 1;
3117 for (
auto withClaim : {
false,
true})
3120 XEnv scEnv(*
this,
true);
3131 auto const amt =
XRP(1000);
3171 for (
auto withClaim : {
true})
3174 XEnv scEnv(*
this,
true);
3185 auto const amt =
XRP(1000);
3227 for (
auto withClaim : {
true})
3230 XEnv scEnv(*
this,
true);
3241 auto const amt =
XRP(1000);
3283 for (
auto withClaim : {
false,
true})
3286 XEnv scEnv(*
this,
true);
3299 auto const amt =
XRP(1000);
3350 scEnv.
tx(txns.back());
3367 for (
auto withClaim : {
false,
true})
3370 XEnv scEnv(*
this,
true);
3385 auto const amt =
XRP(1000);
3421 for (
auto withClaim : {
false,
true})
3424 XEnv scEnv(*
this,
true);
3436 auto const amt =
XRP(1000);
3464 scEnv.
tx(txns.back()).
close();
3480 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3484 scEnv.
tx(txns.back()).
close();
3497 scEnv.
tx(txns.back()).
close();
3498 BEAST_EXPECT(scBob_bal.
diff() == amt);
3504 for (
auto withClaim : {
false,
true})
3507 XEnv scEnv(*
this,
true);
3519 auto const amt =
XRP(1000);
3547 scEnv.
tx(txns.back()).
close();
3562 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3566 scEnv.
tx(txns.back()).
close();
3580 scEnv.
tx(txns.back()).
close();
3581 BEAST_EXPECT(scBob_bal.
diff() == amt);
3591 XEnv scEnv(*
this,
true);
3603 auto const amt =
XRP(1000);
3628 BEAST_EXPECT(scCarol_bal.
diff() == amt);
3633 for (
auto withClaim : {
true})
3636 XEnv scEnv(*
this,
true);
3647 auto const amt =
XRP(1000);
3686 for (
auto withClaim : {
false,
true})
3689 XEnv scEnv(*
this,
true);
3700 auto const amt =
XRP(1000);
3733 claim_cost += tx_fee;
3738 scAlice_bal.
diff() == -claim_cost);
3744 for (
auto withClaim : {
false,
true})
3747 XEnv scEnv(*
this,
true);
3758 auto const amt =
XRP(1000);
3790 claim_cost += tx_fee;
3803 for (
auto withClaim : {
false,
true})
3806 XEnv scEnv(*
this,
true);
3811 alt_payees.back() =
Account(
"inexistent");
3820 auto const amt =
XRP(1000);
3858 for (
auto withClaim : {
false,
true})
3861 XEnv scEnv(*
this,
true);
3873 auto const amt =
XRP(1000);
3878 Balance last_signer(scEnv, unpaid);
3950 using namespace jtx;
3957 XEnv scEnv(*
this,
true);
3959 auto const amt =
XRP(111);
3960 auto const amt_plus_reward = amt +
reward;
4004 BEAST_EXPECT(carol.
diff() == -tx_fee);
4091 BEAST_EXPECT(door.
diff() == -tx_fee);
4115 using namespace jtx;
4138 auto const minAccountCreate =
XRP(20);
4165 using namespace jtx;
4167 testcase(
"Bridge Delete Door Account");
4169 auto const acctDelFee{
4180 for (
size_t i = 0; i < 256; ++i)
4192 XEnv scEnv(*
this,
true);
4201 for (
size_t i = 0; i < 256; ++i)
4215 using namespace jtx;
4220 XEnv scEnv(*
this,
true);
4223 auto const amt =
XRP(1000);
4241 auto k = jvAtt[
"PublicKey"].asString();
4243 jvAtt[
"PublicKey"] = k;
4250 XEnv scEnv(*
this,
true);
4253 auto const amt =
XRP(1000);
4254 auto const rewardAmt =
XRP(1);
4271 auto k = jvAtt[
"PublicKey"].asString();
4273 jvAtt[
"PublicKey"] = k;
4374 for (
auto const& c : claims)
4388 size_t num_successful = 0;
4389 for (
auto const& c : claims)
4400 return num_successful;
4406 bool callback_called;
4413 callback_called =
false;
4421 auto& create_claims =
4422 claims.create_claims[c.claim_count];
4423 auto num_attns = create_claims.size();
4427 i,
bridge, create_claims);
4429 assert(claims.create_claims[c.claim_count].empty());
4434 if (c.num_create_attn_sent >=
bridge->quorum)
4436 callback_called =
true;
4437 c.create_callbacks[c.claim_count](c.signers);
4439 c.num_create_attn_sent = 0;
4443 }
while (callback_called);
4468 it->second.expectedDiff +=
4506 for (
auto const& [acct, state] :
accounts)
4507 if (!state.verify(
env, acct))
4600 return static_cast<T&
>(*this).a2b() ?
st_->a_ :
st_->b_;
4606 return static_cast<T&
>(*this).a2b() ?
st_->b_ :
st_->a_;
4702 if (counters.create_callbacks.size() <
cr.
claim_id)
4703 counters.create_callbacks.resize(
cr.
claim_id);
4706 auto num_attestors =
signers.size();
4712 assert(
cr.
claim_id - 1 == counters.claim_count);
4726 counters.create_callbacks[
cr.
claim_id - 1] = std::move(complete_cb);
4957 bool verify_balances =
true)
4959 using namespace jtx;
4969 auto vis = [&](
auto& sm) {
4970 uint32_t rnd = distrib(gen);
4971 return sm.advance(time, rnd);
4973 auto& [t, sm] = *it;
4981 st->sendAttestations();
4987 if (verify_balances)
4989 BEAST_EXPECT(st->verify());
4997 using namespace jtx;
4999 testcase(
"Bridge usage simulation");
5002 XEnv scEnv(*
this,
true);
5004 auto st = std::make_shared<ChainStateTracker>(mcEnv, scEnv);
5008 Account doorXRPLocking(
"doorXRPLocking"),
5009 doorUSDLocking(
"doorUSDLocking"), doorUSDIssuing(
"doorUSDIssuing");
5011 constexpr size_t num_acct = 10;
5012 auto a = [&doorXRPLocking, &doorUSDLocking, &doorUSDIssuing]() {
5013 using namespace std::literals;
5016 for (
int i = 0; i < num_acct; ++i)
5021 doorXRPLocking = result.
back();
5023 doorUSDLocking = result.
back();
5025 doorUSDIssuing = result.
back();
5029 for (
auto& acct : a)
5033 mcEnv.
fund(amt, acct);
5034 scEnv.
fund(amt, acct);
5036 Account USDLocking{
"USDLocking"};
5037 IOU usdLocking{USDLocking[
"USD"]};
5038 IOU usdIssuing{doorUSDIssuing[
"USD"]};
5040 mcEnv.
fund(
XRP(100000), USDLocking);
5042 mcEnv.
tx(
trust(doorUSDLocking, usdLocking(100000)));
5044 mcEnv.
tx(
pay(USDLocking, doorUSDLocking, usdLocking(50000)));
5046 for (
int i = 0; i < a.size(); ++i)
5051 mcEnv.
tx(
trust(acct, usdLocking(100000)));
5052 scEnv.
tx(
trust(acct, usdIssuing(100000)));
5057 st->init(s.account);
5062 constexpr size_t num_ua = 20;
5064 using namespace std::literals;
5067 for (
int i = 0; i < num_ua; ++i)
5075 auto initBridge = [&mcEnv, &scEnv, &st](
BridgeDef& bd) {
5076 bd.initBridge(mcEnv, scEnv);
5077 st->a_.spendFee(bd.doorA, 2);
5078 st->b_.spendFee(bd.doorB, 2);
5116 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
true});
5117 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
true});
5122 ac(0, st, xrp_b, {a[0], ua[0],
XRP(777), xrp_b.reward,
false});
5123 xfer(8, st, xrp_b, {a[0], ua[0], a[2],
XRP(3),
false});
5130 xfer(1, st, xrp_b, {a[1], a[1], a[1],
XRP(1),
true});
5131 xfer(2, st, xrp_b, {a[0], a[0], a[1],
XRP(3),
false});
5132 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(5),
false});
5134 xfer(2, st, xrp_b, {a[1], a[1], a[1],
XRP(9),
true});
5139 xfer(0, st, usd_b, {a[0], a[1], a[2], usdLocking(3),
true});
5144 xfer(0, st, usd_b, {a[0], a[0], a[1], usdLocking(6),
true});
5145 xfer(1, st, usd_b, {a[0], a[0], a[1], usdIssuing(8),
false});
5146 xfer(1, st, usd_b, {a[1], a[1], a[1], usdLocking(1),
true});
5147 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(3),
false});
5148 xfer(2, st, usd_b, {a[1], a[1], a[1], usdIssuing(5),
false});
5149 xfer(2, st, usd_b, {a[0], a[0], a[1], usdIssuing(7),
false});
5150 xfer(2, st, usd_b, {a[1], a[1], a[1], usdLocking(9),
true});
5155 xfer(0, st, xrp_b, {a[0], a[0], a[0],
XRP(1),
true});
5156 xfer(0, st, usd_b, {a[1], a[3], a[3], usdIssuing(3),
false});
5157 xfer(0, st, usd_b, {a[3], a[2], a[1], usdIssuing(5),
false});
5159 xfer(1, st, xrp_b, {a[0], a[0], a[0],
XRP(4),
false});
5160 xfer(1, st, xrp_b, {a[1], a[1], a[0],
XRP(8),
true});
5161 xfer(1, st, usd_b, {a[4], a[1], a[1], usdLocking(7),
true});
5163 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(7),
true});
5164 xfer(3, st, xrp_b, {a[0], a[4], a[3],
XRP(2),
false});
5165 xfer(3, st, xrp_b, {a[1], a[1], a[0],
XRP(9),
true});
5166 xfer(3, st, usd_b, {a[3], a[1], a[1], usdIssuing(11),
false});
5171 ac(0, st, xrp_b, {a[0], ua[1],
XRP(301), xrp_b.reward,
true});
5172 ac(0, st, xrp_b, {a[1], ua[2],
XRP(302), xrp_b.reward,
true});
5173 ac(1, st, xrp_b, {a[0], ua[3],
XRP(303), xrp_b.reward,
true});
5174 ac(2, st, xrp_b, {a[1], ua[4],
XRP(304), xrp_b.reward,
true});
5175 ac(3, st, xrp_b, {a[0], ua[5],
XRP(305), xrp_b.reward,
true});
5176 ac(4, st, xrp_b, {a[1], ua[6],
XRP(306), xrp_b.reward,
true});
5177 ac(6, st, xrp_b, {a[0], ua[7],
XRP(307), xrp_b.reward,
true});
5178 ac(7, st, xrp_b, {a[2], ua[8],
XRP(308), xrp_b.reward,
true});
5179 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5180 ac(9, st, xrp_b, {a[0], ua[9],
XRP(309), xrp_b.reward,
true});
5181 ac(10, st, xrp_b, {a[0], ua[10],
XRP(310), xrp_b.reward,
true});
5182 ac(12, st, xrp_b, {a[0], ua[11],
XRP(311), xrp_b.reward,
true});
5183 ac(12, st, xrp_b, {a[3], ua[12],
XRP(312), xrp_b.reward,
true});
5184 ac(12, st, xrp_b, {a[4], ua[13],
XRP(313), xrp_b.reward,
true});
5185 ac(12, st, xrp_b, {a[3], ua[14],
XRP(314), xrp_b.reward,
true});
5186 ac(12, st, xrp_b, {a[6], ua[15],
XRP(315), xrp_b.reward,
true});
5187 ac(13, st, xrp_b, {a[7], ua[16],
XRP(316), xrp_b.reward,
true});
5188 ac(15, st, xrp_b, {a[3], ua[17],
XRP(317), xrp_b.reward,
true});
5200BEAST_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)
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
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.