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.

pull/3554/head
derekpierre 2024-06-28 16:41:48 -04:00
parent ad04e6efa1
commit acc1615529
No known key found for this signature in database
2 changed files with 49 additions and 44 deletions

View File

@ -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}",
)

View File

@ -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: