Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XLS-XXd: SelfPaymentMakesTrustline #3

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 79;
static constexpr std::size_t numFeatures = 80;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down Expand Up @@ -372,6 +372,7 @@ extern uint256 const fixEnforceNFTokenTrustline;
extern uint256 const fixInnerObjTemplate2;
extern uint256 const featureInvariantsV1_1;
extern uint256 const fixNFTokenPageLinks;
extern uint256 const featureSelfPaymentMakesTrustline;

} // namespace ripple

Expand Down
1 change: 1 addition & 0 deletions src/libxrpl/protocol/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ REGISTER_FIX (fixReducedOffersV2, Supported::yes, VoteBehavior::De
REGISTER_FIX (fixEnforceNFTokenTrustline, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixInnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixNFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(SelfPaymentMakesTrustline, Supported::yes, VoteBehavior::DefaultNo);
// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
REGISTER_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo);
Expand Down
235 changes: 233 additions & 2 deletions src/test/app/Flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ getNoRippleFlag(

struct Flow_test : public beast::unit_test::suite
{
// Helper function that returns the owner count on an account.
std::uint32_t
ownerCount(test::jtx::Env const& env, test::jtx::Account const& account)
{
std::uint32_t ret{0};
if (auto const sleAccount = env.le(account))
ret = sleAccount->at(sfOwnerCount);
return ret;
}

void
testDirectStep(FeatureBitset features)
{
Expand Down Expand Up @@ -964,8 +974,16 @@ struct Flow_test : public beast::unit_test::suite
{
auto const offer = *offerPtr;
BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER);
BEAST_EXPECT(offer[sfTakerGets] == EUR(594));
BEAST_EXPECT(offer[sfTakerPays] == USD(495));
if (features[featureSelfPaymentMakesTrustline])
{
BEAST_EXPECT(offer[sfTakerGets] == EUR(540));
BEAST_EXPECT(offer[sfTakerPays] == USD(450));
}
else
{
BEAST_EXPECT(offer[sfTakerGets] == EUR(594));
BEAST_EXPECT(offer[sfTakerPays] == USD(495));
}
}
}
void
Expand Down Expand Up @@ -1404,12 +1422,223 @@ struct Flow_test : public beast::unit_test::suite
env.require(balance(alice, XRP(9000) - drops(20)));
}

void
testSelfPaymentMakesTrustline(FeatureBitset features)
{
testcase("SelfPaymentMakesTrustline");

using namespace jtx;

auto const alice = Account("alice");
auto const bob = Account("bob");
auto const gw = Account("gw");

auto const USD = gw["USD"];
auto const EUR = gw["EUR"];

{
// XRP -> IOU
Env env(*this, features);
auto const selfPaymentMakesTrustline =
features[featureSelfPaymentMakesTrustline];

env.fund(XRP(10000), alice, gw);

env(offer(gw, XRP(1000), USD(1000)));
env.close();

TER const expectedTER = selfPaymentMakesTrustline
? static_cast<TER>(tesSUCCESS)
: static_cast<TER>(tecPATH_DRY);

// payment without trustline
env(pay(alice, alice, USD(10)), sendmax(XRP(10)), ter(expectedTER));
env.close();
auto const expectedOwnerCount = selfPaymentMakesTrustline ? 1 : 0;
// BEAST_EXPECT(owners(env, alice) == expectedOwnerCount);
env.require(owners(alice, expectedOwnerCount));
if (selfPaymentMakesTrustline)
{
auto jrr = ledgerEntryState(env, alice, gw, "USD");
BEAST_EXPECT(
jrr[jss::node][sfBalance.fieldName][jss::value] == "-10");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.fieldName][jss::value] == "0");
}

// payment with trustline (limit over)
env(pay(alice, alice, USD(20)), sendmax(XRP(20)), ter(expectedTER));
env.close();
if (selfPaymentMakesTrustline)
{
auto jrr = ledgerEntryState(env, alice, gw, "USD");
BEAST_EXPECT(
jrr[jss::node][sfBalance.fieldName][jss::value] == "-30");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.fieldName][jss::value] == "0");
}

// payment with trustline (limit not over)
env.trust(USD(10000), alice);
env(pay(alice, alice, USD(40)), sendmax(XRP(40)));
env.close();
if (selfPaymentMakesTrustline)
{
auto jrr = ledgerEntryState(env, alice, gw, "USD");
// shoud 30
BEAST_EXPECT(
jrr[jss::node][sfBalance.fieldName][jss::value] == "-70");
// should 30
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.fieldName][jss::value] ==
"10000");
}
}

