1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Adds decETHToDecWEI util method (#9141)

This commit is contained in:
Dan J Miller 2020-08-06 13:52:12 -02:30 committed by GitHub
parent ecaa6c55dd
commit a914eae51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -129,3 +129,12 @@ export function hexWEIToDecGWEI (decGWEI) {
toDenomination: 'GWEI',
})
}
export function decETHToDecWEI (decEth) {
return conversionUtil(decEth, {
fromNumericBase: 'dec',
toNumericBase: 'dec',
fromDenomination: 'ETH',
toDenomination: 'WEI',
})
}

View File

@ -0,0 +1,29 @@
import * as utils from './conversions.util'
import assert from 'assert'
describe('decETHToDecWEI', function () {
it('should correctly convert 1 ETH to WEI', function () {
const weiValue = utils.decETHToDecWEI('1')
assert.equal(weiValue, '1000000000000000000')
})
it('should correctly convert 0.000000000000000001 ETH to WEI', function () {
const weiValue = utils.decETHToDecWEI('0.000000000000000001')
assert.equal(weiValue, '1')
})
it('should correctly convert 1000000.000000000000000001 ETH to WEI', function () {
const weiValue = utils.decETHToDecWEI('1000000.000000000000000001')
assert.equal(weiValue, '1000000000000000000000001')
})
it('should correctly convert 9876.543210 ETH to WEI', function () {
const weiValue = utils.decETHToDecWEI('9876.543210')
assert.equal(weiValue, '9876543210000000000000')
})
it('should correctly convert 1.0000000000000000 ETH to WEI', function () {
const weiValue = utils.decETHToDecWEI('1.0000000000000000')
assert.equal(weiValue, '1000000000000000000')
})
})