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';
|
||||
|
||||
export default class BackupController {
|
||||
export default class Backup {
|
||||
constructor(opts = {}) {
|
||||
const {
|
||||
preferencesController,
|
@ -1,6 +1,6 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import sinon from 'sinon';
|
||||
import BackupController from './backup';
|
||||
import Backup from './backup';
|
||||
|
||||
function getMockPreferencesController() {
|
||||
const mcState = {
|
||||
@ -151,9 +151,9 @@ const jsonData = JSON.stringify({
|
||||
},
|
||||
});
|
||||
|
||||
describe('BackupController', function () {
|
||||
const getBackupController = () => {
|
||||
return new BackupController({
|
||||
describe('Backup', function () {
|
||||
const getBackup = () => {
|
||||
return new Backup({
|
||||
preferencesController: getMockPreferencesController(),
|
||||
addressBookController: getMockAddressBookController(),
|
||||
networkController: getMockNetworkController(),
|
||||
@ -163,85 +163,81 @@ describe('BackupController', function () {
|
||||
|
||||
describe('constructor', function () {
|
||||
it('should setup correctly', async function () {
|
||||
const backupController = getBackupController();
|
||||
const selectedAddress =
|
||||
backupController.preferencesController.getSelectedAddress();
|
||||
const backup = getBackup();
|
||||
const selectedAddress = backup.preferencesController.getSelectedAddress();
|
||||
assert.equal(selectedAddress, '0x01');
|
||||
});
|
||||
|
||||
it('should restore backup', async function () {
|
||||
const backupController = getBackupController();
|
||||
await backupController.restoreUserData(jsonData);
|
||||
const backup = getBackup();
|
||||
await backup.restoreUserData(jsonData);
|
||||
// check networks backup
|
||||
assert.equal(
|
||||
backupController.networkController.state.networkConfigurations[
|
||||
backup.networkController.state.networkConfigurations[
|
||||
'network-configuration-id-1'
|
||||
].chainId,
|
||||
'0x539',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.networkController.state.networkConfigurations[
|
||||
backup.networkController.state.networkConfigurations[
|
||||
'network-configuration-id-2'
|
||||
].chainId,
|
||||
'0x38',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.networkController.state.networkConfigurations[
|
||||
backup.networkController.state.networkConfigurations[
|
||||
'network-configuration-id-3'
|
||||
].chainId,
|
||||
'0x61',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.networkController.state.networkConfigurations[
|
||||
backup.networkController.state.networkConfigurations[
|
||||
'network-configuration-id-4'
|
||||
].chainId,
|
||||
'0x89',
|
||||
);
|
||||
// make sure identities are not lost after restore
|
||||
assert.equal(
|
||||
backupController.preferencesController.store.identities[
|
||||
backup.preferencesController.store.identities[
|
||||
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
||||
].lastSelected,
|
||||
1655380342907,
|
||||
);
|
||||
assert.equal(
|
||||
backupController.preferencesController.store.identities[
|
||||
backup.preferencesController.store.identities[
|
||||
'0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B'
|
||||
].name,
|
||||
'Account 3',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.preferencesController.store.lostIdentities[
|
||||
backup.preferencesController.store.lostIdentities[
|
||||
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
||||
].lastSelected,
|
||||
1655379648197,
|
||||
);
|
||||
assert.equal(
|
||||
backupController.preferencesController.store.lostIdentities[
|
||||
backup.preferencesController.store.lostIdentities[
|
||||
'0xfd59bbe569376e3d3e4430297c3c69ea93f77435'
|
||||
].name,
|
||||
'Ledger 1',
|
||||
);
|
||||
// make sure selected address is not lost after restore
|
||||
assert.equal(
|
||||
backupController.preferencesController.store.selectedAddress,
|
||||
'0x01',
|
||||
);
|
||||
assert.equal(backup.preferencesController.store.selectedAddress, '0x01');
|
||||
// check address book backup
|
||||
assert.equal(
|
||||
backupController.addressBookController.store.addressBook['0x61'][
|
||||
backup.addressBookController.store.addressBook['0x61'][
|
||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||
].chainId,
|
||||
'0x61',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.addressBookController.store.addressBook['0x61'][
|
||||
backup.addressBookController.store.addressBook['0x61'][
|
||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||
].address,
|
||||
'0x42EB768f2244C8811C63729A21A3569731535f06',
|
||||
);
|
||||
assert.equal(
|
||||
backupController.addressBookController.store.addressBook['0x61'][
|
||||
backup.addressBookController.store.addressBook['0x61'][
|
||||
'0x42EB768f2244C8811C63729A21A3569731535f06'
|
||||
].isEns,
|
||||
false,
|
@ -184,7 +184,7 @@ import AppStateController from './controllers/app-state';
|
||||
import CachedBalancesController from './controllers/cached-balances';
|
||||
import AlertController from './controllers/alert';
|
||||
import OnboardingController from './controllers/onboarding';
|
||||
import BackupController from './controllers/backup';
|
||||
import Backup from './lib/backup';
|
||||
import IncomingTransactionsController from './controllers/incoming-transactions';
|
||||
import DecryptMessageController from './controllers/decrypt-message';
|
||||
import TransactionController from './controllers/transactions';
|
||||
@ -1157,7 +1157,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
});
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
|
||||
this.backupController = new BackupController({
|
||||
this.backup = new Backup({
|
||||
preferencesController: this.preferencesController,
|
||||
addressBookController: this.addressBookController,
|
||||
networkController: this.networkController,
|
||||
@ -1653,7 +1653,6 @@ export default class MetamaskController extends EventEmitter {
|
||||
PermissionController: this.permissionController,
|
||||
PermissionLogController: this.permissionLogController.store,
|
||||
SubjectMetadataController: this.subjectMetadataController,
|
||||
BackupController: this.backupController,
|
||||
AnnouncementController: this.announcementController,
|
||||
GasFeeController: this.gasFeeController,
|
||||
TokenListController: this.tokenListController,
|
||||
@ -1701,7 +1700,6 @@ export default class MetamaskController extends EventEmitter {
|
||||
PermissionController: this.permissionController,
|
||||
PermissionLogController: this.permissionLogController.store,
|
||||
SubjectMetadataController: this.subjectMetadataController,
|
||||
BackupController: this.backupController,
|
||||
AnnouncementController: this.announcementController,
|
||||
GasFeeController: this.gasFeeController,
|
||||
TokenListController: this.tokenListController,
|
||||
@ -2213,7 +2211,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
smartTransactionsController,
|
||||
txController,
|
||||
assetsContractController,
|
||||
backupController,
|
||||
backup,
|
||||
approvalController,
|
||||
} = this;
|
||||
|
||||
@ -2759,9 +2757,9 @@ export default class MetamaskController extends EventEmitter {
|
||||
removePollingTokenFromAppState:
|
||||
appStateController.removePollingToken.bind(appStateController),
|
||||
|
||||
// BackupController
|
||||
backupUserData: backupController.backupUserData.bind(backupController),
|
||||
restoreUserData: backupController.restoreUserData.bind(backupController),
|
||||
// Backup
|
||||
backupUserData: backup.backupUserData.bind(backup),
|
||||
restoreUserData: backup.restoreUserData.bind(backup),
|
||||
|
||||
// DetectTokenController
|
||||
detectNewTokens: detectTokensController.detectNewTokens.bind(
|
||||
|
Loading…
Reference in New Issue
Block a user