From 4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Mon, 5 Nov 2018 16:06:34 -0300 Subject: Update watchAsset ERC20 validation (#5653) * update ERC20 token valodation for watchAsset * update ERC20 validation test descriptions --- .../app/controllers/preferences-controller-test.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/unit/app/controllers/preferences-controller-test.js') diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index c64c47ae9..674cf5167 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -453,6 +453,32 @@ describe('preferences controller', function () { const assetImages = preferencesController.getAssetImages() assert.ok(assetImages[address], `set image correctly`) }) + it('should validate ERC20 asset correctly', async function () { + const validateSpy = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpy({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC', decimals: 0}) } catch (e) {} + assert.equal(validateSpy.threw(), false, 'correct options object') + const validateSpyAddress = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyAddress({symbol: 'ABC', decimals: 0}) } catch (e) {} + assert.equal(validateSpyAddress.threw(), true, 'options object with no address') + const validateSpySymbol = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpySymbol({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', decimals: 0}) } catch (e) {} + assert.equal(validateSpySymbol.threw(), true, 'options object with no symbol') + const validateSpyDecimals = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyDecimals({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC'}) } catch (e) {} + assert.equal(validateSpyDecimals.threw(), true, 'options object with no decimals') + const validateSpyInvalidSymbol = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyInvalidSymbol({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 0}) } catch (e) {} + assert.equal(validateSpyInvalidSymbol.threw(), true, 'options object with invalid symbol') + const validateSpyInvalidDecimals1 = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyInvalidDecimals1({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: -1}) } catch (e) {} + assert.equal(validateSpyInvalidDecimals1.threw(), true, 'options object with decimals less than zero') + const validateSpyInvalidDecimals2 = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyInvalidDecimals2({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 38}) } catch (e) {} + assert.equal(validateSpyInvalidDecimals2.threw(), true, 'options object with decimals more than 36') + const validateSpyInvalidAddress = sandbox.spy(preferencesController._validateERC20AssetParams) + try { validateSpyInvalidAddress({rawAddress: '0x123', symbol: 'ABC', decimals: 0}) } catch (e) {} + assert.equal(validateSpyInvalidAddress.threw(), true, 'options object with address invalid') + }) }) describe('setPasswordForgotten', function () { -- cgit v1.2.3 From c76c9ca2c86317f902f443db2c5704d4bf6311c0 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Thu, 27 Sep 2018 14:19:09 -0400 Subject: EIP-1102: updated implementation --- test/unit/app/controllers/preferences-controller-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit/app/controllers/preferences-controller-test.js') diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index 674cf5167..473f22f8b 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -418,7 +418,7 @@ describe('preferences controller', function () { req.params.options = { address, symbol, decimals, image } sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true) - preferencesController.showWatchAssetUi = async () => {} + preferencesController.openPopup = async () => {} await preferencesController._handleWatchAssetERC20(req.params.options) const suggested = preferencesController.getSuggestedTokens() @@ -438,7 +438,7 @@ describe('preferences controller', function () { req.params.options = { address, symbol, decimals, image } sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true) - preferencesController.showWatchAssetUi = async () => { + preferencesController.openPopup = async () => { await preferencesController.addToken(address, symbol, decimals, image) } -- cgit v1.2.3 From 1988e1e96b09a47ad5428083bb2ed38cb2d7e0a8 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Fri, 16 Nov 2018 21:24:55 -0330 Subject: ESLint fixes (#5775) * eslint . --fix * Upgrade all ESLint warnings to errors --- test/unit/app/controllers/preferences-controller-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit/app/controllers/preferences-controller-test.js') diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index 473f22f8b..67d1875c1 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -515,14 +515,14 @@ describe('preferences controller', function () { it('should add custom RPC url to state', function () { preferencesController.addToFrequentRpcList('rpc_url', 1) preferencesController.addToFrequentRpcList('http://localhost:8545', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) preferencesController.addToFrequentRpcList('rpc_url', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) }) it('should remove custom RPC url from state', function () { preferencesController.addToFrequentRpcList('rpc_url', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) preferencesController.removeFromFrequentRpcList('other_rpc_url') preferencesController.removeFromFrequentRpcList('http://localhost:8545') preferencesController.removeFromFrequentRpcList('rpc_url') -- cgit v1.2.3