mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Rename BackupController to Backup (#20465)
The backup module has been renamed so that it isn't confused with a controller. The "backup controller" has never managed any state or extended the controller base class. It is a module for backing up data, but it's not a controller. The backup controller's current inclusion in the `store` and `memstore` `ComposableObservableStore`s was getting in the way of some other enhancements to that class (which will come in a later PR).
This commit is contained in:
parent
b874a301f5
commit
3ab5c1bf88
@ -1,6 +1,6 @@
|
|||||||
import { prependZero } from '../../../shared/modules/string-utils';
|
import { prependZero } from '../../../shared/modules/string-utils';
|
||||||
|
|
||||||
export default class BackupController {
|
export default class Backup {
|
||||||
constructor(opts = {}) {
|
constructor(opts = {}) {
|
||||||
const {
|
const {
|
||||||
preferencesController,
|
preferencesController,
|
@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import BackupController from './backup';
|
import Backup from './backup';
|
||||||
|
|
||||||
function getMockPreferencesController() {
|
function getMockPreferencesController() {
|
||||||
const mcState = {
|
const mcState = {
|
||||||
@ -151,9 +151,9 @@ const jsonData = JSON.stringify({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BackupController', function () {
|
describe('Backup', function () {
|
||||||
const getBackupController = () => {
|
const getBackup = () => {
|
||||||
return new BackupController({
|
return new Backup({
|
||||||
preferencesController: getMockPreferencesController(),
|
preferencesController: getMockPreferencesController(),
|
||||||
addressBookController: getMockAddressBookController(),
|
addressBookController: getMockAddressBookController(),
|
||||||
networkController: getMockNetworkController(),
|
networkController: getMockNetworkController(),
|
||||||
@ -163,85 +163,81 @@ describe('BackupController', function () {
|
|||||||
|
|
||||||
describe('constructor', function () {
|
describe('constructor', function () {
|
||||||
it('should setup correctly', async function () {
|
it('should setup correctly', async function () {
|
||||||
const backupController = getBackupController();
|
const backup = getBackup();
|
||||||
const selectedAddress =
|
const selectedAddress = backup.preferencesController.getSelectedAddress();
|
||||||
backupController.preferencesController.getSelectedAddress();
|
|
||||||
assert.equal(selectedAddress, '0x01');
|
assert.equal(selectedAddress, '0x01');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should restore backup', async function () {
|
it('should restore backup', async function () {
|
||||||
const backupController = getBackupController();
|
const backup = getBackup();
|
||||||
await backupController.restoreUserData(jsonData);
|
await backup.restoreUserData(jsonData);
|
||||||
// check networks backup
|
// check networks backup
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.networkController.state.networkConfigurations[
|
backup.networkController.state.networkConfigurations[
|
||||||
'network-configuration-id-1'
|
'network-configuration-id-1'
|
||||||
].chainId,
|
].chainId,
|
||||||
'0x539',
|
'0x539',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.networkController.state.networkConfigurations[
|
backup.networkController.state.networkConfigurations[
|
||||||
'network-configuration-id-2'
|
'network-configuration-id-2'
|
||||||
].chainId,
|
].chainId,
|
||||||
'0x38',
|
'0x38',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.networkController.state.networkConfigurations[
|
backup.networkController.state.networkConfigurations[
|
||||||
'network-configuration-id-3'
|
'network-configuration-id-3'
|
||||||
].chainId,
|
].chainId,
|
||||||
'0x61',
|
'0x61',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.networkController.state.networkConfigurations[
|
backup.networkController.state.networkConfigurations[
|
||||||
'network-configuration-id-4'
|
'network-configuration-id-4'
|
||||||
].chainId,
|
].chainId,
|
||||||
'0x89',
|
'0x89',
|
||||||
);
|
);
|
||||||
// make sure identities are not lost after restore
|
// make sure identities are not lost after restore
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.preferencesController.store.identities[
|
backup.preferencesController.store.identities[
|
||||||
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
||||||
].lastSelected,
|
].lastSelected,
|
||||||
1655380342907,
|
1655380342907,
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.preferencesController.store.identities[
|
backup.preferencesController.store.identities[
|
||||||
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
||||||
].name,
|
].name,
|
||||||
'Account 3',
|
'Account 3',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.preferencesController.store.lostIdentities[
|
backup.preferencesController.store.lostIdentities[
|
||||||
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
||||||
].lastSelected,
|
].lastSelected,
|
||||||
1655379648197,
|
1655379648197,
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.preferencesController.store.lostIdentities[
|
backup.preferencesController.store.lostIdentities[
|
||||||
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
||||||
].name,
|
].name,
|
||||||
'Ledger 1',
|
'Ledger 1',
|
||||||
);
|
);
|
||||||
// make sure selected address is not lost after restore
|
// make sure selected address is not lost after restore
|
||||||
assert.equal(
|
assert.equal(backup.preferencesController.store.selectedAddress, '0x01');
|
||||||
backupController.preferencesController.store.selectedAddress,
|
|
||||||
'0x01',
|
|
||||||
);
|
|
||||||
// check address book backup
|
// check address book backup
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.addressBookController.store.addressBook['0x61'][
|
backup.addressBookController.store.addressBook['0x61'][
|
||||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||||
].chainId,
|
].chainId,
|
||||||
'0x61',
|
'0x61',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.addressBookController.store.addressBook['0x61'][
|
backup.addressBookController.store.addressBook['0x61'][
|
||||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||||
].address,
|
].address,
|
||||||
'0x42EB768f2244C8811C63729A21A3569731535f06',
|
'0x42EB768f2244C8811C63729A21A3569731535f06',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
backupController.addressBookController.store.addressBook['0x61'][
|
backup.addressBookController.store.addressBook['0x61'][
|
||||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||||
].isEns,
|
].isEns,
|
||||||
false,
|
false,
|
@ -184,7 +184,7 @@ import AppStateController from './controllers/app-state';
|
|||||||
import CachedBalancesController from './controllers/cached-balances';
|
import CachedBalancesController from './controllers/cached-balances';
|
||||||
import AlertController from './controllers/alert';
|
import AlertController from './controllers/alert';
|
||||||
import OnboardingController from './controllers/onboarding';
|
import OnboardingController from './controllers/onboarding';
|
||||||
import BackupController from './controllers/backup';
|
import Backup from './lib/backup';
|
||||||
import IncomingTransactionsController from './controllers/incoming-transactions';
|
import IncomingTransactionsController from './controllers/incoming-transactions';
|
||||||
import DecryptMessageController from './controllers/decrypt-message';
|
import DecryptMessageController from './controllers/decrypt-message';
|
||||||
import TransactionController from './controllers/transactions';
|
import TransactionController from './controllers/transactions';
|
||||||
@ -1157,7 +1157,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
});
|
});
|
||||||
///: END:ONLY_INCLUDE_IN
|
///: END:ONLY_INCLUDE_IN
|
||||||
|
|
||||||
this.backupController = new BackupController({
|
this.backup = new Backup({
|
||||||
preferencesController: this.preferencesController,
|
preferencesController: this.preferencesController,
|
||||||
addressBookController: this.addressBookController,
|
addressBookController: this.addressBookController,
|
||||||
networkController: this.networkController,
|
networkController: this.networkController,
|
||||||
@ -1653,7 +1653,6 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
PermissionController: this.permissionController,
|
PermissionController: this.permissionController,
|
||||||
PermissionLogController: this.permissionLogController.store,
|
PermissionLogController: this.permissionLogController.store,
|
||||||
SubjectMetadataController: this.subjectMetadataController,
|
SubjectMetadataController: this.subjectMetadataController,
|
||||||
BackupController: this.backupController,
|
|
||||||
AnnouncementController: this.announcementController,
|
AnnouncementController: this.announcementController,
|
||||||
GasFeeController: this.gasFeeController,
|
GasFeeController: this.gasFeeController,
|
||||||
TokenListController: this.tokenListController,
|
TokenListController: this.tokenListController,
|
||||||
@ -1701,7 +1700,6 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
PermissionController: this.permissionController,
|
PermissionController: this.permissionController,
|
||||||
PermissionLogController: this.permissionLogController.store,
|
PermissionLogController: this.permissionLogController.store,
|
||||||
SubjectMetadataController: this.subjectMetadataController,
|
SubjectMetadataController: this.subjectMetadataController,
|
||||||
BackupController: this.backupController,
|
|
||||||
AnnouncementController: this.announcementController,
|
AnnouncementController: this.announcementController,
|
||||||
GasFeeController: this.gasFeeController,
|
GasFeeController: this.gasFeeController,
|
||||||
TokenListController: this.tokenListController,
|
TokenListController: this.tokenListController,
|
||||||
@ -2213,7 +2211,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
smartTransactionsController,
|
smartTransactionsController,
|
||||||
txController,
|
txController,
|
||||||
assetsContractController,
|
assetsContractController,
|
||||||
backupController,
|
backup,
|
||||||
approvalController,
|
approvalController,
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
@ -2759,9 +2757,9 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
removePollingTokenFromAppState:
|
removePollingTokenFromAppState:
|
||||||
appStateController.removePollingToken.bind(appStateController),
|
appStateController.removePollingToken.bind(appStateController),
|
||||||
|
|
||||||
// BackupController
|
// Backup
|
||||||
backupUserData: backupController.backupUserData.bind(backupController),
|
backupUserData: backup.backupUserData.bind(backup),
|
||||||
restoreUserData: backupController.restoreUserData.bind(backupController),
|
restoreUserData: backup.restoreUserData.bind(backup),
|
||||||
|
|
||||||
// DetectTokenController
|
// DetectTokenController
|
||||||
detectNewTokens: detectTokensController.detectNewTokens.bind(
|
detectNewTokens: detectTokensController.detectNewTokens.bind(
|
||||||
|
Loading…
Reference in New Issue
Block a user