Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Finalize tests for new API specs
Browse files Browse the repository at this point in the history
  • Loading branch information
toschdev committed Jun 30, 2017
1 parent a4ef05b commit 58a158a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 379 deletions.
17 changes: 10 additions & 7 deletions lib/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

var LiskJS = {};
LiskJS.crypto = require('../transactions/crypto');
LiskJS.dapp = require('../transactions/dapp');
LiskJS.multisignature = require('../transactions/multisignature');
LiskJS.signature = require('../transactions/signature');
LiskJS.delegate = require('../transactions/delegate');
LiskJS.transaction = require('../transactions/transaction');
LiskJS.transfer = require('../transactions/transfer');
LiskJS.vote = require('../transactions/vote');
var privateApi = require('./privateApi');

function LiskAPI (options) {
Expand Down Expand Up @@ -186,12 +193,7 @@ LiskAPI.prototype.sendRequest = function (requestType, options, callback) {
that.sendRequest(requestType, options, callback);
}, 1000);
} else {
var rejectAnswer = { success: false, error: error, message: 'could not create http request to any of the given peers' };

if (callback && (typeof callback === 'function')) {
callback(rejectAnswer);
}
return rejectAnswer;
return { success: false, error: error, message: 'could not create http request to any of the given peers' };
}
});
};
Expand Down Expand Up @@ -361,7 +363,7 @@ LiskAPI.prototype.listVotes = function (address, callback) {

/**
* @method listVoters
* @param publicKey
* @param address
* @param callback
*
* @return API object
Expand Down Expand Up @@ -394,6 +396,7 @@ LiskAPI.prototype.sendLSK = function (recipient, amount, secret, secondSecret, c
* @method multiSignatureSign
* @param transaction object
* @param secret
* @param callback
*
* @return API object
*/
Expand Down
104 changes: 104 additions & 0 deletions test/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ describe('Lisk.api()', function () {
(callback.calledWith(expectedResponse)).should.be.true();
LSK.sendRequest.restore();
});

});

describe('#getTransaction', function () {
Expand Down Expand Up @@ -857,6 +858,109 @@ describe('Lisk.api()', function () {
});
});

describe('#createDelegate', function () {

it('should be able to create a delegate', function () {

var LSK = lisk.api({ testnet: true });
var callback = sinon.spy();

sinon.stub(LSK, 'broadcastSignedTransaction').callsArg(1);

LSK.createDelegate('secret', 'testUsername', 'secondSecret', callback);

(LSK.broadcastSignedTransaction.called).should.be.true();
(LSK.broadcastSignedTransaction.args[0][0].type).should.be.equal(2);
(LSK.broadcastSignedTransaction.args[0][0].fee).should.be.equal(2500000000);
(LSK.broadcastSignedTransaction.args[0][0].asset.delegate.username).should.be.equal('testUsername');
LSK.broadcastSignedTransaction.restore();

});

});

describe('#multiSignatureSign', function () {

it('should be able to create a multiSignatureSign', function () {

var LSK = lisk.api({ testnet: true });
var callback = sinon.spy();

sinon.stub(LSK, 'broadcastSignedTransaction').yields();

var tx = {
amount: "100",
asset: {},
fee: 10000000,
id: "15936820115091968386",
recipientId: "784237489382434L",
requesterPublicKey: "5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09",
senderPublicKey: "5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09",
signSignature: "d06822a99d799b90dcf739acfbbc9a03a946d8fcb649545a32269de2d09d7ea11bf5a23ac0a4965b0d178a01c3277594893deaed5185085c5f948e7897081b02",
signature: "5ad2f6454d92e163c9e4edfdff5b1b8b6684b7d83654ecf63d16edb21bbd085aefe8d2bd7f75cca9425fc03fac90eb69602d686ca24e12242557bf990840570a",
signatures: [],
timestamp: 34702079,
type: 0
};

LSK.multiSignatureSign('secret', tx, callback);

(LSK.broadcastSignedTransaction.called).should.be.true();
(LSK.broadcastSignedTransaction.args[0][0]).should.be.equal('5ad2f6454d92e163c9e4edfdff5b1b8b6684b7d83654ecf63d16edb21bbd085aefe8d2bd7f75cca9425fc03fac90eb69602d686ca24e12242557bf990840570a');
LSK.broadcastSignedTransaction.restore();

});

});

describe('#createMultisignature', function () {

it('should be able to create a multisignature account', function () {

var minimumSignatures = 6;
var requestLifeTime = 8;
var multiSignaturePublicKeyArray = ['+123456789', '+1236345489', '+123452349', '-987654321', '+12323432489','+1234234789', '-82348375839'];

var LSK = lisk.api({ testnet: true });
var callback = sinon.spy();

sinon.stub(LSK, 'broadcastSignedTransaction').callsArg(1);


LSK.createMultisignature('secret', multiSignaturePublicKeyArray, requestLifeTime, minimumSignatures, 'secondSecret', callback);

(LSK.broadcastSignedTransaction.args[0][0].type).should.be.equal(4);
(LSK.broadcastSignedTransaction.args[0][0].fee).should.be.equal(4000000000);
(LSK.broadcastSignedTransaction.args[0][0].asset.multisignature).should.be.type('object');
LSK.broadcastSignedTransaction.restore();

});

});

describe('#sendVotes', function () {

it('should be able to send votes', function () {

var votes = ['+dd786687dd2399605ce8fe70212d078db1a2fc6effba127defb176a004cec6d4', '+adc4942d3821c8803f8794646c3e3934eb08d3768dff3f2fd9e9e6030635e344', '-ae5afc2db90302dbf9253640467dfbc107b29ed35b8752df9775acd7f644992c'];

var LSK = lisk.api({ testnet: true });
var callback = sinon.spy();

sinon.stub(LSK, 'broadcastSignedTransaction').callsArg(1);


LSK.sendVotes('secret', votes, 'secondSecret', callback);

(LSK.broadcastSignedTransaction.args[0][0].type).should.be.equal(3);
(LSK.broadcastSignedTransaction.args[0][0].fee).should.be.equal(100000000);
(LSK.broadcastSignedTransaction.args[0][0].asset.votes).should.be.eql(votes);
LSK.broadcastSignedTransaction.restore();

});

});

describe('#broadcastSignedTransaction', function () {

it('should be able to broadcast a finished and signed transaction', function (done) {
Expand Down

0 comments on commit 58a158a

Please sign in to comment.