1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/app/scripts/migrations/migrations.test.js

155 lines
5.5 KiB
JavaScript
Raw Normal View History

/* eslint-disable jest/valid-expect-in-promise */
import wallet1 from '../../../test/lib/migrations/001.json';
import vault4 from '../../../test/lib/migrations/004.json';
import migration2 from './002';
import migration3 from './003';
import migration4 from './004';
import migration5 from './005';
import migration6 from './006';
import migration7 from './007';
import migration8 from './008';
import migration9 from './009';
import migration10 from './010';
import migration11 from './011';
import migration12 from './012';
import migration13 from './013';
2016-04-12 23:16:39 +02:00
let vault5, vault6, vault7, vault8, vault9; // vault10, vault11
const oldTestRpc = 'https://rawtestrpc.metamask.io/';
const newTestRpc = 'https://testrpc.metamask.io/';
2016-04-12 23:16:39 +02:00
describe('wallet1 is migrated successfully', () => {
it('should convert providers', () => {
wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null };
migration2
2020-11-03 00:41:28 +01:00
.migrate(wallet1)
.then((secondResult) => {
const secondData = secondResult.data;
expect(secondData.config.provider.type).toStrictEqual('rpc');
expect(secondData.config.provider.rpcTarget).toStrictEqual(
2020-11-03 00:41:28 +01:00
'https://rpc.metamask.io/',
);
secondResult.data.config.provider.rpcTarget = oldTestRpc;
return migration3.migrate(secondResult);
2020-11-03 00:41:28 +01:00
})
.then((thirdResult) => {
expect(thirdResult.data.config.provider.rpcTarget).toStrictEqual(
2020-11-03 00:41:28 +01:00
newTestRpc,
);
return migration4.migrate(thirdResult);
2020-11-03 00:41:28 +01:00
})
.then((fourthResult) => {
const fourthData = fourthResult.data;
expect(fourthData.config.provider.rpcTarget).toBeUndefined();
expect(fourthData.config.provider.type).toStrictEqual('testnet');
return migration5.migrate(vault4);
2020-11-03 00:41:28 +01:00
})
.then((fifthResult) => {
const fifthData = fifthResult.data;
expect(fifthData.vault).toBeUndefined();
expect(fifthData.walletNicknames).toBeUndefined();
expect(fifthData.config.selectedAccount).toBeUndefined();
expect(fifthData.KeyringController.vault).toStrictEqual(
2020-11-03 00:41:28 +01:00
vault4.data.vault,
);
expect(fifthData.KeyringController.selectedAccount).toStrictEqual(
2020-11-03 00:41:28 +01:00
vault4.data.config.selectedAccount,
);
expect(
2020-11-03 00:41:28 +01:00
fifthData.KeyringController.walletNicknames[
'0x0beb674745816b125fbc07285d39fd373e64895c'
],
).toStrictEqual(
2020-11-03 00:41:28 +01:00
vault4.data.walletNicknames[
'0x0beb674745816b125fbc07285d39fd373e64895c'
],
);
vault5 = fifthResult;
return migration6.migrate(fifthResult);
2020-11-03 00:41:28 +01:00
})
.then((sixthResult) => {
expect(
2020-11-03 00:41:28 +01:00
sixthResult.data.KeyringController.selectedAccount,
).toBeUndefined();
expect(
2020-11-03 00:41:28 +01:00
sixthResult.data.PreferencesController.selectedAddress,
).toStrictEqual(vault5.data.KeyringController.selectedAccount);
vault6 = sixthResult;
return migration7.migrate(sixthResult);
2020-11-03 00:41:28 +01:00
})
.then((seventhResult) => {
expect(seventhResult.data.transactions).toBeUndefined();
expect(seventhResult.data.gasMultiplier).toBeUndefined();
expect(
2020-11-03 00:41:28 +01:00
seventhResult.data.TransactionManager.transactions[0].id,
).toStrictEqual(vault6.data.transactions[0].id);
expect(
2020-11-03 00:41:28 +01:00
seventhResult.data.TransactionManager.gasMultiplier,
).toStrictEqual(vault6.data.gasMultiplier);
vault7 = seventhResult;
return migration8.migrate(seventhResult);
2020-11-03 00:41:28 +01:00
})
.then((eighthResult) => {
expect(eighthResult.data.noticesList).toBeUndefined();
expect(
2020-11-03 00:41:28 +01:00
eighthResult.data.NoticeController.noticesList[0].title,
).toStrictEqual(vault7.data.noticesList[0].title);
vault8 = eighthResult;
return migration9.migrate(eighthResult);
2020-11-03 00:41:28 +01:00
})
.then((ninthResult) => {
expect(ninthResult.data.currentFiat).toBeUndefined();
expect(ninthResult.data.fiatCurrency).toBeUndefined();
expect(ninthResult.data.conversionRate).toBeUndefined();
expect(ninthResult.data.conversionDate).toBeUndefined();
expect(
2020-11-03 00:41:28 +01:00
ninthResult.data.CurrencyController.currentCurrency,
).toStrictEqual(vault8.data.fiatCurrency);
expect(
2020-11-03 00:41:28 +01:00
ninthResult.data.CurrencyController.conversionRate,
).toStrictEqual(vault8.data.conversionRate);
expect(
2020-11-03 00:41:28 +01:00
ninthResult.data.CurrencyController.conversionDate,
).toStrictEqual(vault8.data.conversionDate);
vault9 = ninthResult;
return migration10.migrate(ninthResult);
2020-11-03 00:41:28 +01:00
})
.then((tenthResult) => {
expect(tenthResult.data.shapeShiftTxList).toBeUndefined();
expect(
2020-11-03 00:41:28 +01:00
tenthResult.data.ShapeShiftController.shapeShiftTxList[0].transaction,
).toStrictEqual(vault9.data.shapeShiftTxList[0].transaction);
return migration11.migrate(tenthResult);
2020-11-03 00:41:28 +01:00
})
.then((eleventhResult) => {
expect(eleventhResult.data.isDisclaimerConfirmed).toBeUndefined();
expect(eleventhResult.data.TOSHash).toBeUndefined();
return migration12.migrate(eleventhResult);
2020-11-03 00:41:28 +01:00
})
.then((twelfthResult) => {
expect(
2020-11-03 00:41:28 +01:00
twelfthResult.data.NoticeController.noticesList[0].body,
).toStrictEqual('');
expect(
2020-11-03 00:41:28 +01:00
twelfthResult.data.NoticeController.noticesList[1].body,
).toStrictEqual('nonempty');
expect(twelfthResult.data.config.provider.type).toStrictEqual(
2020-11-03 00:41:28 +01:00
'testnet',
);
return migration13.migrate(twelfthResult);
});
});
});