aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-08-10 06:39:48 +0800
committerGitHub <noreply@github.com>2018-08-10 06:39:48 +0800
commitef7e638dda63a715c796c210dadbe82430537b6a (patch)
tree23b5b62ac378f5cc302a0d9019fba8a7c622cf04 /test
parent0601df9dae488d997277bb6b52c28df27546e27c (diff)
parent06633da1b395829b475ccafb429af040256d863c (diff)
downloadtangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar.gz
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar.bz2
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar.lz
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar.xz
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.tar.zst
tangerine-wallet-browser-ef7e638dda63a715c796c210dadbe82430537b6a.zip
Merge pull request #5025 from MetaMask/v4.9.2v4.9.2.1
v4.9.2
Diffstat (limited to 'test')
-rw-r--r--test/e2e/beta/contract-test/contract.js5
-rw-r--r--test/e2e/beta/contract-test/index.html3
-rw-r--r--test/e2e/beta/from-import-beta-ui.spec.js2
-rw-r--r--test/e2e/beta/metamask-beta-ui.spec.js100
-rwxr-xr-xtest/e2e/beta/run-all.sh4
-rw-r--r--test/integration/lib/tx-list-items.js5
-rw-r--r--test/unit/app/controllers/detect-tokens-test.js21
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js158
-rw-r--r--test/unit/migrations/028-test.js46
9 files changed, 260 insertions, 84 deletions
diff --git a/test/e2e/beta/contract-test/contract.js b/test/e2e/beta/contract-test/contract.js
index 8af008dce..51891ea21 100644
--- a/test/e2e/beta/contract-test/contract.js
+++ b/test/e2e/beta/contract-test/contract.js
@@ -50,15 +50,20 @@ deployButton.addEventListener('click', async function (event) {
console.log(`contract`, contract)
+ document.getElementById('contractStatus').innerHTML = 'Deployed'
+
depositButton.addEventListener('click', function (event) {
+ document.getElementById('contractStatus').innerHTML = 'Deposit initiated'
contract.deposit({ from: web3.eth.accounts[0], value: '0x3782dace9d900000' }, function (result) {
console.log(result)
+ document.getElementById('contractStatus').innerHTML = 'Deposit completed'
})
})
withdrawButton.addEventListener('click', function (event) {
contract.withdraw('0xde0b6b3a7640000', { from: web3.eth.accounts[0] }, function (result) {
console.log(result)
+ document.getElementById('contractStatus').innerHTML = 'Withdrawn'
})
})
}
diff --git a/test/e2e/beta/contract-test/index.html b/test/e2e/beta/contract-test/index.html
index 0d63fd940..f6e6f44c7 100644
--- a/test/e2e/beta/contract-test/index.html
+++ b/test/e2e/beta/contract-test/index.html
@@ -10,6 +10,9 @@
<button id="depositButton">Deposit</button>
<button id="withdrawButton">Withdraw</button>
</div>
+ <div id="contractStatus" style="display: flex; font-size: 1rem;">
+ Not yet deployed
+ </div>
</div>
<div style="display: flex; flex-flow: column;">
<div style="display: flex; font-size: 1.25rem;">Send eth</div>
diff --git a/test/e2e/beta/from-import-beta-ui.spec.js b/test/e2e/beta/from-import-beta-ui.spec.js
index 06e669e5b..5582d4697 100644
--- a/test/e2e/beta/from-import-beta-ui.spec.js
+++ b/test/e2e/beta/from-import-beta-ui.spec.js
@@ -232,7 +232,7 @@ describe('Using MetaMask with an existing account', function () {
const [localhost] = await findElements(driver, By.xpath(`//span[contains(text(), 'Localhost')]`))
await localhost.click()
- await delay(largeDelayMs * 2)
+ await delay(largeDelayMs)
})
it('choose Create Account from the account menu', async () => {
diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js
index 98132e68c..3ad5c2d61 100644
--- a/test/e2e/beta/metamask-beta-ui.spec.js
+++ b/test/e2e/beta/metamask-beta-ui.spec.js
@@ -195,7 +195,16 @@ describe('MetaMask', function () {
await delay(regularDelayMs)
})
- async function retypeSeedPhrase (words, wasReloaded) {
+ async function clickWordAndWait (word) {
+ const xpathClass = 'backup-phrase__confirm-seed-option backup-phrase__confirm-seed-option--unselected'
+ const xpath = `//button[@class='${xpathClass}' and contains(text(), '${word}')]`
+ const word0 = await findElement(driver, By.xpath(xpath), 10000)
+
+ await word0.click()
+ await delay(tinyDelayMs)
+ }
+
+ async function retypeSeedPhrase (words, wasReloaded, count = 0) {
try {
if (wasReloaded) {
const byRevealButton = By.css('.backup-phrase__secret-blocker .backup-phrase__reveal-button')
@@ -209,67 +218,26 @@ describe('MetaMask', function () {
await delay(regularDelayMs)
}
- const word0 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[0]}')]`), 10000)
-
- await word0.click()
- await delay(tinyDelayMs)
-
- const word1 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[1]}')]`), 10000)
-
- await word1.click()
- await delay(tinyDelayMs)
-
- const word2 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[2]}')]`), 10000)
-
- await word2.click()
- await delay(tinyDelayMs)
-
- const word3 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[3]}')]`), 10000)
-
- await word3.click()
- await delay(tinyDelayMs)
-
- const word4 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[4]}')]`), 10000)
-
- await word4.click()
- await delay(tinyDelayMs)
-
- const word5 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[5]}')]`), 10000)
-
- await word5.click()
- await delay(tinyDelayMs)
-
- const word6 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[6]}')]`), 10000)
+ await clickWordAndWait(words[0])
+ await clickWordAndWait(words[1])
+ await clickWordAndWait(words[2])
+ await clickWordAndWait(words[3])
+ await clickWordAndWait(words[4])
+ await clickWordAndWait(words[5])
+ await clickWordAndWait(words[6])
+ await clickWordAndWait(words[7])
+ await clickWordAndWait(words[8])
+ await clickWordAndWait(words[9])
+ await clickWordAndWait(words[10])
+ await clickWordAndWait(words[11])
- await word6.click()
- await delay(tinyDelayMs)
-
- const word7 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[7]}')]`), 10000)
-
- await word7.click()
- await delay(tinyDelayMs)
-
- const word8 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[8]}')]`), 10000)
-
- await word8.click()
- await delay(tinyDelayMs)
-
- const word9 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[9]}')]`), 10000)
-
- await word9.click()
- await delay(tinyDelayMs)
-
- const word10 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[10]}')]`), 10000)
-
- await word10.click()
- await delay(tinyDelayMs)
-
- const word11 = await findElement(driver, By.xpath(`//button[contains(text(), '${words[11]}')]`), 10000)
- await word11.click()
- await delay(tinyDelayMs)
} catch (e) {
- await loadExtension(driver, extensionId)
- await retypeSeedPhrase(words, true)
+ if (count > 2) {
+ throw e
+ } else {
+ await loadExtension(driver, extensionId)
+ await retypeSeedPhrase(words, true, count + 1)
+ }
}
}
@@ -516,7 +484,7 @@ describe('MetaMask', function () {
it('displays the contract creation data', async () => {
const dataTab = await findElement(driver, By.xpath(`//li[contains(text(), 'Data')]`))
- dataTab.click()
+ await dataTab.click()
await delay(regularDelayMs)
await findElement(driver, By.xpath(`//div[contains(text(), '127.0.0.1')]`))
@@ -526,7 +494,7 @@ describe('MetaMask', function () {
assert.equal(confirmDataText.match(/0x608060405234801561001057600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff/))
const detailsTab = await findElement(driver, By.xpath(`//li[contains(text(), 'Details')]`))
- detailsTab.click()
+ await detailsTab.click()
await delay(regularDelayMs)
})
@@ -547,9 +515,15 @@ describe('MetaMask', function () {
await driver.switchTo().window(dapp)
await delay(regularDelayMs)
+ let contractStatus = await driver.findElement(By.css('#contractStatus'))
+ await driver.wait(until.elementTextMatches(contractStatus, /Deployed/))
+
const depositButton = await findElement(driver, By.css('#depositButton'))
await depositButton.click()
- await delay(regularDelayMs)
+ await delay(largeDelayMs)
+
+ contractStatus = await driver.findElement(By.css('#contractStatus'))
+ await driver.wait(until.elementTextMatches(contractStatus, /Deposit\sinitiated/))
await driver.switchTo().window(extension)
await delay(largeDelayMs)
diff --git a/test/e2e/beta/run-all.sh b/test/e2e/beta/run-all.sh
index 493e1360a..7da61e504 100755
--- a/test/e2e/beta/run-all.sh
+++ b/test/e2e/beta/run-all.sh
@@ -6,5 +6,5 @@ set -o pipefail
export PATH="$PATH:./node_modules/.bin"
-shell-parallel -s 'npm run ganache:start' -x 'sleep 5 && superstatic test/e2e/beta/contract-test/ --port 8080 --host 127.0.0.1' -x 'sleep 5 && mocha test/e2e/beta/metamask-beta-ui.spec'
-shell-parallel -s 'npm run ganache:start -- -d' -x 'sleep 5 && superstatic test/e2e/beta/contract-test/ --port 8080 --host 127.0.0.1' -x 'sleep 5 && mocha test/e2e/beta/from-import-beta-ui.spec'
+shell-parallel -s 'npm run ganache:start' -x 'sleep 5 && static-server test/e2e/beta/contract-test/ --port 8080' -x 'sleep 5 && mocha test/e2e/beta/metamask-beta-ui.spec'
+shell-parallel -s 'npm run ganache:start -- -d' -x 'sleep 5 && static-server test/e2e/beta/contract-test/ --port 8080' -x 'sleep 5 && mocha test/e2e/beta/from-import-beta-ui.spec'
diff --git a/test/integration/lib/tx-list-items.js b/test/integration/lib/tx-list-items.js
index b7aca44d5..9075efe03 100644
--- a/test/integration/lib/tx-list-items.js
+++ b/test/integration/lib/tx-list-items.js
@@ -14,6 +14,11 @@ QUnit.test('renders list items successfully', (assert) => {
})
})
+global.ethQuery = global.ethQuery || {}
+global.ethQuery.getTransactionCount = (_, cb) => {
+ cb(null, '0x3')
+}
+
async function runTxListItemsTest (assert, done) {
console.log('*** start runTxListItemsTest')
const selectState = await queryAsync($, 'select')
diff --git a/test/unit/app/controllers/detect-tokens-test.js b/test/unit/app/controllers/detect-tokens-test.js
index 426ffe23a..d6c3fad8a 100644
--- a/test/unit/app/controllers/detect-tokens-test.js
+++ b/test/unit/app/controllers/detect-tokens-test.js
@@ -7,10 +7,11 @@ const PreferencesController = require('../../../../app/scripts/controllers/prefe
describe('DetectTokensController', () => {
const sandbox = sinon.createSandbox()
- let clock
- let keyringMemStore
- before(async () => {
+ let clock, keyringMemStore, network, preferences
+ beforeEach(async () => {
keyringMemStore = new ObservableStore({ isUnlocked: false})
+ network = new NetworkController({ provider: { type: 'mainnet' }})
+ preferences = new PreferencesController({ network })
})
after(() => {
sandbox.restore()
@@ -25,9 +26,7 @@ describe('DetectTokensController', () => {
it('should be called on every polling period', async () => {
clock = sandbox.useFakeTimers()
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -45,9 +44,7 @@ describe('DetectTokensController', () => {
})
it('should not check tokens while in test network', async () => {
- const network = new NetworkController()
network.setProviderType('rinkeby')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -61,9 +58,7 @@ describe('DetectTokensController', () => {
})
it('should only check and add tokens while in main network', async () => {
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -80,9 +75,7 @@ describe('DetectTokensController', () => {
})
it('should not detect same token while in main network', async () => {
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8)
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
@@ -100,9 +93,7 @@ describe('DetectTokensController', () => {
})
it('should trigger detect new tokens when change address', async () => {
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -112,9 +103,7 @@ describe('DetectTokensController', () => {
})
it('should trigger detect new tokens when submit password', async () => {
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.selectedAddress = '0x0'
@@ -124,9 +113,7 @@ describe('DetectTokensController', () => {
})
it('should not trigger detect new tokens when not open or not unlocked', async () => {
- const network = new NetworkController()
network.setProviderType('mainnet')
- const preferences = new PreferencesController()
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = false
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index e055500b1..9b2c846bd 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -1,11 +1,14 @@
const assert = require('assert')
+const ObservableStore = require('obs-store')
const PreferencesController = require('../../../../app/scripts/controllers/preferences')
describe('preferences controller', function () {
let preferencesController
+ let network
beforeEach(() => {
- preferencesController = new PreferencesController()
+ network = {providerStore: new ObservableStore({ type: 'mainnet' })}
+ preferencesController = new PreferencesController({ network })
})
describe('setAddresses', function () {
@@ -28,6 +31,20 @@ describe('preferences controller', function () {
})
})
+ it('should create account tokens for each account in the store', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ const accountTokens = preferencesController.store.getState().accountTokens
+
+ assert.deepEqual(accountTokens, {
+ '0xda22le': {},
+ '0x7e57e2': {},
+ })
+ })
+
it('should replace its list of addresses', function () {
preferencesController.setAddresses([
'0xda22le',
@@ -64,6 +81,17 @@ describe('preferences controller', function () {
assert.equal(preferencesController.store.getState().identities['0xda22le'], undefined)
})
+ it('should remove an address from state and respective tokens', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ preferencesController.removeAddress('0xda22le')
+
+ assert.equal(preferencesController.store.getState().accountTokens['0xda22le'], undefined)
+ })
+
it('should switch accounts if the selected address is removed', function () {
preferencesController.setAddresses([
'0xda22le',
@@ -158,6 +186,42 @@ describe('preferences controller', function () {
await preferencesController.addToken(address, symbol, decimals)
assert.equal(preferencesController.getTokens().length, 1, 'one token added for 2nd address')
})
+
+ it('should add token per account', async function () {
+ const addressFirst = '0xabcdef1234567'
+ const addressSecond = '0xabcdef1234568'
+ const symbolFirst = 'ABBR'
+ const symbolSecond = 'ABBB'
+ const decimals = 5
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken(addressFirst, symbolFirst, decimals)
+ const tokensFirstAddress = preferencesController.getTokens()
+
+ await preferencesController.setSelectedAddress('0xda22le')
+ await preferencesController.addToken(addressSecond, symbolSecond, decimals)
+ const tokensSeconAddress = preferencesController.getTokens()
+
+ assert.notEqual(tokensFirstAddress, tokensSeconAddress, 'add different tokens for two account and tokens are equal')
+ })
+
+ it('should add token per network', async function () {
+ const addressFirst = '0xabcdef1234567'
+ const addressSecond = '0xabcdef1234568'
+ const symbolFirst = 'ABBR'
+ const symbolSecond = 'ABBB'
+ const decimals = 5
+
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken(addressFirst, symbolFirst, decimals)
+ const tokensFirstAddress = preferencesController.getTokens()
+
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken(addressSecond, symbolSecond, decimals)
+ const tokensSeconAddress = preferencesController.getTokens()
+
+ assert.notEqual(tokensFirstAddress, tokensSeconAddress, 'add different tokens for two networks and tokens are equal')
+ })
})
describe('removeToken', function () {
@@ -182,6 +246,98 @@ describe('preferences controller', function () {
const [token1] = tokens
assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
})
+
+ it('should remove a token from its state on corresponding address', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.removeToken('0xa')
+
+ const tokensFirst = preferencesController.getTokens()
+ assert.equal(tokensFirst.length, 1, 'one token removed in account')
+
+ const [token1] = tokensFirst
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'token deleted for account')
+ })
+
+ it('should remove a token from its state on corresponding network', async function () {
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.removeToken('0xa')
+
+ const tokensFirst = preferencesController.getTokens()
+ assert.equal(tokensFirst.length, 1, 'one token removed in network')
+
+ const [token1] = tokensFirst
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+
+ network.providerStore.updateState({ type: 'rinkeby' })
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'token deleted for network')
+ })
+ })
+
+ describe('on setSelectedAddress', function () {
+ it('should update tokens from its state on corresponding address', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ await preferencesController.addToken('0xa', 'C', 4)
+ await preferencesController.addToken('0xb', 'D', 5)
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ const initialTokensFirst = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const initialTokensSecond = preferencesController.getTokens()
+
+ assert.notDeepEqual(initialTokensFirst, initialTokensSecond, 'tokens not equal for different accounts and tokens')
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ const tokensFirst = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const tokensSecond = preferencesController.getTokens()
+
+ assert.deepEqual(tokensFirst, initialTokensFirst, 'tokens equal for same account')
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'tokens equal for same account')
+ })
+ })
+
+ describe('on updateStateNetworkType', function () {
+ it('should remove a token from its state on corresponding network', async function () {
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensFirst = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken('0xa', 'C', 4)
+ await preferencesController.addToken('0xb', 'D', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+
+ assert.notDeepEqual(initialTokensFirst, initialTokensSecond, 'tokens not equal for different networks and tokens')
+
+ network.providerStore.updateState({ type: 'mainnet' })
+ const tokensFirst = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'rinkeby' })
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensFirst, initialTokensFirst, 'tokens equal for same network')
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'tokens equal for same network')
+ })
})
})
diff --git a/test/unit/migrations/028-test.js b/test/unit/migrations/028-test.js
new file mode 100644
index 000000000..a9c7dcdf1
--- /dev/null
+++ b/test/unit/migrations/028-test.js
@@ -0,0 +1,46 @@
+const assert = require('assert')
+const migration28 = require('../../../app/scripts/migrations/028')
+
+const oldStorage = {
+ 'meta': {},
+ 'data': {
+ 'PreferencesController': {
+ 'tokens': [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}],
+ 'identities': {
+ '0x6d14': {},
+ '0x3695': {},
+ },
+ },
+ },
+}
+
+describe('migration #28', () => {
+ it('should add corresponding tokens to accountTokens', (done) => {
+ migration28.migrate(oldStorage)
+ .then((newStorage) => {
+ const newTokens = newStorage.data.PreferencesController.tokens
+ const newAccountTokens = newStorage.data.PreferencesController.accountTokens
+
+ const testTokens = [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}]
+ assert.equal(newTokens.length, 0, 'tokens is expected to have the length of 0')
+ assert.equal(newAccountTokens['0x6d14']['mainnet'].length, 2, 'tokens for address is expected to have the length of 2')
+ assert.equal(newAccountTokens['0x3695']['mainnet'].length, 2, 'tokens for address is expected to have the length of 2')
+ assert.equal(Object.keys(newAccountTokens).length, 2, 'account tokens should be created for all identities')
+ assert.deepEqual(newAccountTokens['0x6d14']['mainnet'], testTokens, 'tokens for address should be the same than before')
+ assert.deepEqual(newAccountTokens['0x3695']['mainnet'], testTokens, 'tokens for address should be the same than before')
+ done()
+ })
+ .catch(done)
+ })
+
+ it('should successfully migrate first time state', (done) => {
+ migration28.migrate({
+ meta: {},
+ data: require('../../../app/scripts/first-time-state'),
+ })
+ .then((migratedData) => {
+ assert.equal(migratedData.meta.version, migration28.version)
+ done()
+ }).catch(done)
+ })
+})