Skip to content

Commit

Permalink
remove unwanted event when upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Mar 8, 2021
1 parent 11911ac commit f4d225d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions contracts/proxy/ERC1967/ERC1967Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ abstract contract ERC1967ImplementationUtils {
*/
function _upgradeToAndCallSecure(address newImplementation, bytes memory data) internal virtual {
address oldImplementation = _getImplementation();
// do inital upgrade
_upgradeToAndCall(newImplementation, data);
// check if nested in an upgrade check
StorageSlot.BooleanSlot storage upgradePending = StorageSlot.getBooleanSlot(_UPGRADE_PENDING_SLOT);
// do inital upgrade
_setImplementation(newImplementation);
// do setup call
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
}
if (!upgradePending.value) {
// trigger upgrade check with flag set to true
upgradePending.value = true;
Expand All @@ -75,11 +79,11 @@ abstract contract ERC1967ImplementationUtils {
upgradePending.value = false;
// check upgrade was effective
require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
// reset
// reset upgrade
_setImplementation(newImplementation);
// emit event
emit Upgraded(newImplementation);
}
// emit event
emit Upgraded(newImplementation);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/proxy/ERC1967/ERC1967Upgrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ contract('ERC1967Upgrade', function (accounts) {

it('upgrade to basic implementation', async function () {
const { receipt } = await this.instance.upgradeToAndCall(this.testimpl1.address, '0x');
// console.log(receipt.logs.filter(({ event }) => event === 'Upgraded').length);
expectEvent(receipt, 'Upgraded', { implementation: this.testimpl1.address });
});

it('upgrade to secure implementation', async function () {
const { receipt } = await this.instance.upgradeToAndCall(this.testimpl2.address, '0x');
// console.log(receipt.logs.filter(({ event }) => event === 'Upgraded').length);
expect(receipt.logs.filter(({ event }) => event === 'Upgraded').length).to.be.equal(1);
expectEvent(receipt, 'Upgraded', { implementation: this.testimpl2.address });
});

Expand Down

0 comments on commit f4d225d

Please sign in to comment.