def setUp(self): self._state_db_root_path = '.db' self._score_root_path = '.score' rmtree(self._score_root_path) rmtree(self._state_db_root_path) engine = IconServiceEngine() conf = IconConfig("", default_icon_config) conf.load() conf.update_conf({ ConfigKey.BUILTIN_SCORE_OWNER: str(create_address(AddressPrefix.EOA)), ConfigKey.SCORE_ROOT_PATH: self._score_root_path, ConfigKey.STATE_DB_ROOT_PATH: self._state_db_root_path }) # engine._load_builtin_scores = Mock() # engine._init_global_value_by_governance_score = Mock() engine.open(conf) self._engine = engine self._genesis_address = create_address(AddressPrefix.EOA) self._treasury_address = create_address(AddressPrefix.EOA) self._governance_score_address =\ Address.from_string('cx0000000000000000000000000000000000000001') self.from_ = self._genesis_address self._to = create_address(AddressPrefix.EOA) self._icon_score_address = create_address(AddressPrefix.CONTRACT) self._total_supply = 100 * 10**18 accounts = [{ 'name': 'god', 'address': self._genesis_address, 'balance': self._total_supply }, { 'name': 'treasury', 'address': self._treasury_address, 'balance': 0 }] block = Block(0, create_block_hash(), 0, None) tx = { 'method': '', 'params': { 'txHash': create_tx_hash() }, 'genesisData': { 'accounts': accounts } } tx_lists = [tx] self._engine.invoke(block, tx_lists) self._engine.commit(block) self.genesis_block = block
def tearDown(self): try: self._context = IconScoreContext(IconScoreContextType.DIRECT) self._icx_storage.close(self._context) finally: remove_path = os.path.join(TEST_ROOT_PATH, self._ROOT_SCORE_PATH) rmtree(remove_path) remove_path = os.path.join(TEST_ROOT_PATH, self._TEST_DB_PATH) rmtree(remove_path)
def setUp(self): state_db_root_path = 'state_db' self.state_db_root_path = state_db_root_path rmtree(state_db_root_path) os.mkdir(state_db_root_path) address = Address.from_data(AddressPrefix.CONTRACT, b'0') db_path = os.path.join(state_db_root_path, 'db') context_db = ContextDatabase.from_path(db_path, True) self.db = IconScoreDatabase(address, context_db=context_db, prefix=b'') self.address = address
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)
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)
def setUp(self): state_db_root_path = 'state_db' self.state_db_root_path = state_db_root_path rmtree(state_db_root_path) os.mkdir(state_db_root_path) address = Address.from_data(AddressPrefix.CONTRACT, b'score') context = IconScoreContext(IconScoreContextType.INVOKE) context.block_batch = BlockBatch() context.tx_batch = TransactionBatch() db_path = os.path.join(state_db_root_path, 'db') context_db = ContextDatabase.from_path(db_path, True) meta_context_db = MetaContextDatabase(context_db.key_value_db) self.context_db = context_db self.meta_context_db = meta_context_db self.address = address self.context = context
def setUp(self): state_db_root_path = 'state_db' self.state_db_root_path = state_db_root_path rmtree(state_db_root_path) os.mkdir(state_db_root_path) address = Address.from_data(AddressPrefix.CONTRACT, b'score') context_factory = IconScoreContextFactory(max_size=2) context = context_factory.create(IconScoreContextType.INVOKE) context.block_batch = BlockBatch() context.tx_batch = TransactionBatch() db_path = os.path.join(state_db_root_path, 'db') context_db = ContextDatabase.from_path(db_path, True) self.context_factory = context_factory self.context_db = context_db self.address = address self.context = context
def tearDown(self): ContextContainer._pop_context() rmtree(self._score_root_path) sys.path.remove(self._score_root_path)
def tearDown(self): ContextContainer._pop_context() rmtree(self._score_path)
def tearDown(self): self._engine.close() rmtree(self._score_root_path) rmtree(self._state_db_root_path)
def tearDown(self): self.context.func_type = IconScoreFuncType.WRITABLE self.context_db.close(self.context) rmtree(self.state_db_root_path)
def tearDown(self): self.db.close() rmtree(self.state_db_root_path)
def setUp(self): self.state_db_root_path = 'state_db' rmtree(self.state_db_root_path) os.mkdir(self.state_db_root_path) self.db = KeyValueDatabase.from_path(self.state_db_root_path, True)
def clear_inner_task(): rmtree(default_icon_config[ConfigKey.SCORE_ROOT_PATH]) rmtree(default_icon_config[ConfigKey.STATE_DB_ROOT_PATH])
def test_put(self): for i in RANGE_LIST: rmtree(f"{DB_PATH}_{i}") for i in RANGE_LIST: self._put(i, self._hash_key_bypass)
def test_create_db(self): for i in RANGE_LIST: rmtree(f"{DB_PATH}{i}") for i in RANGE_LIST: self._create_new_db(i)