Esempio n. 1
0
    def test_deploy_when_score_depth_is_different_above_revision3(self):
        """
        Reads all files from the depth lower than where the file 'package.json' is
        and test deploying successfully.
        """
        zip_list = [('score_registry.zip', [
            'interfaces/__init__.py', 'interfaces/abc_owned.py',
            'interfaces/abc_score_registry.py', 'package.json',
            'score_registry/__init__.py', 'score_registry/score_registry.py',
            'utility/__init__.py', 'utility/owned.py', 'utility/utils.py'
        ]), ('fakedir.zip', ['__init__.py', 'call_class1.py', 'package.json']),
                    ('nodir.zip',
                     ['__init__.py', 'package.json', 'sample_token.py'])]

        for zip_file, expected_list in zip_list:
            address: 'Address' = create_address(AddressPrefix.CONTRACT)
            self.archive_path = os.path.join(DIRECTORY_PATH, 'sample',
                                             zip_file)
            tx_hash1 = create_tx_hash()
            score_deploy_path: str = get_score_deploy_path(
                self.score_root_path, address, tx_hash1)

            IconScoreDeployer.deploy(
                score_deploy_path,
                self.read_zipfile_as_byte(self.archive_path),
                Revision.THREE.value)
            self.assertEqual(True, os.path.exists(score_deploy_path))

            installed_files = self.get_installed_files(score_deploy_path)
            installed_files.sort()
            self.assertEqual(installed_files, expected_list)

            score_path: str = get_score_path(self.score_root_path, address)
            remove_path(score_path)
Esempio n. 2
0
    def test_deploy_raise_no_package_above_revision3(self):
        """
        if package doesn't contain package.json, raise exception(no package.json) above revision 3
        """
        zip_list = ['nodir_nopackage.zip', 'normal_nopackage.zip']

        for zip_item in zip_list:
            address: 'Address' = create_address(AddressPrefix.CONTRACT)
            self.archive_path = os.path.join(DIRECTORY_PATH, 'sample',
                                             zip_item)
            tx_hash1 = create_tx_hash()
            score_deploy_path: str = get_score_deploy_path(
                self.score_root_path, address, tx_hash1)

            with self.assertRaises(BaseException) as e:
                IconScoreDeployer.deploy(
                    score_deploy_path,
                    self.read_zipfile_as_byte(self.archive_path),
                    Revision.THREE.value)
            self.assertEqual(e.exception.code, ExceptionCode.INVALID_PACKAGE)
            self.assertEqual(e.exception.message, "package.json not found")
            self.assertTrue(os.path.exists(score_deploy_path))

            score_path: str = get_score_path(self.score_root_path, address)
            remove_path(score_path)
Esempio n. 3
0
    def test_deploy_when_score_depth_is_different(self):
        """
        Reads all files from the depth lower than where the file 'package.json' is
        and test deploying successfully.
        """
        zip_list = ['score_registry.zip', 'fakedir.zip', 'nodir.zip']

        for zip_item in zip_list:
            address: 'Address' = create_address(AddressPrefix.CONTRACT)
            self.archive_path = os.path.join(DIRECTORY_PATH, 'sample',
                                             zip_item)
            tx_hash1 = create_tx_hash()
            score_deploy_path: str = get_score_deploy_path(
                self.score_root_path, address, tx_hash1)

            IconScoreDeployer.deploy(
                score_deploy_path,
                self.read_zipfile_as_byte(self.archive_path))
            self.assertEqual(True, os.path.exists(score_deploy_path))

            zip_file_info_gen = IconScoreDeployer._extract_files_gen(
                self.read_zipfile_as_byte(self.archive_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)

            score_path: str = get_score_path(self.score_root_path, address)
            remove_path(score_path)
Esempio n. 4
0
 def setUp(self):
     self.score_root_path = './'
     self.address: 'Address' = create_address(AddressPrefix.CONTRACT)
     self.score_path = get_score_path(self.score_root_path, self.address)