1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fixes #12073: Extra account with zero balance always added when importing wallet with seed and when first account's balance is non-zero (#12074)

* add command to debug unit tests

* remove extra zero balance account potentially created from seeking ahead

* Add PR 12074 to CHANGELOG

* Revert "Add PR 12074 to CHANGELOG"

This reverts commit 9f6f7eec1cac163c0ce1c711b1c205322aa5b2af.

* Remove test debug command
This commit is contained in:
Muin Momin 2021-09-16 16:20:57 -05:00 committed by GitHub
parent a7561aaef3
commit ae84b0cb6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -1303,6 +1303,12 @@ export default class MetamaskController extends EventEmitter {
); );
} }
// remove extra zero balance account potentially created from seeking ahead
if (accounts.length > 1 && lastBalance === '0x0') {
await this.removeAccount(accounts[accounts.length - 1]);
accounts = await keyringController.getAccounts();
}
// set new identities // set new identities
this.preferencesController.setAddresses(accounts); this.preferencesController.setAddresses(accounts);
this.selectFirstIdentity(); this.selectFirstIdentity();

View File

@ -91,7 +91,6 @@ const MetaMaskController = proxyquire('./metamask-controller', {
const currentNetworkId = '42'; const currentNetworkId = '42';
const DEFAULT_LABEL = 'Account 1'; const DEFAULT_LABEL = 'Account 1';
const DEFAULT_LABEL_2 = 'Account 2';
const TEST_SEED = const TEST_SEED =
'debris dizzy just program just float decrease vacant alarm reduce speak stadium'; 'debris dizzy just program just float decrease vacant alarm reduce speak stadium';
const TEST_ADDRESS = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'; const TEST_ADDRESS = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
@ -360,7 +359,7 @@ describe('MetaMaskController', function () {
}); });
}); });
it('should restore any consecutive accounts with balances', async function () { it('should restore any consecutive accounts with balances without extra zero balance accounts', async function () {
sandbox.stub(metamaskController, 'getBalance'); sandbox.stub(metamaskController, 'getBalance');
metamaskController.getBalance.withArgs(TEST_ADDRESS).callsFake(() => { metamaskController.getBalance.withArgs(TEST_ADDRESS).callsFake(() => {
return Promise.resolve('0x14ced5122ce0a000'); return Promise.resolve('0x14ced5122ce0a000');
@ -386,7 +385,6 @@ describe('MetaMaskController', function () {
delete identities[TEST_ADDRESS].lastSelected; delete identities[TEST_ADDRESS].lastSelected;
assert.deepEqual(identities, { assert.deepEqual(identities, {
[TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL }, [TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL },
[TEST_ADDRESS_2]: { address: TEST_ADDRESS_2, name: DEFAULT_LABEL_2 },
}); });
}); });
}); });