Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [[Unreleased]]

### Fixed
- Rectify error in the Directory model in the LedgerEntry request.

## [[4.4.0]] - 2025-12-16

### Added
Expand Down
60 changes: 60 additions & 0 deletions tests/integration/reqs/test_ledger_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import (
fund_wallet_async,
sign_and_reliable_submission_async,
test_async_and_sync,
)
from xrpl.models.requests import LedgerEntry
from xrpl.models.requests.ledger_entry import Directory
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import DIDSet
from xrpl.wallet import Wallet

_VALID_FIELD = "1234567890abcdefABCDEF"


class TestLedgerEntry(IntegrationTestCase):
@test_async_and_sync(globals())
async def test_fetch_directory_model(self, client):

owner_wallet = Wallet.create()
await fund_wallet_async(owner_wallet)

# Create DID ledger object to populate the directory of owner_wallet account
setup_tx = DIDSet(
account=owner_wallet.address,
did_document=_VALID_FIELD,
uri=_VALID_FIELD,
data=_VALID_FIELD,
)
response = await sign_and_reliable_submission_async(
setup_tx, owner_wallet, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")

# fetch the directory using the Dataclass model
response = await client.request(
LedgerEntry(directory=Directory(owner=owner_wallet.address, sub_index=0))
)
self.assertTrue(response.is_successful())
self.assertEqual(response.result["node"]["LedgerEntryType"], "DirectoryNode")

DIR_NODE_INDEX = response.result["index"]

# fetch directory using JSON input
response = await client.request(
LedgerEntry(
directory={
"owner": owner_wallet.address,
"sub_index": 0,
},
)
)
self.assertTrue(response.is_successful())
self.assertEqual(response.result["node"]["LedgerEntryType"], "DirectoryNode")

# fetch directory using the ledger index
response = await client.request(LedgerEntry(index=DIR_NODE_INDEX))
self.assertTrue(response.is_successful())
self.assertEqual(response.result["node"]["LedgerEntryType"], "DirectoryNode")
20 changes: 10 additions & 10 deletions xrpl/models/requests/ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ class DepositPreauth(BaseModel):
@dataclass(frozen=True, **KW_ONLY_DATACLASS)
class Directory(BaseModel):
"""
Required fields for requesting a DirectoryNode if not querying by
object ID.
The input requires either dir_root or owner as a sub-field, plus optionally a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be checked in the model validation

sub_index sub-field.
Comment on lines +121 to +122
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The input requires either dir_root or owner as a sub-field, plus optionally a
sub_index sub-field.
Required fields for requesting a DirectoryNode if not querying by
object ID.
The input requires either dir_root or owner as a sub-field, plus optionally a
sub_index sub-field.

"""

owner: str = REQUIRED
owner: Optional[str] = None
"""
This field is required.

:meta hide-value:
(Optional) Unique address of the account associated with this directory.
"""

dir_root: str = REQUIRED
dir_root: Optional[str] = None
"""
This field is required.

:meta hide-value:
(Optional) Unique index identifying the directory to retrieve, as a hex string.
"""

sub_index: Optional[int] = None
"""
(Optional) If provided, jumps to a later "page" of the DirectoryNode.
"""


@require_kwargs_on_init
Expand Down