From 0a7dfcd55d02a7204d8f0773ff9d91f325aabea8 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 16 Aug 2018 09:58:27 -0230 Subject: Connect the gas-button-group component to redux and a live api. --- ui/app/selectors/tests/custom-gas.test.js | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 ui/app/selectors/tests/custom-gas.test.js (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js new file mode 100644 index 000000000..d53c1ec98 --- /dev/null +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -0,0 +1,140 @@ +import assert from 'assert' +import proxyquire from 'proxyquire' + +const { + getCustomGasErrors, + getCustomGasLimit, + getCustomGasPrice, + getCustomGasTotal, + getRenderableBasicEstimateData, +} = proxyquire('../custom-gas', {}) + +describe('custom-gas selectors', () => { + + describe('getCustomGasPrice()', () => { + it('should return gas.customData.price', () => { + const mockState = { gas: { customData: { price: 'mockPrice' } } } + assert.equal(getCustomGasPrice(mockState), 'mockPrice') + }) + }) + + describe('getCustomGasLimit()', () => { + it('should return gas.customData.limit', () => { + const mockState = { gas: { customData: { limit: 'mockLimit' } } } + assert.equal(getCustomGasLimit(mockState), 'mockLimit') + }) + }) + + describe('getCustomGasTotal()', () => { + it('should return gas.customData.total', () => { + const mockState = { gas: { customData: { total: 'mockTotal' } } } + assert.equal(getCustomGasTotal(mockState), 'mockTotal') + }) + }) + + describe('getCustomGasErrors()', () => { + it('should return gas.errors', () => { + const mockState = { gas: { errors: 'mockErrors' } } + assert.equal(getCustomGasErrors(mockState), 'mockErrors') + }) + }) + + describe('getRenderableBasicEstimateData()', () => { + const tests = [ + { + expectedResult: [ + { + feeInPrimaryCurrency: '$0.05', + feeInSecondaryCurrency: '0.00021 ETH', + timeEstimate: '~7 sec', + priceInHexWei: '0x2540be400', + }, + { + feeInPrimaryCurrency: '$0.03', + feeInSecondaryCurrency: '0.000105 ETH', + timeEstimate: '~46 sec', + priceInHexWei: '0x12a05f200', + }, + { + feeInPrimaryCurrency: '$0.01', + feeInSecondaryCurrency: '0.0000525 ETH', + timeEstimate: '~1 min 33 sec', + priceInHexWei: '0x9502f900', + }, + ], + mockState: { + metamask: { + conversionRate: 255.71, + currentCurrency: 'usd', + send: { + gasLimit: '0x5208', + }, + }, + gas: { + basicEstimates: { + blockTime: 14.16326530612245, + safeLow: 25, + safeLowWait: 6.6, + average: 50, + avgWait: 3.3, + fast: 100, + fastWait: 0.5, + }, + }, + }, + }, + { + expectedResult: [ + { + feeInPrimaryCurrency: '$1.07', + feeInSecondaryCurrency: '0.00042 ETH', + timeEstimate: '~14 sec', + priceInHexWei: '0x4a817c800', + }, + { + feeInPrimaryCurrency: '$0.54', + feeInSecondaryCurrency: '0.00021 ETH', + timeEstimate: '~1 min 33 sec', + priceInHexWei: '0x2540be400', + }, + { + feeInPrimaryCurrency: '$0.27', + feeInSecondaryCurrency: '0.000105 ETH', + timeEstimate: '~3 min 7 sec', + priceInHexWei: '0x12a05f200', + }, + ], + mockState: { + metamask: { + conversionRate: 2557.1, + currentCurrency: 'usd', + send: { + gasLimit: '0x5208', + }, + }, + gas: { + basicEstimates: { + blockTime: 14.16326530612245, + safeLow: 50, + safeLowWait: 13.2, + average: 100, + avgWait: 6.6, + fast: 200, + fastWait: 1.0, + }, + }, + }, + }, + ] + it('should return renderable data about basic estimates', () => { + tests.forEach(test => { + assert.deepEqual( + getRenderableBasicEstimateData(test.mockState), + test.expectedResult + ) + }) + }) + + }) + +}) -- cgit From 5354325fab9b9ab3091e3c49e6b940fa713d1799 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 20 Sep 2018 01:46:43 -0230 Subject: Test updates and additions for button integration with send screen. --- ui/app/selectors/tests/custom-gas.test.js | 99 +++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js index d53c1ec98..5fde61c9b 100644 --- a/ui/app/selectors/tests/custom-gas.test.js +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -7,6 +7,7 @@ const { getCustomGasPrice, getCustomGasTotal, getRenderableBasicEstimateData, + getRenderableEstimateDataForSmallButtons, } = proxyquire('../custom-gas', {}) describe('custom-gas selectors', () => { @@ -137,4 +138,102 @@ describe('custom-gas selectors', () => { }) + describe('getRenderableEstimateDataForSmallButtons()', () => { + const tests = [ + { + expectedResult: [ + { + feeInSecondaryCurrency: '$0.05', + feeInPrimaryCurrency: '0.00021 ETH', + labelKey: 'fast', + priceInHexWei: '0x2540be400', + }, + { + feeInSecondaryCurrency: '$0.03', + feeInPrimaryCurrency: '0.0001 ETH', + labelKey: 'average', + priceInHexWei: '0x12a05f200', + }, + { + feeInSecondaryCurrency: '$0.01', + feeInPrimaryCurrency: '0.00005 ETH', + labelKey: 'slow', + priceInHexWei: '0x9502f900', + }, + ], + mockState: { + metamask: { + conversionRate: 255.71, + currentCurrency: 'usd', + send: { + gasLimit: '0x5208', + }, + }, + gas: { + basicEstimates: { + blockTime: 14.16326530612245, + safeLow: 25, + safeLowWait: 6.6, + average: 50, + avgWait: 3.3, + fast: 100, + fastWait: 0.5, + }, + }, + }, + }, + { + expectedResult: [ + { + feeInSecondaryCurrency: '$1.07', + feeInPrimaryCurrency: '0.00042 ETH', + labelKey: 'fast', + priceInHexWei: '0x4a817c800', + }, + { + feeInSecondaryCurrency: '$0.54', + feeInPrimaryCurrency: '0.00021 ETH', + labelKey: 'average', + priceInHexWei: '0x2540be400', + }, + { + feeInSecondaryCurrency: '$0.27', + feeInPrimaryCurrency: '0.0001 ETH', + labelKey: 'slow', + priceInHexWei: '0x12a05f200', + }, + ], + mockState: { + metamask: { + conversionRate: 2557.1, + currentCurrency: 'usd', + send: { + gasLimit: '0x5208', + }, + }, + gas: { + basicEstimates: { + blockTime: 14.16326530612245, + safeLow: 50, + safeLowWait: 13.2, + average: 100, + avgWait: 6.6, + fast: 200, + fastWait: 1.0, + }, + }, + }, + }, + ] + it('should return renderable data about basic estimates appropriate for buttons with less info', () => { + tests.forEach(test => { + assert.deepEqual( + getRenderableEstimateDataForSmallButtons(test.mockState), + test.expectedResult + ) + }) + }) + + }) + }) -- cgit From d14af8346af2517db2e50f142377948c9f2ae5e9 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Wed, 24 Oct 2018 01:52:22 -0230 Subject: Improve data management and tests for gas-modal-page-container price estimates. --- ui/app/selectors/tests/custom-gas.test.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js index 5fde61c9b..1099670f2 100644 --- a/ui/app/selectors/tests/custom-gas.test.js +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -6,6 +6,9 @@ const { getCustomGasLimit, getCustomGasPrice, getCustomGasTotal, + getEstimatedGasPrices, + getEstimatedGasTimes, + getPriceAndTimeEstimates, getRenderableBasicEstimateData, getRenderableEstimateDataForSmallButtons, } = proxyquire('../custom-gas', {}) @@ -40,6 +43,35 @@ describe('custom-gas selectors', () => { }) }) + describe('getPriceAndTimeEstimates', () => { + it('should return price and time estimates', () => { + const mockState = { gas: { priceAndTimeEstimates: 'mockPriceAndTimeEstimates' } } + assert.equal(getPriceAndTimeEstimates(mockState), 'mockPriceAndTimeEstimates') + }) + }) + + describe('getEstimatedGasPrices', () => { + it('should return price and time estimates', () => { + const mockState = { gas: { priceAndTimeEstimates: [ + { gasprice: 12, somethingElse: 20 }, + { gasprice: 22, expectedTime: 30 }, + { gasprice: 32, somethingElse: 40 }, + ] } } + assert.deepEqual(getEstimatedGasPrices(mockState), [12, 22, 32]) + }) + }) + + describe('getEstimatedGasTimes', () => { + it('should return price and time estimates', () => { + const mockState = { gas: { priceAndTimeEstimates: [ + { somethingElse: 12, expectedTime: 20 }, + { gasPrice: 22, expectedTime: 30 }, + { somethingElse: 32, expectedTime: 40 }, + ] } } + assert.deepEqual(getEstimatedGasTimes(mockState), [20, 30, 40]) + }) + }) + describe('getRenderableBasicEstimateData()', () => { const tests = [ { -- cgit From 3162a2747c0e54f729405caaef777519e4ded4dc Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 25 Oct 2018 01:25:39 -0230 Subject: Redesign of gas customization basic tab. --- ui/app/selectors/tests/custom-gas.test.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js index 1099670f2..8a6e7e351 100644 --- a/ui/app/selectors/tests/custom-gas.test.js +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -77,18 +77,21 @@ describe('custom-gas selectors', () => { { expectedResult: [ { + labelKey: 'fastest', feeInPrimaryCurrency: '$0.05', feeInSecondaryCurrency: '0.00021 ETH', timeEstimate: '~7 sec', priceInHexWei: '0x2540be400', }, { + labelKey: 'fast', feeInPrimaryCurrency: '$0.03', feeInSecondaryCurrency: '0.000105 ETH', timeEstimate: '~46 sec', priceInHexWei: '0x12a05f200', }, { + labelKey: 'slow', feeInPrimaryCurrency: '$0.01', feeInSecondaryCurrency: '0.0000525 ETH', timeEstimate: '~1 min 33 sec', @@ -119,18 +122,21 @@ describe('custom-gas selectors', () => { { expectedResult: [ { + labelKey: 'fastest', feeInPrimaryCurrency: '$1.07', feeInSecondaryCurrency: '0.00042 ETH', timeEstimate: '~14 sec', priceInHexWei: '0x4a817c800', }, { + labelKey: 'fast', feeInPrimaryCurrency: '$0.54', feeInSecondaryCurrency: '0.00021 ETH', timeEstimate: '~1 min 33 sec', priceInHexWei: '0x2540be400', }, { + labelKey: 'slow', feeInPrimaryCurrency: '$0.27', feeInSecondaryCurrency: '0.000105 ETH', timeEstimate: '~3 min 7 sec', -- cgit From 7f2c5c09de67a67972fcbaae254d39aac6c96f56 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Tue, 13 Nov 2018 13:06:52 -0330 Subject: Uses more reliable api on main send screen; caches basic api results in modal --- ui/app/selectors/tests/custom-gas.test.js | 94 +++++++++++++++---------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js index 8a6e7e351..037b1e86e 100644 --- a/ui/app/selectors/tests/custom-gas.test.js +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -10,7 +10,7 @@ const { getEstimatedGasTimes, getPriceAndTimeEstimates, getRenderableBasicEstimateData, - getRenderableEstimateDataForSmallButtons, + getRenderableEstimateDataForSmallButtonsFromGWEI, } = proxyquire('../custom-gas', {}) describe('custom-gas selectors', () => { @@ -80,21 +80,21 @@ describe('custom-gas selectors', () => { labelKey: 'fastest', feeInPrimaryCurrency: '$0.05', feeInSecondaryCurrency: '0.00021 ETH', - timeEstimate: '~7 sec', + timeEstimate: '~30 sec', priceInHexWei: '0x2540be400', }, { labelKey: 'fast', feeInPrimaryCurrency: '$0.03', feeInSecondaryCurrency: '0.000105 ETH', - timeEstimate: '~46 sec', + timeEstimate: '~3 min 18 sec', priceInHexWei: '0x12a05f200', }, { labelKey: 'slow', feeInPrimaryCurrency: '$0.01', feeInSecondaryCurrency: '0.0000525 ETH', - timeEstimate: '~1 min 33 sec', + timeEstimate: '~6 min 36 sec', priceInHexWei: '0x9502f900', }, ], @@ -111,10 +111,10 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 25, safeLowWait: 6.6, - average: 50, - avgWait: 3.3, - fast: 100, - fastWait: 0.5, + fast: 50, + fastWait: 3.3, + fastest: 100, + fastestWait: 0.5, }, }, }, @@ -125,21 +125,21 @@ describe('custom-gas selectors', () => { labelKey: 'fastest', feeInPrimaryCurrency: '$1.07', feeInSecondaryCurrency: '0.00042 ETH', - timeEstimate: '~14 sec', + timeEstimate: '~1 min', priceInHexWei: '0x4a817c800', }, { labelKey: 'fast', feeInPrimaryCurrency: '$0.54', feeInSecondaryCurrency: '0.00021 ETH', - timeEstimate: '~1 min 33 sec', + timeEstimate: '~6 min 36 sec', priceInHexWei: '0x2540be400', }, { labelKey: 'slow', feeInPrimaryCurrency: '$0.27', feeInSecondaryCurrency: '0.000105 ETH', - timeEstimate: '~3 min 7 sec', + timeEstimate: '~13 min 12 sec', priceInHexWei: '0x12a05f200', }, ], @@ -156,10 +156,10 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, - average: 100, - avgWait: 6.6, - fast: 200, - fastWait: 1.0, + fast: 100, + fastWait: 6.6, + fastest: 200, + fastestWait: 1.0, }, }, }, @@ -176,27 +176,27 @@ describe('custom-gas selectors', () => { }) - describe('getRenderableEstimateDataForSmallButtons()', () => { + describe('getRenderableEstimateDataForSmallButtonsFromGWEI()', () => { const tests = [ { expectedResult: [ { - feeInSecondaryCurrency: '$0.05', - feeInPrimaryCurrency: '0.00021 ETH', - labelKey: 'fast', - priceInHexWei: '0x2540be400', + feeInSecondaryCurrency: '$0.54', + feeInPrimaryCurrency: '0.0021 ETH', + labelKey: 'fastest', + priceInHexWei: '0x174876e800', }, { - feeInSecondaryCurrency: '$0.03', - feeInPrimaryCurrency: '0.0001 ETH', - labelKey: 'average', - priceInHexWei: '0x12a05f200', + feeInSecondaryCurrency: '$0.27', + feeInPrimaryCurrency: '0.00105 ETH', + labelKey: 'fast', + priceInHexWei: '0xba43b7400', }, { - feeInSecondaryCurrency: '$0.01', - feeInPrimaryCurrency: '0.00005 ETH', + feeInSecondaryCurrency: '$0.13', + feeInPrimaryCurrency: '0.00052 ETH', labelKey: 'slow', - priceInHexWei: '0x9502f900', + priceInHexWei: '0x5d21dba00', }, ], mockState: { @@ -212,10 +212,10 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 25, safeLowWait: 6.6, - average: 50, - avgWait: 3.3, - fast: 100, - fastWait: 0.5, + fast: 50, + fastWait: 3.3, + fastest: 100, + fastestWait: 0.5, }, }, }, @@ -223,22 +223,22 @@ describe('custom-gas selectors', () => { { expectedResult: [ { - feeInSecondaryCurrency: '$1.07', - feeInPrimaryCurrency: '0.00042 ETH', - labelKey: 'fast', - priceInHexWei: '0x4a817c800', + feeInSecondaryCurrency: '$10.74', + feeInPrimaryCurrency: '0.0042 ETH', + labelKey: 'fastest', + priceInHexWei: '0x2e90edd000', }, { - feeInSecondaryCurrency: '$0.54', - feeInPrimaryCurrency: '0.00021 ETH', - labelKey: 'average', - priceInHexWei: '0x2540be400', + feeInSecondaryCurrency: '$5.37', + feeInPrimaryCurrency: '0.0021 ETH', + labelKey: 'fast', + priceInHexWei: '0x174876e800', }, { - feeInSecondaryCurrency: '$0.27', - feeInPrimaryCurrency: '0.0001 ETH', + feeInSecondaryCurrency: '$2.68', + feeInPrimaryCurrency: '0.00105 ETH', labelKey: 'slow', - priceInHexWei: '0x12a05f200', + priceInHexWei: '0xba43b7400', }, ], mockState: { @@ -254,10 +254,10 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, - average: 100, - avgWait: 6.6, - fast: 200, - fastWait: 1.0, + fast: 100, + fastWait: 6.6, + fastest: 200, + fastestWait: 1.0, }, }, }, @@ -266,7 +266,7 @@ describe('custom-gas selectors', () => { it('should return renderable data about basic estimates appropriate for buttons with less info', () => { tests.forEach(test => { assert.deepEqual( - getRenderableEstimateDataForSmallButtons(test.mockState), + getRenderableEstimateDataForSmallButtonsFromGWEI(test.mockState), test.expectedResult ) }) -- cgit From d8e41a6aa5a4c64538063c6dde7afdf77b0e5793 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Tue, 27 Nov 2018 14:00:41 -0330 Subject: Final gas customization fixes --- ui/app/selectors/tests/custom-gas.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ui/app/selectors/tests') diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js index 037b1e86e..ebc300160 100644 --- a/ui/app/selectors/tests/custom-gas.test.js +++ b/ui/app/selectors/tests/custom-gas.test.js @@ -109,11 +109,11 @@ describe('custom-gas selectors', () => { gas: { basicEstimates: { blockTime: 14.16326530612245, - safeLow: 25, + safeLow: 2.5, safeLowWait: 6.6, - fast: 50, + fast: 5, fastWait: 3.3, - fastest: 100, + fastest: 10, fastestWait: 0.5, }, }, @@ -154,11 +154,11 @@ describe('custom-gas selectors', () => { gas: { basicEstimates: { blockTime: 14.16326530612245, - safeLow: 50, + safeLow: 5, safeLowWait: 13.2, - fast: 100, + fast: 10, fastWait: 6.6, - fastest: 200, + fastest: 20, fastestWait: 1.0, }, }, -- cgit