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

Commit

Permalink
Merge pull request #130 from LiskHQ/127_transaction-amount-inconsistence
Browse files Browse the repository at this point in the history
Fix transaction amount inconsistency - Closes #127
  • Loading branch information
karmacoma authored Apr 24, 2017
2 parents f1dbc8a + 18ab779 commit f6b03d2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/services/lsk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ BigNumber.config({ ERRORS: false });

app.factory('lsk', () => ({
normalize(value) {
return new BigNumber(value || 0).dividedBy(Math.pow(10, 8)).toString();
return new BigNumber(value || 0).dividedBy(new BigNumber(10).pow(8)).toFixed();
},
from(value) {
return parseInt(value * Math.pow(10, 8), 10);
return new BigNumber(value * new BigNumber(10).pow(8)).round(0).toNumber();
},
}));
58 changes: 58 additions & 0 deletions src/test/services/lsk.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const chai = require('chai');

const expect = chai.expect;

describe('Factory: lsk', () => {
let lsk;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_lsk_) => {
lsk = _lsk_;
}));

describe('normalize(value)', () => {
it('converts 1 to \'0.00000001\'', () => {
expect(lsk.normalize(1)).to.equal('0.00000001');
});
});

describe('from(value)', () => {
it('converts 0.00000001 to 1', () => {
expect(lsk.from(0.00000001)).to.equal(1);
});

it('converts 1 to 100000000', () => {
expect(lsk.from(1)).to.equal(100000000);
});

it('converts 10535.67379498 to 1053567379498', () => {
expect(lsk.from(10535.67379498)).to.equal(1053567379498);
});
});

describe('normalize(from(value))', () => {
it('is identity function on 1', () => {
const value = '1';
expect(lsk.normalize(lsk.from(value))).to.equal(value);
});

it('is identity function on 10535.67379498', () => {
const value = '10535.67379498';
expect(lsk.normalize(lsk.from(value))).to.equal(value);
});
});

describe('from(normalize(value))', () => {
it('is identity function on 100000000', () => {
const value = 100000000;
expect(lsk.from(lsk.normalize(value))).to.equal(value);
});

it('is identity function on 1053567379498', () => {
const value = 1053567379498;
expect(lsk.from(lsk.normalize(value))).to.equal(value);
});
});
});

1 change: 1 addition & 0 deletions src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require('./components/timestamp/timestamp.spec');
require('./components/transactions/transactions.spec');

require('./services/peers/peers.spec');
require('./services/lsk.spec');

require('./util/animateOnChange/animateOnChange.spec');

0 comments on commit f6b03d2

Please sign in to comment.