MyCrypto/spec/libs/units.spec.js
William O'Beirne bf4171dfbd Transaction confirmation modal (#108)
* Add a little arrow icon.

* Replaced toEther function with toUnit to reduce the number of conversion functions wed need. Add tests for conversion functions.

* First pass at a styled confirm transaction modal.

* More data about data

* Hook up generated transaction with modal

* Fix modal position

* Add from address. Restyle a bit.

* Only show textareas and button if transaction has been generated.

* Remove need for param.

* Copy.

* Use non-relative path.

* Initial crack at transaction token support.

* Fix flow type

* Unit tests for contracts and erc20

* Convert contract class to ethereumjs-abi, caught a bug

* Add decodeArgs for contracts, decodeTransfer for erc20

* Show token value in modal

* Show value from transaction data in confirmation.

* Show address of receiver, not token contract

* Flow type

* Only accept bigs

* Unlog

* Use ethereumjs-abis method ID function

* Get transaction stuff out of state. Leave todo notes.

* Intuit token from transaction to address.

* Move generate transaction out of node and into libs/transaction.

* timeout -> interval

* Promise.reject -> throw

* Get default currency from network.

* Add more unit tests for decoding. Adopt the $ prefix for decoding calls.

* Use signed transaction in confirmation modal.
2017-08-23 08:57:18 +02:00

51 lines
1.2 KiB
JavaScript

import Big from 'bignumber.js';
import { toWei, toUnit } from '../../common/libs/units';
describe('Units', () => {
describe('toWei', () => {
const conversions = [
{
value: '0.001371',
unit: 'ether',
wei: '1371000000000000'
},
{
value: '9',
unit: 'gwei',
wei: '9000000000'
}
];
conversions.forEach(c => {
it(`should return '${c.wei}' given ${c.value} ${c.unit}`, () => {
const big = new Big(c.value);
expect(toWei(big, c.unit).toString()).toEqual(c.wei);
});
});
});
describe('toUnit', () => {
const conversions = [
{
value: '.41849',
fromUnit: 'ether',
toUnit: 'gwei',
output: '418490000'
},
{
value: '4924.71',
fromUnit: 'nanoether',
toUnit: 'szabo',
output: '4.92471'
}
];
conversions.forEach(c => {
it(`should return '${c.output}' when converting ${c.value} ${c.fromUnit} to ${c.toUnit}`, () => {
const big = new Big(c.value);
expect(toUnit(big, c.fromUnit, c.toUnit).toString()).toEqual(c.output);
});
});
});
});