2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
2021-03-16 22:00:08 +01:00
|
|
|
import firstTimeState from '../first-time-state';
|
|
|
|
import migration28 from './028';
|
2018-08-09 22:41:16 +02:00
|
|
|
|
|
|
|
const oldStorage = {
|
2020-11-03 00:41:28 +01:00
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
PreferencesController: {
|
|
|
|
tokens: [
|
|
|
|
{ address: '0xa', symbol: 'A', decimals: 4 },
|
|
|
|
{ address: '0xb', symbol: 'B', decimals: 4 },
|
|
|
|
],
|
|
|
|
identities: {
|
2018-08-09 22:41:16 +02:00
|
|
|
'0x6d14': {},
|
|
|
|
'0x3695': {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-09 22:41:16 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('migration #28', function () {
|
|
|
|
it('should add corresponding tokens to accountTokens', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration28
|
|
|
|
.migrate(oldStorage)
|
2018-08-09 22:41:16 +02:00
|
|
|
.then((newStorage) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const newTokens = newStorage.data.PreferencesController.tokens;
|
2020-11-03 00:41:28 +01:00
|
|
|
const newAccountTokens =
|
2021-02-04 19:15:23 +01:00
|
|
|
newStorage.data.PreferencesController.accountTokens;
|
2018-08-09 22:41:16 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const testTokens = [
|
|
|
|
{ address: '0xa', symbol: 'A', decimals: 4 },
|
|
|
|
{ address: '0xb', symbol: 'B', decimals: 4 },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
newTokens.length,
|
|
|
|
0,
|
|
|
|
'tokens is expected to have the length of 0',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
newAccountTokens['0x6d14'].mainnet.length,
|
|
|
|
2,
|
|
|
|
'tokens for address is expected to have the length of 2',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
newAccountTokens['0x3695'].mainnet.length,
|
|
|
|
2,
|
|
|
|
'tokens for address is expected to have the length of 2',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
Object.keys(newAccountTokens).length,
|
|
|
|
2,
|
|
|
|
'account tokens should be created for all identities',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
newAccountTokens['0x6d14'].mainnet,
|
|
|
|
testTokens,
|
|
|
|
'tokens for address should be the same than before',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
newAccountTokens['0x3695'].mainnet,
|
|
|
|
testTokens,
|
|
|
|
'tokens for address should be the same than before',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
done();
|
2018-08-09 22:41:16 +02:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
2018-08-09 22:41:16 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should successfully migrate first time state', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration28
|
|
|
|
.migrate({
|
|
|
|
meta: {},
|
|
|
|
data: firstTimeState,
|
|
|
|
})
|
2018-08-09 22:41:16 +02:00
|
|
|
.then((migratedData) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(migratedData.meta.version, migration28.version);
|
|
|
|
done();
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
|
|
|
});
|