Пример #1
0
    def setUp(self):
        empty_address = MalformedAddress.from_string('')
        short_address_without_hx = MalformedAddress.from_string('12341234')
        short_address = MalformedAddress.from_string('hx1234512345')
        long_address_without_hx = MalformedAddress.from_string(
            'cf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf')
        long_address = MalformedAddress.from_string(
            'hxdf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf'
        )
        self.malformed_addresses = [
            empty_address, short_address_without_hx, short_address,
            long_address_without_hx, long_address
        ]

        self.db_name = 'engine.db'
        db = ContextDatabase.from_path(self.db_name)
        self.engine = IcxEngine()
        self._from = Address.from_string('hx' + 'a' * 40)
        self.to = Address.from_string('hx' + 'b' * 40)
        self.genesis_address = Address.from_string('hx' + '0' * 40)
        self.fee_treasury_address = Address.from_string('hx' + '1' * 40)
        self.total_supply = 10**20  # 100 icx

        self.context = IconScoreContext(IconScoreContextType.DIRECT)

        icx_storage = IcxStorage(db)
        self.engine.open(icx_storage)

        self.engine.init_account(self.context, AccountType.GENESIS, 'genesis',
                                 self.genesis_address, self.total_supply)
        self.engine.init_account(self.context, AccountType.TREASURY,
                                 'treasury', self.fee_treasury_address, 0)
Пример #2
0
def storage():
    db_name = 'fee.db'
    db = ContextDatabase.from_path(db_name)
    assert db is not None
    storage = FeeStorage(db)
    yield storage
    rmtree(db_name)
Пример #3
0
    def setUp(self):
        empty_address = MalformedAddress.from_string('')
        short_address_without_hx = MalformedAddress.from_string('12341234')
        short_address = MalformedAddress.from_string('hx1234512345')
        long_address_without_hx = MalformedAddress.from_string(
            'cf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf')
        long_address = MalformedAddress.from_string(
            'hxcf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf'
        )
        self.addresses = [
            empty_address, short_address_without_hx, short_address,
            long_address_without_hx, long_address
        ]

        self.db_name = 'icx.db'
        db = ContextDatabase.from_path(self.db_name)
        self.assertIsNotNone(db)

        self.storage = IcxStorage(db)

        context = IconScoreContext(IconScoreContextType.DIRECT)
        mock_block: 'Mock' = Mock(spec=Block)
        mock_block.attach_mock(Mock(return_value=0), 'height')
        context.block = mock_block

        self.context = context
Пример #4
0
def storage(context):
    db_name = 'icx.db'
    db = ContextDatabase.from_path(db_name)
    storage = Storage(db)
    context.storage = ContextStorage(icx=storage)
    storage.open(context)
    yield storage
    storage.close(context)
    shutil.rmtree(db_name)
Пример #5
0
    def setUp(self):
        self.db_name = 'fee.db'
        self.address = create_address(AddressPrefix.EOA)
        db = ContextDatabase.from_path(self.db_name)
        self.assertIsNotNone(db)

        self.storage = FeeStorage(db)

        context = IconScoreContext(IconScoreContextType.DIRECT)
        context.tx_batch = TransactionBatch()
        context.block_batch = BlockBatch()
        self.context = context
Пример #6
0
    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
Пример #7
0
    def setUp(self):
        self.db_name = 'icx.db'
        self.address = create_address(AddressPrefix.EOA)
        db = ContextDatabase.from_path(self.db_name)
        self.assertIsNotNone(db)

        self.storage = IcxStorage(db)

        self.factory = IconScoreContextFactory(max_size=1)
        context = self.factory.create(IconScoreContextType.DIRECT)
        context.tx_batch = TransactionBatch()
        context.block_batch = BlockBatch()
        self.context = context
Пример #8
0
    def setUp(self):
        self.db_name = 'icx.db'

        db = ContextDatabase.from_path(self.db_name)
        self.assertIsNotNone(db)

        self.storage = IcxStorage(db)

        context = IconScoreContext(IconScoreContextType.DIRECT)
        context.tx_batch = TransactionBatch()
        mock_block: 'Mock' = Mock(spec=Block)
        mock_block.attach_mock(Mock(return_value=0), 'height')
        context.block = mock_block
        context.block_batch = BlockBatch()
        self.context = context
