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_deploy_case_tx_param_none(self, mock_engine, context, mocker):
"""case when tx_param is None"""
self.set_test(mocker, get_deploy_tx_param_return_value=None)
with pytest.raises(InvalidParamsException) as e:
mock_engine.deploy(context, context.tx.hash)
context.storage.deploy.get_deploy_tx_params.assert_called_with(
context, context.tx.hash
)
assert e.value.code == ExceptionCode.INVALID_PARAMETER
mock_engine._score_deploy.assert_not_called()
context.storage.deploy.update_score_info.assert_not_called()
mocker.stopall()
def test_from_string_invalid(self, address):
with pytest.raises(BaseException) as e:
Address.from_string(address)
assert e.value.code == ExceptionCode.INVALID_PARAMETER
assert e.value.message == "Invalid address"
for i in range(IISS_MAX_DELEGATIONS):
delegation_info: dict = {
"address": str(self._addr_array[1]),
"value": hex(delegation_amount)
}
delegations.append(delegation_info)
# setDelegation request will be failed due to duplicated addresses
tx_results = self._delegate(self._addr_array[0], delegations)
tx_result: 'TransactionResult' = tx_results[0]
assert len(tx_results) == 1
assert isinstance(tx_results, list)
assert isinstance(tx_result, TransactionResult)
assert tx_result.status == 0 # Failure
assert tx_result.failure.code == ExceptionCode.INVALID_PARAMETER
response: dict = self._get_delegation(self._addr_array[0])
delegations: list = response['delegations']
total_delegated: int = response['totalDelegated']
self.assertEqual(0, len(delegations))
self.assertEqual(0, total_delegated)
func_name="add_score_func",
params={"score_addr": str(score_addr1)},
)
query_request = {
"version": self._version,
"from": self._admin,
"to": score_addr2,
"dataType": "call",
"data": {"method": "get_value", "params": {}},
}
with self.assertRaises(DatabaseException) as e:
self._query(query_request)
self.assertEqual(e.exception.code, ExceptionCode.ACCESS_DENIED)
self.assertEqual(e.exception.message, "No permission to write")
value2 = 2 * ICX_IN_LOOP
self.score_call(
from_=self._accounts[0],
to_=score_addr2,
func_name="set_value",
params={"value": hex(value2)},
)
# 2. deploy update (wait audit)
value2 = 2
tx_results: List['TransactionResult'] = self._deploy_score(
score_name="install/sample_score_with_korean_comments",
value=value2,
to_=score_addr1)
tx_hash3 = tx_results[0].tx_hash
# 3. accept SCORE : tx_hash3
raise_exception_start_tag("test_score_with_korean_comments")
tx_results: List['TransactionResult'] = self.accept_score(tx_hash=tx_hash3,
expected_status=False)
raise_exception_end_tag("test_score_with_korean_comments")
self.assertEqual(tx_results[0].failure.code, ExceptionCode.SYSTEM_ERROR)
# 4. assert get value: value1
self._assert_get_value(self._accounts[0], score_addr1, "get_value", value1)
# 5. set value: value3
value3 = 3
self.score_call(from_=self._accounts[0],
to_=score_addr1,
func_name="set_value",
params={"value": hex(value3 * ICX_IN_LOOP)})
# 6. assert get value: value3
self._assert_get_value(self._accounts[0], score_addr1, "get_value", value3)
context.tx = Transaction(os.urandom(32), tx_index, from_, 0)
context.msg = Message(from_)
def intercept_charge_transaction_fee(*args, **kwargs):
return {}, Mock(spec=int)
IconServiceEngine._charge_transaction_fee.side_effect = (
intercept_charge_transaction_fee
)
icon_service_engine._icon_score_deploy_engine.attach_mock(
Mock(return_value=False), "is_data_type_supported"
)
error = Mock(spec=str)
code = ExceptionCode.INVALID_PARAMETER
mock_exception = Mock(side_effect=InvalidParamsException(error))
IconScoreEngine.invoke.side_effect = mock_exception
raise_exception_start_tag("test_throw")
tx_result = icon_service_engine._handle_icx_send_transaction(
context, {"version": 3, "from": from_, "to": to_}
)
raise_exception_end_tag("test_throw")
assert 0 == tx_result.status
IconServiceEngine._charge_transaction_fee.assert_called()
context.traces.append.assert_called()
trace = context.traces.append.call_args[0][0]
assert TraceType.THROW == trace.trace
assert code == trace.data[0]
assert error == trace.data[1]
zip_file_info_gen = IconScoreDeployer._extract_files_gen(self.read_zipfile_as_byte(self.normal_score_path))
file_path_list = [name for name, info, parent_dir in zip_file_info_gen]
installed_contents = self.get_installed_files(score_deploy_path)
self.assertTrue(self.check_package_json_validity(installed_contents))
installed_contents.sort()
file_path_list.sort()
self.assertEqual(installed_contents, file_path_list)
# Case when installing SCORE with bad-zip-file Data.
tx_hash2 = create_tx_hash()
score_deploy_path: str = get_score_deploy_path(self.score_root_path, self.address, tx_hash2)
with self.assertRaises(BaseException) as e:
IconScoreDeployer.deploy(score_deploy_path, self.read_zipfile_as_byte(self.bad_zip_file_path))
self.assertEqual(e.exception.code, ExceptionCode.INVALID_PACKAGE)
self.assertTrue(os.path.exists(score_deploy_path))
# Case when the user specifies an installation path that does not have permission.
score_deploy_path: str = get_score_deploy_path('/', self.address, tx_hash1)
with self.assertRaises(BaseException) as e:
IconScoreDeployer.deploy(score_deploy_path, self.read_zipfile_as_byte(self.normal_score_path))
self.assertIsInstance(e.exception, PermissionError)
# Case when the user try to install scores inner directories.
tx_hash3 = create_tx_hash()
score_deploy_path: str = get_score_deploy_path(self.score_root_path, self.address, tx_hash3)
IconScoreDeployer.deploy(score_deploy_path, self.read_zipfile_as_byte(self.inner_dir_path))
self.assertEqual(True, os.path.exists(score_deploy_path))
def __init__(self, message: Optional[str]):
super().__init__(message, ExceptionCode.OUT_OF_BALANCE)
def __init__(self, message: Optional[str], index: int = 0):
if not isinstance(index, int):
raise InvalidParamsException('Invalid index type: not an integer')
code = ExceptionCode.SCORE_ERROR + index
if code < ExceptionCode.SCORE_ERROR:
code = ExceptionCode.SCORE_ERROR
elif code > ExceptionCode.END:
code = ExceptionCode.END
super().__init__(message, code)
def __init__(self, message: Optional[str]):
super().__init__(message, ExceptionCode.INVALID_PACKAGE)