mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
86b165ea83
Maker has upgraded its Dai token to "Multi-Collateral Dai" (MCD) and requires all users interacting with Dai migrate their tokens to the new version. Dai now exclusively refers to Multi-Collateral Dai and what was previouly called Dai is now Sai (Single Collateral Dai). In this description, Sai refers to what was (prior to the 2019-11-18) known as Dai. Dai is the _new_ token. This changeset: 1. Only affects users who had non-zero Sai at the old contract address 2. Displays a persistent notification for users with Sai 3. Updates the token symbol for users already tracking the Sai token 4. Bumps our direct and indirect eth-contract-metadata dependencies The notification copy: > A message from Maker: The new Multi-Collateral Dai token has been released. Your old tokens are now called Sai. Please upgrade your Sai tokens to the new Dai. The copy is from the Maker team.
420 lines
11 KiB
JavaScript
420 lines
11 KiB
JavaScript
const assert = require('assert')
|
|
const migration39 = require('../../../app/scripts/migrations/039')
|
|
|
|
describe('migration #39', () => {
|
|
it('should update the version metadata', (done) => {
|
|
const oldStorage = {
|
|
'meta': {
|
|
'version': 38,
|
|
},
|
|
'data': {},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.meta, {
|
|
'version': 39,
|
|
})
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should update old DAI token symbol to SAI in tokens', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': [{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
}, {
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'symbol': 'BAT',
|
|
'decimals': 18,
|
|
}, {
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'symbol': 'META',
|
|
'decimals': 18,
|
|
}],
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data.PreferencesController, {
|
|
'tokens': [{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'SAI',
|
|
}, {
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'symbol': 'BAT',
|
|
'decimals': 18,
|
|
}, {
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'symbol': 'META',
|
|
'decimals': 18,
|
|
}],
|
|
})
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should update old DAI token symbol to SAI in accountTokens', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'accountTokens': {
|
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
},
|
|
],
|
|
},
|
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
|
'mainnet': [],
|
|
'rinkeby': [],
|
|
},
|
|
'0x8e5d75d60224ea0c33d1041e75de68b1c3cb6dd5': {},
|
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
},
|
|
{
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'decimals': 18,
|
|
'symbol': 'BAT',
|
|
},
|
|
{
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'decimals': 18,
|
|
'symbol': 'META',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data.PreferencesController, {
|
|
'accountTokens': {
|
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'SAI',
|
|
},
|
|
],
|
|
},
|
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
|
'mainnet': [],
|
|
'rinkeby': [],
|
|
},
|
|
'0x8e5d75d60224ea0c33d1041e75de68b1c3cb6dd5': {},
|
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'SAI',
|
|
},
|
|
{
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'decimals': 18,
|
|
'symbol': 'BAT',
|
|
},
|
|
{
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'decimals': 18,
|
|
'symbol': 'META',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
})
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if accountTokens is not an object', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'accountTokens': [],
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if accountTokens is an object with invalid values', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'accountTokens': {
|
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': [
|
|
{
|
|
'address': '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
},
|
|
],
|
|
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359': null,
|
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
|
'mainnet': [
|
|
null,
|
|
undefined,
|
|
[],
|
|
42,
|
|
],
|
|
'rinkeby': null,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if accountTokens includes the new DAI token', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'accountTokens': {
|
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
},
|
|
],
|
|
},
|
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
|
'mainnet': [],
|
|
'rinkeby': [],
|
|
},
|
|
'0x8e5d75d60224ea0c33d1041e75de68b1c3cb6dd5': {},
|
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
|
|
'mainnet': [
|
|
{
|
|
'address': '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
'decimals': 18,
|
|
'symbol': 'DAI',
|
|
},
|
|
{
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'decimals': 18,
|
|
'symbol': 'BAT',
|
|
},
|
|
{
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'decimals': 18,
|
|
'symbol': 'META',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if tokens includes the new DAI token', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': [{
|
|
'address': '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
'symbol': 'DAI',
|
|
'decimals': 18,
|
|
}, {
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'symbol': 'META',
|
|
'decimals': 18,
|
|
}],
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if tokens does not include DAI', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': [{
|
|
'address': '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
|
|
'symbol': 'BAT',
|
|
'decimals': 18,
|
|
}, {
|
|
'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
'symbol': 'META',
|
|
'decimals': 18,
|
|
}],
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if a tokens property has invalid entries', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': [
|
|
null,
|
|
[],
|
|
undefined,
|
|
42,
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if a tokens property is not an array', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': {},
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if a tokens property is null', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
'tokens': null,
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if a tokens property is missing', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if a accountTokens property is missing', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {
|
|
'PreferencesController': {
|
|
},
|
|
},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
|
|
it('should NOT change any state if PreferencesController is missing', (done) => {
|
|
const oldStorage = {
|
|
'meta': {},
|
|
'data': {},
|
|
}
|
|
|
|
migration39.migrate(oldStorage)
|
|
.then((newStorage) => {
|
|
assert.deepEqual(newStorage.data, oldStorage.data)
|
|
done()
|
|
})
|
|
.catch(done)
|
|
})
|
|
})
|