Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: PatStLouis <[email protected]>
  • Loading branch information
PatStLouis committed Sep 27, 2024
1 parent 36c31ac commit 3b21535
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
26 changes: 15 additions & 11 deletions aries_cloudagent/vc/data_integrity/tests/test_cryptosuites.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aries_cloudagent.vc.data_integrity.cryptosuites import EddsaJcs2022
from aries_cloudagent.wallet.in_memory import InMemoryWallet
from aries_cloudagent.core.in_memory import InMemoryProfile
from aries_cloudagent.vc.data_integrity.models.options import DataIntegrityProofOptions


class TestEddsaJcs2022(IsolatedAsyncioTestCase):
Expand All @@ -17,12 +18,14 @@ class TestEddsaJcs2022(IsolatedAsyncioTestCase):
multikey = "z6MkgKA7yrw5kYSiDuQFcye4bMaJpcfHFry3Bx45pdWh3s8i"

unsecured_document = {"hello": "world"}
options = {
"type": "DataIntegrityProof",
"cryptosuite": cryptosuite,
"proofPurpose": "assertionMethod",
"verificationMethod": f"did:key:{multikey}#{multikey}",
}
options = DataIntegrityProofOptions.deserialize(
{
"type": "DataIntegrityProof",
"cryptosuite": cryptosuite,
"proofPurpose": "assertionMethod",
"verificationMethod": f"did:key:{multikey}#{multikey}",
}
)

async def asyncSetUp(self):
try:
Expand All @@ -36,11 +39,12 @@ async def test_create_proof(self):
proof = await EddsaJcs2022(session=session).create_proof(
self.unsecured_document, self.options
)
proof = proof.serialize()
assert isinstance(proof, dict)
assert proof["type"] == self.options["type"]
assert proof["cryptosuite"] == self.options["cryptosuite"]
assert proof["proofPurpose"] == self.options["proofPurpose"]
assert proof["verificationMethod"] == self.options["verificationMethod"]
assert proof["type"] == self.options.type
assert proof["cryptosuite"] == self.options.cryptosuite
assert proof["proofPurpose"] == self.options.proof_purpose
assert proof["verificationMethod"] == self.options.verification_method
assert proof["proofValue"]

async def test_verify_proof(self):
Expand All @@ -49,6 +53,6 @@ async def test_verify_proof(self):
proof = await cryptosuite_instance.create_proof(
self.unsecured_document, self.options
)
secured_document = self.unsecured_document | {"proof": proof}
secured_document = self.unsecured_document | {"proof": proof.serialize()}
verification = await cryptosuite_instance.verify_proof(secured_document)
assert verification["verified"]
35 changes: 19 additions & 16 deletions aries_cloudagent/vc/data_integrity/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from aries_cloudagent.wallet.keys.manager import MultikeyManager
from aries_cloudagent.core.in_memory import InMemoryProfile
from aries_cloudagent.vc.data_integrity.manager import DataIntegrityManager
from aries_cloudagent.vc.data_integrity.models.options import DataIntegrityProofOptions


class TestDiManager(IsolatedAsyncioTestCase):
Expand All @@ -13,12 +14,14 @@ class TestDiManager(IsolatedAsyncioTestCase):
verification_method = f"did:key:{multikey}#{multikey}"
cryptosuite = "eddsa-jcs-2022"
unsecured_document = {"hello": "world"}
options = {
"type": "DataIntegrityProof",
"cryptosuite": cryptosuite,
"proofPurpose": "assertionMethod",
"verificationMethod": f"did:key:{multikey}#{multikey}",
}
options = DataIntegrityProofOptions.deserialize(
{
"type": "DataIntegrityProof",
"cryptosuite": cryptosuite,
"proofPurpose": "assertionMethod",
"verificationMethod": f"did:key:{multikey}#{multikey}",
}
)

async def asyncSetUp(self):
try:
Expand All @@ -35,10 +38,10 @@ async def test_add_proof(self):
proof = secured_document.pop("proof", None)
assert isinstance(proof, list)
assert len(proof) == 1
assert proof[0]["type"] == self.options["type"]
assert proof[0]["cryptosuite"] == self.options["cryptosuite"]
assert proof[0]["proofPurpose"] == self.options["proofPurpose"]
assert proof[0]["verificationMethod"] == self.options["verificationMethod"]
assert proof[0]["type"] == self.options.type
assert proof[0]["cryptosuite"] == self.options.cryptosuite
assert proof[0]["proofPurpose"] == self.options.proof_purpose
assert proof[0]["verificationMethod"] == self.options.verification_method
assert proof[0]["proofValue"]

async def test_add_proof_set(self):
Expand All @@ -53,10 +56,10 @@ async def test_add_proof_set(self):
assert isinstance(proof_set, list)
assert len(proof_set) == 2
for proof in proof_set:
assert proof["type"] == self.options["type"]
assert proof["cryptosuite"] == self.options["cryptosuite"]
assert proof["proofPurpose"] == self.options["proofPurpose"]
assert proof["verificationMethod"] == self.options["verificationMethod"]
assert proof["type"] == self.options.type
assert proof["cryptosuite"] == self.options.cryptosuite
assert proof["proofPurpose"] == self.options.proof_purpose
assert proof["verificationMethod"] == self.options.verification_method
assert proof["proofValue"]

async def test_add_proof_chain(self):
Expand Down Expand Up @@ -86,12 +89,12 @@ async def test_verify_proof_set(self):
secured_document, self.options
)
verification = await di_manager.verify_proof(secured_document_with_proof_set)
assert verification["verified"]
assert verification.verified
bad_proof = secured_document_with_proof_set["proof"][0].copy()
bad_proof["proofValue"] = bad_proof["proofValue"][:-1]
secured_document_with_proof_set["proof"][0] = bad_proof
verification = await di_manager.verify_proof(secured_document_with_proof_set)
assert not verification["verified"]
assert not verification.verified

async def test_verify_proof_chain(self):
pass

0 comments on commit 3b21535

Please sign in to comment.