From c0516ddf333336a7784787a02183c4fe212364b9 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 17 May 2017 00:09:59 -0700 Subject: Add test requiring high precision --- test/unit/components/bn-as-decimal-input-test.js | 59 ++++++++++++++++++++++++ test/unit/components/pending-tx-test.js | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/unit/components/bn-as-decimal-input-test.js (limited to 'test') 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..4ea910fb0 --- /dev/null +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -0,0 +1,59 @@ +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.only('BnInput', function () { + let bnInput + const message = 'Hello, world!' + const buffer = new Buffer(message, 'utf8') + const hex = buffer.toString('hex') + + it('can tolerate a large number at a high precision', function (done) { + + const renderer = ReactTestUtils.createRenderer(); + + let valueStr = '1' + while (valueStr.length < 18 + 7) { + valueStr += '0' + } + const value = new BN(valueStr, 10) + + let inputStr = '11' + while (inputStr.length < 7) { + inputStr += '0' + } + inputStr += '.01' + + let targetStr = inputStr.split('.').join() + while (targetStr.length < 18 + 7) { + targetStr += '0' + } + const target = new BN(targetStr, 10) + + const precision = 1e18 // ether precision + + const props = { + value, + precision, + onChange: (newBn) => { + assert.equal(newBn.toString(), targetValue.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 index fe8290003..166b471cb 100644 --- a/test/unit/components/pending-tx-test.js +++ b/test/unit/components/pending-tx-test.js @@ -9,7 +9,7 @@ const Factory = createReactFactory(PendingTx) const ReactTestUtils = require('react-addons-test-utils') const ethUtil = require('ethereumjs-util') -describe.only('PendingTx', function () { +describe('PendingTx', function () { let pendingTxComponent const identities = { -- cgit v1.2.3 From e26501aa0192b26880a8fe63f41d76fdfa849d7b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 17 May 2017 00:19:31 -0700 Subject: Simplify test to represent realistic use case --- test/unit/components/bn-as-decimal-input-test.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 4ea910fb0..1f589c210 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -14,24 +14,20 @@ describe.only('BnInput', function () { const buffer = new Buffer(message, 'utf8') const hex = buffer.toString('hex') - it('can tolerate a large number at a high precision', function (done) { + it('can tolerate a gas decimal number at a high precision', function (done) { const renderer = ReactTestUtils.createRenderer(); - let valueStr = '1' - while (valueStr.length < 18 + 7) { + let valueStr = '20' + while (valueStr.length < 20) { valueStr += '0' } const value = new BN(valueStr, 10) - let inputStr = '11' - while (inputStr.length < 7) { - inputStr += '0' - } - inputStr += '.01' + let inputStr = '2.3' - let targetStr = inputStr.split('.').join() - while (targetStr.length < 18 + 7) { + let targetStr = '23' + while (targetStr.length < 19) { targetStr += '0' } const target = new BN(targetStr, 10) -- cgit v1.2.3 From 6f02f5bc5d741810edb2c011fc3095ee50f84bf9 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 17 May 2017 00:33:19 -0700 Subject: Clean up test --- test/unit/components/bn-as-decimal-input-test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 1f589c210..502c9a2de 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -8,11 +8,8 @@ const BN = ethUtil.BN var BnInput = require('../../../ui/app/components/bn-as-decimal-input') -describe.only('BnInput', function () { +describe('BnInput', function () { let bnInput - const message = 'Hello, world!' - const buffer = new Buffer(message, 'utf8') - const hex = buffer.toString('hex') it('can tolerate a gas decimal number at a high precision', function (done) { -- cgit v1.2.3 From bfb1c92ded2bef1a2f08e1c185721010278ca69b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 17 May 2017 00:34:56 -0700 Subject: Linted test --- test/unit/components/bn-as-decimal-input-test.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 502c9a2de..034bc3e18 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -9,11 +9,9 @@ const BN = ethUtil.BN var BnInput = require('../../../ui/app/components/bn-as-decimal-input') describe('BnInput', function () { - let bnInput - it('can tolerate a gas decimal number at a high precision', function (done) { - const renderer = ReactTestUtils.createRenderer(); + const renderer = ReactTestUtils.createRenderer() let valueStr = '20' while (valueStr.length < 20) { @@ -35,9 +33,9 @@ describe('BnInput', function () { value, precision, onChange: (newBn) => { - assert.equal(newBn.toString(), targetValue.toString(), 'should tolerate increase') + assert.equal(newBn.toString(), target.toString(), 'should tolerate increase') done() - } + }, } const inputComponent = h(BnInput, props) @@ -46,7 +44,7 @@ describe('BnInput', function () { const input = additions.find(component, 'input.hex-input')[0] ReactTestUtils.Simulate.change(input, { preventDefault() {}, target: { value: inputStr, - checkValidity() {return true} }, + checkValidity() { return true } }, }) }) }) -- cgit v1.2.3 From 717db41d0b7bcd7b6f88a5c460aa4dcbc5828116 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 17 May 2017 14:18:01 -0700 Subject: Modify test, replace clone package. --- test/unit/components/bn-as-decimal-input-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 034bc3e18..f515003bb 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -14,7 +14,7 @@ describe('BnInput', function () { const renderer = ReactTestUtils.createRenderer() let valueStr = '20' - while (valueStr.length < 20) { + while (valueStr.length < 15) { valueStr += '0' } const value = new BN(valueStr, 10) @@ -22,7 +22,7 @@ describe('BnInput', function () { let inputStr = '2.3' let targetStr = '23' - while (targetStr.length < 19) { + while (targetStr.length < 14) { targetStr += '0' } const target = new BN(targetStr, 10) -- cgit v1.2.3 From 31d17c9e25458cd47f8c18ec3b967aecff236ba6 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 23 May 2017 14:26:37 -0700 Subject: Fix test, create new value for precision/scale --- test/unit/components/bn-as-decimal-input-test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index f515003bb..6fe684dc5 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -10,7 +10,6 @@ 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' @@ -27,10 +26,12 @@ describe('BnInput', function () { } const target = new BN(targetStr, 10) - const precision = 1e18 // ether precision + const precision = 13 // ether precision + const scale = 13 const props = { value, + scale, precision, onChange: (newBn) => { assert.equal(newBn.toString(), target.toString(), 'should tolerate increase') -- cgit v1.2.3 From 5e19a4a8332703aa3467470073411ad9cccca52a Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 24 May 2017 10:51:44 -0700 Subject: Modfiy test to ether standards. --- test/unit/components/bn-as-decimal-input-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 6fe684dc5..b3365b6f9 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -13,7 +13,7 @@ describe('BnInput', function () { const renderer = ReactTestUtils.createRenderer() let valueStr = '20' - while (valueStr.length < 15) { + while (valueStr.length < 20) { valueStr += '0' } const value = new BN(valueStr, 10) @@ -21,13 +21,13 @@ describe('BnInput', function () { let inputStr = '2.3' let targetStr = '23' - while (targetStr.length < 14) { + while (targetStr.length < 19) { targetStr += '0' } const target = new BN(targetStr, 10) - const precision = 13 // ether precision - const scale = 13 + const precision = 18 // ether precision + const scale = 18 const props = { value, -- cgit v1.2.3