Skip to content

Commit

Permalink
Merge pull request #682 from sklump/avoid-duplicating-schema-created-…
Browse files Browse the repository at this point in the history
…record

only add schema creation non-secrets record on actual schema creation…
  • Loading branch information
andrewwhitehead committed Aug 21, 2020
2 parents e15214f + 9a50108 commit a54a271
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
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

0 comments on commit a54a271

Please sign in to comment.