Exemple #1
0
    def tearDown(self):
        self.engine = None
        self.icx_storage.close(self._context)
        self.factory.destroy(self._context)
        ContextDatabaseFactory.close()

        remove_path = os.path.join(TEST_ROOT_PATH, self._ROOT_SCORE_PATH)
        IconScoreDeployer.remove_existing_score(remove_path)
        remove_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        IconScoreDeployer.remove_existing_score(remove_path)
Exemple #2
0
    def tearDown(self):
        self.engine = None
        self.icx_storage.close(self._context)
        ContextDatabaseFactory.close()

        path = os.path.join(TEST_ROOT_PATH, self._SCORE_ROOT_PATH)
        remove_path(path)
        path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        remove_path(path)

        IconScoreClassLoader.exit(self._SCORE_ROOT_PATH)
Exemple #3
0
    def setUp(self):
        db_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        score_path = os.path.join(TEST_ROOT_PATH, self._ROOT_SCORE_PATH)

        self._tx_index = 0
        self.__ensure_dir(db_path)

        self._icx_db = ContextDatabaseFactory.create_by_name('icx_db')
        self._icx_db.address = ICX_ENGINE_ADDRESS
        self._icx_storage = IcxStorage(self._icx_db)
        self._icon_deploy_storage = IconScoreDeployStorage(self._icx_db)

        self._engine = IconScoreDeployEngine()
        self._icon_score_loader = IconScoreLoader(score_path, 0)
        IconScoreMapper.icon_score_loader = self._icon_score_loader
        IconScoreMapper.deploy_storage = self._icon_deploy_storage
        self._icon_score_mapper = IconScoreMapper()

        IconScoreContext.icon_score_manager = Mock(spec=IconScoreManager)

        self._engine.open(
            score_root_path=score_path,
            flag=0,
            icon_deploy_storage=self._icon_deploy_storage)

        self.from_address = create_address(AddressPrefix.EOA)

        self.sample_token_address = create_address(AddressPrefix.CONTRACT)

        self._factory = IconScoreContextFactory(max_size=1)
        self.make_context()

        self._one_icx = 1 * 10 ** 18
        self._one_icx_to_token = 1
Exemple #4
0
    def setUp(self):
        db_path = os.path.join(PROJECT_ROOT_PATH, self._TEST_DB_PATH)
        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 setUp(self):
        rmtree(self._ROOT_SCORE_PATH)
        rmtree(self._TEST_DB_PATH)

        archive_path = 'tests/sample/valid.zip'
        archive_path = os.path.join(TEST_ROOT_PATH, archive_path)
        zip_bytes = self.read_zipfile_as_byte(archive_path)
        install_path = os.path.join(TEST_ROOT_PATH, self._ROOT_SCORE_PATH)
        self.__unpack_zip_file(install_path, zip_bytes)

        db_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        ContextDatabaseFactory.open(
            db_path, ContextDatabaseFactory.Mode.SINGLE_DB)

        self.__ensure_dir(db_path)

        icx_db = ContextDatabaseFactory.create_by_name('icx_db')
        self.icx_storage = IcxStorage(icx_db)
        deploy_storage = IconScoreDeployStorage(self.icx_storage.db)
        deploy_engine = IconScoreDeployEngine()
        deploy_engine.open(self._ROOT_SCORE_PATH, 0, deploy_storage)
        IconScoreContext.icon_score_manager = IconScoreManager(deploy_engine)

        self.icon_score_loader = IconScoreLoader(self._ROOT_SCORE_PATH, 0)

        IconScoreMapper.icon_score_loader = self.icon_score_loader
        IconScoreMapper.deploy_storage = deploy_storage
        self.icon_score_mapper = IconScoreMapper()

        self.engine = IconScoreEngine()
        self.engine.open(
            self.icx_storage,
            self.icon_score_mapper)

        self._from = create_address(AddressPrefix.EOA)
        self._icon_score_address = create_address(AddressPrefix.CONTRACT)

        self.factory = IconScoreContextFactory(max_size=1)
        IconScoreContext.icon_score_mapper = self.icon_score_mapper
        self._context = self.factory.create(IconScoreContextType.DIRECT)
        self._context.msg = Message(self._from, 0)
        tx_hash = create_tx_hash()
        self._context.tx = Transaction(
            tx_hash, origin=create_address(AddressPrefix.EOA))
        block_hash = create_block_hash()
        self._context.block = Block(1, block_hash, 0, None)
