Skip to content

Commit 1533991

Browse files
committed
use the address helper to mock invalid proxy
1 parent 2e958b3 commit 1533991

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

contracts/mocks/proxy/UUPSUpgradeableMock.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock {
2929
function upgradeToAndCall(address newImplementation, bytes memory data) public payable override {
3030
ERC1967Utils.upgradeToAndCall(newImplementation, data, false);
3131
}
32-
33-
function functionDelegateCall(address target, bytes memory data) public {
34-
Address.functionDelegateCall(target, data);
35-
}
3632
}
3733

3834
contract UUPSUnsupportedProxiableUUID is UUPSUpgradeableMock {

test/proxy/utils/UUPSUpgradeable.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const UUPSUpgradeableMock = artifacts.require('UUPSUpgradeableMock');
77
const UUPSUpgradeableUnsafeMock = artifacts.require('UUPSUpgradeableUnsafeMock');
88
const NonUpgradeableMock = artifacts.require('NonUpgradeableMock');
99
const UUPSUnsupportedProxiableUUID = artifacts.require('UUPSUnsupportedProxiableUUID');
10+
const Address = artifacts.require('$Address');
1011

1112
contract('UUPSUpgradeable', function () {
1213
before(async function () {
@@ -15,6 +16,7 @@ contract('UUPSUpgradeable', function () {
1516
this.implUpgradeUnsafe = await UUPSUpgradeableUnsafeMock.new();
1617
this.implUpgradeNonUUPS = await NonUpgradeableMock.new();
1718
this.implUnsupportedUUID = await UUPSUnsupportedProxiableUUID.new();
19+
this.helper = await Address.new();
1820
});
1921

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

46-
it('rejects upgrading directly from the implementation', async function () {
48+
it('calling upgradeTo on the implementation reverts', async function () {
4749
await expectRevertCustomError(
4850
this.implInitial.upgradeTo(this.implUpgradeOk.address),
4951
'UUPSUnauthorizedCallContext',
5052
[],
5153
);
5254
});
5355

54-
it('rejects upgrading directly from the implementation with call', async function () {
56+
it('calling upgradeToAndCall on the implementation reverts', async function () {
5557
await expectRevertCustomError(
5658
this.implInitial.upgradeToAndCall(
5759
this.implUpgradeOk.address,
@@ -62,9 +64,9 @@ contract('UUPSUpgradeable', function () {
6264
);
6365
});
6466

65-
it('rejects upgrading from an invalid proxy', async function () {
67+
it('calling upgradeTo from a contract that is not a proxy reverts', async function () {
6668
await expectRevertCustomError(
67-
this.implUpgradeUnsafe.functionDelegateCall(
69+
this.helper.$functionDelegateCall(
6870
this.implUpgradeOk.address,
6971
this.implUpgradeOk.contract.methods.upgradeTo(this.implUpgradeUnsafe.address).encodeABI(),
7072
),
@@ -73,9 +75,9 @@ contract('UUPSUpgradeable', function () {
7375
);
7476
});
7577

76-
it('rejects upgrading from an invalid proxy with call', async function () {
78+
it('calling upgradeTo from a contract that is not a proxy reverts', async function () {
7779
await expectRevertCustomError(
78-
this.implUpgradeUnsafe.functionDelegateCall(
80+
this.helper.$functionDelegateCall(
7981
this.implUpgradeOk.address,
8082
this.implUpgradeOk.contract.methods.upgradeToAndCall(this.implUpgradeUnsafe.address, '0x').encodeABI(),
8183
),

0 commit comments

Comments
 (0)