aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/app')
-rw-r--r--test/unit/app/controllers/network-contoller-test.js2
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js46
2 files changed, 37 insertions, 11 deletions
diff --git a/test/unit/app/controllers/network-contoller-test.js b/test/unit/app/controllers/network-contoller-test.js
index 822311931..7959e6cc1 100644
--- a/test/unit/app/controllers/network-contoller-test.js
+++ b/test/unit/app/controllers/network-contoller-test.js
@@ -47,7 +47,7 @@ describe('# Network Controller', function () {
describe('#setNetworkState', function () {
it('should update the network', function () {
- networkController.setNetworkState(1)
+ networkController.setNetworkState(1, 'rpc')
const networkState = networkController.getNetworkState()
assert.equal(networkState, 1, 'network is 1')
})
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index 7f2804a83..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)
}
@@ -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 () {
@@ -487,20 +513,20 @@ describe('preferences controller', function () {
describe('on updateFrequentRpcList', function () {
it('should add custom RPC url to state', function () {
- preferencesController.addToFrequentRpcList('rpc_url')
- preferencesController.addToFrequentRpcList('http://localhost:8545')
- assert.deepEqual(preferencesController.store.getState().frequentRpcList, ['rpc_url'])
- preferencesController.addToFrequentRpcList('rpc_url')
- assert.deepEqual(preferencesController.store.getState().frequentRpcList, ['rpc_url'])
+ 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: '' }] )
+ preferencesController.addToFrequentRpcList('rpc_url', 1)
+ 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')
- assert.deepEqual(preferencesController.store.getState().frequentRpcList, ['rpc_url'])
+ preferencesController.addToFrequentRpcList('rpc_url', 1)
+ 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')
- assert.deepEqual(preferencesController.store.getState().frequentRpcList, [])
+ assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [])
})
})
})