Skip to content

Commit

Permalink
chore: add pre-commit check
Browse files Browse the repository at this point in the history
  • Loading branch information
sqfasd committed Aug 25, 2018
1 parent 8cc2b01 commit 36a7ce4
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 44 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
src/model/*
test/utils
test/scripts
node_modules
build
coverage
data
chains
public
jest.config.js
2 changes: 2 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint import/no-extraneous-dependencies: 0 */

const shell = require('shelljs')
const moment = require('moment')
const path = require('path')
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"private": true,
"scripts": {
"start": "node app.js",
"lint": "eslint .",
"test": "LOG_LEVEL=error jest --globalSetup ./test/integration/setup.js --globalTeardown ./test/integration/teardown.js ./test/integration"
},
"pre-commit": [
"lint"
],
"author": "Qingfeng Shan <sqf1225@foxmail.com>",
"dependencies": {
"asch-core": "https://github.com/AschPlatform/asch-core/tarball/develop",
Expand All @@ -17,11 +21,12 @@
},
"devDependencies": {
"asch-js": "https://github.com/AschPlatform/asch-js/tarball/master",
"eslint-config-asch-base": "*",
"jest": "=23.4.1",
"debug": "=3.1.0",
"moment": "^2.9.0",
"shelljs": "^0.7.8",
"supertest": "^1.0.1"
"eslint-config-asch-base": "https://github.com/AschPlatform/eslint-config-asch-base/tarball/master",
"jest": "=23.4.1",
"moment": "=2.9.0",
"pre-commit": "=1.2.2",
"shelljs": "=0.7.8",
"supertest": "=1.0.1"
}
}
14 changes: 6 additions & 8 deletions src/contract/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ module.exports = {
return null
},

async replaceDelegate(chain, from, to) {
// app.sdb.update('ChainDelegate', { delegate: to }, { delegate: from, chain: chain })
async replaceDelegate(/* chain, from, to */) {
return 'unsupported feature'
},

async addDelegate(chain, key) {
// app.sdb.create('ChainDelegate', { chain: chain, delegate: key })
// app.sdb.increment('Chain', { unlockNumber: 1 }, { name: chain })
async addDelegate(/* chain, key */) {
return 'unsupported feature'
},

async removeDelegate(chain, key) {
// app.sdb.del('ChainDelegate', { chain: chain, delegate: key })
// app.sdb.increment('Chain', { unlockNumber: -1 }, { name: chain })
async removeDelegate(/* chain, key */) {
return 'unsupported feature'
},

async deposit(chainName, currency, amount) {
Expand Down
2 changes: 1 addition & 1 deletion src/contract/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ module.exports = {
}
app.sdb.del('GroupMember', { member: address, name: this.sender.name })
return null
}
},
}
9 changes: 4 additions & 5 deletions src/interface/blocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const _ = require('lodash')

module.exports = (router) => {
router.get('/', async (req) => {
const query = req.query
Expand All @@ -18,6 +16,7 @@ module.exports = (router) => {
}
const withTransactions = !!query.transactions
let blocks = await modules.blocks.getBlocks(minHeight, maxHeight, withTransactions)
const _ = app.util.lodash
if (needReverse) {
blocks = _.reverse(blocks)
}
Expand All @@ -29,16 +28,16 @@ module.exports = (router) => {
const idOrHeight = req.params.idOrHeight
let block
if (idOrHeight.length === 64) {
let id = idOrHeight
const id = idOrHeight
block = await app.sdb.getBlockById(id)
} else {
let height = Number(idOrHeight)
const height = Number(idOrHeight)
if (Number.isInteger(height) && height >= 0) {
block = await app.sdb.getBlockByHeight(height)
}
}
if (!block) throw new Error('Block not found')
if (!!req.query.transactions) {
if (req.query.transactions) {
const transactions = await app.sdb.findAll('Transaction', {
condition: {
height: block.height,
Expand Down
2 changes: 1 addition & 1 deletion src/interface/delegates.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = (router) => {
module.exports = () => {
}
2 changes: 1 addition & 1 deletion test/integration/interface/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jest.setTimeout(1000000)

describe('block interfaces', () => {
test('/api/v2/blocks', async () => {
let ret = await lib.apiGetAsync('/v2/blocks')
const ret = await lib.apiGetAsync('/v2/blocks')
expect(ret.body).toBeTruthy()
debug('get blocks length', ret.body.blocks)
expect(ret.body.success).toEqual(true)
Expand Down
14 changes: 11 additions & 3 deletions test/integration/setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
const lib = require('../lib')

module.exports = async function () {
module.exports = async () => {
console.log('\r\n=============setup=============')
console.log('starting asch service ....')
require('../../app.js')
await lib.sleep(5000)
await lib.onNewBlockAsync()
await lib.sleep(2000)

let height = null
while (!height) {
try {
height = await lib.getHeight()
} catch (e) {
height = null
}
}
console.log('asch service started')
}
2 changes: 1 addition & 1 deletion test/integration/teardown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async function () {
module.exports = async () => {
console.log('=============teardown=============')
process.exit(0)
}
41 changes: 22 additions & 19 deletions test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,6 @@ function randomCoin() {
return Math.floor(Math.random() * (10000 * 100000000)) + (1000 * 100000000)
}

async function _getHeight() {
const ret = await apiGetAsync('/blocks/getHeight')
debug('get height response', ret.body)
return ret.body.height
}

async function onNewBlockAsync(cb) {
const firstHeight = await _getHeight()
while (true) {
await sleep(1000)
let height = await _getHeight()
if (height > firstHeight) {
break
}
}
}

function randomSecret() {
return Math.random().toString(36).substring(7)
}
Expand Down Expand Up @@ -87,7 +70,9 @@ function apiGet(path, cb) {
.expect(200)
.end(cb)
}
const apiGetAsync = PIFY(apiGet)
function apiGetAsync(path) {
return PIFY(apiGet)(path)
}

function transactionUnsigned(trs, cb) {
api.put('/transactions')
Expand Down Expand Up @@ -133,7 +118,24 @@ function giveMoney(address, amount, cb) {
.end(cb)
}

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

async function getHeight() {
const ret = await apiGetAsync('/blocks/getHeight')
debug('get height response', ret.body)
return ret.body.height
}

async function onNewBlockAsync() {
const firstHeight = await getHeight()
let height
do {
await sleep(1000)
height = await getHeight()
} while (height <= firstHeight)
}

async function giveMoneyAndWaitAsync(addresses) {
for (let i = 0; i < addresses.length; i++) {
Expand Down Expand Up @@ -195,6 +197,7 @@ module.exports = {
api,
apiGet,
apiGetAsync,
getHeight,
AschJS,
config,
sleep,
Expand Down

0 comments on commit 36a7ce4

Please sign in to comment.