def inner_task(mocker, request):
    mocker.patch.object(IconScoreInnerTask, "_open")
    mocker.patch.object(IconScoreInnerTask, "_close")
    inner_task = IconScoreInnerTask(Mock(spec=IconConfig))
    inner_task._thread_flag = request.param
    icon_service_engine = Mock(spec=IconServiceEngine)
    inner_task._icon_service_engine = icon_service_engine

    return inner_task
예제 #2
0
def _create_inner_task(
        prep_storage_open,
        prep_engine_open,
        iiss_storage_open,
        iiss_engine_open,
        load_last_tx_index,
        rc_db_from_path,
        db_factory_create_by_name,
        icx_engine_open,
        service_engine_load_builtin_scores,
        service_engine_init_global_value_by_governance_score):
    state_db = {}
    rc_db = {}

    def state_put(self, key, value):
        state_db[key] = value

    def state_get(self, key):
        return state_db.get(key)

    def rc_put(key, value):
        rc_db[key] = value

    def rc_get(key):
        return rc_db.get(key)

    context_db = Mock(spec=ContextDatabase)
    context_db.key_value_db = state_db
    context_db.get = state_get
    context_db.put = state_put

    iiss_mock_db = Mock(spec=KeyValueDatabase)
    iiss_mock_db.get = rc_get
    iiss_mock_db.put = rc_put

    db_factory_create_by_name.return_value = context_db
    rc_db_from_path.return_value = iiss_mock_db
    load_last_tx_index.return_value = 0
    inner_task = IconScoreInnerTask(IconConfig("", default_icon_config))

    # Patches create_by_name to pass creating DB
    db_factory_create_by_name.assert_called()
    icx_engine_open.assert_called()
    service_engine_load_builtin_scores.assert_called()
    service_engine_init_global_value_by_governance_score.assert_called()

    # Mocks _init_global_value_by_governance_score
    # to ignore initializing governance SCORE
    inner_task._icon_service_engine._init_global_value_by_governance_score = \
        service_engine_init_global_value_by_governance_score

    return inner_task
예제 #3
0
def generate_inner_task(db_factory_create_by_name, icx_engine_open,
                        service_engine_load_builtin_scores,
                        service_engine_init_global_value_by_governance_score):
    memory_db = {}

    def put(self, key, value):
        memory_db[key] = value

    def get(self, key):
        return memory_db.get(key)

    context_db = Mock(spec=ContextDatabase)
    context_db.get = get
    context_db.put = put

    db_factory_create_by_name.return_value = context_db
    inner_task = IconScoreInnerTask(IconConfig("", default_icon_config))

    # Patches create_by_name to pass creating DB
    db_factory_create_by_name.assert_called()
    icx_engine_open.assert_called()
    service_engine_load_builtin_scores.assert_called()
    service_engine_init_global_value_by_governance_score.assert_called()

    # Mocks get_balance so, it returns always 100 icx
    inner_task._icon_service_engine._icx_engine.get_balance = \
        Mock(return_value=100 * 10 ** 18)

    # Mocks _init_global_value_by_governance_score
    # to ignore initializing governance SCORE
    inner_task._icon_service_engine._init_global_value_by_governance_score = \
        service_engine_init_global_value_by_governance_score

    # Ignores icx transfer
    inner_task._icon_service_engine._icx_engine._transfer = Mock()

    # Ignores revision
    inner_task._icon_service_engine._set_revision_to_context = Mock()

    return inner_task
예제 #4
0
    def setUp(self):
        self.icon_inner_task_open_patcher = patch(
            'iconservice.icon_inner_service.IconScoreInnerTask._open')
        self.icon_inner_task_close_patcher = patch(
            'iconservice.icon_inner_service.IconScoreInnerTask._close')
        _ = self.icon_inner_task_open_patcher.start()
        _ = self.icon_inner_task_close_patcher.start()

        IconScoreInnerTask._open = Mock()
        self.inner_task = IconScoreInnerTask(Mock(spec=IconConfig))
        icon_service_engine = Mock(spec=IconServiceEngine)
        self.inner_task._icon_service_engine = icon_service_engine

        block = {
            ConstantKeys.BLOCK_HEIGHT: hex(0),
            ConstantKeys.BLOCK_HASH: create_block_hash().hex(),
            ConstantKeys.TIMESTAMP: hex(0),
            ConstantKeys.PREV_BLOCK_HASH: create_block_hash().hex()
        }
        self.mocked_invoke_request = {"block": block, "transactions": []}
        self.mocked_write_precommit_request = {
            ConstantKeys.BLOCK_HEIGHT: hex(0),
            ConstantKeys.BLOCK_HASH: create_block_hash().hex()
        }
        self.mocked_query_request = {
            ConstantKeys.METHOD: "icx_call",
            ConstantKeys.PARAMS: {}
        }

        exception_msg = "non fatal exception"
        exception_list = [
            InvalidBaseTransactionException, IconServiceBaseException,
            Exception
        ]
        self.exception_list = list(
            map(lambda exception: exception(exception_msg), exception_list))