@yoroi/common
Version:
The Common package of Yoroi SDK
100 lines (99 loc) • 3.07 kB
JavaScript
;
var _bignumber = _interopRequireDefault(require("bignumber.js"));
var _atomicBreakdown = require("./atomic-breakdown");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
describe('atomicBreakdown', () => {
it('should split a bigint into int dec and bn', () => {
let bigInt = BigInt(123_456_789);
let decimalPlaces = 3;
let expected = {
integer: '123456',
fraction: '789',
bn: new _bignumber.default('123456.789'),
bi: bigInt,
decimalPlaces,
str: '123456.789'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(987_654_321);
decimalPlaces = 2;
expected = {
integer: '9876543',
fraction: '21',
bn: new _bignumber.default('9876543.21'),
bi: bigInt,
decimalPlaces,
str: '9876543.21'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(1_432_116_543);
decimalPlaces = 5;
expected = {
integer: '14321',
fraction: '16543',
bn: new _bignumber.default('14321.16543'),
bi: bigInt,
decimalPlaces,
str: '14321.16543'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(123);
decimalPlaces = 6;
expected = {
integer: '0',
fraction: '000123',
bn: new _bignumber.default('0.000123'),
bi: bigInt,
decimalPlaces,
str: '0.000123'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(123);
decimalPlaces = 3;
expected = {
integer: '0',
fraction: '123',
bn: new _bignumber.default('0.123'),
bi: bigInt,
decimalPlaces,
str: '0.123'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
});
it('should handle negative bigint', () => {
let bigInt = BigInt(-123_456_789);
let decimalPlaces = 3;
let expected = {
integer: '123456',
fraction: '789',
bn: new _bignumber.default('-123456.789'),
bi: bigInt,
decimalPlaces,
str: '-123456.789'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(-987_654_321);
decimalPlaces = 2;
expected = {
integer: '9876543',
fraction: '21',
bn: new _bignumber.default('-9876543.21'),
bi: bigInt,
decimalPlaces,
str: '-9876543.21'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
bigInt = BigInt(-1_000);
decimalPlaces = 0;
expected = {
integer: '1000',
fraction: '',
bn: new _bignumber.default('-1000'),
bi: bigInt,
decimalPlaces,
str: '-1000'
};
expect((0, _atomicBreakdown.atomicBreakdown)(bigInt, decimalPlaces)).toEqual(expected);
});
});
//# sourceMappingURL=atomic-breakdown.test.js.map