diff --git a/test/transactions/dapp.js b/test/transactions/dapp.js index ea3459e0f..a83723086 100644 --- a/test/transactions/dapp.js +++ b/test/transactions/dapp.js @@ -71,29 +71,28 @@ describe('dapp.js', () => { }); describe('timestamp', () => { - let now; - let clock; + const timeWithOffset = 38350086; + let stub; beforeEach(() => { - now = new Date(); - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { trs = createDapp('secret', null, options); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { const offset = -10; trs = createDapp('secret', null, options, offset); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); diff --git a/test/transactions/delegate.js b/test/transactions/delegate.js index 932c01c97..c67ef8a89 100644 --- a/test/transactions/delegate.js +++ b/test/transactions/delegate.js @@ -32,23 +32,20 @@ describe('delegate.js', () => { }); describe('timestamp', () => { - let now; - let clock; + const timeWithOffset = 38350086; + let stub; beforeEach(() => { - now = new Date(); - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { trs = createDelegate('secret', 'delegate', null); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); - - clock.restore(); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { @@ -56,7 +53,7 @@ describe('delegate.js', () => { trs = createDelegate('secret', 'delegate', null, offset); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); diff --git a/test/transactions/multisignature.js b/test/transactions/multisignature.js index 547e323a9..3b8fa99be 100644 --- a/test/transactions/multisignature.js +++ b/test/transactions/multisignature.js @@ -1,6 +1,5 @@ import slots from '../../src/time/slots'; import multisignature from '../../src/transactions/multisignature'; -import cryptoModule from '../../src/transactions/crypto'; describe('multisignature.js', () => { it('should be ok', () => { @@ -84,21 +83,21 @@ describe('multisignature.js', () => { const minimumSignatures = 2; const requestLifeTime = 5; const multiSignaturePublicKeyArray = ['+123456789', '-987654321']; - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { const trs = multisignature.createMultisignature('secret', '', multiSignaturePublicKeyArray, requestLifeTime, minimumSignatures); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { @@ -106,7 +105,7 @@ describe('multisignature.js', () => { const trs = multisignature.createMultisignature('secret', '', multiSignaturePublicKeyArray, requestLifeTime, minimumSignatures, offset); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); @@ -159,7 +158,7 @@ describe('multisignature.js', () => { it('should create a multisignature transaction without requesterPublicKey and secondSecret', () => { const msigTransaction2 = multisignature.createTransaction(recipientId, amount, secret); - const pubKey = cryptoModule.getPrivateAndPublicKeyFromSecret(secret).publicKey; + const pubKey = 'f120fd1ac603e3049328a0cb87ba226bff44d329b2738a7db2b0a1e3d95000d4'; (msigTransaction2.requesterPublicKey).should.be.equal(pubKey); }); diff --git a/test/transactions/signature.js b/test/transactions/signature.js index 90292e0ca..4c3a3ee96 100644 --- a/test/transactions/signature.js +++ b/test/transactions/signature.js @@ -29,20 +29,20 @@ describe('signature.js', () => { }); describe('timestamp', () => { - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { sgn = createSignature('secret', 'second secret'); - (sgn).should.have.property('timestamp').and.be.equal(slots.getTime()); + (sgn).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { @@ -50,7 +50,7 @@ describe('signature.js', () => { sgn = createSignature('secret', 'second secret', offset); - (sgn).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (sgn).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); diff --git a/test/transactions/transaction.js b/test/transactions/transaction.js index 5e7b0babe..71dad9964 100644 --- a/test/transactions/transaction.js +++ b/test/transactions/transaction.js @@ -37,21 +37,21 @@ describe('transaction.js', () => { }); describe('timestamp', () => { - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { trs = createTransaction(testRecipientAddress, testAmountThousand, testSecret); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { @@ -66,7 +66,7 @@ describe('transaction.js', () => { offset, ); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); diff --git a/test/transactions/transfer.js b/test/transactions/transfer.js index 18e0991e6..a4fcdda92 100644 --- a/test/transactions/transfer.js +++ b/test/transactions/transfer.js @@ -74,28 +74,28 @@ describe('transfer.js', () => { }); describe('timestamp', () => { - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { const trs = createInTransfer(dappId, amount, secret); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { const offset = -10; const trs = createInTransfer(dappId, amount, secret, null, offset); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); }); @@ -174,21 +174,21 @@ describe('transfer.js', () => { }); describe('timestamp', () => { - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { const trs = createOutTransfer(dappId, transactionId, recipientId, amount, secret); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime()); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { @@ -197,7 +197,7 @@ describe('transfer.js', () => { dappId, transactionId, recipientId, amount, secret, null, offset, ); - (trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (trs).should.have.property('timestamp').and.be.equal(timeWithOffset); }); }); }); diff --git a/test/transactions/vote.js b/test/transactions/vote.js index 00e6c4a19..b48414b9a 100644 --- a/test/transactions/vote.js +++ b/test/transactions/vote.js @@ -34,27 +34,27 @@ describe('vote.js', () => { }); describe('timestamp', () => { - const now = new Date(); - let clock; + const timeWithOffset = 38350076; + let stub; beforeEach(() => { - clock = sinon.useFakeTimers(now, 'Date'); + stub = sinon.stub(slots, 'getTimeWithOffset').returns(timeWithOffset); }); afterEach(() => { - clock.restore(); + stub.restore(); }); it('should use time slots to get the time for the timestamp', () => { const vt = createVote('secret', publicKeys, null); - (vt).should.have.property('timestamp').and.be.equal(slots.getTime()); + (vt).should.have.property('timestamp').and.be.equal(timeWithOffset); }); it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => { const offset = -10; const vt = createVote('secret', publicKeys, null, offset); - (vt).should.have.property('timestamp').and.be.equal(slots.getTime() + offset); + (vt).should.have.property('timestamp').and.be.equal(timeWithOffset); }); });