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 _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
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) 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_deployer = Mock() self._context.validate_score_blacklist = Mock() self._context.is_service_flag_on = Mock(return_value=False)
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( 'hxdf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf' ) self.malformed_addresses = [ empty_address, short_address_without_hx, short_address, long_address_without_hx, long_address ] self.db_name = 'engine.db' db = ContextDatabase.from_path(self.db_name) self.engine = IcxEngine() self._from = Address.from_string('hx' + 'a' * 40) self.to = Address.from_string('hx' + 'b' * 40) self.genesis_address = Address.from_string('hx' + '0' * 40) self.fee_treasury_address = Address.from_string('hx' + '1' * 40) self.total_supply = 10**20 # 100 icx self.context = IconScoreContext(IconScoreContextType.DIRECT) block = Mock(spec=Block) block.attach_mock(Mock(return_value=0), 'height') self.context.block = block self.storage = IcxStorage(db) self.engine.open() accounts: list = [{ 'address': self.genesis_address, 'balance': self.total_supply }, { 'address': self.fee_treasury_address, 'balance': 0 }] self.context.storage = ContextStorage(deploy=None, fee=None, icx=self.storage, iiss=None, prep=None, issue=None, rc=None, meta=None) self.storage.put_genesis_accounts(self.context, accounts)
def make_context(self): self._tx_index += 1 self._context = IconScoreContext(IconScoreContextType.DIRECT) self._context.msg = Message(self.addr1, 0) self._context.tx = Transaction(create_tx_hash(), origin=self.addr1) 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.__step_counter_factory = IconScoreStepCounterFactory() self._context.revision = 0 self._context.new_icon_score_mapper = {} self._step_counter: IconScoreStepCounter = \ self.__step_counter_factory.create(IconScoreContextType.INVOKE) self._context.step_counter = self._step_counter self._context.icx.open(self._icx_storage) self._context.event_logs = Mock(spec=list) self._context.traces = Mock(spec=list)
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)
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()
def setUp(self): self.db_name = 'engine.db' db = ContextDatabase.from_path(self.db_name) self.engine = IcxEngine() self.storage = IcxStorage(db) self.from_ = Address.from_string('hx' + 'a' * 40) self.to = Address.from_string('hx' + 'b' * 40) self.genesis_address = Address.from_string('hx' + '0' * 40) self.fee_treasury_address = Address.from_string('hx' + '1' * 40) self.total_supply = 10**20 # 100 icx self.fee_treasury_address_icx_amount = 0 self.context = IconScoreContext(IconScoreContextType.DIRECT) block = Mock(spec=Block) block.attach_mock(Mock(return_value=0), 'height') self.context.block = block self.engine.open() accounts: list = [{ 'address': self.genesis_address, 'balance': self.total_supply }, { 'address': self.fee_treasury_address, 'balance': 0 }] self.context.storage = ContextStorage(deploy=None, fee=None, icx=self.storage, iiss=None, prep=None, issue=None, rc=None, meta=None) self.storage.put_genesis_accounts(self.context, accounts)
def icx_engine(): engine = IcxEngine() engine.open() yield engine engine.close()