{
// IOU -> IOU
Env env(*this, features);

env.fund(XRP(10000), alice, gw);

env.trust(EUR(10000), alice);
env(pay(gw, alice, EUR(100)));

env(offer(gw, EUR(100), USD(100)));
env.close();

// BEAST_EXPECT(owners(env, alice) == 1);
env.require(owners(alice, 1));

TER const expectedTER = features[featureSelfPaymentMakesTrustline]
? static_cast<TER>(tesSUCCESS)
: static_cast<TER>(tecPATH_DRY);

// payment without trustline
env(pay(alice, alice, USD(10)), sendmax(EUR(10)), ter(expectedTER));
env.close();
auto const expectedOwnerCount =
features[featureSelfPaymentMakesTrustline] ? 2 : 1;
// BEAST_EXPECT(owners(env, alice) == expectedOwnerCount);
env.require(owners(alice, expectedOwnerCount));
}

{
// Inssufficient reserve
Env env(*this, features);

auto const fee = env.current()->fees().base;
env.fund(XRP(10000), gw);
env.fund(reserve(env, 0) + fee * 1, alice);

env(offer(gw, XRP(100), USD(100)));
env.close();

TER const expectedTER = features[featureSelfPaymentMakesTrustline]
? static_cast<TER>(tecNO_LINE_INSUF_RESERVE)
: static_cast<TER>(tecPATH_DRY);
env(pay(alice, alice, USD(100)),
sendmax(XRP(100)),
ter(expectedTER));
env.close();
}

{
// trustline to self doesn't allowed
Env env(*this, features);

env.fund(XRP(10000), gw);

env(pay(gw, gw, USD(100)), sendmax(XRP(100)), ter(tecPATH_PARTIAL));
env.close();
}

{
// RequireAuth trustline to self doesn't allowed
Env env(*this, features);

env.fund(XRP(10000), gw, alice);

env(fset(gw, asfRequireAuth));
env.close();

env(offer(gw, XRP(100), USD(100)));

env(pay(alice, alice, USD(10)), sendmax(XRP(10)), ter(tecPATH_DRY));
env.close();
}

{
// Payment to other does't make trustline
Env env(*this, features);

env.fund(XRP(10000), gw, alice, bob);

env.trust(USD(10000), alice);
env(pay(gw, alice, USD(100)));

env(pay(alice, bob, USD(100)), ter(tecPATH_DRY));
env.close();
}

{
// Patial payment
// XRP -> IOU
Env env(*this, features);
auto const selfPaymentMakesTrustline =
features[featureSelfPaymentMakesTrustline];

env.fund(XRP(10000), alice, gw);

env(offer(gw, XRP(100), USD(100)));
env.close();

TER const expectedTER = selfPaymentMakesTrustline
? static_cast<TER>(tesSUCCESS)
: static_cast<TER>(tecPATH_DRY);

// payment without trustline
env(pay(alice, alice, USD(10)),
sendmax(XRP(5)),
txflags(tfPartialPayment),
ter(expectedTER));
env.close();
auto const expectedOwnerCount = selfPaymentMakesTrustline ? 1 : 0;
// BEAST_EXPECT(owners(env, alice) == expectedOwne..rCount);
env.require(owners(alice, expectedOwnerCount));
if (selfPaymentMakesTrustline)
{
auto jrr = ledgerEntryState(env, alice, gw, "USD");
BEAST_EXPECT(
jrr[jss::node][sfBalance.fieldName][jss::value] == "-5");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.fieldName][jss::value] == "0");
}

// payment with trustline
env(pay(alice, alice, USD(10)),
sendmax(XRP(1)),
txflags(tfPartialPayment),
ter(expectedTER));
if (selfPaymentMakesTrustline)
{
auto jrr = ledgerEntryState(env, alice, gw, "USD");
BEAST_EXPECT(
jrr[jss::node][sfBalance.fieldName][jss::value] == "-6");
BEAST_EXPECT(
jrr[jss::node][sfHighLimit.fieldName][jss::value] == "0");
}
}
}

void
testWithFeats(FeatureBitset features)
{
using namespace jtx;
FeatureBitset const ownerPaysFee{featureOwnerPaysFee};
FeatureBitset const reducedOffersV2(fixReducedOffersV2);
FeatureBitset const selfPaymentMakesTrustline{
featureSelfPaymentMakesTrustline};

testLineQuality(features);
testFalseDry(features);
Expand All @@ -1427,6 +1656,8 @@ struct Flow_test : public beast::unit_test::suite
testReexecuteDirectStep(features);
testSelfPayLowQualityOffer(features);
testTicketPay(features);
testSelfPaymentMakesTrustline(features - selfPaymentMakesTrustline);
testSelfPaymentMakesTrustline(features);
}

void
Expand Down
Loading
Loading