예제 #1
0
    def test_update_transaction_data(
            self, db_session, persistence_module: SQLPersistenceInterface):
        transaction = BlockchainTransaction()
        db_session.add(transaction)

        db_session.commit()

        persistence_module.update_transaction_data(transaction.id, {
            'status': 'SUCCESS',
            'ignore': True
        })

        assert transaction.status == 'SUCCESS'
        assert transaction.ignore is True
예제 #2
0
    def test_add_prior_tasks(self, db_session,
                             persistence_int: SQLPersistenceInterface):

        prior_1 = BlockchainTask(uuid=str_uuid())
        prior_2 = BlockchainTask(uuid=str_uuid())
        uuid_1 = prior_1.uuid
        uuid_2 = prior_2.uuid

        posterior = BlockchainTask(uuid=str_uuid())

        db_session.add_all([prior_1, prior_2, posterior])
        db_session.commit()

        persistence_int.add_prior_tasks(posterior, [uuid_1, uuid_2])

        assert prior_1 in posterior.prior_tasks
        assert prior_2 in posterior.prior_tasks
예제 #3
0
    def test_create_blockchain_wallet_from_private_key(
            self, db_session, persistence_module: SQLPersistenceInterface):

        from utils import keypair

        kp = keypair()

        trans = persistence_module.create_blockchain_wallet_from_private_key(
            kp['pk'])

        assert trans.address == kp['address']
예제 #4
0
    def test_create_blockchain_transaction(
            self, db_session, persistence_module: SQLPersistenceInterface):

        wallet = BlockchainWallet()
        db_session.add(wallet)

        task = BlockchainTask(str_uuid())
        task.signing_wallet = wallet
        db_session.add(task)

        trans = persistence_module.create_blockchain_transaction(
            task_uuid=task.uuid)

        assert trans.task.uuid == task.uuid
예제 #5
0
    def test_deploy_contract_test(self, db_session,
                                  persistence_module: SQLPersistenceInterface):
        signing_wallet_obj = BlockchainWallet()
        db_session.add(signing_wallet_obj)

        uuid = str_uuid()
        contract_name = 'ERC20'
        args = []
        kwargs = None
        gas_limit = None
        prior_tasks = None

        trans = persistence_module.create_deploy_contract_task(
            uuid, signing_wallet_obj, contract_name, args, kwargs, gas_limit,
            prior_tasks)

        assert trans.uuid == uuid
        assert trans.type == 'DEPLOY_CONTRACT'
예제 #6
0
 def test_add_transaction_filter(
         self, blockchain_sync, persistence_module: SQLPersistenceInterface,
         block_epoch, expected_max_block):
     # Build filter
     blockchain_sync.add_transaction_filter(self.contract_address,
                                            self.contract_type,
                                            self.filter_parameters,
                                            self.filter_type, self.decimals,
                                            block_epoch)
     # Query the filter
     f = persistence_module.check_if_synchronization_filter_exists(
         self.contract_address, self.filter_parameters)
     # Validate the filter object
     assert f.contract_type == self.contract_type
     assert f.filter_parameters == self.filter_parameters
     assert f.filter_type == self.filter_type
     assert f.decimals == self.decimals
     assert f.max_block == expected_max_block
예제 #7
0
    def test_create_function_task(self, db_session,
                                  persistence_module: SQLPersistenceInterface):

        signing_wallet_obj = BlockchainWallet()
        db_session.add(signing_wallet_obj)

        uuid = str_uuid()
        contract_address = '0x1234'
        abi_type = "ERC20"  # aka contract_type
        function_name = "transferFrom"
        args = ['0x1234', '0x2345', int(1e36)]
        kwargs = None
        signing_address = None
        encrypted_private_key = None
        gas_limit = None
        prior_tasks = None
        reserves_task = None

        trans = persistence_module.create_function_task(
            uuid, signing_wallet_obj, contract_address, abi_type,
            function_name, args, kwargs, gas_limit, prior_tasks, reserves_task)

        assert trans.uuid == uuid
        assert trans.type == 'FUNCTION'
예제 #8
0
    from celo_integration import CeloTransactionProcessor

    w3.middleware_onion.inject(geth_poa_middleware, layer=0)
    w3_websocket.middleware_onion.inject(geth_poa_middleware, layer=0)
    w3.eth.account = Account

    TransactionProcessorClass = CeloTransactionProcessor
else:
    TransactionProcessorClass = EthTransactionProcessor

red = redis.Redis.from_url(config.REDIS_URL)

first_block_hash = w3.eth.getBlock(0).hash.hex()

persistence_module = SQLPersistenceInterface(red=red,
                                             session=session,
                                             first_block_hash=first_block_hash)

processor = TransactionProcessorClass(
    ethereum_chain_id=chain_config['CHAIN_ID'],
    gas_price_wei=w3.toWei(chain_config['GAS_PRICE'], 'gwei'),
    gas_limit=chain_config['GAS_LIMIT'],
    w3=w3,
    persistence=persistence_module)

supervisor = TransactionSupervisor(red=red,
                                   persistence=persistence_module,
                                   processor=processor)

task_manager = TaskManager(persistence=persistence_module,
                           transaction_supervisor=supervisor)
예제 #9
0
                    broker=config.REDIS_URL,
                    backend=config.REDIS_URL,
                    task_serializer='json')

celery_app.conf.beat_schedule = {
    "maintain_eth_balances": {
        "task": utils.eth_endpoint('topup_wallets'),
        "schedule": 600.0
    },
}

w3 = Web3(HTTPProvider(config.ETH_HTTP_PROVIDER))

red = redis.Redis.from_url(config.REDIS_URL)

persistence_interface = SQLPersistenceInterface(w3=w3, red=red)

blockchain_processor = TransactionProcessor(
    **eth_config,
    w3=w3,
    red=red,
    persistence_interface=persistence_interface
)

import eth_manager.celery_tasks
#
# blockchain_processor.registry.register_contract(
#     config.ETH_CONTRACT_ADDRESS,
#     dai_abi.abi,
#     contract_name='Dai Stablecoin v1.0'
# )
예제 #10
0
def persistence_int(db_session):
    red = redis.Redis.from_url(config.REDIS_URL)

    return SQLPersistenceInterface(
        red=red, session=db_session, first_block_hash='deadbeef01'
    )