From f9ee28a6eb9a15ffa507d1a5f73c9d17893e09be Mon Sep 17 00:00:00 2001 From: Andrei Stefan Date: Wed, 18 May 2022 10:41:59 +0300 Subject: [PATCH] fix remove wallet using an index when an account address and address lowercase are equal #5049 --- CHANGELOG.md | 1 + packages/web3-eth-accounts/src/index.js | 6 ++++-- test/eth.accounts.wallet.js | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 282489a17f4..22697a82d29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -548,6 +548,7 @@ Released with 1.0.0-beta.37 code base. - Fix static tuple encoding (#4673) (#4884) - Fix bug in handleRevert logic for eth_sendRawTransaction (#4902) - Fix resolve type of getBlock function (#4911) +- Fix remove wallet using an index when an account address and address lowercase are equal (#5049) ### Changed - Replace deprecated String.prototype.substr() (#4855) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 1f2ec649b62..3efa7ed4c5e 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -678,8 +678,10 @@ Wallet.prototype.remove = function(addressOrIndex) { this[account.address].privateKey = null; delete this[account.address]; // address lowercase - this[account.address.toLowerCase()].privateKey = null; - delete this[account.address.toLowerCase()]; + if (this[account.address.toLowerCase()]) { + this[account.address.toLowerCase()].privateKey = null; + delete this[account.address.toLowerCase()]; + } // index this[account.index].privateKey = null; delete this[account.index]; diff --git a/test/eth.accounts.wallet.js b/test/eth.accounts.wallet.js index d27da2b417d..fa6f5342039 100644 --- a/test/eth.accounts.wallet.js +++ b/test/eth.accounts.wallet.js @@ -17,6 +17,12 @@ var tests = [ data: 'Some data!%$$%&@*', // signature done with personal_sign signature: '0x05252412b097c5d080c994d1ea12abcee6f1cae23feb225517a0b691a66e12866b3f54292f9cfef98f390670b4d010fc4af7fcd46e41d72870602c117b14921c1c' + }, { + address: '0x92b7254537e2890f728187988b829b28a01333ce', + privateKey: '0xaa237230fc60e46175256cbc931852514364089a9f4e5b59b5217483b2df4df7', + data: 'Some data!%$$%&@*', + // signature done with personal_sign + signature: '0xb9772194346dbf4fabf34e47f6305edf25c3de0b26b2b85f4778b49c1990115149ba4bf730ae3f9cd303769bb5bdcdf564e3a467ae061031dc368aab798fec091b' } ];