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_to_bytes_from_bytes(self):
"""
- Checks if Deposit object in bytes is converted into Deposit object correctly.
- Checks if Deposit object is converted into Deposit object in bytes correctly.
"""
deposit = Deposit()
deposit.id = create_tx_hash()
deposit.score_address = create_address(AddressPrefix.CONTRACT)
deposit.sender = create_address(AddressPrefix.EOA)
deposit.deposit_amount = 10000
deposit.deposit_used = 10000
deposit.created = 10
deposit.expires = 1000000
deposit.virtual_step_issued = 100000000000
deposit.virtual_step_used = 200000000000
deposit.prev_id = create_tx_hash()
deposit.next_id = create_tx_hash()
deposit_in_bytes = deposit.to_bytes()
self.assertIsInstance(deposit_in_bytes, bytes)
deposit2 = Deposit.from_bytes(deposit_in_bytes)
self.assertIsInstance(deposit2, Deposit)
self.assertEqual(deposit, deposit2)
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)
def test_put_and_get(self):
"""
"""
context = self.context
address = Address.from_data(AddressPrefix.CONTRACT, b'score')
value = 100
self.context_db._put(context, address.body, value.to_bytes(32, 'big'), True)
value = self.context_db.get(context, address.body)
self.assertEqual(100, int.from_bytes(value, 'big'))
IconScoreMapper.deploy_storage = self._deploy_storage
self._icon_score_mapper = IconScoreMapper()
self._context_container = TestContextContainer()
self._score_deploy_engine.open(
score_root_path=score_path,
flag=IconDeployFlag.ENABLE_TBEARS_MODE.value,
icon_deploy_storage=self._deploy_storage)
self.score_engine = IconScoreEngine()
self.score_engine.open(
self._icx_storage, self._icon_score_mapper)
self._addr1 = create_address(AddressPrefix.EOA)
self._addr2 = create_address(AddressPrefix.EOA)
self._addr3 = create_address(AddressPrefix.EOA)
self._addr_token_score = create_address(AddressPrefix.CONTRACT)
self._addr_crowd_sale_score = create_address(AddressPrefix.CONTRACT)
self._factory = IconScoreContextFactory(max_size=1)
IconScoreContext.icon_score_manager = self._icon_score_manager
IconScoreContext.icon_score_mapper = self._icon_score_mapper
self.make_context()
self._total_supply = 1000 * 10 ** 18
self._one_icx = 1 * 10 ** 18
self._one_icx_to_token = 1
IconScoreMapper.icon_score_loader = self._icon_score_loader
IconScoreMapper.deploy_storage = self._deploy_storage
self._icon_score_mapper = IconScoreMapper()
self._context_container = TestContextContainer()
self._score_deploy_engine.open(
score_root_path=score_path,
flag=IconDeployFlag.ENABLE_TBEARS_MODE.value,
icon_deploy_storage=self._deploy_storage)
self.score_engine = IconScoreEngine()
self.score_engine.open(
self._icx_storage, self._icon_score_mapper)
self._addr1 = create_address(AddressPrefix.EOA)
self._addr2 = create_address(AddressPrefix.EOA)
self._addr3 = create_address(AddressPrefix.EOA)
self._addr_token_score = create_address(AddressPrefix.CONTRACT)
self._addr_crowd_sale_score = create_address(AddressPrefix.CONTRACT)
self._factory = IconScoreContextFactory(max_size=1)
IconScoreContext.icon_score_manager = self._icon_score_manager
IconScoreContext.icon_score_mapper = self._icon_score_mapper
self.make_context()
self._total_supply = 1000 * 10 ** 18
self._one_icx = 1 * 10 ** 18
self._one_icx_to_token = 1
def setUp(self):
self.tx_hash = create_tx_hash(b'tx_hash')
self.tx_batch = TransactionBatch(self.tx_hash)
self.score_address = create_address(AddressPrefix.CONTRACT, b'score')
self.eoa_address = create_address(AddressPrefix.EOA, b'eoa')
self.tx_batch.put(self.score_address, self.eoa_address, value=int_to_bytes(1))
(Address, create_address(AddressPrefix.CONTRACT)),
(Address, create_address(AddressPrefix.EOA))
])
def test_var_db(self, score_db, value_type, expected_value):
test_var = VarDB('test_var', score_db, value_type=value_type)
assert test_var._db != score_db
assert test_var._db._prefix == b'\x02'
test_var.set(expected_value)
assert test_var.get() == expected_value
score_path = os.path.join(PROJECT_ROOT_PATH, self._ROOT_SCORE_PATH)
self.score_path = score_path
self._tx_index = 0
self.__ensure_dir(db_path)
self._icx_db = ContextDatabaseFactory.create_by_name(ICON_DEX_DB_NAME)
self._icx_db.address = ICX_ENGINE_ADDRESS
self._icx_storage = IcxStorage(self._icx_db)
self._score_deploy_engine = isde.Engine()
self._deploy_storage = DeployStorage(self._icx_db)
self._icon_score_mapper = IconScoreMapper()
self.addr1 = create_address(AddressPrefix.EOA)
self.addr2 = create_address(AddressPrefix.EOA)
self.score_address = create_address(AddressPrefix.CONTRACT)
self._score_deploy_engine.open()
IconScoreContext.storage = ContextStorage(
deploy=self._deploy_storage,
fee=None,
icx=None,
iiss=None,
prep=None,
issue=None,
rc=None,
meta=None,
)
self.make_context()
def test_get_prefix_EOA(self):
addr = create_address()
self.assertEqual(str(addr.prefix), ICON_EOA_ADDRESS_PREFIX)
self.assertTrue(addr.prefix == AddressPrefix.EOA)
sender_account = context.storage.icx.get_account(
context, SENDER_ADDRESS, Intent.ALL
)
cached_accounts[SENDER_ADDRESS] = sender_account, 0
# Put old delegations to cached_accounts
for address, value in sender_account.delegations:
account = context.storage.icx.get_account(
context, address, Intent.DELEGATED
)
cached_accounts[address] = account, -value
# Put new delegations to cached_accounts
for i in range(10):
value: int = i + 11
address = Address.from_prefix_and_int(AddressPrefix.EOA, value)
account = context.storage.icx.get_account(
context, address, Intent.DELEGATED
)
cached_accounts[address] = account, value
updated_accounts: List["Account"] = IISSEngine._put_delegation_to_state_db(
context, SENDER_ADDRESS, new_delegations, cached_accounts
)
# sender_account(1) + old_delegated_accounts(10) + new_delegated_accounts(10)
assert len(updated_accounts) == len(cached_accounts) == 21
assert len(context.storage.icx.put_account.call_args_list) == len(
cached_accounts
)
for i, address in enumerate(cached_accounts):