@parity/api
Version:
The Parity Promise-based API library for interfacing with Ethereum over RPC
49 lines (48 loc) • 1.82 kB
JavaScript
;
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
Object.defineProperty(exports, "__esModule", { value: true });
var wei_1 = require("./wei");
describe('util/wei', function () {
/**
* @test {_getUnitMultiplier}
*/
describe('_getUnitMultiplier', function () {
it('returns 10^0 for wei', function () {
expect(wei_1._getUnitMultiplier('wei')).toEqual(Math.pow(10, 0));
});
it('returns 10^15 for finney', function () {
expect(wei_1._getUnitMultiplier('finney')).toEqual(Math.pow(10, 15));
});
it('returns 10^18 for ether', function () {
expect(wei_1._getUnitMultiplier('ether')).toEqual(Math.pow(10, 18));
});
it('throws an error on invalid units', function () {
expect(function () { return wei_1._getUnitMultiplier('invalid'); }).toThrow(/passed to wei formatter/);
});
});
/**
* @test {fromWei}
*/
describe('fromWei', function () {
it('formats into ether when nothing specified', function () {
expect(wei_1.fromWei('1230000000000000000').toString()).toEqual('1.23');
});
it('formats into finney when specified', function () {
expect(wei_1.fromWei('1230000000000000000', 'finney').toString()).toEqual('1230');
});
});
/**
* @test {toWei}
*/
describe('toWei', function () {
it('formats from ether when nothing specified', function () {
expect(wei_1.toWei(1.23).toString()).toEqual('1230000000000000000');
});
it('formats from finney when specified', function () {
expect(wei_1.toWei(1230, 'finney').toString()).toEqual('1230000000000000000');
});
});
});