diff --git a/app.js b/app.js index 74261dabe32..ff62721a283 100644 --- a/app.js +++ b/app.js @@ -71,9 +71,6 @@ if (program.snapshot) { ); } -// Define top endpoint availability -process.env.TOP = appConfig.topAccounts; - var config = { db: appConfig.db, modules: { diff --git a/config.json b/config.json index fe097630842..e3d8dfef2aa 100644 --- a/config.json +++ b/config.json @@ -6,7 +6,6 @@ "logFileName": "logs/lisk.log", "consoleLogLevel": "info", "trustProxy": false, - "topAccounts": false, "db": { "host": "localhost", "port": 5432, diff --git a/helpers/z_schema.js b/helpers/z_schema.js index 978089f6225..502bc6f8579 100644 --- a/helpers/z_schema.js +++ b/helpers/z_schema.js @@ -3,30 +3,6 @@ var ip = require('ip'); var z_schema = require('z-schema'); -z_schema.registerFormat('id', function (str) { - if (str.length === 0) { - return true; - } - - return /^[0-9]+$/g.test(str); -}); - -z_schema.registerFormat('address', function (str) { - if (str.length === 0) { - return true; - } - - return /^[0-9]+[L]$/ig.test(str); -}); - -z_schema.registerFormat('username', function (str) { - if (str.length === 0) { - return true; - } - - return /^[a-z0-9!@$&_.]+$/ig.test(str); -}); - z_schema.registerFormat('hex', function (str) { try { new Buffer(str, 'hex'); @@ -101,22 +77,6 @@ z_schema.registerFormat('ip', function (str) { return ip.isV4Format(str); }); -z_schema.registerFormat('os', function (str) { - if (str.length === 0) { - return true; - } - - return /^[a-z0-9-_.]+$/ig.test(str); -}); - -z_schema.registerFormat('version', function (str) { - if (str.length === 0) { - return true; - } - - return /^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})([a-z]{1})?$/g.test(str); -}); - // var registeredFormats = z_schema.getRegisteredFormats(); // console.log(registeredFormats); diff --git a/logic/transaction.js b/logic/transaction.js index f741509ebb5..e18cac596e7 100644 --- a/logic/transaction.js +++ b/logic/transaction.js @@ -6,7 +6,6 @@ var ByteBuffer = require('bytebuffer'); var constants = require('../helpers/constants.js'); var crypto = require('crypto'); var exceptions = require('../helpers/exceptions.js'); -var extend = require('extend'); var slots = require('../helpers/slots.js'); var sql = require('../sql/transactions.js'); @@ -821,7 +820,7 @@ Transaction.prototype.dbRead = function (raw) { var asset = __private.types[tx.type].dbRead.call(this, raw); if (asset) { - tx.asset = extend(tx.asset, asset); + tx.asset = _.extend(tx.asset, asset); } return tx; diff --git a/modules/accounts.js b/modules/accounts.js index e24f99b9504..cb024e6619c 100644 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -116,9 +116,6 @@ __private.openAccount = function (secret, cb) { } if (account) { - if (account.publicKey == null) { - account.publicKey = publicKey; - } return setImmediate(cb, null, account); } else { return setImmediate(cb, null, { diff --git a/modules/blocks.js b/modules/blocks.js index 492560b0643..65ac8a00f65 100644 --- a/modules/blocks.js +++ b/modules/blocks.js @@ -502,15 +502,6 @@ Blocks.prototype.getCommonBlock = function (peer, height, cb) { } }); }, - function (res, waterCb) { - library.schema.validate(res.body.common, schema.getCommonBlock, function (err) { - if (err) { - return setImmediate(waterCb, err[0].message); - } else { - return setImmediate(waterCb, null, res); - } - }); - }, function (res, waterCb) { library.db.query(sql.getCommonBlock(res.body.common.previousBlock), { id: res.body.common.id, diff --git a/modules/dapps.js b/modules/dapps.js index b49e78cfbed..e5f8fff92b1 100644 --- a/modules/dapps.js +++ b/modules/dapps.js @@ -672,7 +672,7 @@ __private.getInstalledIds = function (cb) { if (err) { return setImmediate(cb, err); } else { - var regExp = new RegExp(/[0-9]{1,20}/); + var regExp = new RegExp(/[0-9]{18,20}/); ids = _.filter(ids, function (f) { return regExp.test(f.toString()); diff --git a/modules/peers.js b/modules/peers.js index b122f65097f..2cc0f376d3f 100644 --- a/modules/peers.js +++ b/modules/peers.js @@ -144,7 +144,7 @@ __private.getByFilter = function (filter, cb) { var where = []; var params = {}; - if (filter.state >= 0) { + if (filter.state) { where.push('"state" = ${state}'); params.state = filter.state; } @@ -216,7 +216,6 @@ Peers.prototype.inspect = function (peer) { } peer.port = parseInt(peer.port); - peer.port = isNaN(peer.port) ? 0 : peer.port; if (peer.ip) { peer.string = (peer.ip + ':' + peer.port || 'unknown'); diff --git a/modules/transactions.js b/modules/transactions.js index 922a008f416..7ff6f5bee87 100644 --- a/modules/transactions.js +++ b/modules/transactions.js @@ -188,6 +188,8 @@ __private.addUnconfirmedTransaction = function (transaction, sender, cb) { if (err) { self.removeUnconfirmedTransaction(transaction.id); return setImmediate(cb, err); + } else if (modules.loader.syncing()) { + self.undoUnconfirmed(transaction, cb); } else { transaction.receivedAt = new Date(); __private.unconfirmedTransactions.push(transaction); @@ -235,11 +237,6 @@ Transactions.prototype.processUnconfirmedTransaction = function (transaction, br return setImmediate(cb, 'Missing transaction'); } - // Ignore transaction when syncing - if (modules.loader.syncing()) { - return setImmediate(cb); - } - // Check transaction indexes if (__private.unconfirmedTransactionsIdIndex[transaction.id] !== undefined) { library.logger.debug('Transaction is already processed: ' + transaction.id); diff --git a/modules/transport.js b/modules/transport.js index 9c9d6cf33b3..adaeaa91235 100644 --- a/modules/transport.js +++ b/modules/transport.js @@ -438,7 +438,7 @@ Transport.prototype.getFromPeer = function (peer, options, cb) { var req = { url: 'http://' + peer.ip + ':' + peer.port + url, method: options.method, - headers: extend({}, __private.headers, options.headers), + headers: _.extend({}, __private.headers, options.headers), timeout: library.config.peers.options.timeout }; diff --git a/schema/accounts.js b/schema/accounts.js index 44f6db70c71..0bd3f091233 100644 --- a/schema/accounts.js +++ b/schema/accounts.js @@ -19,9 +19,7 @@ module.exports = { properties: { address: { type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + minLength: 1 } }, required: ['address'] @@ -32,9 +30,7 @@ module.exports = { properties: { address: { type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + minLength: 1 } }, required: ['address'] @@ -45,8 +41,7 @@ module.exports = { properties: { secret: { type: 'string', - minLength: 1, - maxLength: 100 + minLength: 1 } }, required: ['secret'] @@ -57,9 +52,7 @@ module.exports = { properties: { address: { type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + minLength: 1 } }, required: ['address'] @@ -70,8 +63,7 @@ module.exports = { properties: { secret: { type: 'string', - minLength: 1, - maxLength: 100 + minLength: 1 }, publicKey: { type: 'string', @@ -79,8 +71,7 @@ module.exports = { }, secondSecret: { type: 'string', - minLength: 1, - maxLength: 100 + minLength: 1 } } }, @@ -90,9 +81,7 @@ module.exports = { properties: { address: { type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + minLength: 1 } }, required: ['address'] diff --git a/schema/blocks.js b/schema/blocks.js index 99c3e8f0b71..87ace052ea0 100644 --- a/schema/blocks.js +++ b/schema/blocks.js @@ -13,9 +13,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 } }, required: ['id'] @@ -26,7 +24,7 @@ module.exports = { properties: { limit: { type: 'integer', - minimum: 1, + minimum: 0, maximum: 100 }, orderBy: { @@ -55,38 +53,11 @@ module.exports = { minimum: 0 }, previousBlock: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + type: 'string' }, height: { - type: 'integer', - minimum: 1 + type: 'integer' } } - }, - getCommonBlock: { - id: 'blocks.getCommonBlock', - type: 'object', - properties: { - id: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 - }, - previousBlock: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 - }, - height: { - type: 'integer', - minimum: 1 - } - }, - required: ['id', 'previousBlock', 'height'] } }; diff --git a/schema/dapps.js b/schema/dapps.js index 4b7d9fd0f02..9841058999e 100644 --- a/schema/dapps.js +++ b/schema/dapps.js @@ -64,9 +64,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 } }, required: ['id'] @@ -77,7 +75,6 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', minLength: 1, maxLength: 20 }, @@ -104,18 +101,18 @@ module.exports = { minLength: 1, maxLength: 2000 }, - orderBy: { - type: 'string', - minLength: 1 - }, limit: { type: 'integer', - minimum: 1, + minimum: 0, maximum: 100 }, offset: { type: 'integer', minimum: 0 + }, + orderBy: { + type: 'string', + minLength: 1 } } }, @@ -129,9 +126,7 @@ module.exports = { }, id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 }, master: { type: 'string', @@ -165,7 +160,6 @@ module.exports = { }, dappId: { type: 'string', - format: 'id', minLength: 1, maxLength: 20 }, @@ -192,8 +186,7 @@ module.exports = { }, recipientId: { type: 'string', - format: 'address', - minLength: 1, + minLength: 2, maxLength: 22 }, secondSecret: { @@ -203,13 +196,11 @@ module.exports = { }, dappId: { type: 'string', - format: 'id', minLength: 1, maxLength: 20 }, transactionId: { type: 'string', - format: 'id', minLength: 1, maxLength: 20 }, @@ -247,9 +238,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 }, master: { type: 'string', @@ -264,9 +253,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 }, master: { type: 'string', @@ -281,9 +268,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 }, master: { type: 'string', diff --git a/schema/delegates.js b/schema/delegates.js index 1b6b681f0c9..36dd2aaaf97 100644 --- a/schema/delegates.js +++ b/schema/delegates.js @@ -54,10 +54,7 @@ module.exports = { type: 'string' }, username: { - type: 'string', - format: 'username', - minLength: 1, - maxLength: 20 + type: 'string' } } }, @@ -137,10 +134,7 @@ module.exports = { maxLength: 100 }, username: { - type: 'string', - format: 'username', - minLength: 1, - maxLength: 20 + type: 'string' } }, required: ['secret'] diff --git a/schema/loader.js b/schema/loader.js index 00a42dae447..2e476b3cd70 100644 --- a/schema/loader.js +++ b/schema/loader.js @@ -54,16 +54,10 @@ module.exports = { maximum: 3 }, os: { - type: 'string', - format: 'os', - minLength: 1, - maxLength: 64 + type: 'string' }, version: { - type: 'string', - format: 'version', - minLength: 5, - maxLength: 12 + type: 'string' } }, required: ['ip', 'port', 'state'] @@ -74,7 +68,7 @@ module.exports = { properties: { height: { type: 'integer', - minimum: 1 + minimum: 0 } }, required: ['height'] diff --git a/schema/multisignatures.js b/schema/multisignatures.js index cccc0cb00da..98581b58257 100644 --- a/schema/multisignatures.js +++ b/schema/multisignatures.js @@ -42,10 +42,7 @@ module.exports = { format: 'publicKey' }, transactionId: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + type: 'string' } }, required: ['transactionId', 'secret'] diff --git a/schema/peers.js b/schema/peers.js index a60c69bea0d..0ac2287e414 100644 --- a/schema/peers.js +++ b/schema/peers.js @@ -29,19 +29,15 @@ module.exports = { state: { type: 'integer', minimum: 0, - maximum: 2 + maximum: 3 }, os: { type: 'string', - format: 'os', - minLength: 1, maxLength: 64 }, version: { type: 'string', - format: 'version', - minLength: 5, - maxLength: 12 + maxLength: 11 } }, required: ['ip', 'port', 'state'] @@ -51,10 +47,6 @@ module.exports = { id: 'peer.getPeers', type: 'object', properties: { - ip: { - type: 'string', - format: 'ip' - }, port: { type: 'integer', minimum: 1, @@ -63,26 +55,22 @@ module.exports = { state: { type: 'integer', minimum: 0, - maximum: 2 + maximum: 3 }, os: { type: 'string', - format: 'os', - minLength: 1, maxLength: 64 }, version: { type: 'string', - format: 'version', - minLength: 5, - maxLength: 12 + maxLength: 11 }, orderBy: { type: 'string' }, limit: { type: 'integer', - minimum: 1, + minimum: 0, maximum: 100 }, offset: { diff --git a/schema/signatures.js b/schema/signatures.js index 2f8c8b62f6f..80738f65702 100644 --- a/schema/signatures.js +++ b/schema/signatures.js @@ -7,13 +7,11 @@ module.exports = { properties: { secret: { type: 'string', - minLength: 1, - maxLength: 100 + minLength: 1 }, secondSecret: { type: 'string', - minLength: 1, - maxLength: 100 + minLength: 1 }, publicKey: { type: 'string', diff --git a/schema/transactions.js b/schema/transactions.js index e8eed073f0a..2b05e34d9a4 100644 --- a/schema/transactions.js +++ b/schema/transactions.js @@ -8,21 +8,24 @@ module.exports = { type: 'object', properties: { blockId: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + type: 'string' + }, + limit: { + type: 'integer', + minimum: 0, + maximum: 100 }, type: { type: 'integer', minimum: 0, maximum: 10 }, - senderId: { - type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + orderBy: { + type: 'string' + }, + offset: { + type: 'integer', + minimum: 0 }, senderPublicKey: { type: 'string', @@ -33,16 +36,13 @@ module.exports = { format: 'publicKey' }, ownerAddress: { - type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + type: 'string' + }, + senderId: { + type: 'string' }, recipientId: { - type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + type: 'string' }, amount: { type: 'integer', @@ -53,18 +53,6 @@ module.exports = { type: 'integer', minimum: 0, maximum: constants.fixedPoint - }, - orderBy: { - type: 'string' - }, - limit: { - type: 'integer', - minimum: 1, - maximum: 100 - }, - offset: { - type: 'integer', - minimum: 0 } } }, @@ -74,9 +62,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 } }, required: ['id'] @@ -87,9 +73,7 @@ module.exports = { properties: { id: { type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + minLength: 1 } }, required: ['id'] @@ -103,10 +87,7 @@ module.exports = { format: 'publicKey' }, address: { - type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + type: 'string' } } }, @@ -126,9 +107,7 @@ module.exports = { }, recipientId: { type: 'string', - format: 'address', - minLength: 1, - maxLength: 22 + minLength: 1 }, publicKey: { type: 'string', diff --git a/schema/transport.js b/schema/transport.js index 84f10f27efe..269199e9de9 100644 --- a/schema/transport.js +++ b/schema/transport.js @@ -16,19 +16,15 @@ module.exports = { }, os: { type: 'string', - format: 'os', - minLength: 1, maxLength: 64 }, - version: { - type: 'string', - format: 'version', - minLength: 5, - maxLength: 12 - }, nethash: { type: 'string', maxLength: 64 + }, + version: { + type: 'string', + maxLength: 11 } }, required: ['ip', 'port', 'nethash', 'version'] @@ -49,10 +45,7 @@ module.exports = { type: 'object', properties: { lastBlockId: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + type: 'string' } }, }, @@ -64,10 +57,7 @@ module.exports = { type: 'object', properties: { transaction: { - type: 'string', - format: 'id', - minLength: 1, - maxLength: 20 + type: 'string' }, signature: { type: 'string', diff --git a/test/api/accounts.js b/test/api/accounts.js index 4a5b9b4b9c9..b5704271b6a 100644 --- a/test/api/accounts.js +++ b/test/api/accounts.js @@ -121,7 +121,7 @@ describe('GET /api/accounts/getBalance?address=', function () { it('using invalid address should fail', function (done) { getBalance('thisIsNOTALiskAddress', function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.eql('Object didn\'t pass validation for format address: thisIsNOTALiskAddress'); + node.expect(res.body).to.have.property('error').to.eql('Invalid address'); done(); }); }); @@ -161,7 +161,7 @@ describe('GET /api/accounts/getPublicKey?address=', function () { it('using invalid address should fail', function (done) { getPublicKey('thisIsNOTALiskAddress', function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.contain('Object didn\'t pass validation for format address: thisIsNOTALiskAddress'); + node.expect(res.body).to.have.property('error').to.contain('Invalid address'); done(); }); }); @@ -281,10 +281,10 @@ describe('GET /accounts?address=', function () { }); it('using invalid address should fail', function (done) { - getAccounts('thisIsNOTALiskAddress', function (err, res) { + getAccounts('thisIsNOTAValidLiskAddress', function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; node.expect(res.body).to.have.property('error'); - node.expect(res.body.error).to.contain('Object didn\'t pass validation for format address: thisIsNOTALiskAddress'); + node.expect(res.body.error).to.contain('Invalid address'); done(); }); }); diff --git a/test/api/dapps.js b/test/api/dapps.js index 959f9adcf98..063730de381 100644 --- a/test/api/dapps.js +++ b/test/api/dapps.js @@ -427,7 +427,7 @@ describe('PUT /api/dapps/transaction', function () { putTransaction(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.not.be.ok; - node.expect(res.body).to.have.property('error').to.match(/Application not found: [0-9]+/); + node.expect(res.body).to.have.property('error').to.equal('Application not found: ' + validParams.dappId); done(); }); }); @@ -600,7 +600,7 @@ describe('PUT /api/dapps/withdrawal', function () { putWithdrawal(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.not.be.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format id: 1L'); + node.expect(res.body).to.have.property('error').to.equal('Application not found: 1L'); done(); }); }); @@ -660,7 +660,7 @@ describe('PUT /api/dapps/withdrawal', function () { putWithdrawal(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.not.be.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format id: 1L'); + node.expect(res.body).to.have.property('error').to.equal('Invalid outTransfer transactionId'); done(); }); }); @@ -710,7 +710,7 @@ describe('PUT /api/dapps/withdrawal', function () { putWithdrawal(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.not.be.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format address: 1'); + node.expect(res.body).to.have.property('error').to.equal('String is too short (1 chars), minimum 2'); done(); }); }); @@ -730,7 +730,7 @@ describe('PUT /api/dapps/withdrawal', function () { putWithdrawal(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.not.be.ok; - node.expect(res.body).to.have.property('error').to.match(/Object didn\'t pass validation for format address: [0-9]+/); + node.expect(res.body).to.have.property('error').to.equal('Invalid recipient'); done(); }); }); diff --git a/test/api/delegates.js b/test/api/delegates.js index 41eb1241f97..f9bcea81cc8 100644 --- a/test/api/delegates.js +++ b/test/api/delegates.js @@ -391,6 +391,108 @@ describe('GET /api/delegates', function () { }); }); + it('using string limit should fail', function (done) { + var limit = 'one'; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); + done(); + }); + }); + + it('using limit == -1 should fail', function (done) { + var limit = -1; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 1'); + done(); + }); + }); + + it('using limit == 0 should fail', function (done) { + var limit = 0; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Value 0 is less than minimum 1'); + done(); + }); + }); + + it('using limit == 1 should be ok', function (done) { + var limit = 1; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.ok; + node.expect(res.body).to.have.property('delegates').that.is.an('array'); + node.expect(res.body.delegates).to.have.lengthOf(1); + done(); + }); + }); + + it('using limit == 101 should be ok', function (done) { + var limit = 101; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.ok; + node.expect(res.body).to.have.property('delegates').that.is.an('array'); + node.expect(res.body.delegates).to.have.lengthOf(101); + done(); + }); + }); + + it('using limit > 101 should fail', function (done) { + var limit = 102; + var params = 'limit=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Value 102 is greater than maximum 101'); + done(); + }); + }); + + it('using string offset should fail', function (done) { + var limit = 'one'; + var params = 'offset=' + limit; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); + done(); + }); + }); + + it('using offset == 1 should be ok', function (done) { + var offset = 1; + var params = 'offset=' + offset; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.ok; + node.expect(res.body).to.have.property('delegates').that.is.an('array'); + node.expect(res.body.delegates).to.have.lengthOf(101); + done(); + }); + }); + + it('using offset == -1 should fail', function (done) { + var offset = -1; + var params = 'offset=' + offset; + + node.get('/api/delegates?' + params, function (err, res) { + node.expect(res.body).to.have.property('success').to.be.not.ok; + node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 0'); + done(); + }); + }); + it('using orderBy == "unknown:asc" should fail', function (done) { var orderBy = 'unknown:asc'; var params = 'orderBy=' + orderBy; @@ -529,108 +631,6 @@ describe('GET /api/delegates', function () { done(); }); }); - - it('using string limit should fail', function (done) { - var limit = 'one'; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); - done(); - }); - }); - - it('using limit == -1 should fail', function (done) { - var limit = -1; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 1'); - done(); - }); - }); - - it('using limit == 0 should fail', function (done) { - var limit = 0; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 0 is less than minimum 1'); - done(); - }); - }); - - it('using limit == 1 should be ok', function (done) { - var limit = 1; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('delegates').that.is.an('array'); - node.expect(res.body.delegates).to.have.lengthOf(1); - done(); - }); - }); - - it('using limit == 101 should be ok', function (done) { - var limit = 101; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('delegates').that.is.an('array'); - node.expect(res.body.delegates).to.have.lengthOf(101); - done(); - }); - }); - - it('using limit > 101 should fail', function (done) { - var limit = 102; - var params = 'limit=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 102 is greater than maximum 101'); - done(); - }); - }); - - it('using string offset should fail', function (done) { - var limit = 'one'; - var params = 'offset=' + limit; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); - done(); - }); - }); - - it('using offset == 1 should be ok', function (done) { - var offset = 1; - var params = 'offset=' + offset; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('delegates').that.is.an('array'); - node.expect(res.body.delegates).to.have.lengthOf(101); - done(); - }); - }); - - it('using offset == -1 should fail', function (done) { - var offset = -1; - var params = 'offset=' + offset; - - node.get('/api/delegates?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 0'); - done(); - }); - }); }); describe('GET /api/delegates/count', function () { diff --git a/test/api/peer.js b/test/api/peer.js index 58ebcd0d525..a419562816d 100644 --- a/test/api/peer.js +++ b/test/api/peer.js @@ -24,14 +24,13 @@ describe('GET /peer/list', function () { .end(function (err, res) { node.debug('> Response:'.grey, JSON.stringify(res.body)); node.expect(res.body).to.have.property('peers').that.is.an('array'); + node.expect(res.body.peers).to.have.length.of.at.least(1); res.body.peers.forEach(function (peer) { node.expect(peer).to.have.property('ip').that.is.a('string'); node.expect(peer).to.have.property('port').that.is.a('number'); node.expect(peer).to.have.property('state').that.is.a('number'); node.expect(peer).to.have.property('os'); node.expect(peer).to.have.property('version'); - node.expect(peer).to.have.property('broadhash'); - node.expect(peer).to.have.property('height'); }); done(); }); diff --git a/test/api/peer.signatures.js b/test/api/peer.signatures.js index 881c8333e62..b6a1b76c3ba 100644 --- a/test/api/peer.signatures.js +++ b/test/api/peer.signatures.js @@ -66,7 +66,7 @@ describe('POST /peer/signatures', function () { }); it('using unprocessable signature should fail', function (done) { - validParams.signature.transaction = '1'; + validParams.signature.transaction = 'invalidId'; node.post('/peer/signatures', validParams) .end(function (err, res) { diff --git a/test/api/peers.js b/test/api/peers.js index e2bccfa0fff..a47c0a22f43 100644 --- a/test/api/peers.js +++ b/test/api/peers.js @@ -16,76 +16,25 @@ describe('GET /api/peers/version', function () { describe('GET /api/peers', function () { - it('using invalid ip should fail', function (done) { - var ip = 'invalid'; - var params = 'ip=' + ip; + it('using empty parameters should fail', function (done) { + var params = [ + 'state=', + 'os=', + 'shared=', + 'version=', + 'limit=', + 'offset=', + 'orderBy=' + ]; - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format ip: invalid'); - done(); - }); - }); - - it('using valid ip should be ok', function (done) { - var ip = '0.0.0.0'; - var params = 'ip=' + ip; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using port < 1 should fail', function (done) { - var port = 0; - var params = 'port=' + port; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 0 is less than minimum 1'); - done(); - }); - }); - - it('using port == 65535 be ok', function (done) { - var port = 65535; - var params = 'port=' + port; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using port > 65535 should fail', function (done) { - var port = 65536; - var params = 'port=' + port; - - node.get('/api/peers?' + params, function (err, res) { + node.get('/api/peers?' + params.join('&'), function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 65536 is greater than maximum 65535'); + node.expect(res.body).to.have.property('error'); done(); }); }); - it('using state == 0 should be ok', function (done) { - var state = 0; - var params = 'state=' + state; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('peers').that.is.an('array'); - if (res.body.peers.length > 0) { - for (var i = 0; i < res.body.peers.length; i++) { - node.expect(res.body.peers[i].state).to.equal(parseInt(state)); - } - } - done(); - }); - }); - - it('using state == 1 should be ok', function (done) { + it('using state should be ok', function (done) { var state = 1; var params = 'state=' + state; @@ -101,129 +50,19 @@ describe('GET /api/peers', function () { }); }); - it('using state == 2 should be ok', function (done) { - var state = 2; - var params = 'state=' + state; + it('using limit should be ok', function (done) { + var limit = 3; + var params = 'limit=' + limit; node.get('/api/peers?' + params, function (err, res) { node.expect(res.body).to.have.property('success').to.be.ok; node.expect(res.body).to.have.property('peers').that.is.an('array'); - if (res.body.peers.length > 0) { - for (var i = 0; i < res.body.peers.length; i++) { - node.expect(res.body.peers[i].state).to.equal(parseInt(state)); - } - } - done(); - }); - }); - - it('using state > 2 should fail', function (done) { - var state = 3; - var params = 'state=' + state; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 3 is greater than maximum 2'); - done(); - }); - }); - - it('using os with length == 1 should be ok', function (done) { - var os = 'b'; - var params = 'os=' + os; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using os with length == 64 should be ok', function (done) { - var os = 'battle-claw-lunch-confirm-correct-limb-siege-erode-child-libert'; - var params = 'os=' + os; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using os with length > 64 should be ok', function (done) { - var os = 'battle-claw-lunch-confirm-correct-limb-siege-erode-child-liberty-'; - var params = 'os=' + os; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('String is too long (65 chars), maximum 64'); - done(); - }); - }); - - it('using version == "999.999.999" characters should be ok', function (done) { - var version = '999.999.999'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using version == "9999.999.999" characters should fail', function (done) { - var version = '9999.999.999'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format version: 9999.999.999'); - done(); - }); - }); - - it('using version == "999.9999.999" characters should fail', function (done) { - var version = '999.9999.999'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format version: 999.9999.999'); - done(); - }); - }); - - it('using version == "999.999.9999" characters should fail', function (done) { - var version = '999.999.9999'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format version: 999.999.9999'); - done(); - }); - }); - - it('using version == "999.999.999a" characters should be ok', function (done) { - var version = '999.999.999a'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - done(); - }); - }); - - it('using version == "999.999.999ab" characters should fail', function (done) { - var version = '999.999.999ab'; - var params = 'version=' + version; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Object didn\'t pass validation for format version: 999.999.999ab'); + node.expect(res.body.peers.length).to.be.at.most(limit); done(); }); }); - it('using orderBy == "state:desc" should be ok', function (done) { + it('using orderBy should be ok', function (done) { var orderBy = 'state:desc'; var params = 'orderBy=' + orderBy; @@ -233,8 +72,8 @@ describe('GET /api/peers', function () { if (res.body.peers.length > 0) { for (var i = 0; i < res.body.peers.length; i++) { - if (res.body.peers[i + 1] != null) { - node.expect(res.body.peers[i + 1].state).to.be.at.most(res.body.peers[i].state); + if (res.body.peers[i+1] != null) { + node.expect(res.body.peers[i+1].state).to.at.most(res.body.peers[i].state); } } } @@ -243,102 +82,31 @@ describe('GET /api/peers', function () { }); }); - it('using string limit should fail', function (done) { - var limit = 'one'; - var params = 'limit=' + limit; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); - done(); - }); - }); - - it('using limit == -1 should fail', function (done) { - var limit = -1; - var params = 'limit=' + limit; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 1'); - done(); - }); - }); - - it('using limit == 0 should fail', function (done) { - var limit = 0; - var params = 'limit=' + limit; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 0 is less than minimum 1'); - done(); - }); - }); - - it('using limit == 1 should be ok', function (done) { - var limit = 1; - var params = 'limit=' + limit; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('peers').that.is.an('array'); - node.expect(res.body.peers.length).to.be.at.most(limit); - done(); - }); - }); - - it('using limit == 100 should be ok', function (done) { - var limit = 100; - var params = 'limit=' + limit; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; - node.expect(res.body).to.have.property('peers').that.is.an('array'); - node.expect(res.body.peers.length).to.be.at.most(limit); - done(); - }); - }); - it('using limit > 100 should fail', function (done) { var limit = 101; var params = 'limit=' + limit; node.get('/api/peers?' + params, function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value 101 is greater than maximum 100'); - done(); - }); - }); - - it('using string offset should fail', function (done) { - var offset = 'one'; - var params = 'offset=' + offset; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Expected type integer but found type string'); + node.expect(res.body).to.have.property('error'); done(); }); }); - it('using offset == -1 should fail', function (done) { - var offset = -1; - var params = 'offset=' + offset; + it('using invalid parameters should fail', function (done) { + var params = [ + 'state=invalid', + 'os=invalid', + 'shared=invalid', + 'version=invalid', + 'limit=invalid', + 'offset=invalid', + 'orderBy=invalid' + ]; - node.get('/api/peers?' + params, function (err, res) { + node.get('/api/peers?' + params.join('&'), function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; - node.expect(res.body).to.have.property('error').to.equal('Value -1 is less than minimum 0'); - done(); - }); - }); - - it('using offset == 1 should be ok', function (done) { - var offset = 1; - var params = 'offset=' + offset; - - node.get('/api/peers?' + params, function (err, res) { - node.expect(res.body).to.have.property('success').to.be.ok; + node.expect(res.body).to.have.property('error'); done(); }); }); diff --git a/test/api/transactions.js b/test/api/transactions.js index 95bf0f83253..4a38efa2738 100644 --- a/test/api/transactions.js +++ b/test/api/transactions.js @@ -73,7 +73,7 @@ describe('GET /api/transactions', function () { var orderBy = 'amount:asc'; var params = [ - 'blockId=' + '1', + 'blockId=', 'senderId=' + node.gAccount.address, 'recipientId=' + account.address, 'limit=' + limit, diff --git a/test/config.json b/test/config.json index c1e97530e7a..594b1c0e8bc 100644 --- a/test/config.json +++ b/test/config.json @@ -6,7 +6,6 @@ "logFileName": "logs/lisk.log", "consoleLogLevel": "debug", "trustProxy": false, - "topAccounts": false, "db": { "host": "localhost", "port": 5432, @@ -176,5 +175,5 @@ "masterpassword": "", "autoexec": [] }, - "nethash": "198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d" + "nethash":"198f2b61a8eb95fbeed58b8216780b68f697f26b849acf00c8c93bb9b24f783d" } diff --git a/test/node.js b/test/node.js index aba4b68016d..6fd058e0dac 100644 --- a/test/node.js +++ b/test/node.js @@ -177,8 +177,9 @@ node.waitForNewBlock = function (height, cb) { // Adds peers to local node node.addPeers = function (numOfPeers, cb) { var operatingSystems = ['win32','win64','ubuntu','debian', 'centos']; - var port = 4000; - var os, version; + var ports = [4000, 5000, 7000, 8000]; + + var os, version, port; var i = 0; node.async.whilst(function () { @@ -186,6 +187,7 @@ node.addPeers = function (numOfPeers, cb) { }, function (next) { os = operatingSystems[node.randomizeSelection(operatingSystems.length)]; version = node.config.version; + port = ports[node.randomizeSelection(ports.length)]; var request = node.popsicle.get({ url: node.baseUrl + '/peer/height',