Testing and Running UDF

Before deploying your UDF, it's important to test it to ensure it works as expected.

Unit Tests

Write unit tests for your processing logic:

import unittest from your_udf_jobs import YourCustomJob from hemera.dataclasses import Transaction

class TestYourCustomJob(unittest.TestCase):

def test_process(self):
    # Setup test data
    transactions = [
        Transaction(hash='0x1', value='0xde0b6b3a7640000', from_address='0xabc'),  # 1 Ether
        Transaction(hash='0x2', value='0x1bc16d674ec80000', from_address='0xdef'),  # 2 Ether
    ]
    job = YourCustomJob()
    # Run the process method
    result = job.process(transactions)
    # Assert the results
    self.assertEqual(len(result), 1)
    self.assertEqual(result[0].field1, '0x2')
    # Add more assertions as necessary

if name == 'main': unittest.main()

Integration Tests

Run the indexer with your UDF in a test environment:

  • Use a test blockchain network (e.g., Ganache, or a testnet) to provide blockchain data.

  • Use a test database to avoid affecting production data.

  • Run the indexer and verify that your UDF processes data correctly and stores it in the database.

Running the hemera indexer with UDFs

Once you've tested your UDF, you can deploy it as part of the Hemera Indexer in your production environment.

Steps to Running

  1. Ensure Code is in the Correct Location: Place your UDF code in the appropriate directories within the Hemera Indexer project.

  2. Update Configuration: Make sure any configuration files or scripts include your UDF.

  3. Update Database: Apply any new database migrations.

  4. Restart the Indexer: Restart the Hemera Indexer to pick up the new UDF.

Using Docker

If you're using Docker to run Hemera Indexer:

  • Update the Docker Image: Include your UDF code in the Docker image.

  • Rebuild the Image:

docker-compose build
  • Restart the Containers:

docker-compose up -d

Running from Source

  1. Install development tools as specified in the Hemera documentation.

  2. Prepare PostgreSQL and other dependencies.

  3. Setup the enviroment:

make development
source .venv/bin/activate

Run the hemera Indexer through CLI:


 python3 hemera.py stream \  --provider-uri https://ethereum.publicnode.com \  --start-block 12598072 \  --end-block 20804486 \
  --output-types UniswapV3Token \
  --block-batch-size 10000 \
  --postgres-url postgresql://hemera:123asd@localhost:5432/demo \
  --output postgres \
  --config-file config/indexer-config-template.yaml

Another way to test whether your UDFs are correctly configured and functioning is by checking the output folder or the PostgreSQL database. If you're using a PostgreSQL database, you can query the relevant table to verify the data.

For more detailed setup and deployment options, refer to the Installation section.

Last updated