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()
def context(): ctx = IconScoreContext(IconScoreContextType.DIRECT) block = Block(0, None, 0, None, 0) ctx.block = block ContextContainer._push_context(ctx) yield ctx ContextContainer._pop_context()
def context(): context = IconScoreContext(IconScoreContextType.DIRECT) context.tx_batch = TransactionBatch() context.block_batch = BlockBatch() ContextContainer._push_context(context) yield context ContextContainer._pop_context()
def context(): IconScoreContext.icon_score_deploy_engine = Mock(spec=DeployEngine) context = Mock(spec=IconScoreContext) context.attach_mock(Mock(spec=Transaction), "tx") context.attach_mock(Mock(spec=Block), "block") context.attach_mock(Mock(spec=Message), "msg") ContextContainer._push_context(context) yield context ContextContainer._pop_context()
def intercept_invoke(*args, **kwargs): ContextContainer._push_context(args[0]) context_db = inner_task._icon_service_engine._icx_context_db score_address = create_address(AddressPrefix.CONTRACT, b'address') score = SampleScore(IconScoreDatabase(score_address, context_db)) address = create_address(AddressPrefix.EOA, b'address') score.SampleEvent(b'i_data', address, 10, b'data', 'text') ContextContainer._pop_context()
def tearDown(self): self._engine = None ContextContainer._pop_context() self._icon_score_mapper.close() path = os.path.join(TEST_ROOT_PATH, 'tests') remove_path(path) path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH) remove_path(path) IconScoreContextUtil.validate_score_blacklist = VALIDATE_SCORE_BLACK_LIST IconScoreContextUtil.get_owner = GET_OWNER IconScoreContextUtil.get_icon_score = GET_ICON_SCORE IconScoreContextUtil.is_service_flag_on = IS_SERVICE_FLAG_ON
def context(): ctx = IconScoreContext(IconScoreContextType.DIRECT) ctx.tx = Transaction(tx_hash=create_tx_hash(), origin=EOA1) ctx.block = Block(block_height=0, block_hash=create_block_hash(), timestamp=0, prev_hash=None) ctx.msg = Message(sender=EOA1, value=0) ctx.icon_score_mapper = IconScoreMapper() ctx.new_icon_score_mapper = {} ctx.step_counter = IconScoreStepCounter(1, {}, 1000, False) ctx.event_logs = [] ctx.traces = [] ctx.current_address = EOA1 IconScoreContext.storage = ContextStorage(deploy=Mock(spec=Storage), fee=None, icx=None, iiss=None, prep=None, issue=None, meta=None, rc=None, inv=None) ContextContainer._push_context(ctx) yield ctx ContextContainer._pop_context()