Exemple #1
0
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(score_db):
    context = IconScoreContext(IconScoreContextType.DIRECT)
    context.current_address = score_db.address

    ContextContainer._push_context(context)
    yield context
    ContextContainer._clear_context()
Exemple #3
0
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()
Exemple #4
0
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()
Exemple #6
0
        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 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()
    def make_context(self):
        self._tx_index += 1
        self._context = IconScoreContext(IconScoreContextType.DIRECT)
        self._context.msg = Message(self.from_address, 0)

        tx_hash = create_tx_hash()
        self._context.new_icon_score_mapper = IconScoreMapper()
        self._context.tx = Transaction(tx_hash,
                                       origin=self.from_address,
                                       timestamp=randrange(1, 1000),
                                       nonce=randrange(1, 1000))
        self._context.block = Block(1, create_block_hash(), 0, None, 0)
        self._context.icon_score_mapper = self._icon_score_mapper
        self._context.icx = IcxEngine()
        self._context.icx.open(self._icx_storage)
        ContextContainer._push_context(self._context)
        self._context.validate_score_blacklist = Mock()
        self._context.is_service_flag_on = Mock(return_value=False)
    def setUp(self):
        address = Address.from_data(AddressPrefix.CONTRACT, os.urandom(20))
        db = Mock(spec=IconScoreDatabase)
        db.attach_mock(address, 'address')
        context = IconScoreContext()
        traces = Mock(spec=list)
        step_counter = Mock(spec=IconScoreStepCounter)

        IconScoreContext.engine = ContextEngine(
            icx=Mock(IcxEngine),
            deploy=Mock(DeployEngine),
            fee=None,
            iiss=None,
            prep=None,
            issue=None,
        )
        IconScoreContext.storage = ContextStorage(icx=Mock(IcxStorage),
                                                  deploy=Mock(DeployStorage),
                                                  fee=None,
                                                  iiss=None,
                                                  prep=None,
                                                  issue=None,
                                                  rc=None,
                                                  meta=None)

        IconScoreContext.icx_engine = Mock(spec=IcxEngine)
        context.type = IconScoreContextType.INVOKE
        context.func_type = IconScoreFuncType.WRITABLE
        context.tx_batch = TransactionBatch()
        context.event_logs = []
        context.traces = traces
        context.step_counter = step_counter
        context.get_owner = Mock()
        ContextContainer._push_context(context)

        self._mock_score = EventlogScore(db)
def set_container_and_intercall_before_test(monkeypatch, context):
    monkeypatch.setattr(InternalCall, "_other_score_call", Mock())
    ContextContainer._push_context(context)
    yield
    ContextContainer._clear_context()
    monkeypatch.undo()