aboutsummaryrefslogtreecommitdiffstats
path: root/ui/test/unit/util_test.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-04-14 06:28:44 +0800
committerDan Finlay <dan@danfinlay.com>2016-04-14 06:28:44 +0800
commitd814a45dffa6a872f6e336cad33ca41ffb102887 (patch)
treed8cdd0c4b8c6559efaf6846b24f0d6440f3c94f5 /ui/test/unit/util_test.js
parent9f1438b85b3dac8f1dd98f7bd6e101035cfce0a5 (diff)
downloadtangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.gz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.bz2
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.lz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.xz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.zst
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.zip
Moved UI into repo with its own dependency stack
Diffstat (limited to 'ui/test/unit/util_test.js')
-rw-r--r--ui/test/unit/util_test.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/ui/test/unit/util_test.js b/ui/test/unit/util_test.js
new file mode 100644
index 000000000..52635eb89
--- /dev/null
+++ b/ui/test/unit/util_test.js
@@ -0,0 +1,102 @@
+var assert = require('assert')
+var sinon = require('sinon')
+const ethUtil = require('ethereumjs-util')
+
+var path = require('path')
+var util = require(path.join(__dirname, '..', '..', 'app', 'util.js'))
+
+describe('util', function() {
+ var ethInWei = '1'
+ for (var i = 0; i < 18; i++ ) { ethInWei += '0' }
+
+ beforeEach(function() {
+ this.sinon = sinon.sandbox.create()
+ })
+
+ afterEach(function() {
+ this.sinon.restore()
+ })
+
+ describe('numericBalance', function() {
+
+ it('should return a BN 0 if given nothing', function() {
+ var result = util.numericBalance()
+ assert.equal(result.toString(10), 0)
+ })
+
+ it('should work with hex prefix', function() {
+ var result = util.numericBalance('0x012')
+ assert.equal(result.toString(10), '18')
+ })
+
+ it('should work with no hex prefix', function() {
+ var result = util.numericBalance('012')
+ assert.equal(result.toString(10), '18')
+ })
+
+ })
+
+ describe('#ethToWei', function() {
+
+ it('should take an eth BN, returns wei BN', function() {
+ var input = new ethUtil.BN(1, 10)
+ var result = util.ethToWei(input)
+ assert.equal(result, ethInWei, '18 zeroes')
+ })
+
+ })
+
+ describe('#weiToEth', function() {
+
+ it('should take a wei BN and return an eth BN', function() {
+ var result = util.weiToEth(new ethUtil.BN(ethInWei))
+ assert.equal(result, '1', 'equals 1 eth')
+ })
+
+ })
+
+ describe('#formatBalance', function() {
+
+ it('when given nothing', function() {
+ var result = util.formatBalance()
+ assert.equal(result, 'None', 'should return "None"')
+ })
+
+ it('should return eth as string followed by ETH', function() {
+ var input = new ethUtil.BN(ethInWei).toJSON()
+ var result = util.formatBalance(input)
+ assert.equal(result, '1 ETH')
+ })
+
+ })
+
+ describe('#normalizeToWei', function() {
+ it('should convert an eth to the appropriate equivalent values', function() {
+ var valueTable = {
+ wei: '1000000000000000000',
+ kwei: '1000000000000000',
+ mwei: '1000000000000',
+ gwei: '1000000000',
+ szabo: '1000000',
+ finney:'1000',
+ ether: '1',
+ kether:'0.001',
+ mether:'0.000001',
+ // AUDIT: We're getting BN numbers on these ones.
+ // I think they're big enough to ignore for now.
+ // gether:'0.000000001',
+ // tether:'0.000000000001',
+ }
+ var oneEthBn = new ethUtil.BN(ethInWei, 10)
+
+ for(var currency in valueTable) {
+
+ var value = new ethUtil.BN(valueTable[currency], 10)
+ var output = util.normalizeToWei(value, currency)
+ assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`)
+
+ }
+ })
+ })
+
+})