Exemple #6
0
    def setUp(self):
        rmtree(self._SCORE_ROOT_PATH)
        rmtree(self._TEST_DB_PATH)

        archive_path = 'tests/sample/normal_score.zip'
        archive_path = os.path.join(TEST_ROOT_PATH, archive_path)
        zip_bytes = self.read_zipfile_as_byte(archive_path)
        install_path = os.path.join(TEST_ROOT_PATH, self._SCORE_ROOT_PATH)
        self.__unpack_zip_file(install_path, zip_bytes)

        db_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        ContextDatabaseFactory.open(db_path,
                                    ContextDatabaseFactory.Mode.SINGLE_DB)

        self.__ensure_dir(db_path)

        icx_db = ContextDatabaseFactory.create_by_name('icx_db')
        self.icx_storage = IcxStorage(icx_db)
        deploy_storage = IconScoreDeployStorage(self.icx_storage.db)
        deploy_engine = IconScoreDeployEngine()
        deploy_engine.open(deploy_storage)

        IconScoreClassLoader.init(self._SCORE_ROOT_PATH)

        IconScoreMapper.deploy_storage = deploy_storage
        self.icon_score_mapper = IconScoreMapper()

        self.engine = IconScoreEngine()
        # Use mock to prevent an exception from IconScoreEngine._validate_score_blacklist().
        IconScoreEngine._validate_score_blacklist = mock.Mock()

        self._from = create_address(AddressPrefix.EOA)
        self._icon_score_address = create_address(AddressPrefix.CONTRACT)

        IconScoreContext.icon_score_deploy_engine = deploy_engine
        self._context = IconScoreContext(IconScoreContextType.DIRECT)
        self._context.msg = Message(self._from, 0)
        tx_hash = create_tx_hash()
        self._context.tx = Transaction(tx_hash,
                                       origin=create_address(
                                           AddressPrefix.EOA))
        block_hash = create_block_hash()
        self._context.block = Block(1, block_hash, 0, None)
Exemple #7
0
    def setUp(self):
        db_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        score_path = os.path.join(TEST_ROOT_PATH, self._ROOT_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 = IconScoreDeployEngine()
        self._deploy_storage = IconScoreDeployStorage(self._icx_db)

        self._icon_score_loader = IconScoreClassLoader(score_path)
        self._icon_score_mapper = IconScoreMapper()

        self._addr1 = create_address(AddressPrefix.EOA)
        self._score_deploy_engine.open(
            score_root_path=score_path,
            score_deploy_storage=self._deploy_storage)

        self.make_context()
Exemple #8
0
    def setUp(self):
        db_path: str = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH)
        # score_root_path: str = os.path.join(TEST_ROOT_PATH, self._SCORE_ROOT_PATH)

        self._tx_index = 0
        self.__ensure_dir(db_path)

        self._icx_db = ContextDatabaseFactory.create_by_name('icx_db')
        self._icx_db.address = ICX_ENGINE_ADDRESS
        self._icx_storage = IcxStorage(self._icx_db)
        self._icon_deploy_storage = DeployStorage(self._icx_db)

        self._icon_score_mapper = IconScoreMapper()

        IconScoreContextUtil.validate_score_blacklist = Mock()
        IconScoreContextUtil.get_owner = Mock()
        IconScoreContextUtil.get_icon_score = Mock()
        IconScoreContextUtil.is_service_flag_on = Mock()

        self.from_address = create_address(AddressPrefix.EOA)
        self.sample_token_address = create_address(AddressPrefix.CONTRACT)

        self.make_context()
        self._engine = DeployEngine()
        self._engine.open(self._icon_deploy_storage)
        IconScoreContext.storage = ContextStorage(
            deploy=Mock(DeployStorage),
            fee=None,
            icx=None,
            iiss=None,
            prep=None,
            issue=None,
            rc=None,
            meta=None
        )

        self._one_icx = 1 * 10 ** 18
        self._one_icx_to_token = 1
Exemple #9
0
 def tearDownClass(cls):
     ContextDatabaseFactory.close()
Exemple #10
0
 def setUpClass(cls):
     db_path = os.path.join(TEST_ROOT_PATH, cls._TEST_DB_PATH)
     ContextDatabaseFactory.open(
         db_path, ContextDatabaseFactory.Mode.SINGLE_DB)