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 23, 2024
1 parent f142494 commit eb0ff11
Show file tree
Hide file tree
Showing 13 changed files with 1,421 additions and 9 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
62 changes: 62 additions & 0 deletions src/test/app/AccountDelete_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,67 @@ 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 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));
}

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

Expand Down
Loading

0 comments on commit eb0ff11

Please sign in to comment.