You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using Upgrades.upgradeProxy() to upgrade proxy contracts pointing to new implementations. A vanilla test case works. But I tried to test revoke ownership and then upgrade which should fail, but it fails with an error that I assume is not correct.
I expect OwnableUnauthorizedAccount and I get this error (instead of passing, I assume)
[FAIL. Reason: revert: Failed to deploy contract MyTokenV2.sol:MyTokenV2 using constructor data ""] testRevokingOwnership() (gas: 8237465)
if I don’t expect OwnableUnauthorizedAccount I get this error
which is what I expect, if I don't expect the OwnableUnauthorizedAccount error
So why do I get revert: Failed to deploy contract MyTokenV2.sol:MyTokenV2 using constructor data ""] - this doesn't compute with my current understanding
Here are necessary parts of the contracts and tests 👇
function setUp() public {
// Deploy the token implementation
MyToken implementation =newMyToken();
// Define the owner address
owner = vm.addr(1);
vm.startPrank(owner);
// Deploy the proxy and initialize the contract through the proxy
proxy =newERC1967Proxy(address(implementation), abi.encodeCall(implementation.initialize, owner));
vm.stopPrank();
// remember: Call your contract's functions as normal, but remember to always use the proxy address:// Attach the MyToken interface to the deployed proxy
myToken =MyToken(address(proxy));
// Emit the owner address for debugging purposesemitlog_address(owner);
}
test case
// upgrade should revert, since no ownershipfunction testRevokingOwnership() public {
// revoke ownership
vm.startPrank(owner);
myToken.renounceOwnership();
bytesmemory data =abi.encodeCall(MyTokenV2.initialize, owner);
bytesmemory expectedRevertData =abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, owner);
vm.expectRevert(expectedRevertData); // reverts with another reason (unclear if goal achieved)
Upgrades.upgradeProxy(address(proxy), "MyTokenV2.sol:MyTokenV2", data, owner);
// no mint possible (as expected)
vm.expectRevert(expectedRevertData);
myToken.mint(owner, 100e18);
vm.stopPrank();
}
The text was updated successfully, but these errors were encountered:
yvesbou
changed the title
Not matching error
Unclear error: revert: Failed to deploy contract MyTokenV2.sol:MyTokenV2 using constructor data ""
Sep 2, 2024
yvesbou
changed the title
Unclear error: revert: Failed to deploy contract MyTokenV2.sol:MyTokenV2 using constructor data ""
Unclear error: revert: Failed to deploy contract using constructor data ""
Sep 2, 2024
Upgrades.upgradeProxy consists of two separate calls: one to deploy the new implementation, and another to upgrade the proxy to use that new implementation.
It looks like the error is occurring on the call to deploy the new implementation. Specifically, it might be related to the "Gotcha: Usage with low-level calls" section of https://book.getfoundry.sh/cheatcodes/expect-revert
Since what you want to test is the revert reason during the upgrade, you can break this down into two separate steps: use Upgrade.prepareUpgrade to validate and deploy the new implementation itself, then use the vm.expectRevert before calling the proxy's upgradeToAndCall function.
I’m using
Upgrades.upgradeProxy()
to upgrade proxy contracts pointing to new implementations. A vanilla test case works. But I tried to test revoke ownership and then upgrade which should fail, but it fails with an error that I assume is not correct.I expect
OwnableUnauthorizedAccount
and I get this error (instead of passing, I assume)if I don’t expect
OwnableUnauthorizedAccount
I get this error[FAIL. Reason: OwnableUnauthorizedAccount(0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf)] testRevokingOwnership() (gas: 8242052)
which is what I expect, if I don't expect the
OwnableUnauthorizedAccount
errorHere are necessary parts of the contracts and tests 👇
contract
I just have one argument in the
initializer
V2 of token
it's reinitialisable, thus I want to call it with an initialiser argument, like the first init
setup
test case
The text was updated successfully, but these errors were encountered: