Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self) -> None:
self.converter = PRepAddressConverter()
self.node_addresses = []
self.prep_addresses = []
# Generate sample addresses for test
for i in range(10):
node_address = Address.from_data(
AddressPrefix.EOA, f"node_address{i}".encode("utf-8")
)
prep_address = Address.from_data(
AddressPrefix.EOA, f"prep_address{i}".encode("utf-8")
)
self.node_addresses.append(node_address)
self.prep_addresses.append(prep_address)
def setUp(self):
self._state_db_root_path = '.statedb'
self._score_root_path = '.score'
rmtree(self._score_root_path)
rmtree(self._state_db_root_path)
self._block_height = 0
self._prev_block_hash = None
self._version = 3
self._step_limit = 4 * 10 ** 6
self._icx_factor = 10 ** 18
self._admin_addr = create_address(AddressPrefix.EOA)
self._genesis_addr = create_address(AddressPrefix.EOA)
self._inner_task = None
def _create_dummy_prep(index: int, status: 'PRepStatus' = PRepStatus.ACTIVE) -> 'PRep':
address = Address(AddressPrefix.EOA, os.urandom(20))
return PRep(
address=address,
status=status,
name=f"node{index}",
country="KOR",
city="Seoul",
email=f"node{index}@example.com",
website=f"https://node{index}.example.com",
details=f"https://node{index}.example.com/details",
p2p_endpoint=f"node{index}.example.com:7100",
delegated=random.randint(0, 1000),
irep=10_000,
irep_block_height=index,
block_height=index
)
def setUp(self):
self._state_db_root_path = '.statedb'
self._score_root_path = '.score'
rmtree(self._score_root_path)
rmtree(self._state_db_root_path)
self._block_height = 0
self._prev_block_hash = None
self._version = 3
self._step_limit = 4 * 10 ** 6
self._admin_addr = create_address(AddressPrefix.EOA, b'ADMIN')
conf = IconConfig("", default_icon_config)
conf.load()
conf.update_conf({ConfigKey.BUILTIN_SCORE_OWNER: str(self._admin_addr)})
self._inner_task = IconScoreInnerTask(conf)
self._inner_task._open()
self._genesis_addr = create_address(AddressPrefix.EOA, b'genesis')
is_commit, tx_results = self._run_async(self._genesis_invoke())
self.assertEqual(is_commit, True)
self.assertEqual(tx_results[0]['status'], hex(1))
self._tx_index = 0
self.__ensure_dir(db_path)
self._icx_db = ContextDatabaseFactory.create_by_name('icx_db')
self._icx_db.address = ICX_ENGINE_ADDRESS
self._icx_storage = IcxStorage(self._icx_db)
self._icon_deploy_storage = DeployStorage(self._icx_db)
self._icon_score_mapper = IconScoreMapper()
IconScoreContextUtil.validate_score_blacklist = Mock()
IconScoreContextUtil.get_owner = Mock()
IconScoreContextUtil.get_icon_score = Mock()
IconScoreContextUtil.is_service_flag_on = Mock()
self.from_address = create_address(AddressPrefix.EOA)
self._engine = DeployEngine()
IconScoreContext.storage = ContextStorage(
deploy=self._icon_deploy_storage,
fee=None,
icx=None,
iiss=None,
prep=None,
issue=None,
rc=None,
meta=None
)
self.make_context()
self._icon_deploy_storage.open(self._context)
self._engine.open(self._icon_deploy_storage)
def test_success_call_method(self):
self._mock_context.readonly = False
self._mock_context.func_type = IconScoreFuncType.WRITABLE
self.ins = CallClass2(create_mock_icon_score_db())
self._mock_context.msg = Message(create_address(AddressPrefix.EOA), 0)
self._mock_context.type = IconScoreContextType.INVOKE
func = getattr(self.ins, '_IconScoreBase__external_call')
# func('func1', {})
func('func2', (1, 2), {})
self._mock_context.type = IconScoreContextType.QUERY
# func('func3', {})
self._mock_context.type = IconScoreContextType.INVOKE
func('func4', (1, 2), {})
func('func5', (1, 2), {})
# func('func6', {})
print(self.ins.get_api())
def setUp(self):
super().setUp()
self.sample_root = "test_deploy_scores"
self._addr1 = create_address(AddressPrefix.EOA)
conf = IconConfig("", default_icon_config)
conf.load()
conf.update_conf({ConfigKey.BUILTIN_SCORE_OWNER: str(self._admin_addr)})
self._inner_task = IconScoreInnerTask(conf)
self._inner_task._open()
is_commit, tx_results = self._run_async(self._genesis_invoke())
self.assertEqual(is_commit, True)
self.assertEqual(tx_results[0]['status'], hex(1))
def setUp(self):
self.addr1 = create_address(AddressPrefix.EOA, b'addr1')
self.addr2 = create_address(AddressPrefix.EOA, b'addr2')
self.addr3 = create_address(AddressPrefix.EOA, b'addr3')
self.icon_score_batch = IconScoreBatch(self.addr1)
self.icon_score_batch[self.addr2] = 100
self.icon_score_batch[self.addr3] = 200
def setUp(self):
super().setUp()
self.sample_root = "test_deploy_scores"
self._addr1 = create_address(AddressPrefix.EOA)
conf = IconConfig("", default_icon_config)
conf.load()
conf.update_conf({ConfigKey.BUILTIN_SCORE_OWNER: str(self._admin_addr),
ConfigKey.SERVICE: {ConfigKey.SERVICE_AUDIT: True}})
self._inner_task = IconScoreInnerTask(conf)
self._inner_task._open()
is_commit, tx_results = self._run_async(self._genesis_invoke())
self.assertEqual(is_commit, True)
self.assertEqual(tx_results[0]['status'], hex(1))
def from_string(prefix: str):
"""
Returns address prefix enumerator
:param prefix: 2-byte address prefix (hx or cx)
:return: (AddressPrefix) address prefix enumerator
"""
if prefix == ICON_EOA_ADDRESS_PREFIX:
return AddressPrefix.EOA
if prefix == ICON_CONTRACT_ADDRESS_PREFIX:
return AddressPrefix.CONTRACT
raise InvalidParamsException('Invalid address prefix')