Unverified Commit 55c77aa2 authored by Tomasz Drwięga's avatar Tomasz Drwięga
Browse files

Fix parsing 0s in RLP.

parent f70ae73e
......@@ -48,10 +48,10 @@ let unitMap = {
function getValueOfUnit (unit) {
unit = unit ? unit.toLowerCase() : 'ether'
var unitValue = unitMap[unit]
var unitValue = unitMap[unit] || 0
return new BigNumber(unitValue, 10)
}
export function fromWei (number, unit) {
return new BigNumber(number, 16).dividedBy(getValueOfUnit(unit)).toString(10)
return new BigNumber(number || 0, 16).dividedBy(getValueOfUnit(unit)).toString(10)
}
......@@ -24,4 +24,12 @@ describe('units', () => {
let ether = fromWei(wei)
expect(ether).toEqual('0.000000000000021')
})
it('should return BigNumber for undefined values', () => {
expect(fromWei(null)).toEqual('0')
expect(fromWei(undefined)).toEqual('0')
expect(fromWei(0)).toEqual('0')
expect(fromWei('0')).toEqual('0')
expect(fromWei('')).toEqual('0')
})
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment