def update_contract_v1(contract_id: str, update: dict) -> dict: """Update an existing contract on the chain Args: contract_id: The contract_id of the contract update: The parsed body, supplied by user. This is used to create an update data model Returns: DTO of the contract at rest which has been updated """ # Get existing model, and check state contract = smart_contract_dao.get_contract_by_id(contract_id) contract_update = smart_contract_model.new_update_contract( update, existing_contract=contract) if smart_contract_model.ContractState.is_updatable_state( contract.status["state"]): raise exceptions.BadStateError( f'State {contract.status["state"]} not valid to begin updates') # Create and validate update model contract_update.start_state = contract.status["state"] # Set state to updating contract.set_state(smart_contract_model.ContractState.UPDATING) contract.save() try: job_processor.begin_task( contract_update, task_type=smart_contract_model.ContractActions.UPDATE) except RuntimeError: contract.set_state( state=smart_contract_model.ContractState.ACTIVE, msg="Contract update failed: could not start update.") contract.save() raise return contract.export_as_at_rest()
def test_webserver_error_handler_bad_state_error(self, mock_http_response, mock_report_exception): exception = exceptions.BadStateError() helpers.webserver_error_handler(exception) mock_report_exception.assert_not_called() mock_http_response.assert_called_once_with(400, ANY)