Skip to content

maxence-cornaton/iExecTechnicalTest

Repository files navigation

iExecTechnicalTest

Build Status

Overview

This project presents the result of the technical test offer by iExec. It is composed of a few steps, some of them being optional.

The following features are currently available:

  1. An API allows to create tasks and retrieve the count of tasks.
  2. These tasks are stored in a database.
  3. Requesting the count of tasks on an already-deployed Smart-Contract.

The following feature is still to be added:

  1. Adding a new endpoint POST /blockchain/tasks allowing to trigger the newTask() function on the same Smart-Contract. The BlockchainTask (with transaction ID and date) should be stored in MongoDB in a dedicated collection ( BlockchainTask collection).

Besides, a bunch of tools has been set up, so it's easier to build and deploy:

Building & running

The project has been thought to be docker-izable, i.e. it can easily be started as a Docker container. It can also be started as a more traditional Java application. Use the version that fits the most your use cases!

Before running the app, some properties need to be defined.

Defining the properties

The application supports three ways to define some properties:

  • Using variable environments as screaming snake case (e.g. DB_NAME);
  • Using JVM options as screaming snake case (e.g. DB_NAME).
  • Using Java application properties as lowercase separated by points (e.g. db.name). The first is most significant than the second, meaning that if a property is defined in both way, it will take the value of the variable environment.

The following properties can be defined to customize the application:

  • DB_HOST: host name of the database. Default to 127.0.0.1.
  • DB_NAME: database name. Default to iexec.
  • DB_PORT: database port. Default to 27017.
  • BLOCKCHAIN_ID: used blockchain id. Default to 5 (Goerli Tesnet blockchain id).
  • BLOCKCHAIN_CONTRACT_TASKCOUNT_URL: TaskCount contract url. Default to 0xf837B595Fb53B3e8a1feBE0846d8a0e53f44e72a.
  • BLOCKCHAIN_PRIVATE_KEY: private key to use the blockchain. No default value so it should always be provided.
  • BLOCKCHAIN_GAS_PRICE: gas price on the blockchain. Default to 2000000000.
  • BLOCKCHAIN_GAS_LIMIT: gas limit on the blockchain. Default to 1000000000.

Running as traditional Java application

How to build the traditional application

The build is done using gradle. It is as simple as:

# If Gradle is installed globally:
gradle assemble

# If Gradle is installed locally:
./gradlew assemble

How to run the traditional application

The application requires a MongoDB server running, either locally or remotely. Do not forget to provide your private key.

# Running the application with a locally running MongoDB server:
java -DBLOCKCHAIN_PRIVATE_KEY=${PRIVATE_KEY} -jar build/libs/iexec-0.0.1-SNAPSHOT.jar

# Running the application with a remotely running MongoDB server:
java -DBLOCKCHAIN_PRIVATE_KEY=${PRIVATE_KEY} -DDB_HOST=${REMOTE_HOST} -jar build/libs/iexec-0.0.1-SNAPSHOT.jar

Running as a Docker container

How to build the Docker image

The application still has to be built before being dockerized:

# If Gradle is installed globally:
gradle assemble

# If Gradle is installed locally:
./gradlew assemble

The Docker image is then built using the Dockerfile provided at the root of the repository:

docker build -t iexec .

How to run the Docker image

When running this project in a Docker container, it should be linked to a dockerized MongoDB instance. Do not forget to provide your private key.

docker run --name mongo -p 27017:27017 -d -t mongo
docker run --rm --name iexec --link mongo --env BLOCKCHAIN_PRIVATE_KEY=${PRIVATE_KEY} -p 8080:8080 -t iexec

Note that you can change the MongoDB container name. In this case, you'll have to overload the DB_HOST environment variable and to change the link parameter:

docker run --name ${MONGO_CONTAINER_NAME} -p 27017:27017 -d -t mongo
docker run --rm --name iexec --link ${MONGO_CONTAINER_NAME} --env DB_HOST=${MONGO_CONTAINER_NAME} --env BLOCKCHAIN_PRIVATE_KEY=${PRIVATE_KEY} -p 8080:8080 -t iexec

Build & run in a single step

The project provides a docker-compose configuration file, so it can be run in a single and easy command line:

docker-compose up

Testing

The easiest way to start tests is to run the gradle test command:

# If Gradle is installed globally:
gradle test

# If Gradle is installed locally:
./gradlew test

Please note that the MongoDB server should be up and reachable to ensure the tests will work.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages