Skip to content

Commit c93d6fd

Browse files
author
Yuki I
committed
test: improve coverage for error related to profile context switching
Signed-off-by: Yuki I <omoge.real@gmail.com>
1 parent 76146aa commit c93d6fd

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

acapy_agent/ledger/indy_vdr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,6 @@ async def send_revoc_reg_entry(
12801280
)
12811281

12821282
if endorser_did and not write_ledger:
1283-
LOGGER.debug("Adding endorser to request")
12841283
revoc_reg_entry_req.set_endorser(endorser_did)
12851284

12861285
legacy_indy_registry = LegacyIndyRegistry()

acapy_agent/ledger/tests/test_indy_vdr.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ...wallet.did_info import DIDInfo
1414
from ...wallet.did_method import SOV, DIDMethod, DIDMethods, HolderDefinedDid
1515
from ...wallet.did_posture import DIDPosture
16+
from ...wallet.error import WalletNotFoundError
1617
from ...wallet.key_type import ED25519, KeyTypes
1718
from ..endpoint_type import EndpointType
1819
from ..indy_vdr import (
@@ -1463,3 +1464,57 @@ async def test_ledger_txn_submit_uses_passed_profile(self, ledger: IndyVdrLedger
14631464
assert submit_kwargs["sign"] is True
14641465
assert submit_kwargs["sign_did"] is test_sign_did
14651466
assert submit_kwargs["write_ledger"] is True
1467+
1468+
@pytest.mark.asyncio
1469+
async def test_submit_wallet_not_found_error(self, ledger: IndyVdrLedger):
1470+
async with ledger.profile.session() as session:
1471+
wallet = session.inject(BaseWallet)
1472+
test_did = await wallet.create_public_did(SOV, ED25519)
1473+
# Create a DID not present in the wallet
1474+
invalid_did = DIDInfo(
1475+
did="did:sov:invalid",
1476+
verkey="invalid_verkey",
1477+
metadata={},
1478+
method=SOV,
1479+
key_type=ED25519,
1480+
)
1481+
async with ledger:
1482+
test_msg = indy_vdr.ledger.build_get_txn_request(test_did.did, 1, 1)
1483+
with pytest.raises(WalletNotFoundError):
1484+
await ledger._submit(
1485+
test_msg, sign=True, sign_did=invalid_did, write_ledger=False
1486+
)
1487+
1488+
@pytest.mark.asyncio
1489+
async def test_submit_unexpected_error(self, ledger: IndyVdrLedger):
1490+
async with ledger.profile.session() as session:
1491+
wallet = session.inject(BaseWallet)
1492+
test_did = await wallet.create_public_did(SOV, ED25519)
1493+
async with ledger:
1494+
test_msg = indy_vdr.ledger.build_get_txn_request(test_did.did, 1, 1)
1495+
ledger.pool_handle.submit_request.side_effect = ValueError("Unexpected error")
1496+
with pytest.raises(LedgerTransactionError) as exc_info:
1497+
await ledger._submit(test_msg)
1498+
assert "Unexpected error during ledger submission" in str(exc_info.value)
1499+
assert isinstance(exc_info.value.__cause__, ValueError)
1500+
1501+
@pytest.mark.asyncio
1502+
async def test_txn_submit_passes_profile(self, ledger: IndyVdrLedger):
1503+
tenant_profile = await self._create_tenant_profile(
1504+
ledger.profile, "submit_tenant"
1505+
)
1506+
test_txn_data = '{"req": "data"}'
1507+
mock_sign_did = mock.MagicMock(spec=DIDInfo)
1508+
ledger._submit = mock.CoroutineMock(return_value={"result": "ok"})
1509+
1510+
await ledger.txn_submit(
1511+
test_txn_data,
1512+
sign=True,
1513+
sign_did=mock_sign_did,
1514+
write_ledger=True,
1515+
profile=tenant_profile,
1516+
)
1517+
1518+
ledger._submit.assert_awaited_once()
1519+
_, kwargs = ledger._submit.call_args
1520+
assert kwargs.get("profile") == tenant_profile

0 commit comments

Comments
 (0)