Merge branch 'master' into next-v5.0

This commit is contained in:
Francisco Giordano
2023-05-16 00:07:07 -03:00
308 changed files with 21085 additions and 11515 deletions

View File

@ -5,6 +5,7 @@ const ImplV1 = artifacts.require('DummyImplementation');
const ImplV2 = artifacts.require('DummyImplementationV2');
const ProxyAdmin = artifacts.require('ProxyAdmin');
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
contract('ProxyAdmin', function (accounts) {
const [proxyAdminOwner, newAdmin, anotherAccount] = accounts;
@ -17,12 +18,13 @@ contract('ProxyAdmin', function (accounts) {
beforeEach(async function () {
const initializeData = Buffer.from('');
this.proxyAdmin = await ProxyAdmin.new({ from: proxyAdminOwner });
this.proxy = await TransparentUpgradeableProxy.new(
const proxy = await TransparentUpgradeableProxy.new(
this.implementationV1.address,
this.proxyAdmin.address,
initializeData,
{ from: proxyAdminOwner },
);
this.proxy = await ITransparentUpgradeableProxy.at(proxy.address);
});
it('has an owner', async function () {
@ -41,7 +43,7 @@ contract('ProxyAdmin', function (accounts) {
await this.proxyAdmin.changeProxyAdmin(this.proxy.address, newAdmin, { from: proxyAdminOwner });
const newProxyAdmin = await getAddressInSlot(this.proxy, AdminSlot);
expect(newProxyAdmin).to.be.eq(newAdmin);
expect(newProxyAdmin).to.be.equal(newAdmin);
});
});
@ -60,7 +62,7 @@ contract('ProxyAdmin', function (accounts) {
await this.proxyAdmin.upgrade(this.proxy.address, this.implementationV2.address, { from: proxyAdminOwner });
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.eq(this.implementationV2.address);
expect(implementationAddress).to.be.equal(this.implementationV2.address);
});
});
});
@ -97,7 +99,7 @@ contract('ProxyAdmin', function (accounts) {
from: proxyAdminOwner,
});
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.eq(this.implementationV2.address);
expect(implementationAddress).to.be.equal(this.implementationV2.address);
});
});
});

View File

@ -3,8 +3,8 @@ const { ZERO_ADDRESS } = constants;
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { expect } = require('chai');
const { web3 } = require('hardhat');
const Proxy = artifacts.require('Proxy');
const Implementation1 = artifacts.require('Implementation1');
const Implementation2 = artifacts.require('Implementation2');
const Implementation3 = artifacts.require('Implementation3');
@ -121,13 +121,11 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
expect(balance.toString()).to.be.bignumber.equal(value.toString());
});
it.skip('uses the storage of the proxy', async function () {
it('uses the storage of the proxy', async function () {
// storage layout should look as follows:
// - 0: Initializable storage
// - 1-50: Initailizable reserved storage (50 slots)
// - 51: initializerRan
// - 52: x
const storedValue = await Proxy.at(this.proxyAddress).getStorageAt(52);
// - 0: Initializable storage ++ initializerRan ++ onlyInitializingRan
// - 1: x
const storedValue = await web3.eth.getStorageAt(this.proxyAddress, 1);
expect(parseInt(storedValue)).to.eq(42);
});
});
@ -304,7 +302,6 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
const initializeData = Buffer.from('');
this.impl = await ClashingImplementation.new();
this.proxy = await createProxy(this.impl.address, proxyAdminAddress, initializeData, { from: proxyAdminOwner });
this.clashing = new ClashingImplementation(this.proxy.address);
});
@ -314,6 +311,29 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
'TransparentUpgradeableProxy: admin cannot fallback to proxy target',
);
});
describe('when function names clash', function () {
it('when sender is proxy admin should run the proxy function', async function () {
const receipt = await this.proxy.changeAdmin(anotherAccount, { from: proxyAdminAddress, value: 0 });
expectEvent(receipt, 'AdminChanged');
});
it('when sender is other should delegate to implementation', async function () {
const receipt = await this.proxy.changeAdmin(anotherAccount, { from: anotherAccount, value: 0 });
expectEvent.notEmitted(receipt, 'AdminChanged');
expectEvent.inTransaction(receipt.tx, this.clashing, 'ClashingImplementationCall');
});
it('when sender is proxy admin value should not be accepted', async function () {
await expectRevert.unspecified(this.proxy.changeAdmin(anotherAccount, { from: proxyAdminAddress, value: 1 }));
});
it('when sender is other value should be accepted', async function () {
const receipt = await this.proxy.changeAdmin(anotherAccount, { from: anotherAccount, value: 1 });
expectEvent.notEmitted(receipt, 'AdminChanged');
expectEvent.inTransaction(receipt.tx, this.clashing, 'ClashingImplementationCall');
});
});
});
describe('regression', () => {

View File

@ -2,12 +2,14 @@ const shouldBehaveLikeProxy = require('../Proxy.behaviour');
const shouldBehaveLikeTransparentUpgradeableProxy = require('./TransparentUpgradeableProxy.behaviour');
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
contract('TransparentUpgradeableProxy', function (accounts) {
const [proxyAdminAddress, proxyAdminOwner] = accounts;
const createProxy = async function (logic, admin, initData, opts) {
return TransparentUpgradeableProxy.new(logic, admin, initData, opts);
const { address } = await TransparentUpgradeableProxy.new(logic, admin, initData, opts);
return ITransparentUpgradeableProxy.at(address);
};
shouldBehaveLikeProxy(createProxy, proxyAdminAddress, proxyAdminOwner);