From acc161552918cbfd24e8fcded92560f52ddc1490 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Fri, 28 Jun 2024 16:41:48 -0400 Subject: [PATCH] Re-organize code to make testing easier for now - this should probably be made cleaner, but in the interim it allows the tests to pass. --- nucypher/blockchain/eth/actors.py | 46 ++++-------------------------- nucypher/blockchain/eth/agents.py | 47 +++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 93f08e85b..7941bec25 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -815,47 +815,11 @@ class Operator(BaseActor): """Check that the encryption is authorized for this ritual""" ciphertext_header = decryption_request.ciphertext_header authorization = decryption_request.acp.authorization - ritual = self._resolve_ritual(decryption_request.ritual_id) - abi = """[ - { - "type": "function", - "name": "isAuthorized", - "stateMutability": "view", - "inputs": [ - { - "name": "ritualId", - "type": "uint32", - "internalType": "uint32" - }, - { - "name": "evidence", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "ciphertextHeader", - "type": "bytes", - "internalType": "bytes" - } - ], - "outputs": [ - { - "name": "", - "type": "bool", - "internalType": "bool" - } - ] - } - ]""" - encryption_authorizer = self.coordinator_agent.blockchain.w3.eth.contract( - address=ritual.access_controller, abi=abi - ) - is_authorized = encryption_authorizer.functions.isAuthorized( - decryption_request.ritual_id, - authorization, - bytes(ciphertext_header), - ).call() - if not is_authorized: + if not self.coordinator_agent.is_encryption_authorized( + ritual_id=decryption_request.ritual_id, + evidence=authorization, + ciphertext_header=bytes(ciphertext_header), + ): raise self.UnauthorizedRequest( f"Encrypted data not authorized for ritual {decryption_request.ritual_id}", ) diff --git a/nucypher/blockchain/eth/agents.py b/nucypher/blockchain/eth/agents.py index db490bf3a..ffa815301 100644 --- a/nucypher/blockchain/eth/agents.py +++ b/nucypher/blockchain/eth/agents.py @@ -699,10 +699,51 @@ class CoordinatorAgent(EthereumContractAgent): This contract read is relayed through coordinator to the access controller contract associated with a given ritual. """ - result = self.contract.functions.isEncryptionAuthorized( - ritual_id, evidence, ciphertext_header + + # TODO this makes the test pass more easily - find a better way + # for this access controller calling logic + ritual = self.get_ritual(ritual_id=ritual_id) + abi = """[ + { + "type": "function", + "name": "isAuthorized", + "stateMutability": "view", + "inputs": [ + { + "name": "ritualId", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "evidence", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "ciphertextHeader", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ] + } + ]""" + encryption_authorizer = self.blockchain.w3.eth.contract( + address=ritual.access_controller, abi=abi + ) + is_authorized = encryption_authorizer.functions.isAuthorized( + ritual_id, + evidence, + ciphertext_header, ).call() - return result + + return is_authorized @contract_api(CONTRACT_CALL) def is_provider_public_key_set(self, staking_provider: ChecksumAddress) -> bool: