aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEsteban MiƱo <efmino@uc.cl>2018-11-06 03:06:34 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-11-06 03:06:34 +0800
commit4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1 (patch)
treee90e28e3ffe696fe51750f01cd7faccbe3d3bea8 /test
parent6883787c14ba5e3a26a865887e0626a01e96e56a (diff)
downloadtangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar.gz
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar.bz2
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar.lz
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar.xz
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.tar.zst
tangerine-wallet-browser-4489a57f2fd32ae4b9b5aa12aede289fa0b03fb1.zip
Update watchAsset ERC20 validation (#5653)
* update ERC20 token valodation for watchAsset * update ERC20 validation test descriptions
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js26
1 files changed, 26 insertions, 0 deletions
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 () {