def inv_container(dummy_invs): container = INVContainer(False) for value in dummy_invs.values(): container.set_inv(value) assert len(container._tx_batch) == 0 return container
def settable_inv_container(): default_service_config: int = 0 default_step_costs = { 'default': 1_000_000, 'contractCall': 15_000, 'contractCreate': 200_000, 'contractUpdate': 80_000, 'contractDestruct': -70_000, 'contractSet': 30_000, 'get': 0, 'set': 200, 'replace': 50, 'delete': -150, 'input': 200, 'eventLog': 100, 'apiCall': 0 } default_step_costs = { StepType(key): val for key, val in default_step_costs.items() } default_max_step_limits: dict = { IconScoreContextType.INVOKE: 2_500_000_000, IconScoreContextType.QUERY: 50_000_000 } default_step_price: int = 0 default_score_black_list: list = [] default_import_white_list = {"iconservice": ['*']} inv_container = INVContainer(is_migrated=False) inv_container._icon_network_values = { IconNetworkValueType.REVISION_CODE: RevisionCode(0), IconNetworkValueType.SCORE_BLACK_LIST: ScoreBlackList(default_score_black_list), IconNetworkValueType.STEP_PRICE: StepPrice(default_step_price), IconNetworkValueType.STEP_COSTS: StepCosts(default_step_costs), IconNetworkValueType.MAX_STEP_LIMITS: MaxStepLimits(default_max_step_limits), IconNetworkValueType.SERVICE_CONFIG: ServiceConfig(default_service_config), IconNetworkValueType.IMPORT_WHITE_LIST: ImportWhiteList(default_import_white_list) } return inv_container
def test_set_invalid_key(self, invalid_key): batch_dict = INVContainer.BatchDict() temp_value = "value" with pytest.raises(ValueError) as e: batch_dict[invalid_key] = temp_value assert e.value.args[0].startswith("Invalid value key")
def test_set_invalid_value_type(self, invalid_value): batch_dict = INVContainer.BatchDict() valid_key_type = IconNetworkValueType.STEP_COSTS with pytest.raises(ValueError) as e: batch_dict[valid_key_type] = invalid_value assert e.value.args[0].startswith("Invalid value type")
def context(settable_inv_container: INVContainer): prep_engine = PRepEngine() prep_engine.prep_address_converter = mock.Mock() inv_engine = INVEngine() settable_inv_container.set_inv(StepPrice(10**10)) settable_inv_container.set_inv(StepCosts(STEP_COSTS)) settable_inv_container.set_inv( MaxStepLimits({IconScoreContextType.INVOKE: 2_500_000_000})) settable_inv_container.set_inv(RevisionCode(Revision.THREE.value)) inv_engine._inv_container = settable_inv_container IconScoreContext.engine = ContextEngine(prep=prep_engine, inv=inv_engine) context_factory = IconScoreContextFactory() block = Block(block_height=1, block_hash=b"1" * 40, prev_hash=b"0" * 40, timestamp=0) context = context_factory.create(IconScoreContextType.INVOKE, block) step_limit = 1_000_000_000 context.set_step_counter(step_limit) ContextContainer._push_context(context) yield context ContextContainer._pop_context()