diff --git a/test/common.js b/test/common.js index e2f88f8ad..6556901b9 100644 --- a/test/common.js +++ b/test/common.js @@ -3,6 +3,16 @@ var cryptoLib = require('crypto-browserify'); var should = require('should'); var sinon = require('sinon'); +should.use(function (should, Assertion) { + Assertion.add('hexString', function () { + this.params = { + operator: 'to be hex string', + }; + (Buffer.from(this.obj, 'hex').toString('hex')) + .should.equal(this.obj); + }); +}); + // See https://github.com/shouldjs/should.js/issues/41 Object.defineProperty(global, 'should', { value: should }); global.sinon = sinon; diff --git a/test/transactions/crypto.js b/test/transactions/crypto.js index 1e2443e55..eadee87ac 100644 --- a/test/transactions/crypto.js +++ b/test/transactions/crypto.js @@ -214,14 +214,8 @@ describe('crypto.js', function () { (keys).should.be.ok(); (keys).should.be.type('object'); - (keys).should.have.property('publicKey').and.be.type('string'); - (keys).should.have.property('privateKey').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(keys.publicKey, 'hex'); - }); - should.doesNotThrow(function () { - Buffer.from(keys.privateKey, 'hex'); - }); + (keys).should.have.property('publicKey').and.be.type('string').and.be.hexString(); + (keys).should.have.property('privateKey').and.be.type('string').and.be.hexString(); }); }); diff --git a/test/transactions/dapp.js b/test/transactions/dapp.js index 8fd07ed8f..955eaa5f7 100644 --- a/test/transactions/dapp.js +++ b/test/transactions/dapp.js @@ -109,10 +109,7 @@ describe('dapp.js', function () { }); it('should have senderPublicKey as hex string', function () { - (trs).should.have.property('senderPublicKey').and.be.type('string'); - return should.doesNotThrow(function () { - Buffer.from(trs.senderPublicKey, 'hex'); - }); + (trs).should.have.property('senderPublicKey').and.be.type('string').and.be.hexString(); }); it('should have timestamp as number', function () { @@ -159,17 +156,11 @@ describe('dapp.js', function () { }); it('should have signature as hex string', function () { - (trs).should.have.property('signature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signature, 'hex'); - }); + (trs).should.have.property('signature').and.be.type('string').and.be.hexString(); }); it('should have second signature in hex', function () { - (trs).should.have.property('signSignature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signSignature, 'hex'); - }); + (trs).should.have.property('signSignature').and.be.type('string').and.be.hexString(); }); it('should be signed correctly', function () { diff --git a/test/transactions/delegate.js b/test/transactions/delegate.js index e45e2906c..737655683 100644 --- a/test/transactions/delegate.js +++ b/test/transactions/delegate.js @@ -102,24 +102,15 @@ describe('delegate.js', function () { }); it('should have senderPublicKey in hex', function () { - (trs).should.have.property('senderPublicKey').and.type('string').and.equal(keys.publicKey); - should.doesNotThrow(function () { - Buffer.from(trs.senderPublicKey, 'hex'); - }); + (trs).should.have.property('senderPublicKey').and.type('string').and.equal(keys.publicKey).and.be.hexString(); }); it('should have signature in hex', function () { - (trs).should.have.property('signature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signature, 'hex'); - }); + (trs).should.have.property('signature').and.be.type('string').and.be.hexString(); }); it('should have second signature in hex', function () { - (trs).should.have.property('signSignature').and.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signSignature, 'hex'); - }); + (trs).should.have.property('signSignature').and.type('string').and.be.hexString(); }); it('should have delegate asset', function () { diff --git a/test/transactions/signature.js b/test/transactions/signature.js index 8d17c9489..626e74280 100644 --- a/test/transactions/signature.js +++ b/test/transactions/signature.js @@ -99,10 +99,7 @@ describe('signature.js', function () { }); it('should have publicKey in hex', function () { - (sgn.asset.signature).should.have.property('publicKey').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(sgn.asset.signature.publicKey, 'hex'); - }); + (sgn.asset.signature).should.have.property('publicKey').and.be.type('string').and.be.hexString(); }); it('should have publicKey in 32 bytes', function () { diff --git a/test/transactions/transaction.js b/test/transactions/transaction.js index 9bef58297..47ef1854a 100644 --- a/test/transactions/transaction.js +++ b/test/transactions/transaction.js @@ -81,10 +81,7 @@ describe('transaction.js', function () { }); it('should have senderPublicKey as hex string', function () { - (trs).should.have.property('senderPublicKey').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.senderPublicKey, 'hex'); - }); + (trs).should.have.property('senderPublicKey').and.be.type('string').and.be.hexString(); }); it('should have recipientId as string and to be equal 58191285901858109L', function () { @@ -104,10 +101,7 @@ describe('transaction.js', function () { }); it('should have signature as hex string', function () { - (trs).should.have.property('signature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signature, 'hex'); - }); + (trs).should.have.property('signature').and.be.type('string').and.be.hexString(); }); it('should be signed correctly', function () { @@ -160,10 +154,7 @@ describe('transaction.js', function () { }); it('should have senderPublicKey as hex string', function () { - (trs).should.have.property('senderPublicKey').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.senderPublicKey, 'hex'); - }); + (trs).should.have.property('senderPublicKey').and.be.type('string').and.be.hexString(); }); it('should have recipientId as string and to be equal 58191285901858109L', function () { @@ -183,17 +174,11 @@ describe('transaction.js', function () { }); it('should have signature as hex string', function () { - (trs).should.have.property('signature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signature, 'hex'); - }); + (trs).should.have.property('signature').and.be.type('string').and.be.hexString(); }); it('should have signSignature as hex string', function () { - (trs).should.have.property('signSignature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(trs.signSignature, 'hex'); - }); + (trs).should.have.property('signSignature').and.be.type('string').and.be.hexString(); }); it('should be signed correctly', function () { diff --git a/test/transactions/vote.js b/test/transactions/vote.js index c6df39df9..f3498a395 100644 --- a/test/transactions/vote.js +++ b/test/transactions/vote.js @@ -101,24 +101,15 @@ describe('vote.js', function () { }); it('should have senderPublicKey hex string equal to sender public key', function () { - (vt).should.have.property('senderPublicKey').and.be.type('string').and.equal(publicKey); - should.doesNotThrow(function () { - Buffer.from(vt.senderPublicKey, 'hex'); - }); + (vt).should.have.property('senderPublicKey').and.be.type('string').and.equal(publicKey).and.be.hexString(); }); it('should have signature hex string', function () { - (vt).should.have.property('signature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(vt.signature, 'hex'); - }); + (vt).should.have.property('signature').and.be.type('string').and.be.hexString(); }); it('should have second signature hex string', function () { - (vt).should.have.property('signSignature').and.be.type('string'); - should.doesNotThrow(function () { - Buffer.from(vt.signSignature, 'hex'); - }); + (vt).should.have.property('signSignature').and.be.type('string').and.be.hexString(); }); it('should be signed correctly', function () { @@ -167,10 +158,8 @@ describe('vote.js', function () { it('should have public keys in hex', function () { vt.asset.votes.forEach(function (v) { - (v).should.be.type('string').startWith('+'); - should.doesNotThrow(function () { - Buffer.from(v.substring(1, v.length), 'hex'); - }); + (v).should.be.type('string').and.startWith('+'); + (v.slice(1)).should.be.hexString(); }); });