Skip to content

Commit

Permalink
RXI-1153 Credentials unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Aug 31, 2024
1 parent 0ac3ab3 commit 0cb86b1
Show file tree
Hide file tree
Showing 17 changed files with 2,144 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/xrpl/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ JSS(Fee); // in/out: TransactionSign; field.
JSS(FeeSettings); // ledger type.
JSS(Flags); // in/out: TransactionSign; field.
JSS(Invalid); //
JSS(Issuer); // in: Credential transactions
JSS(LastLedgerSequence); // in: TransactionSign; field
JSS(LastUpdateTime); // field.
JSS(LedgerHashes); // ledger type.
Expand Down Expand Up @@ -145,6 +146,7 @@ JSS(Signature); // in: Credential transactions
JSS(SignerList); // ledger type.
JSS(SignerListSet); // transaction type.
JSS(SigningPubKey); // field.
JSS(Subject); // in: Credential transactions
JSS(TakerGets); // field.
JSS(TakerPays); // field.
JSS(Ticket); // ledger type.
Expand Down
111 changes: 111 additions & 0 deletions src/test/app/AccountDelete_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,116 @@ class AccountDelete_test : public beast::unit_test::suite
env.close();
}

void
testDestCreds()
{
{
testcase("Destination Constraints with Credentials");

using namespace test::jtx;

Account const alice{"alice"};
Account const becky{"becky"};
Account const carol{"carol"};

const char credType[] = "abcd";

Env env{*this};
env.fund(XRP(100000), alice, becky, carol);
env.close();

// carol issue credentials for becky
env(credentials::create(becky, carol, credType));
env.close();
// becky accept the credentials
env(credentials::accept(becky, carol, credType));
env.close();
// get credentials index
auto const jCred =
credentials::ledgerEntryCredential(env, becky, carol, credType);
std::string const credIdx =
jCred[jss::result][jss::index].asString();

// alice sets the lsfDepositAuth flag on her account. This should
// prevent becky from deleting her account while using alice as the
// destination.
env(fset(alice, asfDepositAuth), fee(drops(10)));
env.close();
// and create DepositPreauth Object
env(deposit::auth(
alice,
std::vector<deposit::AuthorizeCredentials>{{carol, credType}}));
env.close();

// Close enough ledgers to be able to delete becky's account.
incLgrSeqForAccDel(env, becky);

auto const acctDelFee{drops(env.current()->fees().increment)};

// becky attempts to delete her account, but alice won't take her
// XRP, so the delete is blocked.
env(acctdelete(becky, alice),
fee(acctDelFee),
ter(tecNO_PERMISSION));
env.close();

// becky use bad credentials and can't delete account
env(acctdelete(
becky,
alice,
{"48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6E"
"A288BE4"}),
fee(acctDelFee),
ter(temBAD_CREDENTIALS));
env.close();

// becky use credentials and can delete account
env(acctdelete(becky, alice, {credIdx}), fee(acctDelFee));
env.close();

// check that credential object deleted too
auto const jNoCred =
credentials::ledgerEntryCredential(env, becky, carol, credType);
BEAST_EXPECT(
jNoCred.isObject() && jNoCred.isMember(jss::result) &&
jNoCred[jss::result].isMember(jss::error));
}

{
testcase("Credentials feature disabled");
using namespace test::jtx;

Account const alice{"alice"};
Account const becky{"becky"};
Account const carol{"carol"};

Env env{*this, supported_amendments() - featureCredentials};
env.fund(XRP(100000), alice, becky, carol);
env.close();

// alice sets the lsfDepositAuth flag on her account. This should
// prevent becky from deleting her account while using alice as the
// destination.
env(fset(alice, asfDepositAuth), fee(drops(10)));
env.close();

// Close enough ledgers to be able to delete becky's account.
incLgrSeqForAccDel(env, becky);

auto const acctDelFee{drops(env.current()->fees().increment)};

// becky can't delete account as feature disabled
env(acctdelete(
becky,
alice,
{"098B7F1B146470A1C5084DC7832C04A72939E3EBC58E68AB8B579BA07"
"2B0CECB"}),
fee(acctDelFee),
ter(temDISABLED));
env.close();
}
}

void
run() override
{
Expand All @@ -925,6 +1035,7 @@ class AccountDelete_test : public beast::unit_test::suite
testBalanceTooSmallForFee();
testWithTickets();
testDest();
testDestCreds();
}
};

Expand Down
Loading

0 comments on commit 0cb86b1

Please sign in to comment.