mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
featureDisallowIncoming: Opt-out of incoming Checks, PayChans, NFTokenOffers and Trustlines (#4336)
featureDisallowIncoming is a new amendment that would allow users to opt-out of incoming Checks, Payment Channels, NFTokenOffers, and trust lines. This commit includes tests. Adds four new AccountSet Flags: 1. asfDisallowIncomingNFTOffer 2. asfDisallowIncomingCheck 3. asfDisallowIncomingPayChan 4. asfDisallowIncomingTrustline
This commit is contained in:
@@ -26,9 +26,14 @@ namespace test {
|
||||
|
||||
class SetTrust_test : public beast::unit_test::suite
|
||||
{
|
||||
FeatureBitset const disallowIncoming{featureDisallowIncoming};
|
||||
|
||||
public:
|
||||
void
|
||||
testFreeTrustlines(bool thirdLineCreatesLE, bool createOnHighAcct)
|
||||
testFreeTrustlines(
|
||||
FeatureBitset features,
|
||||
bool thirdLineCreatesLE,
|
||||
bool createOnHighAcct)
|
||||
{
|
||||
if (thirdLineCreatesLE)
|
||||
testcase("Allow two free trustlines");
|
||||
@@ -36,7 +41,7 @@ public:
|
||||
testcase("Dynamic reserve for trustline");
|
||||
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
Env env(*this, features);
|
||||
|
||||
auto const gwA = Account{"gwA"};
|
||||
auto const gwB = Account{"gwB"};
|
||||
@@ -107,14 +112,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testTicketSetTrust()
|
||||
testTicketSetTrust(FeatureBitset features)
|
||||
{
|
||||
testcase("SetTrust using a ticket");
|
||||
|
||||
using namespace jtx;
|
||||
|
||||
// Verify that TrustSet transactions can use tickets.
|
||||
Env env{*this};
|
||||
Env env{*this, features};
|
||||
auto const gw = Account{"gateway"};
|
||||
auto const alice = Account{"alice"};
|
||||
auto const USD = gw["USD"];
|
||||
@@ -152,12 +157,12 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testMalformedTransaction()
|
||||
testMalformedTransaction(FeatureBitset features)
|
||||
{
|
||||
testcase("SetTrust checks for malformed transactions");
|
||||
|
||||
using namespace jtx;
|
||||
Env env{*this};
|
||||
Env env{*this, features};
|
||||
|
||||
auto const gw = Account{"gateway"};
|
||||
auto const alice = Account{"alice"};
|
||||
@@ -199,14 +204,17 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testModifyQualityOfTrustline(bool createQuality, bool createOnHighAcct)
|
||||
testModifyQualityOfTrustline(
|
||||
FeatureBitset features,
|
||||
bool createQuality,
|
||||
bool createOnHighAcct)
|
||||
{
|
||||
testcase << "SetTrust " << (createQuality ? "creates" : "removes")
|
||||
<< " quality of trustline for "
|
||||
<< (createOnHighAcct ? "high" : "low") << " account";
|
||||
|
||||
using namespace jtx;
|
||||
Env env{*this};
|
||||
Env env{*this, features};
|
||||
|
||||
auto const alice = Account{"alice"};
|
||||
auto const bob = Account{"bob"};
|
||||
@@ -249,20 +257,119 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
testDisallowIncoming(FeatureBitset features)
|
||||
{
|
||||
testFreeTrustlines(true, false);
|
||||
testFreeTrustlines(false, true);
|
||||
testFreeTrustlines(false, true);
|
||||
testcase("Create trustline with disallow incoming");
|
||||
|
||||
using namespace test::jtx;
|
||||
|
||||
// test flag doesn't set unless amendment enabled
|
||||
{
|
||||
Env env{*this, features - disallowIncoming};
|
||||
Account const alice{"alice"};
|
||||
env.fund(XRP(10000), alice);
|
||||
env(fset(alice, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
auto const sle = env.le(alice);
|
||||
uint32_t flags = sle->getFlags();
|
||||
BEAST_EXPECT(!(flags & lsfDisallowIncomingTrustline));
|
||||
}
|
||||
|
||||
Env env{*this, features | disallowIncoming};
|
||||
|
||||
auto const gw = Account{"gateway"};
|
||||
auto const alice = Account{"alice"};
|
||||
auto const bob = Account{"bob"};
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
env.fund(XRP(10000), gw, alice, bob);
|
||||
env.close();
|
||||
|
||||
// Set flag on gateway
|
||||
env(fset(gw, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
|
||||
// Create a trustline which will fail
|
||||
env(trust(alice, USD(1000)), ter(tecNO_PERMISSION));
|
||||
env.close();
|
||||
|
||||
// Unset the flag
|
||||
env(fclear(gw, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
|
||||
// Create a trustline which will now succeed
|
||||
env(trust(alice, USD(1000)));
|
||||
env.close();
|
||||
|
||||
// Now the payment succeeds.
|
||||
env(pay(gw, alice, USD(200)));
|
||||
env.close();
|
||||
|
||||
// Set flag on gateway again
|
||||
env(fset(gw, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
|
||||
// Destroy the balance by sending it back
|
||||
env(pay(gw, alice, USD(200)));
|
||||
env.close();
|
||||
|
||||
// The trustline still exists in default state
|
||||
// So a further payment should work
|
||||
env(pay(gw, alice, USD(200)));
|
||||
env.close();
|
||||
|
||||
// Also set the flag on bob
|
||||
env(fset(bob, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
|
||||
// But now bob can't open a trustline because he didn't already have one
|
||||
env(trust(bob, USD(1000)), ter(tecNO_PERMISSION));
|
||||
env.close();
|
||||
|
||||
// The gateway also can't open this trustline because bob has the flag
|
||||
// set
|
||||
env(trust(gw, bob["USD"](1000)), ter(tecNO_PERMISSION));
|
||||
env.close();
|
||||
|
||||
// Unset the flag only on the gateway
|
||||
env(fclear(gw, asfDisallowIncomingTrustline));
|
||||
env.close();
|
||||
|
||||
// Now bob can open a trustline
|
||||
env(trust(bob, USD(1000)));
|
||||
env.close();
|
||||
|
||||
// And the gateway can send bob a balance
|
||||
env(pay(gw, bob, USD(200)));
|
||||
env.close();
|
||||
}
|
||||
|
||||
void
|
||||
testWithFeats(FeatureBitset features)
|
||||
{
|
||||
testFreeTrustlines(features, true, false);
|
||||
testFreeTrustlines(features, false, true);
|
||||
testFreeTrustlines(features, false, true);
|
||||
// true, true case doesn't matter since creating a trustline ledger
|
||||
// entry requires reserve from the creator
|
||||
// independent of hi/low account ids for endpoints
|
||||
testTicketSetTrust();
|
||||
testMalformedTransaction();
|
||||
testModifyQualityOfTrustline(false, false);
|
||||
testModifyQualityOfTrustline(false, true);
|
||||
testModifyQualityOfTrustline(true, false);
|
||||
testModifyQualityOfTrustline(true, true);
|
||||
testTicketSetTrust(features);
|
||||
testMalformedTransaction(features);
|
||||
testModifyQualityOfTrustline(features, false, false);
|
||||
testModifyQualityOfTrustline(features, false, true);
|
||||
testModifyQualityOfTrustline(features, true, false);
|
||||
testModifyQualityOfTrustline(features, true, true);
|
||||
testDisallowIncoming(features);
|
||||
}
|
||||
|
||||
public:
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace test::jtx;
|
||||
auto const sa = supported_amendments();
|
||||
testWithFeats(sa - disallowIncoming);
|
||||
testWithFeats(sa);
|
||||
}
|
||||
};
|
||||
BEAST_DEFINE_TESTSUITE(SetTrust, app, ripple);
|
||||
|
||||
Reference in New Issue
Block a user