def _patch_service_engine(icon_service_engine, revision):
    # Mocks get_balance so, it returns always 100 icx
    # TODO : patch when use get_balance or transfer
    IconScoreContext.engine = ContextEngine(deploy=DeployEngine(),
                                            fee=FeeEngine(),
                                            icx=IcxEngine(),
                                            iiss=IISSEngine(),
                                            prep=PRepEngine(),
                                            issue=IssueEngine(),
                                            inv=INVEngine())

    db = icon_service_engine._icx_context_db
    IconScoreContext.storage = ContextStorage(deploy=DeployStorage(db),
                                              fee=FeeStorage(db),
                                              icx=IcxStorage(db),
                                              iiss=IISSStorage(db),
                                              prep=PRepStorage(db),
                                              issue=IssueStorage(db),
                                              meta=MetaDBStorage(db),
                                              rc=RewardCalcStorage(),
                                              inv=INVStorage(db))
    IconScoreContext.engine.inv._inv_container = generate_inv_container(
        False, revision)

    return icon_service_engine
Example #2
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()
Example #3
0
    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)
Example #4
0
def _patch_service_engine(icon_service_engine, revision):
    # Mocks get_balance so, it returns always 100 icx
    # TODO : patch when use get_balance or transfer
    IconScoreContext.engine = ContextEngine(
        deploy=DeployEngine(),
        fee=FeeEngine(),
        icx=IcxEngine(),
        iiss=IISSEngine(),
        prep=PRepEngine(),
        issue=IssueEngine()
    )

    db = icon_service_engine._icx_context_db
    IconScoreContext.storage = ContextStorage(
        deploy=DeployStorage(db),
        fee=FeeStorage(db),
        icx=IcxStorage(db),
        iiss=IISSStorage(db),
        prep=PRepStorage(db),
        issue=IssueStorage(db),
        meta=MetaDBStorage(db),
        rc=RewardCalcStorage()
    )

    # Patch revision
    def set_revision_to_context(context):
        context.revision = revision

    icon_service_engine._set_revision_to_context = \
        Mock(side_effect=set_revision_to_context)

    return icon_service_engine
def context_factory(settable_inv_container: 'INVContainer', prep_engine: 'PRepEngine'):
    inv_engine = INVEngine()
    settable_inv_container.set_inv(RevisionCode(Revision.REALTIME_P2P_ENDPOINT_UPDATE.value))
    inv_engine._inv_container = settable_inv_container

    IconScoreContext.engine = ContextEngine(prep=prep_engine, inv=inv_engine)
    IconScoreContext.storage = Mock()
    context_factory = IconScoreContextFactory()
    return context_factory
Example #6
0
 def get_context(self):
     context = IconScoreContext(IconScoreContextType.INVOKE)
     context.step_counter = Mock(spec=IconScoreStepCounter)
     context.step_counter.step_price = 10 ** 10
     context.tx = Mock(spec=Transaction)
     context.tx.to = self._score_address
     block = Mock(spec=Block)
     block.attach_mock(Mock(return_value=0), 'height')
     context.block = block
     context.storage = ContextStorage(deploy=self.deploy_storage,fee=self.fee_storage, icx=self.icx_storage,
                                      iiss=None, prep=None, issue=None, rc=None, meta=None)
     context.engine = ContextEngine(deploy=None, fee=None, icx=self._icx_engine, iiss=None, prep=None, issue=None)
     return context
Example #7
0
    def _create_context(self):
        IconScoreContext.engine = \
            ContextEngine(deploy=None, fee=None, icx=None, iiss=None, prep=self._prep_engine, issue=None)

        block = Block(block_height=1, block_hash=b"1" * 40, prev_hash=b"0" * 40, timestamp=0)
        step_counter_factory = self._create_step_counter_factory()

        context_factory = IconScoreContextFactory(step_counter_factory)

        context = context_factory.create(IconScoreContextType.INVOKE, block)
        context.revision = Revision.THREE.value
        context.step_counter.reset(self.step_limit)

        return context
def context(score_db):
    context = IconScoreContext()
    context.icon_score_deploy_engine = Mock()
    traces = Mock(spec=list)

    context.tx = Mock(spec=Transaction)
    context.block = Mock(spec=Block)
    context.cumulative_step_used = Mock(spec=int)
    context.cumulative_step_used.attach_mock(Mock(), '__add__')
    context.step_counter = Mock(spec=IconScoreStepCounter)
    context.event_logs = []
    context.traces = traces
    context.tx_batch = TransactionBatch()
    IconScoreContext.engine = ContextEngine(icx=Mock(spec=IcxEngine),
                                            deploy=Mock(spec=DeployEngine))
    IconScoreContext.storage = ContextStorage(deploy=Mock(spec=DeployStorage))
    context.icon_score_mapper = Mock()
    return context
