Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 1 #4

Merged
merged 8 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.git
.vscode
node_modules
npm-debug.log
coverage
.nyc_output
dist
.env
storage
42 changes: 42 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
LOGGING_LEVEL=debug
LOGGING_FORMAT=text
LOGGING_COLORIZE=false

HTTP_IP=
HTTP_PORT=
ENVIRONMENT=test

APP_API_PREFIX_URL=http://api:3000
APP_FRONTEND_PREFIX_URL=http://token-wallets.com

THROTTLER_WHITE_LIST=
THROTTLER_INTERVAL=
THROTTLER_MAX=10000
THROTTLER_MIN_DIFF=

MONGO_URL=mongodb://mongo:27017/test
ORM_ENTITIES_DIR=src/entities/**/*.ts
ORM_SUBSCRIBER_DIR=src/subscriber/**/*.ts
ORM_MIGRATIONS_DIR=src/migrations/**/*.ts

REDIS_URL=redis://redis:6379

AUTH_VERIFY_URL=
AUTH_ACCESS_JWT=
AUTH_TIMEOUT=

VERIFY_BASE_URL=http://verify:3000
VERIFY_TIMEOUT=

RPC_TYPE=http
RPC_ADDRESS=https://ropsten.infura.io/ujGcHij7xZIyz2afx4h2

WEB3_RESTORE_START_BLOCK=2518791

ICO_SC_ADDRESS=
ICO_SC_ABI_FILEPATH=
WHITELIST_SC_ADDRESS=
WHITELIST_SC_ABI_FILEPATH=
WHITELIST_OWNER_PK_FILEPATH=
ERC20_TOKEN_ADDRESS=0x7267e91c9dd6f402bea68a943374b7652575b989
ERC20_TOKEN_ABI_FILEPATH=test/abi/StandardToken.abi
68 changes: 61 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
node_modules
npm-debug.log
coverage
.nyc_output
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
dist
ts-node

.idea
ts-node
coverage

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.vscode
storage

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
29 changes: 29 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"lines": 80,
"statements": 80,
"functions": 80,
"branches": 68,
"include": [
"**/*.ts"
],
"exclude": [
"**/*.spec.ts",
"coverage",
"*.ts",
"src/*.ts"
],
"reporter": [
"html",
"text",
"text-summary"
],
"require": [
"ts-node/register"
],
"extension": [
".ts"
],
"cache": false,
"all": false,
"check-coverage": true
}
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo: required
services:
- docker
script:
- chmod ugo+x ./build.sh
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "prod"; elif [
"$TRAVIS_BRANCH" == "dev" ]; then echo "stage"; else echo "dev-$(git rev-parse
--short HEAD)"; fi`
- "./build.sh $TAG"
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM mhart/alpine-node:8.6

WORKDIR /usr/src/app
ADD . /usr/src/app

RUN apk add --update --no-cache git python make g++ && \
npm install && \
npm run build && \
npm prune --production && \
apk del --purge git python make g++ && \
rm -rf ./src ./test

CMD npm run serve
7 changes: 7 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mhart/alpine-node:8.9.1

RUN apk update && apk upgrade && apk add git && apk add python && apk add make && apk add g++
VOLUME /usr/src/app
EXPOSE 3000
EXPOSE 4000
WORKDIR /usr/src/app
10 changes: 10 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mhart/alpine-node:8.6

WORKDIR /usr/src/app
ADD . /usr/src/app

RUN apk add --update --no-cache git python make g++ && \
npm install && \
apk del --purge git python make g++

CMD npm start
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# Backend Token Wallets
# Jincor PC Backend
This is backend module of Jincor ICO dashboard: https://contribute.jincor.com.

Todo
It was implemented to provide following functionality:
1. ICO users sign up.
1. Generation of Ethereum address upon user activation.
1. Token purchase.
1. Displaying User's transaction history.
1. All important actions are protected with 2FA (email or google authenticator) by integration with Jincor Backend Verify service (https://github.com/JincorTech/backend-verify)
1. For more info check API docs: https://jincortech.github.io/backend-ico-dashboard

## Technology stack

1. Typescript, Express, InversifyJS (DI), TypeORM (MongoDB interaction).
1. Web3JS - interaction with Ethereum client. ICO backend supports any JSON-RPC compliant client.
1. Mocha/chai - unit/functional tests.
1. Docker.

## How to start development and run tests?

1. Clone this repo.
1. Run `docker-compose build --no-cache`.
1. Run `docker-compose up -d`.
1. Run `cp .env.test .env`.
1. To install dependencies run `docker-compose exec ico npm i`.
1. Run tests `docker-compose exec ico npm test`.

## How to generate docs?

1. Install aglio `npm install -g aglio`.
1. Run `mkdir /usr/local/lib/node_modules/aglio/node_modules/aglio-theme-olio/cache`.
1. Generate `aglio --theme-variables cyborg --theme-template triple -i apiary.apib -o ./docs/index.html`.
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -ex
IMAGE_NAME="jincort/backend-token-wallets"
DOCKER_FILE="Dockerfile.$TAG"
DOCKER_FILE=$( [ -e "$DOCKER_FILE" ] && echo $DOCKER_FILE || echo Dockerfile )
docker build -f $DOCKER_FILE -t ${IMAGE_NAME}:${TAG} . || exit 1
docker push ${IMAGE_NAME}:${TAG}
78 changes: 78 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: '3.2'

networks:
backendTokenWalletsTests:

services:
api:
image: jincort/backend-token-wallets:test
networks:
backendTokenWalletsTests:
aliases:
- api
build:
context: ./
dockerfile: Dockerfile.test
env_file:
- .env.test
command: >
sh -c '
apk add --update --no-cache curl &&
n=1; while [ -z "`nc -z auth 3000 && echo 1`" ] && [ "$$n" != "30" ]; do sleep 1; n=`expr $$n + 1`; echo "Wait auth $$n"; done &&
curl auth:3000/tenant -H "Accept: application/json" -H "Content-Type: application/json" \
-d "{\"email\":\"test@test.com\",\"password\":\"aA1qwerty\"}" ;
export AUTH_ACCESS_JWT=`curl auth:3000/tenant/login -H "Accept: application/json" -H "Content-Type: application/json" \
-d "{\"email\":\"test@test.com\",\"password\":\"aA1qwerty\"}" | grep -oE "accessToken\":\"[^\"]+" | cut -d\" -f3` ;
npm test
'
volumes:
- ./src/:/usr/src/app/src:ro
- ./test/:/usr/src/app/test:ro
links:
- mongo
- redis
- auth
- verify

auth:
image: jincort/backend-auth:production
networks:
backendTokenWalletsTests:
aliases:
- auth
environment:
REDIS_HOST: redis
REDIS_PORT: 6379
FORCE_HTTPS: disabled
JWT_KEY: zd003d435e74b9150aa5573cb73ddfbe1
THROTTLER_WHITE_LIST: "127.0.0.1"
TENANT_WHITE_LIST: "*"
THROTTLER_MAX: "10000"
links:
- redis

verify:
image: jincort/backend-verify:stage
networks:
backendTokenWalletsTests:
environment:
REDIS_URL: 'redis://redis:6379'
THROTTLER_WHITE_LIST: "127.0.0.1"
THROTTLER_MAX: "10000"
links:
- redis
- auth

redis:
image: jincort/backend-redis:latest
networks:
backendTokenWalletsTests:
tmpfs:
- /data

mongo:
image: jincort/backend-mongodb:production
networks:
backendTokenWalletsTests:
tmpfs:
- /data/db
Loading