Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_getitem(self):
self.assertEqual(1, len(self.mapper))
score_address = self.score_address
score = self.load_proj('test_score01', score_address)
score_info = IconScoreInfo(score, self._ZERO_SCORE_ID)
self.mapper[score_address] = score_info
info = self.mapper[score_address]
self.assertTrue(isinstance(info, IconScoreInfo))
address = Address.from_data(AddressPrefix.CONTRACT, b'no_score')
with self.assertRaises(KeyError):
score = self.mapper[address]
self.assertFalse(True)
score = self.mapper.get(address)
self.assertIsNone(score)
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(
def test_minimum_step(self):
step_price = 0
self.icx_engine.get_balance = Mock(return_value=0)
params = {
'version': 3,
'txHash': create_tx_hash(b'tx'),
'from': Address.from_data(AddressPrefix.EOA, b'from'),
'to': Address.from_data(AddressPrefix.CONTRACT, b'to'),
'value': 1,
'stepLimit': 5000,
'timestamp': int(time.time() * 10 ** 6),
'nonce': 1
}
self.icx_engine.get_balance = Mock(return_value=100)
self.validator.execute(params, step_price, 4000)
params = {
'version': 3,
'txHash': create_tx_hash(b'tx'),
'from': Address.from_data(AddressPrefix.EOA, b'from'),
'to': Address.from_data(AddressPrefix.CONTRACT, b'to'),
'value': 10,
'stepLimit': 100,
def test_address_from_to_bytes_EOA(self):
addr1 = create_address()
buf = addr1.to_bytes()
addr2 = Address.from_bytes(buf)
self.assertEqual(addr1, addr2)
if len(delegations) > IISS_MAX_DELEGATIONS:
raise InvalidParamsException("Delegations out of range")
ret_params: dict = TypeConverter.convert(params, ParamType.IISS_SET_DELEGATION)
delegations: List[Dict[str, Union['Address', int]]] = \
ret_params[ConstantKeys.DELEGATIONS]
total_delegating: int = 0
converted_delegations: List[Tuple['Address', int]] = []
delegated_addresses: Dict['Address', int] = {}
for delegation in delegations:
address: 'Address' = delegation["address"]
value: int = delegation["value"]
assert isinstance(address, Address)
assert isinstance(value, int)
if value < 0:
raise InvalidParamsException(f"Invalid delegating amount: {value}")
if address in delegated_addresses:
raise InvalidParamsException(f"Duplicated address: {address}")
delegated_addresses[address] = value
if value > 0:
total_delegating += value
converted_delegations.append((address, value))
return total_delegating, converted_delegations
def __convert_str_to_type(params_type: Any) -> Any:
if not isinstance(params_type, str):
return params_type
if params_type == 'Address':
return Address
else:
return params_type
def generate_score_address(from_: 'Address',
timestamp: int,
nonce: int = None) -> 'Address':
"""Generates a SCORE address from the transaction information.
:param from_:
:param timestamp:
:param nonce:
:return: score address
"""
data = from_.body + timestamp.to_bytes(32, DATA_BYTE_ORDER)
if nonce:
data += nonce.to_bytes(32, DATA_BYTE_ORDER)
return Address.from_data(AddressPrefix.CONTRACT, data)
def str_to_base_object(value: str, type_hint: type) -> BaseObject:
if not isinstance(value, str):
raise InvalidParamsException(f"Type mismatch: value={value} type_hint={type_hint}")
if type_hint is bool:
return bool(str_to_int(value))
if type_hint is bytes:
return hex_to_bytes(value)
if type_hint is int:
return str_to_int(value)
if type_hint is str:
return value
if type_hint is Address:
return Address.from_string(value)
raise InvalidParamsException(f"Unknown type: {type_hint}")