diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-06-13 04:27:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-13 04:27:04 +0800 |
commit | 27220b7bcd5ea1ebdae3bc1b494d28d9c828918c (patch) | |
tree | c9385fba3d742ca9cbfb9f3b4c6c9ef29c4f4a1b /test/unit/components | |
parent | 57d1a1f1860e50837104a10b7b9f86d398c795ec (diff) | |
parent | 8af41f1b0539e70cf4c6e1f4a9f4b10ad13656fc (diff) | |
download | tangerine-wallet-browser-27220b7bcd5ea1ebdae3bc1b494d28d9c828918c.tar.gz tangerine-wallet-browser-27220b7bcd5ea1ebdae3bc1b494d28d9c828918c.tar.zst tangerine-wallet-browser-27220b7bcd5ea1ebdae3bc1b494d28d9c828918c.zip |
Merge branch 'master' into i#1203MainNetSwitch
Diffstat (limited to 'test/unit/components')
-rw-r--r-- | test/unit/components/binary-renderer-test.js | 10 | ||||
-rw-r--r-- | test/unit/components/bn-as-decimal-input-test.js | 51 | ||||
-rw-r--r-- | test/unit/components/pending-tx-test.js | 80 |
3 files changed, 135 insertions, 6 deletions
diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js index 3264faddc..ee2fa8b60 100644 --- a/test/unit/components/binary-renderer-test.js +++ b/test/unit/components/binary-renderer-test.js @@ -1,24 +1,22 @@ var assert = require('assert') var BinaryRenderer = require('../../../ui/app/components/binary-renderer') -describe('BinaryRenderer', function() { - +describe('BinaryRenderer', function () { let binaryRenderer const message = 'Hello, world!' const buffer = new Buffer(message, 'utf8') const hex = buffer.toString('hex') - beforeEach(function() { + beforeEach(function () { binaryRenderer = new BinaryRenderer() }) - it('recovers message', function() { + it('recovers message', function () { const result = binaryRenderer.hexToText(hex) assert.equal(result, message) }) - - it('recovers message with hex prefix', function() { + it('recovers message with hex prefix', function () { const result = binaryRenderer.hexToText('0x' + hex) assert.equal(result, message) }) diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js new file mode 100644 index 000000000..b3365b6f9 --- /dev/null +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -0,0 +1,51 @@ +var assert = require('assert') + +const additions = require('react-testutils-additions') +const h = require('react-hyperscript') +const ReactTestUtils = require('react-addons-test-utils') +const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN + +var BnInput = require('../../../ui/app/components/bn-as-decimal-input') + +describe('BnInput', function () { + it('can tolerate a gas decimal number at a high precision', function (done) { + const renderer = ReactTestUtils.createRenderer() + + let valueStr = '20' + while (valueStr.length < 20) { + valueStr += '0' + } + const value = new BN(valueStr, 10) + + let inputStr = '2.3' + + let targetStr = '23' + while (targetStr.length < 19) { + targetStr += '0' + } + const target = new BN(targetStr, 10) + + const precision = 18 // ether precision + const scale = 18 + + const props = { + value, + scale, + precision, + onChange: (newBn) => { + assert.equal(newBn.toString(), target.toString(), 'should tolerate increase') + done() + }, + } + + const inputComponent = h(BnInput, props) + const component = additions.renderIntoDocument(inputComponent) + renderer.render(inputComponent) + const input = additions.find(component, 'input.hex-input')[0] + ReactTestUtils.Simulate.change(input, { preventDefault() {}, target: { + value: inputStr, + checkValidity() { return true } }, + }) + }) +}) diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js new file mode 100644 index 000000000..52e5e5910 --- /dev/null +++ b/test/unit/components/pending-tx-test.js @@ -0,0 +1,80 @@ +const assert = require('assert') +const additions = require('react-testutils-additions') +const h = require('react-hyperscript') +const PendingTx = require('../../../ui/app/components/pending-tx') +const ReactTestUtils = require('react-addons-test-utils') +const ethUtil = require('ethereumjs-util') + +describe('PendingTx', function () { + const identities = { + '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': { + name: 'Main Account 1', + balance: '0x00000000000000056bc75e2d63100000', + }, + } + + const gasPrice = '0x4A817C800' // 20 Gwei + const txData = { + 'id':5021615666270214, + 'time':1494458763011, + 'status':'unapproved', + 'metamaskNetworkId':'1494442339676', + 'txParams':{ + 'from':'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826', + 'to':'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb', + 'value':'0xde0b6b3a7640000', + gasPrice, + 'gas':'0x7b0c'}, + 'gasLimitSpecified':false, + 'estimatedGas':'0x5208', + } + + + it('should use updated values when edited.', function (done) { + + const renderer = ReactTestUtils.createRenderer() + const newGasPrice = '0x77359400' + + const props = { + identities, + accounts: identities, + txData, + sendTransaction: (txMeta, event) => { + + // Assert changes: + const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice) + assert.notEqual(result, gasPrice, 'gas price should change') + assert.equal(result, newGasPrice, 'gas price assigned.') + done() + }, + } + + const pendingTxComponent = h(PendingTx, props) + const component = additions.renderIntoDocument(pendingTxComponent) + renderer.render(pendingTxComponent) + const result = renderer.getRenderOutput() + assert.equal(result.type, 'div', 'should create a div') + + try { + const input = additions.find(component, '.cell.row input[type="number"]')[1] + ReactTestUtils.Simulate.change(input, { + target: { + value: 2, + checkValidity() { return true }, + }, + }) + + const form = additions.find(component, 'form')[0] + form.checkValidity = () => true + form.getFormEl = () => { return { checkValidity() { return true } } } + ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() { + return true + } } }) + + } catch (e) { + console.log('WHAAAA') + console.error(e) + } + }) +}) + |