text: # -*- coding: utf-8 -*-
  
  from common.base_test import BaseTest
  
  import lemoncheesecake.api as lcc
  from lemoncheesecake.matching import check_that, equal_to
  
  SUITE = {
      "description": "Testing logs of internal operations"
  }
  
  
  @lcc.prop("main", "type")
  @lcc.tags("scenarios", "internal_ops_logs")
  @lcc.suite("Check scenario 'internal_ops_logs'")
  class InternalOperationsLogs(BaseTest):
  
      def __init__(self):
          super().__init__()
          self.__database_api_identifier = None
          self.__registration_api_identifier = None
          self.__history_api_identifier = None
          self.new_account = None
          self.echo_acc0 = None
  
      def setup_suite(self):
          super().setup_suite()
          self._connect_to_ethereum()
          self._connect_to_echopy_lib()
          lcc.set_step("Setup for {}".format(self.__class__.__name__))
          self.__database_api_identifier = self.get_identifier("database")
          self.__registration_api_identifier = self.get_identifier("registration")
          self.__history_api_identifier = self.get_identifier("history")
          lcc.log_info(
              "API identifiers are: database='{}', registration='{}', "
              "history='{}'".format(
                  self.__database_api_identifier, self.__registration_api_identifier, self.__history_api_identifier
              )
          )
          self.echo_acc0 = self.get_account_id(
              self.accounts[0], self.__database_api_identifier, self.__registration_api_identifier
          )
          lcc.log_info("Echo account is '{}'".format(self.echo_acc0))
  
      def teardown_suite(self):
          self._disconnect_to_echopy_lib()
          super().teardown_suite()
  
      @lcc.test("Simple work of operation 'internal_ops_logs'")
      def account_logs(self, get_random_valid_account_name):
          self.new_account = get_random_valid_account_name
  
          lcc.set_step("Create and get new account")
          self.new_account = self.get_account_id(
              self.new_account, self.__database_api_identifier, self.__registration_api_identifier
          )
          lcc.log_info("New Echo account created, account_id='{}'".format(self.new_account))
  
          lcc.set_step("Get account balance in ethereum of new account")
          ethereum_balance = self.utils.get_account_balances(
              self, self.new_account, self.__database_api_identifier, self.eth_asset
          )["amount"]
          check_that("'balance in ethereum'", ethereum_balance, equal_to(0))
  
          lcc.set_step("Generate ethereum address for new account")
          operation = self.echo_ops.get_sidechain_eth_create_address_operation(echo=self.echo, account=self.new_account)
          collected_operation = self.collect_operations(operation, self.__database_api_identifier)
          self.echo_ops.broadcast(echo=self.echo, list_operations=collected_operation)
          lcc.log_info("Ethereum address generated successfully")
  
          lcc.set_step("Get ethereum address of created account in the network")
          eth_account_address = self.utils.get_eth_address(self, self.new_account,
                                                           self.__database_api_identifier)["result"]["eth_addr"]
          lcc.log_info("Ethereum address of '{}' account is '{}'".format(self.new_account, eth_account_address))
  
          if not self.type_validator.is_eth_address(eth_account_address):
              lcc.log_info("Wrong format of eth address, got: {}".format(eth_account_address))
          else:
              lcc.log_info("Eth address has correct format.")
  
          lcc.set_step("Logs of account")
          operation_history_obj = "{}0".format(self.get_object_type(self.echo.config.object_types.OPERATION_HISTORY))
          stop, start = operation_history_obj, operation_history_obj
          limit = 1
          lcc.set_step("Get account history")
          params = [self.new_account, stop, limit, start]
          response_id = self.send_request(self.get_request("get_account_history", params), self.__history_api_identifier)
          self.get_response(response_id)
  
          lcc.set_step("Logs of committee member")
          operation_history_obj = "{}0".format(self.get_object_type(self.echo.config.object_types.OPERATION_HISTORY))
          stop, start = operation_history_obj, operation_history_obj
          limit = 1
          lcc.set_step("Get account history")
          params = ["1.2.6", stop, limit, start]
          response_id = self.send_request(self.get_request("get_account_history", params), self.__history_api_identifier)
          self.get_response(response_id)
  