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

Commit

Permalink
Remove unnecessary cross-module dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
willclarktech committed Aug 14, 2017
1 parent 945ae56 commit c8aa202
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 54 deletions.
13 changes: 6 additions & 7 deletions test/transactions/dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
15 changes: 6 additions & 9 deletions test/transactions/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,28 @@ 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', () => {
const offset = -10;

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);
});
});

Expand Down
15 changes: 7 additions & 8 deletions test/transactions/multisignature.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -84,29 +83,29 @@ 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', () => {
const offset = -10;

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);
});
});

Expand Down Expand Up @@ -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);
});
Expand Down
12 changes: 6 additions & 6 deletions test/transactions/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ 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', () => {
const offset = -10;

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);
});
});

Expand Down
12 changes: 6 additions & 6 deletions test/transactions/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
});
});

Expand Down
24 changes: 12 additions & 12 deletions test/transactions/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/transactions/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit c8aa202

Please sign in to comment.