Пример #9
0
    def setUp(self):
        empty_address = MalformedAddress.from_string('')
        short_address_without_hx = MalformedAddress.from_string('12341234')
        short_address = MalformedAddress.from_string('hx1234512345')
        long_address_without_hx = MalformedAddress.from_string(
            'cf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf')
        long_address = MalformedAddress.from_string(
            'hxdf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf'
        )
        self.malformed_addresses = [
            empty_address, short_address_without_hx, short_address,
            long_address_without_hx, long_address
        ]

        self.db_name = 'engine.db'
        db = ContextDatabase.from_path(self.db_name)
        self.engine = IcxEngine()
        self._from = Address.from_string('hx' + 'a' * 40)
        self.to = Address.from_string('hx' + 'b' * 40)
        self.genesis_address = Address.from_string('hx' + '0' * 40)
        self.fee_treasury_address = Address.from_string('hx' + '1' * 40)
        self.total_supply = 10**20  # 100 icx

        self.context = IconScoreContext(IconScoreContextType.DIRECT)
        block = Mock(spec=Block)
        block.attach_mock(Mock(return_value=0), 'height')
        self.context.block = block

        self.storage = IcxStorage(db)
        self.engine.open()

        accounts: list = [{
            'address': self.genesis_address,
            'balance': self.total_supply
        }, {
            'address': self.fee_treasury_address,
            'balance': 0
        }]
        self.context.storage = ContextStorage(deploy=None,
                                              fee=None,
                                              icx=self.storage,
                                              iiss=None,
                                              prep=None,
                                              issue=None,
                                              rc=None,
                                              meta=None)
        self.storage.put_genesis_accounts(self.context, accounts)
Пример #10
0
    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
Пример #11
0
    def setUp(self):

        self.db_name = 'engine.db'
        db = ContextDatabase.from_path(self.db_name)
        self.engine = IcxEngine()
        self.from_ = Address.from_string('hx' + 'a' * 40)
        self.to = Address.from_string('hx' + 'b' * 40)
        self.genesis_address = Address.from_string('hx' + '0' * 40)
        self.fee_treasury_address = Address.from_string('hx' + '1' * 40)
        self.total_supply = 10**20  # 100 icx

        self.context = IconScoreContext(IconScoreContextType.DIRECT)

        icx_storage = IcxStorage(db)
        self.engine.open(icx_storage)

        self.engine.init_account(self.context, AccountType.GENESIS, 'genesis',
                                 self.genesis_address, self.total_supply)
        self.engine.init_account(self.context, AccountType.TREASURY,
                                 'treasury', self.fee_treasury_address, 0)
Пример #12
0
    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
Пример #13
0
    def setUp(self):
        empty_address = MalformedAddress.from_string('')
        short_address_without_hx = MalformedAddress.from_string('12341234')
        short_address = MalformedAddress.from_string('hx1234512345')
        long_address_without_hx = MalformedAddress.from_string(
            'cf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf')
        long_address = MalformedAddress.from_string(
            'hxcf85fac2d0b507a2db9ce9526e6d01476f16a2d269f51636f9c4b2d512017faf'
        )
        self.addresses = [
            empty_address, short_address_without_hx, short_address,
            long_address_without_hx, long_address
        ]

        self.db_name = 'icx.db'
        db = ContextDatabase.from_path(self.db_name)
        self.assertIsNotNone(db)

        self.storage = IcxStorage(db)

        context = IconScoreContext(IconScoreContextType.DIRECT)
        self.context = context
Пример #14
0
    def setUp(self):

        self.db_name = 'engine.db'
        db = ContextDatabase.from_path(self.db_name)
        self.engine = IcxEngine()
        self.storage = IcxStorage(db)
        self.from_ = Address.from_string('hx' + 'a' * 40)
        self.to = Address.from_string('hx' + 'b' * 40)
        self.genesis_address = Address.from_string('hx' + '0' * 40)
        self.fee_treasury_address = Address.from_string('hx' + '1' * 40)
        self.total_supply = 10**20  # 100 icx
        self.fee_treasury_address_icx_amount = 0

        self.context = IconScoreContext(IconScoreContextType.DIRECT)

        block = Mock(spec=Block)
        block.attach_mock(Mock(return_value=0), 'height')
        self.context.block = block

        self.engine.open()

        accounts: list = [{
            'address': self.genesis_address,
            'balance': self.total_supply
        }, {
            'address': self.fee_treasury_address,
            'balance': 0
        }]
        self.context.storage = ContextStorage(deploy=None,
                                              fee=None,
                                              icx=self.storage,
                                              iiss=None,
                                              prep=None,
                                              issue=None,
                                              rc=None,
                                              meta=None)
        self.storage.put_genesis_accounts(self.context, accounts)