Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add helper
  • Loading branch information
JulissaDantes committed Nov 25, 2022
commit 76291fe7b9d4d35feb63f905c6fac8bc121f7978
6 changes: 6 additions & 0 deletions test/helpers/erc1967.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ function getSlot (address, slot) {
);
}

async function getAddressInSlot (address, slot) {
const implementationSlot = await getSlot(address, slot);
return web3.utils.toChecksumAddress(implementationSlot.substr(-40));
}

module.exports = {
ImplementationLabel,
AdminLabel,
Expand All @@ -21,4 +26,5 @@ module.exports = {
AdminSlot: labelToSlot(AdminLabel),
BeaconSlot: labelToSlot(BeaconLabel),
getSlot,
getAddressInSlot,
};
13 changes: 5 additions & 8 deletions test/proxy/transparent/ProxyAdmin.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { expectRevert } = require('@openzeppelin/test-helpers');
const { getSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { expect } = require('chai');
const ImplV1 = artifacts.require('DummyImplementation');
const ImplV2 = artifacts.require('DummyImplementationV2');
Expand Down Expand Up @@ -39,10 +39,9 @@ contract('ProxyAdmin', function (accounts) {

it('changes proxy admin', async function () {
await this.proxyAdmin.changeProxyAdmin(this.proxy.address, newAdmin, { from: proxyAdminOwner });
const proxyAdminSlot = await getSlot(this.proxy, AdminSlot);
const proxyAdminAddress = web3.utils.toChecksumAddress(proxyAdminSlot.substr(-40));

expect(proxyAdminAddress).to.be.eq(newAdmin);
const newProxyAdmin = await getAddressInSlot(this.proxy, AdminSlot);
expect(newProxyAdmin).to.be.eq(newAdmin);
});
});

Expand All @@ -60,8 +59,7 @@ contract('ProxyAdmin', function (accounts) {
it('upgrades implementation', async function () {
await this.proxyAdmin.upgrade(this.proxy.address, this.implementationV2.address, { from: proxyAdminOwner });

const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementationAddress = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.eq(this.implementationV2.address);
});
});
Expand Down Expand Up @@ -98,8 +96,7 @@ contract('ProxyAdmin', function (accounts) {
await this.proxyAdmin.upgradeAndCall(this.proxy.address, this.implementationV2.address, callData,
{ from: proxyAdminOwner },
);
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementationAddress = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.eq(this.implementationV2.address);
});
});
Expand Down
23 changes: 8 additions & 15 deletions test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { BN, expectRevert, expectEvent, constants } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { getSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');

const { expect } = require('chai');

Expand Down Expand Up @@ -34,8 +34,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro

describe('implementation', function () {
it('returns the current implementation address', async function () {
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementationAddress = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.equal(this.implementationV0);
});

Expand All @@ -55,8 +54,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
it('upgrades to the requested implementation', async function () {
await this.proxy.upgradeTo(this.implementationV1, { from });

const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementationAddress = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.equal(this.implementationV1);
});

Expand Down Expand Up @@ -109,8 +107,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
});

it('upgrades to the requested implementation', async function () {
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementationAddress = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.equal(this.behavior.address);
});

Expand Down Expand Up @@ -175,8 +172,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
});

it('upgrades to the requested version and emits an event', async function () {
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementation = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementation = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementation).to.be.equal(this.behaviorV1.address);
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV1.address });
});
Expand All @@ -202,8 +198,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
});

it('upgrades to the requested version and emits an event', async function () {
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementation = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementation = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementation).to.be.equal(this.behaviorV2.address);
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV2.address });
});
Expand Down Expand Up @@ -232,8 +227,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
});

it('upgrades to the requested version and emits an event', async function () {
const implementationSlot = await getSlot(this.proxy, ImplementationSlot);
const implementation = web3.utils.toChecksumAddress(implementationSlot.substr(-40));
const implementation = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementation).to.be.equal(this.behaviorV3.address);
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV3.address });
});
Expand Down Expand Up @@ -279,8 +273,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
});

it('assigns new proxy admin', async function () {
const proxyAdminSlot = await getSlot(this.proxy, AdminSlot);
const newProxyAdmin = web3.utils.toChecksumAddress(proxyAdminSlot.substr(-40));
const newProxyAdmin = await getAddressInSlot(this.proxy, AdminSlot);
expect(newProxyAdmin).to.be.equal(anotherAccount);
});

Expand Down