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_ne(self):
hex_a = 'hx1234567890123456789012345678901234abcdef'
hex_b = 'hx1234567890123456789012345678901234abcde0'
a = Address.from_string(hex_a)
b = Address.from_string(hex_a)
self.assertFalse(a != b)
b = Address.from_string(hex_b)
self.assertTrue(a != b)
def test_install_step(self):
# Ignores deploy
deploy_engine_invoke = Mock()
IconScoreContext.engine.deploy._invoke = deploy_engine_invoke
tx_hash1: str = bytes.hex(create_tx_hash())
from_ = create_address(AddressPrefix.EOA)
to_ = Address.from_string('cx0000000000000000000000000000000000000000')
content_type = 'application/zip'
data = {
'contentType': content_type,
'content': '0x1867291283973610982301923812873419826abcdef9182731',
}
request1 = create_request([
ReqData(tx_hash1, from_, to_, 0, 'deploy', data),
])
# for StepType.CONTRACT_CREATE
result = self._inner_task_invoke(request1)
self.assertEqual(result['txResults'][tx_hash1]['status'], '0x1')
# for StepType.CONTRACT_UPDATE
to_ = result['txResults'][tx_hash1]['scoreAddress']
def test_address_from_to_string_CONTRACT(self):
addr1 = create_address(prefix=1)
buf = str(addr1)
addr2 = Address.from_string(buf)
self.assertEqual(addr1, addr2)
def test_eq(self):
text = 'hx1234567890123456789012345678901234567890'
a = Address.from_string(text)
b = Address.from_string(text)
self.assertTrue(a == b)
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}
]
def test_get_prefix(self):
text = 'hx1234567890123456789012345678901234567890'
a = Address.from_string(text)
self.assertTrue(a.prefix == AddressPrefix.EOA)
def test_get_prefix(self):
text = 'hx1234567890123456789012345678901234567890'
a = Address.from_string(text)
self.assertTrue(a.prefix == AddressPrefix.EOA)
def test_create_address_object(self):
address = 'hx00c3f694d84074f9145cd0bfa497290ce2d8052f'
_, body = split_icon_address(address)
a = Address.from_string(address)
self.assertEqual(a.prefix, AddressPrefix.EOA)
self.assertEqual(a.body, bytes.fromhex(body))
address = 'cx4ad7f694d84074f9145cd0bfa497290ce2d8052f'
_, body = split_icon_address(address)
a = Address.from_string(address)
self.assertEqual(a.prefix, AddressPrefix.CONTRACT)
self.assertEqual(a.body, bytes.fromhex(body))
def test_hash(self):
a1 = Address.from_string('hx00c3f694d84074f9145cd0bfa497290ce2d8052f')
a2 = Address.from_string('hx00c3f694d84074f9145cd0bfa497290ce2d8052f')
self.assertEqual(a1, a2)
self.assertEqual(hash(a1), hash(a2))
self.assertFalse(a1 is a2)
table = {}
table[a1] = 100
self.assertEqual(table[a1], table[a2])
def load_builtin_scores(context: 'IconScoreContext', builtin_score_owner: 'Address'):
for score_name, value in BUILTIN_SCORE_ADDRESS_MAPPER.items():
score_address = Address.from_string(value)
# If builtin score has been already deployed, exit.
if IconScoreContextUtil.is_score_active(context, score_address):
IconBuiltinScoreLoader._load_score(context, score_address, builtin_score_owner)
else:
IconBuiltinScoreLoader._deploy_score(
context, score_name, score_address, builtin_score_owner)