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

Make vote transaction tests atomic - Closes #274 #283

Merged
merged 4 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions test/transactions/dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,30 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

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);
(stub.calledWithExactly(offset)).should.be.true();
});
});

Expand Down
17 changes: 8 additions & 9 deletions test/transactions/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,30 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

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);
(stub.calledWithExactly(offset)).should.be.true();
});
});

Expand Down
17 changes: 9 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,31 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

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);
(stub.calledWithExactly(offset)).should.be.true();
});
});

Expand Down Expand Up @@ -159,7 +160,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
14 changes: 8 additions & 6 deletions test/transactions/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,30 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

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);
(stub.calledWithExactly(offset)).should.be.true();
});
});

Expand Down
14 changes: 8 additions & 6 deletions test/transactions/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => {
Expand All @@ -66,7 +67,8 @@ describe('transaction.js', () => {
offset,
);

(trs).should.have.property('timestamp').and.be.equal(slots.getTime() + offset);
(trs).should.have.property('timestamp').and.be.equal(timeWithOffset);
(stub.calledWithExactly(offset)).should.be.true();
});
});

Expand Down
28 changes: 16 additions & 12 deletions test/transactions/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,30 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

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);
(stub.calledWithExactly(offset)).should.be.true();
});
});
});
Expand Down Expand Up @@ -174,21 +176,22 @@ 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);
(stub.calledWithExactly(undefined)).should.be.true();
});

it('should use time slots with an offset of -10 seconds to get the time for the timestamp', () => {
Expand All @@ -197,7 +200,8 @@ 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);
(stub.calledWithExactly(offset)).should.be.true();
});
});
});
Expand Down
Loading