mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Introduce Credentials support (XLS-70d): (#5103)
Amendment:
- Credentials
New Transactions:
- CredentialCreate
- CredentialAccept
- CredentialDelete
Modified Transactions:
- DepositPreauth
- Payment
- EscrowFinish
- PaymentChannelClaim
- AccountDelete
New Object:
- Credential
Modified Object:
- DepositPreauth
API updates:
- ledger_entry
- account_objects
- ledger_data
- deposit_authorized
Read full spec: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0070d-credentials
This commit is contained in:
@@ -1508,6 +1508,154 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testCredentials()
|
||||
{
|
||||
testcase("Test with credentials");
|
||||
|
||||
using namespace jtx;
|
||||
using namespace std::chrono;
|
||||
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
Account const dillon{"dillon "};
|
||||
Account const zelda{"zelda"};
|
||||
|
||||
const char credType[] = "abcde";
|
||||
|
||||
{
|
||||
// Credentials amendment not enabled
|
||||
Env env(*this, supported_amendments() - featureCredentials);
|
||||
env.fund(XRP(5000), alice, bob);
|
||||
env.close();
|
||||
|
||||
auto const seq = env.seq(alice);
|
||||
env(escrow(alice, bob, XRP(1000)), finish_time(env.now() + 1s));
|
||||
env.close();
|
||||
|
||||
env(fset(bob, asfDepositAuth));
|
||||
env.close();
|
||||
env(deposit::auth(bob, alice));
|
||||
env.close();
|
||||
|
||||
std::string const credIdx =
|
||||
"48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
|
||||
"E4";
|
||||
env(finish(bob, alice, seq),
|
||||
credentials::ids({credIdx}),
|
||||
ter(temDISABLED));
|
||||
}
|
||||
|
||||
{
|
||||
Env env(*this);
|
||||
|
||||
env.fund(XRP(5000), alice, bob, carol, dillon, zelda);
|
||||
env.close();
|
||||
|
||||
env(credentials::create(carol, zelda, credType));
|
||||
env.close();
|
||||
auto const jv =
|
||||
credentials::ledgerEntry(env, carol, zelda, credType);
|
||||
std::string const credIdx = jv[jss::result][jss::index].asString();
|
||||
|
||||
auto const seq = env.seq(alice);
|
||||
env(escrow(alice, bob, XRP(1000)), finish_time(env.now() + 50s));
|
||||
env.close();
|
||||
|
||||
// Bob require preauthorization
|
||||
env(fset(bob, asfDepositAuth));
|
||||
env.close();
|
||||
|
||||
// Fail, credentials not accepted
|
||||
env(finish(carol, alice, seq),
|
||||
credentials::ids({credIdx}),
|
||||
ter(tecBAD_CREDENTIALS));
|
||||
|
||||
env.close();
|
||||
|
||||
env(credentials::accept(carol, zelda, credType));
|
||||
env.close();
|
||||
|
||||
// Fail, credentials doesn’t belong to root account
|
||||
env(finish(dillon, alice, seq),
|
||||
credentials::ids({credIdx}),
|
||||
ter(tecBAD_CREDENTIALS));
|
||||
|
||||
// Fail, no depositPreauth
|
||||
env(finish(carol, alice, seq),
|
||||
credentials::ids({credIdx}),
|
||||
ter(tecNO_PERMISSION));
|
||||
|
||||
env(deposit::authCredentials(bob, {{zelda, credType}}));
|
||||
env.close();
|
||||
|
||||
// Success
|
||||
env.close();
|
||||
env(finish(carol, alice, seq), credentials::ids({credIdx}));
|
||||
env.close();
|
||||
}
|
||||
|
||||
{
|
||||
testcase("Escrow with credentials without depositPreauth");
|
||||
using namespace std::chrono;
|
||||
|
||||
Env env(*this);
|
||||
|
||||
env.fund(XRP(5000), alice, bob, carol, dillon, zelda);
|
||||
env.close();
|
||||
|
||||
env(credentials::create(carol, zelda, credType));
|
||||
env.close();
|
||||
env(credentials::accept(carol, zelda, credType));
|
||||
env.close();
|
||||
auto const jv =
|
||||
credentials::ledgerEntry(env, carol, zelda, credType);
|
||||
std::string const credIdx = jv[jss::result][jss::index].asString();
|
||||
|
||||
auto const seq = env.seq(alice);
|
||||
env(escrow(alice, bob, XRP(1000)), finish_time(env.now() + 50s));
|
||||
// time advance
|
||||
env.close();
|
||||
env.close();
|
||||
env.close();
|
||||
env.close();
|
||||
env.close();
|
||||
env.close();
|
||||
|
||||
// Succeed, Bob doesn't require preauthorization
|
||||
env(finish(carol, alice, seq), credentials::ids({credIdx}));
|
||||
env.close();
|
||||
|
||||
{
|
||||
const char credType2[] = "fghijk";
|
||||
|
||||
env(credentials::create(bob, zelda, credType2));
|
||||
env.close();
|
||||
env(credentials::accept(bob, zelda, credType2));
|
||||
env.close();
|
||||
auto const credIdxBob =
|
||||
credentials::ledgerEntry(
|
||||
env, bob, zelda, credType2)[jss::result][jss::index]
|
||||
.asString();
|
||||
|
||||
auto const seq = env.seq(alice);
|
||||
env(escrow(alice, bob, XRP(1000)), finish_time(env.now() + 1s));
|
||||
env.close();
|
||||
|
||||
// Bob require preauthorization
|
||||
env(fset(bob, asfDepositAuth));
|
||||
env.close();
|
||||
env(deposit::authCredentials(bob, {{zelda, credType}}));
|
||||
env.close();
|
||||
|
||||
// Use any valid credentials if account == dst
|
||||
env(finish(bob, alice, seq), credentials::ids({credIdxBob}));
|
||||
env.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@@ -1522,6 +1670,7 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
testMetaAndOwnership();
|
||||
testConsequences();
|
||||
testEscrowWithTickets();
|
||||
testCredentials();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user