def setUp(self): db = Mock(spec=IconScoreDatabase) db.address = create_address(AddressPrefix.CONTRACT) context = IconScoreContext() 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 = Mock(spec=list) context.logs_bloom = Mock(spec=BloomFilter) context.traces = traces ContextContainer._push_context(context) context.icon_score_manager = Mock() context.icon_score_manager.get_owner = Mock(return_value=None) context.icon_score_manager.get_tx_hashes_by_score_address = \ Mock(return_value=(create_tx_hash(), create_tx_hash())) context.internal_call = InternalCall(context) context.internal_call._other_score_call = Mock() context.internal_call.icx_engine = Mock(spec=IcxEngine) context.icon_score_mapper = Mock() context.icon_score_mapper.get_icon_score = Mock( return_value=TestScore(db)) context.internal_call._validate_score_blacklist = Mock( return_value=False) self._score = TestScore(db)
def setUp(self): empty_address = MalformedAddress.from_string('') short_address_without_hx = MalformedAddress.from_string('12341234') short_address = MalformedAddress.from_string('hx1234512345') long_address_without_hx = MalformedAddress.from_string( 'cf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf') long_address = MalformedAddress.from_string( 'hxcf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf' ) self.addresses = [ empty_address, short_address_without_hx, short_address, long_address_without_hx, long_address ] self.db_name = 'icx.db' db = ContextDatabase.from_path(self.db_name) self.assertIsNotNone(db) self.storage = IcxStorage(db) context = IconScoreContext(IconScoreContextType.DIRECT) mock_block: 'Mock' = Mock(spec=Block) mock_block.attach_mock(Mock(return_value=0), 'height') context.block = mock_block self.context = context
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.icx_engine = Mock(spec=IcxEngine) IconScoreContext.icon_score_deploy_engine = Mock( spec=IconScoreDeployEngine) context.icon_score_mapper = Mock() context.icon_score_mapper.get_icon_score = Mock( return_value=TestScore(db)) self._score = TestScore(db)
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 _create_base_transaction(self): context = IconScoreContext(IconScoreContextType.DIRECT) context._preps = context.engine.prep.preps.copy(mutable=True) context._term = context.engine.prep.term.copy() block_height: int = self._block_height block_hash = create_block_hash() timestamp_us = create_timestamp() block = Block(block_height, block_hash, timestamp_us, self._prev_block_hash, 0) context.block = block transaction = BaseTransactionCreator.create_base_transaction(context) return transaction
def _create_context(context_type: IconScoreContextType) -> IconScoreContext: context = IconScoreContext(context_type) if context.type == IconScoreContextType.INVOKE: context.block_batch = BlockBatch() context.tx_batch = TransactionBatch() mock_block: 'Mock' = Mock(spec=Block) mock_block.attach_mock(Mock(return_value=0), 'height') context.block = mock_block return context
def _check_calculation_block(self, block: "Block") -> bool: """check calculation block""" context = IconScoreContext(IconScoreContextType.DIRECT) revision = self._engine._get_revision_from_rc(context) context.block = block if revision < Revision.IISS.value: return False start_block = context.engine.iiss.get_start_block_of_calc(context) return start_block == block.height
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
def get_default_context(): context = IconScoreContext() block = Block() context.block = block context.icon_score_mapper = score_mapper context.traces = [] context.validate_score_blacklist = Mock(return_value=True) context.tx = Transaction() context.msg = Message() context.get_icon_score = get_icon_score context.block_batch = None context.tx_batch = None return context
def setUp(self): self.db_name = 'icx.db' db = ContextDatabase.from_path(self.db_name) self.assertIsNotNone(db) self.storage = IcxStorage(db) context = IconScoreContext(IconScoreContextType.DIRECT) context.tx_batch = TransactionBatch() mock_block: 'Mock' = Mock(spec=Block) mock_block.attach_mock(Mock(return_value=0), 'height') context.block = mock_block context.block_batch = BlockBatch() self.context = context
def _make_issue_info(self) -> tuple: context = IconScoreContext(IconScoreContextType.DIRECT) context._preps = context.engine.prep.preps.copy(mutable=True) context._term = context.engine.prep.term.copy() block_height: int = self._block_height block_hash = create_block_hash() timestamp_us = create_timestamp() block = Block(block_height, block_hash, timestamp_us, self._prev_block_hash, 0) context.block = block issue_data = IconScoreContext.engine.issue.create_icx_issue_info(context) total_issue_amount = 0 for group_dict in issue_data.values(): if "value" in group_dict: total_issue_amount += group_dict["value"] return issue_data, total_issue_amount
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 context_with_icx_storage(context_db, genesis_address, fee_treasury_address): accounts: list = [{ 'address': genesis_address, 'balance': TOTAL_SUPPLY }, { 'address': fee_treasury_address, 'balance': 0 }] storage = IcxStorage(context_db) context = IconScoreContext(IconScoreContextType.DIRECT) block = Mock(spec=Block) block.attach_mock(Mock(return_value=0), 'height') context.block = block context.storage = ContextStorage(icx=storage) storage.put_genesis_accounts(context, accounts) yield context storage.close(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
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()