Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only add schema creation non-secrets record on actual schema creation… #682

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,17 @@ async def create_and_send_schema(
else:
raise

schema_id_parts = schema_id.split(":")
schema_tags = {
"schema_id": schema_id,
"schema_issuer_did": public_info.did,
"schema_name": schema_id_parts[-2],
"schema_version": schema_id_parts[-1],
"epoch": str(int(time())),
}
record = StorageRecord(SCHEMA_SENT_RECORD_TYPE, schema_id, schema_tags)
storage = self.get_indy_storage()
await storage.add_record(record)
schema_id_parts = schema_id.split(":")
schema_tags = {
"schema_id": schema_id,
"schema_issuer_did": public_info.did,
"schema_name": schema_id_parts[-2],
"schema_version": schema_id_parts[-1],
"epoch": str(int(time())),
}
record = StorageRecord(SCHEMA_SENT_RECORD_TYPE, schema_id, schema_tags)
storage = self.get_indy_storage()
await storage.add_record(record)

return schema_id, schema_def

Expand Down
30 changes: 23 additions & 7 deletions aries_cloudagent/ledger/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,32 @@ async def test_send_schema_already_exists(
mock_wallet.get_public_did = async_mock.CoroutineMock()
mock_wallet.get_public_did.return_value.did = "abc"

fetch_schema_id = f"{mock_wallet.get_public_did.return_value.did}:{2}:schema_name:schema_version"
fetch_schema_id = (
f"{mock_wallet.get_public_did.return_value.did}:2:"
"schema_name:schema_version"
)
mock_check_existing.return_value = (fetch_schema_id, {})

issuer = async_mock.MagicMock(BaseIssuer)
issuer.create_and_store_schema.return_value = ("1", "{}")
ledger = IndyLedger("name", mock_wallet)

async with ledger:
schema_id, schema_def = await ledger.create_and_send_schema(
issuer, "schema_name", "schema_version", [1, 2, 3]
with async_mock.patch.object(
ledger, "get_indy_storage", async_mock.MagicMock()
) as mock_get_storage:
mock_add_record = async_mock.CoroutineMock()
mock_get_storage.return_value = async_mock.MagicMock(
add_record=mock_add_record
)
assert schema_id == fetch_schema_id
assert schema_def == {}

async with ledger:
schema_id, schema_def = await ledger.create_and_send_schema(
issuer, "schema_name", "schema_version", [1, 2, 3]
)
assert schema_id == fetch_schema_id
assert schema_def == {}

mock_add_record.assert_not_called()

@async_mock.patch("indy.pool.set_protocol_version")
@async_mock.patch("indy.pool.create_pool_ledger_config")
Expand All @@ -556,7 +569,10 @@ async def test_send_schema_ledger_transaction_error_already_exists(
mock_wallet.get_public_did = async_mock.CoroutineMock()
mock_wallet.get_public_did.return_value.did = "abc"

fetch_schema_id = f"{mock_wallet.get_public_did.return_value.did}:{2}:schema_name:schema_version"
fetch_schema_id = (
f"{mock_wallet.get_public_did.return_value.did}:2:"
"schema_name:schema_version"
)
mock_check_existing.side_effect = [None, (fetch_schema_id, "{}")]

issuer = async_mock.MagicMock(BaseIssuer)
Expand Down