Example #9
0
 def setUp(self):
     self.context = IconScoreContext(IconScoreContextType.INVOKE)
     self.context.engine = ContextEngine(deploy=None,
                                         fee=Mock(FeeEngine),
                                         icx=None,
                                         iiss=None,
                                         prep=None,
                                         issue=None)
     self.context.storage = ContextStorage(deploy=Mock(DeployStorage),
                                           fee=Mock(FeeStorage),
                                           icx=None,
                                           iiss=None,
                                           prep=None,
                                           issue=None,
                                           rc=None,
                                           meta=None)
     self.block_height = randrange(0, 100000)
     self.context.block = Block(self.block_height, os.urandom(32), 0,
                                os.urandom(32), 0)
Example #10
0
    def setUp(self):
        db = Mock(spec=IconScoreDatabase)
        db.address = create_address(AddressPrefix.CONTRACT)
        context = IconScoreContext()
        context.icon_score_deploy_engine = Mock()
        traces = Mock(spec=list)

        context.tx = Mock(spec=Transaction)
        context.block = Mock(spec=Block)
        context.cumulative_step_used = Mock(spec=int)
        context.cumulative_step_used.attach_mock(Mock(), '__add__')
        context.step_counter = Mock(spec=IconScoreStepCounter)
        context.event_logs = []
        context.traces = traces
        context.tx_batch = TransactionBatch()

        ContextContainer._push_context(context)

        InternalCall._other_score_call = Mock()

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

        context.icon_score_mapper = Mock()
        context.icon_score_mapper.get_icon_score = Mock(return_value=TestScore(db))
        self._score = TestScore(db)
Example #11
0
 def setUp(self):
     self.validator = IconPreValidator()
     IconScoreContext.engine = ContextEngine(
         icx=Mock(spec=IcxEngine),
         deploy=Mock(spec=DeployEngine),
         fee=None,
         iiss=None,
         prep=None,
         issue=None,
     )
     IconScoreContext.storage = ContextStorage(
         icx=Mock(spec=IcxStorage),
         deploy=Mock(spec=DeployStorage),
         fee=None,
         iiss=None,
         prep=None,
         issue=None,
         rc=None,
         meta=None)
     self.context = IconScoreContext()
Example #12
0
    def setUp(self):
        self._inner_task = generate_inner_task()

        self._inner_task._icon_service_engine._icon_pre_validator = \
            Mock(spec=IconPreValidator)

        factory = self._inner_task._icon_service_engine._step_counter_factory
        self.step_counter = Mock(spec=IconScoreStepCounter)
        factory.create = Mock(return_value=self.step_counter)
        self.step_counter.step_used = 0
        self.step_counter.step_price = 0
        self.step_counter.step_limit = 5000000
        self.step_cost_dict = self._init_step_cost()
        prep_engine = PRepEngine()
        prep_engine.preps = Mock()
        fee_engine = FeeEngine()
        icx_engine = IcxEngine()
        IconScoreContext.engine = ContextEngine(deploy=Mock(),
                                                fee=fee_engine,
                                                icx=icx_engine,
                                                iiss=None,
                                                prep=prep_engine,
                                                issue=None)
Example #13
0
    def setUp(self):
        context = IconScoreContext(IconScoreContextType.DIRECT)
        block = Mock(spec=Block)
        block.attach_mock(Mock(return_value=0), 'height')
        context.block = block

        self._sender = Address.from_data(AddressPrefix.EOA, os.urandom(20))
        self._score_address = Address.from_data(AddressPrefix.CONTRACT, os.urandom(20))

        context_db = create_context_db()

        self.deploy_storage = DeployStorage(context_db)
        deploy_info = IconScoreDeployInfo(self._score_address,
                                          DeployState.ACTIVE,
                                          self._sender,
                                          os.urandom(32),
                                          os.urandom(32))
        self.icx_storage = IcxStorage(context_db)
        self._icx_engine = IcxEngine()

        self.fee_storage = FeeStorage(context_db)
        patch_fee_storage(self.fee_storage)

        self.deploy_storage.put_deploy_info(context, deploy_info)
        context.storage = ContextStorage(deploy=self.deploy_storage, fee=self.fee_storage, icx=self.icx_storage,
                                         iiss=None, prep=None, issue=None, rc=None, meta=None)
        context.engine = ContextEngine(deploy=None, fee=None, icx=self._icx_engine, iiss=None, prep=None, issue=None)
        self._icx_engine.open(self.icx_storage)

        self.icx_storage._put_genesis_data_account(context,
                                                   CoinPartType.GENERAL,
                                                   self._sender,
                                                   100000000 * 10 ** 18)
        self.icx_storage._put_genesis_data_account(context, CoinPartType.TREASURY,
                                                   Address.from_data(AddressPrefix.EOA, os.urandom(20)), 0)

        self._engine = FeeEngine()