-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update definitions.json -- generated from the tip of rippled codebase at commit ea8e77ffec065cf1a8d1cd4517f9cebdab27cc17 Explicity specify featureCredentials inside the conf file. This enables the features inside the genesis ledger * Specify the CredentialCreate transaction * Files relevant to the CredentialAccept transaction * Files pertaining to the CredentialDelete transaction Refactor common elements within Credential-related transactions * Files pertaining to DepositPreauth transaction are included in this commit Deposit_preauth: array length checks on the authcreds and unauthcreds fields * FIX: Update deposit_preauth integration tests to validate the transaction result code * Include account_objects RPC call to verify that cred ledger-object is successfully deleted Updates to Payment transaction model Update AccountDelete transaction model with Credential ID array Update EscrowFinish txn model with CredentialIDs Updates to the PaymentChannelClaim txn model -- Include new unit test file * Updates to DepositAuthorized RPC --------- Co-authored-by: Mayukha Vadari <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Omar Khan <[email protected]>
- Loading branch information
1 parent
b66b14e
commit aaa00ea
Showing
32 changed files
with
1,354 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import DESTINATION, WALLET | ||
from xrpl.models import AccountObjects, AccountObjectType | ||
from xrpl.models.requests.ledger_entry import Credential, LedgerEntry | ||
from xrpl.models.response import ResponseStatus | ||
from xrpl.models.transactions.credential_accept import CredentialAccept | ||
from xrpl.models.transactions.credential_create import CredentialCreate | ||
from xrpl.models.transactions.credential_delete import CredentialDelete | ||
from xrpl.utils import str_to_hex | ||
|
||
_URI = "www.my-id.com/username" | ||
|
||
|
||
def is_cred_object_present( | ||
result: dict, issuer: str, subject: str, cred_type: str | ||
) -> bool: | ||
""" | ||
Args: | ||
result: JSON response from account_objects RPC | ||
issuer: Address of the credential issuer | ||
subject: Address of the credential subject | ||
cred_type: Type of the credential | ||
Returns: | ||
bool: True if credential exists, False otherwise | ||
""" | ||
|
||
for val in result["account_objects"]: | ||
if ( | ||
val["Issuer"] == issuer | ||
and val["Subject"] == subject | ||
and val["CredentialType"] == cred_type | ||
): | ||
return True | ||
|
||
return False | ||
|
||
|
||
class TestCredentials(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_valid(self, client): | ||
# Define entities helpful for Credential lifecycle | ||
_ISSUER = WALLET.address | ||
_SUBJECT = DESTINATION.address | ||
_SUBJECT_WALLET = DESTINATION | ||
|
||
# Disambiguate the sync/async, json/websocket tests with different | ||
# credential type values -- this avoids tecDUPLICATE error | ||
# self.value is defined inside the above decorator | ||
cred_type = str_to_hex("Passport_" + str(self.value)) | ||
|
||
tx = CredentialCreate( | ||
account=_ISSUER, | ||
subject=_SUBJECT, | ||
credential_type=cred_type, | ||
uri=str_to_hex(_URI), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Use the LedgerEntry RPC to validate the creation of the credential object | ||
ledger_entry_response = await client.request( | ||
LedgerEntry( | ||
credential=Credential( | ||
subject=_SUBJECT, issuer=_ISSUER, credential_type=cred_type | ||
) | ||
) | ||
) | ||
|
||
self.assertEqual(ledger_entry_response.status, ResponseStatus.SUCCESS) | ||
|
||
# Execute the CredentialAccept transaction on the above Credential ledger object | ||
tx = CredentialAccept( | ||
issuer=_ISSUER, account=_SUBJECT, credential_type=cred_type | ||
) | ||
# CredentialAccept transaction is submitted by SUBJECT | ||
response = await sign_and_reliable_submission_async(tx, _SUBJECT_WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Execute the CredentialDelete transaction | ||
# Subject initiates the deletion of the Credential ledger object | ||
tx = CredentialDelete( | ||
issuer=_ISSUER, account=_SUBJECT, credential_type=cred_type | ||
) | ||
|
||
response = await sign_and_reliable_submission_async(tx, _SUBJECT_WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# The credential ledger object must be deleted from both the Issuer and Subject | ||
# account's directory pages | ||
account_objects_response = await client.request( | ||
AccountObjects(account=_ISSUER, type=AccountObjectType.CREDENTIAL) | ||
) | ||
self.assertFalse( | ||
is_cred_object_present( | ||
account_objects_response.result, | ||
issuer=_ISSUER, | ||
subject=_SUBJECT, | ||
cred_type=cred_type, | ||
) | ||
) | ||
|
||
# Verify that the Credential object has been deleted from the Subject's | ||
# directory page as well | ||
account_objects_response = await client.request( | ||
AccountObjects(account=_SUBJECT, type=AccountObjectType.CREDENTIAL) | ||
) | ||
self.assertFalse( | ||
is_cred_object_present( | ||
account_objects_response.result, | ||
issuer=_ISSUER, | ||
subject=_SUBJECT, | ||
cred_type=cred_type, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models import DepositAuthorized | ||
|
||
|
||
class TestDepositAuthorized(TestCase): | ||
def test_valid(self): | ||
req = DepositAuthorized( | ||
source_account="srcAccount", | ||
destination_account="dstAccount", | ||
credentials=[ | ||
"EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A" | ||
], | ||
) | ||
self.assertTrue(req.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models.exceptions import XRPLModelException | ||
from xrpl.models.transactions import AccountDelete | ||
from xrpl.models.utils import MAX_CREDENTIAL_ARRAY_LENGTH | ||
|
||
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" | ||
_DESTINATION = "rf7HPydP4ihkFkSRHWFq34b4SXRc7GvPCR" | ||
|
||
|
||
class TestAccountDelete(TestCase): | ||
def test_creds_list_too_long(self): | ||
"""Test that AccountDelete raises exception when credential_ids exceeds max | ||
length.""" | ||
with self.assertRaises(XRPLModelException) as err: | ||
AccountDelete( | ||
account=_ACCOUNT, | ||
destination=_DESTINATION, | ||
credential_ids=[ | ||
"credential_index_" + str(i) | ||
for i in range(MAX_CREDENTIAL_ARRAY_LENGTH + 1) | ||
], | ||
) | ||
|
||
self.assertEqual( | ||
err.exception.args[0], | ||
"{'credential_ids': 'CredentialIDs list cannot exceed " | ||
+ str(MAX_CREDENTIAL_ARRAY_LENGTH) | ||
+ " elements.'}", | ||
) | ||
|
||
def test_creds_list_empty(self): | ||
with self.assertRaises(XRPLModelException) as err: | ||
AccountDelete( | ||
account=_ACCOUNT, | ||
destination=_DESTINATION, | ||
credential_ids=[], | ||
) | ||
self.assertEqual( | ||
err.exception.args[0], | ||
"{'credential_ids': 'CredentialIDs list cannot be empty.'}", | ||
) | ||
|
||
def test_creds_list_duplicates(self): | ||
with self.assertRaises(XRPLModelException) as err: | ||
AccountDelete( | ||
account=_ACCOUNT, | ||
destination=_DESTINATION, | ||
credential_ids=["credential_index" for _ in range(5)], | ||
) | ||
self.assertEqual( | ||
err.exception.args[0], | ||
"{'credential_ids_duplicates': 'CredentialIDs list cannot contain duplicate" | ||
+ " values.'}", | ||
) | ||
|
||
def test_valid_account_delete_txn(self): | ||
tx = AccountDelete( | ||
account=_ACCOUNT, | ||
destination=_DESTINATION, | ||
credential_ids=[ | ||
"EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A" | ||
], | ||
) | ||
self.assertTrue(tx.is_valid()) |
Oops, something went wrong.