Skip to content

Commit

Permalink
use the address helper to mock invalid proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jun 16, 2023
1 parent 2e958b3 commit 1533991
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 0 additions & 4 deletions contracts/mocks/proxy/UUPSUpgradeableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock {
function upgradeToAndCall(address newImplementation, bytes memory data) public payable override {
ERC1967Utils.upgradeToAndCall(newImplementation, data, false);
}

function functionDelegateCall(address target, bytes memory data) public {
Address.functionDelegateCall(target, data);
}
}

contract UUPSUnsupportedProxiableUUID is UUPSUpgradeableMock {
Expand Down
14 changes: 8 additions & 6 deletions test/proxy/utils/UUPSUpgradeable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const UUPSUpgradeableMock = artifacts.require('UUPSUpgradeableMock');
const UUPSUpgradeableUnsafeMock = artifacts.require('UUPSUpgradeableUnsafeMock');
const NonUpgradeableMock = artifacts.require('NonUpgradeableMock');
const UUPSUnsupportedProxiableUUID = artifacts.require('UUPSUnsupportedProxiableUUID');
const Address = artifacts.require('$Address');

contract('UUPSUpgradeable', function () {
before(async function () {
Expand All @@ -15,6 +16,7 @@ contract('UUPSUpgradeable', function () {
this.implUpgradeUnsafe = await UUPSUpgradeableUnsafeMock.new();
this.implUpgradeNonUUPS = await NonUpgradeableMock.new();
this.implUnsupportedUUID = await UUPSUnsupportedProxiableUUID.new();
this.helper = await Address.new();
});

beforeEach(async function () {
Expand Down Expand Up @@ -43,15 +45,15 @@ contract('UUPSUpgradeable', function () {
expect(await this.instance.current()).to.be.bignumber.equal('1');
});

it('rejects upgrading directly from the implementation', async function () {
it('calling upgradeTo on the implementation reverts', async function () {
await expectRevertCustomError(
this.implInitial.upgradeTo(this.implUpgradeOk.address),
'UUPSUnauthorizedCallContext',
[],
);
});

it('rejects upgrading directly from the implementation with call', async function () {
it('calling upgradeToAndCall on the implementation reverts', async function () {
await expectRevertCustomError(
this.implInitial.upgradeToAndCall(
this.implUpgradeOk.address,
Expand All @@ -62,9 +64,9 @@ contract('UUPSUpgradeable', function () {
);
});

it('rejects upgrading from an invalid proxy', async function () {
it('calling upgradeTo from a contract that is not a proxy reverts', async function () {
await expectRevertCustomError(
this.implUpgradeUnsafe.functionDelegateCall(
this.helper.$functionDelegateCall(
this.implUpgradeOk.address,
this.implUpgradeOk.contract.methods.upgradeTo(this.implUpgradeUnsafe.address).encodeABI(),
),
Expand All @@ -73,9 +75,9 @@ contract('UUPSUpgradeable', function () {
);
});

it('rejects upgrading from an invalid proxy with call', async function () {
it('calling upgradeTo from a contract that is not a proxy reverts', async function () {
await expectRevertCustomError(
this.implUpgradeUnsafe.functionDelegateCall(
this.helper.$functionDelegateCall(
this.implUpgradeOk.address,
this.implUpgradeOk.contract.methods.upgradeToAndCall(this.implUpgradeUnsafe.address, '0x').encodeABI(),
),
Expand Down

0 comments on commit 1533991

Please sign in to comment.