aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-07-12 03:59:05 +0800
committerEsteban MIno <efmino@uc.cl>2018-07-12 03:59:05 +0800
commit910713c6b3c5b8f865fdcb989bfe3ee0b14eb364 (patch)
tree8bd0c9d2b2f801738f7daaf6617d1fa56ebde952 /test
parent63b9c8796bf744f05a3b7d88319460eed772efa9 (diff)
downloadtangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.gz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.bz2
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.lz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.xz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.zst
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.zip
improve tests
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/controllers/detect-tokens-test.js105
1 files changed, 49 insertions, 56 deletions
diff --git a/test/unit/app/controllers/detect-tokens-test.js b/test/unit/app/controllers/detect-tokens-test.js
index 82e86bfcc..dca48c6bb 100644
--- a/test/unit/app/controllers/detect-tokens-test.js
+++ b/test/unit/app/controllers/detect-tokens-test.js
@@ -5,6 +5,14 @@ const PreferencesController = require('../../../../app/scripts/controllers/prefe
const ObservableStore = require('obs-store')
describe('DetectTokensController', () => {
+ const sandbox = sinon.createSandbox()
+ let clock
+ before(async () => {
+ })
+ after(() => {
+ sandbox.restore()
+ })
+
it('should poll on correct interval', async () => {
const stub = sinon.stub(global, 'setInterval')
new DetectTokensController({ interval: 1337 }) // eslint-disable-line no-new
@@ -12,82 +20,67 @@ describe('DetectTokensController', () => {
stub.restore()
})
+ it('should be called on every polling period', async () => {
+ clock = sandbox.useFakeTimers()
+ const network = new ObservableStore({provider: {type: 'mainnet'}})
+ const preferences = new PreferencesController()
+ const controller = new DetectTokensController({preferences: preferences, network: network})
+ controller.isActive = true
+
+ var stub = sandbox.stub(controller, 'exploreNewTokens')
+
+ clock.tick(1)
+ sandbox.assert.notCalled(stub)
+ clock.tick(180000)
+ sandbox.assert.called(stub)
+ clock.tick(180000)
+ sandbox.assert.calledTwice(stub)
+ clock.tick(180000)
+ sandbox.assert.calledThrice(stub)
+ })
+
it('should not check tokens while in test network', async () => {
var network = new ObservableStore({provider: {type: 'rinkeby'}})
const preferences = new PreferencesController()
const controller = new DetectTokensController({preferences: preferences, network: network})
controller.isActive = true
- controller.contracts = {
- '0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4': {
- 'name': 'JET8 Token',
- 'logo': 'J8T.svg',
- 'erc20': true,
- 'symbol': 'J8T',
- 'decimals': 8,
- },
- '0xBC86727E770de68B1060C91f6BB6945c73e10388': {
- 'name': 'Ink Protocol',
- 'logo': 'ink_protocol.svg',
- 'erc20': true,
- 'symbol': 'XNK',
- 'decimals': 18,
- },
- }
- controller.fetchContractAccountBalance = address => address
+
+ var stub = sandbox.stub(controller, 'detectTokenBalance')
+ .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4').returns(true)
+ .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388').returns(true)
+
await controller.exploreNewTokens()
- assert.deepEqual(preferences.store.getState().tokens, [])
-})
+ sandbox.assert.notCalled(stub)
+ })
it('should only check and add tokens while in main network', async () => {
const network = new ObservableStore({provider: {type: 'mainnet'}})
const preferences = new PreferencesController()
const controller = new DetectTokensController({preferences: preferences, network: network})
controller.isActive = true
- controller.contracts = {
- '0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4': {
- 'name': 'JET8 Token',
- 'logo': 'J8T.svg',
- 'erc20': true,
- 'symbol': 'J8T',
- 'decimals': 8,
- },
- '0xBC86727E770de68B1060C91f6BB6945c73e10388': {
- 'name': 'Ink Protocol',
- 'logo': 'ink_protocol.svg',
- 'erc20': true,
- 'symbol': 'XNK',
- 'decimals': 18,
- },
- }
- controller.fetchContractAccountBalance = address => address
+
+ sandbox.stub(controller, 'detectTokenBalance')
+ .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4').returns(true)
+ .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388').returns(true)
+
await controller.exploreNewTokens()
- assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'}, {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}])
+ assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'},
+ {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}])
})
it('should not detect same token while in main network', async () => {
const network = new ObservableStore({provider: {type: 'mainnet'}})
const preferences = new PreferencesController()
- preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 8, 'J8T')
+ preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8)
const controller = new DetectTokensController({preferences: preferences, network: network})
controller.isActive = true
- controller.contracts = {
- '0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4': {
- 'name': 'JET8 Token',
- 'logo': 'J8T.svg',
- 'erc20': true,
- 'symbol': 'J8T',
- 'decimals': 8,
- },
- '0xBC86727E770de68B1060C91f6BB6945c73e10388': {
- 'name': 'Ink Protocol',
- 'logo': 'ink_protocol.svg',
- 'erc20': true,
- 'symbol': 'XNK',
- 'decimals': 18,
- },
- }
- controller.fetchContractAccountBalance = address => address
+
+ sandbox.stub(controller, 'detectTokenBalance')
+ .withArgs('0x0D262e5dC4A06a0F1c90cE79C7a60C09DfC884E4').returns(true)
+ .withArgs('0xBC86727E770de68B1060C91f6BB6945c73e10388').returns(true)
+
await controller.exploreNewTokens()
- assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'}, {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}])
+ assert.deepEqual(preferences.store.getState().tokens, [{address: '0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', decimals: 8, symbol: 'J8T'},
+ {address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', decimals: 18, symbol: 'XNK'}])
})
})