From c123c2b1566c63e15fab740dd1a4cb4f79612a22 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov <47551140+Arvolear@users.noreply.github.com> Date: Sun, 17 Dec 2023 19:15:25 +0200 Subject: [PATCH] Feat/clarity (#81) * cleaned up PCR * versions * slight refactoring * visibility * typo --- README.md | 2 +- .../AbstractContractsRegistry.sol | 6 +-- .../pools/AbstractPoolContractsRegistry.sol | 12 +++++- .../pool-factory/AbstractPoolFactory.sol | 8 +--- .../MultiOwnablePoolContractsRegistry.sol | 2 - .../presets/OwnablePoolContractsRegistry.sol | 2 - contracts/package.json | 6 +-- .../proxy => proxy/beacon}/ProxyBeacon.sol | 8 ++-- .../beacon}/PublicBeaconProxy.sol | 11 ++--- .../transparent/TransparentProxyUpgrader.sol} | 19 ++++----- package-lock.json | 32 +++++++-------- package.json | 6 +-- .../pools/pool-factory/PoolFactory.test.ts | 2 +- .../beacon}/ProxyBeacon.test.ts | 0 test/proxy/beacon/PublicBeaconProxy.test.ts | 41 +++++++++++++++++++ .../TransparentProxyUpgrader.test.ts} | 35 ++++++++-------- 16 files changed, 116 insertions(+), 76 deletions(-) rename contracts/{contracts-registry/pools/proxy => proxy/beacon}/ProxyBeacon.sol (72%) rename contracts/{contracts-registry/pools/pool-factory/proxy => proxy/beacon}/PublicBeaconProxy.sol (55%) rename contracts/{contracts-registry/proxy/ProxyUpgrader.sol => proxy/transparent/TransparentProxyUpgrader.sol} (61%) rename test/{contracts-registry/pools => proxy/beacon}/ProxyBeacon.test.ts (100%) create mode 100644 test/proxy/beacon/PublicBeaconProxy.test.ts rename test/{contracts-registry/ProxyUpgrader.test.ts => proxy/transparent/TransparentProxyUpgrader.test.ts} (50%) diff --git a/README.md b/README.md index 05463bc6..f6ab3476 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ # Solidity Library for Savvies by Distributed Lab -The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.2) and **go far beyond mediocre solidity**. +The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.5) and **go far beyond mediocre solidity**. - Implementation of [**Contracts Registry**](https://eips.ethereum.org/EIPS/eip-6224) pattern - Versatile **RBAC** and **MultiOwnable** smart contracts diff --git a/contracts/contracts-registry/AbstractContractsRegistry.sol b/contracts/contracts-registry/AbstractContractsRegistry.sol index d7c0be7f..d3c40791 100644 --- a/contracts/contracts-registry/AbstractContractsRegistry.sol +++ b/contracts/contracts-registry/AbstractContractsRegistry.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.4; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ProxyUpgrader} from "./proxy/ProxyUpgrader.sol"; +import {TransparentProxyUpgrader} from "../proxy/transparent/TransparentProxyUpgrader.sol"; import {AbstractDependant} from "./AbstractDependant.sol"; /** @@ -36,7 +36,7 @@ import {AbstractDependant} from "./AbstractDependant.sol"; * The management is simplified because all of the contracts are now located in a single place. */ abstract contract AbstractContractsRegistry is Initializable { - ProxyUpgrader private _proxyUpgrader; + TransparentProxyUpgrader private _proxyUpgrader; mapping(string => address) private _contracts; mapping(address => bool) private _isProxy; @@ -50,7 +50,7 @@ abstract contract AbstractContractsRegistry is Initializable { * @notice The proxy initializer function */ function __ContractsRegistry_init() internal onlyInitializing { - _proxyUpgrader = new ProxyUpgrader(); + _proxyUpgrader = new TransparentProxyUpgrader(); } /** diff --git a/contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol b/contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol index 254be292..eb08a40d 100644 --- a/contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol +++ b/contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol @@ -9,7 +9,7 @@ import {Paginator} from "../../libs/arrays/Paginator.sol"; import {AbstractDependant} from "../../contracts-registry/AbstractDependant.sol"; -import {ProxyBeacon} from "./proxy/ProxyBeacon.sol"; +import {ProxyBeacon} from "../../proxy/beacon/ProxyBeacon.sol"; /** * @notice The PoolContractsRegistry module @@ -48,6 +48,16 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend _contractsRegistry = contractsRegistry_; } + /** + * @notice The function to add new pools into the registry. Gets called from PoolFactory + * + * Proper only factory access control must be added in descending contracts + `_addProxyPool()` should be called inside. + * + * @param name_ the pool's associated name + * @param poolAddress_ the proxy address of the pool + */ + function addProxyPool(string memory name_, address poolAddress_) public virtual; + /** * @notice The function to get implementation of the specific pools * @param name_ the name of the pools diff --git a/contracts/contracts-registry/pools/pool-factory/AbstractPoolFactory.sol b/contracts/contracts-registry/pools/pool-factory/AbstractPoolFactory.sol index 70e123f0..e35e6304 100644 --- a/contracts/contracts-registry/pools/pool-factory/AbstractPoolFactory.sol +++ b/contracts/contracts-registry/pools/pool-factory/AbstractPoolFactory.sol @@ -6,7 +6,7 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; import {AbstractDependant} from "../../../contracts-registry/AbstractDependant.sol"; import {AbstractPoolContractsRegistry} from "../AbstractPoolContractsRegistry.sol"; -import {PublicBeaconProxy} from "./proxy/PublicBeaconProxy.sol"; +import {PublicBeaconProxy} from "../../../proxy/beacon/PublicBeaconProxy.sol"; /** * @notice The PoolContractsRegistry module @@ -74,11 +74,7 @@ abstract contract AbstractPoolFactory is AbstractDependant { string memory poolType_, address poolProxy_ ) internal virtual { - (bool success, ) = poolRegistry_.call( - abi.encodeWithSignature("addProxyPool(string,address)", poolType_, poolProxy_) - ); - - require(success, "AbstractPoolFactory: failed to register contract"); + AbstractPoolContractsRegistry(poolRegistry_).addProxyPool(poolType_, poolProxy_); } /** diff --git a/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol b/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol index bdc7623f..4d2303a1 100644 --- a/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol +++ b/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol @@ -39,6 +39,4 @@ abstract contract MultiOwnablePoolContractsRegistry is ) external onlyOwner { _injectDependenciesToExistingPoolsWithData(name_, data_, offset_, limit_); } - - function addProxyPool(string memory name_, address poolAddress_) public virtual; } diff --git a/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol b/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol index 0c9a6325..a4b09bd8 100644 --- a/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol +++ b/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol @@ -40,6 +40,4 @@ abstract contract OwnablePoolContractsRegistry is ) external onlyOwner { _injectDependenciesToExistingPoolsWithData(name_, data_, offset_, limit_); } - - function addProxyPool(string memory name_, address poolAddress_) public virtual; } diff --git a/contracts/package.json b/contracts/package.json index ae31d091..0035c46b 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/solidity-lib", - "version": "2.6.11", + "version": "2.6.12", "license": "MIT", "author": "Distributed Lab", "readme": "README.md", @@ -21,8 +21,8 @@ "!mock/**/*" ], "dependencies": { - "@openzeppelin/contracts": "4.9.2", - "@openzeppelin/contracts-upgradeable": "4.9.2", + "@openzeppelin/contracts": "4.9.5", + "@openzeppelin/contracts-upgradeable": "4.9.5", "@uniswap/v2-core": "1.0.1", "@uniswap/v2-periphery": "1.1.0-beta.0", "@uniswap/v3-core": "1.0.1", diff --git a/contracts/contracts-registry/pools/proxy/ProxyBeacon.sol b/contracts/proxy/beacon/ProxyBeacon.sol similarity index 72% rename from contracts/contracts-registry/pools/proxy/ProxyBeacon.sol rename to contracts/proxy/beacon/ProxyBeacon.sol index 3730a014..4f3fab25 100644 --- a/contracts/contracts-registry/pools/proxy/ProxyBeacon.sol +++ b/contracts/proxy/beacon/ProxyBeacon.sol @@ -5,9 +5,9 @@ import {IBeacon} from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; /** - * @notice The PoolContractsRegistry module + * @notice The proxies module * - * This is a utility lightweighted ProxyBeacon contract this is used as a beacon that BeaconProxies point to. + * This is a lightweight utility ProxyBeacon contract that may be used as a beacon that BeaconProxies point to. */ contract ProxyBeacon is IBeacon { using Address for address; @@ -27,7 +27,7 @@ contract ProxyBeacon is IBeacon { _OWNER = msg.sender; } - function upgradeTo(address newImplementation_) external onlyOwner { + function upgradeTo(address newImplementation_) external virtual onlyOwner { require(newImplementation_.isContract(), "ProxyBeacon: not a contract"); _implementation = newImplementation_; @@ -35,7 +35,7 @@ contract ProxyBeacon is IBeacon { emit Upgraded(newImplementation_); } - function implementation() public view override returns (address) { + function implementation() public view virtual override returns (address) { return _implementation; } } diff --git a/contracts/contracts-registry/pools/pool-factory/proxy/PublicBeaconProxy.sol b/contracts/proxy/beacon/PublicBeaconProxy.sol similarity index 55% rename from contracts/contracts-registry/pools/pool-factory/proxy/PublicBeaconProxy.sol rename to contracts/proxy/beacon/PublicBeaconProxy.sol index 292d9a84..cb1e88ed 100644 --- a/contracts/contracts-registry/pools/pool-factory/proxy/PublicBeaconProxy.sol +++ b/contracts/proxy/beacon/PublicBeaconProxy.sol @@ -4,11 +4,12 @@ pragma solidity ^0.8.4; import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; /** - * @notice The PoolContractsRegistry module + * @notice The proxies module * - * The helper BeaconProxy that get deployed by the PoolFactory. Note that the external - * `implementation()` function is added to the contract to provide compatability with the - * Etherscan. This means that the implementation must not have such a function declared. + * The helper BeaconProxy that can be deployed by the factories. + * + * Note that the external `implementation()` function is added to the contract to provide compatability with + * Etherscan. This means that the implementation contract must not have such a function declared. */ contract PublicBeaconProxy is BeaconProxy { constructor(address beacon_, bytes memory data_) payable BeaconProxy(beacon_, data_) {} @@ -17,7 +18,7 @@ contract PublicBeaconProxy is BeaconProxy { * @notice The function that returns implementation contract this proxy points to * @return address the implementation address */ - function implementation() external view virtual returns (address) { + function implementation() public view virtual returns (address) { return _implementation(); } } diff --git a/contracts/contracts-registry/proxy/ProxyUpgrader.sol b/contracts/proxy/transparent/TransparentProxyUpgrader.sol similarity index 61% rename from contracts/contracts-registry/proxy/ProxyUpgrader.sol rename to contracts/proxy/transparent/TransparentProxyUpgrader.sol index b7093f02..fbfe1245 100644 --- a/contracts/contracts-registry/proxy/ProxyUpgrader.sol +++ b/contracts/proxy/transparent/TransparentProxyUpgrader.sol @@ -5,18 +5,17 @@ import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transp import {Address} from "@openzeppelin/contracts/utils/Address.sol"; /** - * @notice The ContractsRegistry module + * @notice The proxies module * - * This is the helper contract that is used by an AbstractContractsRegistry as a proxy admin. - * It is essential to distinguish between the admin and the registry due to the Transparent proxies nature + * This is the lightweight helper contract that may be used as a transparent proxy admin. */ -contract ProxyUpgrader { +contract TransparentProxyUpgrader { using Address for address; address private immutable _OWNER; modifier onlyOwner() { - _onlyOwner(); + require(_OWNER == msg.sender, "TransparentProxyUpgrader: not an owner"); _; } @@ -24,7 +23,7 @@ contract ProxyUpgrader { _OWNER = msg.sender; } - function upgrade(address what_, address to_, bytes calldata data_) external onlyOwner { + function upgrade(address what_, address to_, bytes calldata data_) external virtual onlyOwner { if (data_.length > 0) { ITransparentUpgradeableProxy(payable(what_)).upgradeToAndCall(to_, data_); } else { @@ -32,16 +31,12 @@ contract ProxyUpgrader { } } - function getImplementation(address what_) external view onlyOwner returns (address) { + function getImplementation(address what_) public view virtual returns (address) { // bytes4(keccak256("implementation()")) == 0x5c60da1b (bool success_, bytes memory returndata_) = address(what_).staticcall(hex"5c60da1b"); - require(success_, "ProxyUpgrader: not a proxy"); + require(success_, "TransparentProxyUpgrader: not a proxy"); return abi.decode(returndata_, (address)); } - - function _onlyOwner() internal view { - require(_OWNER == msg.sender, "ProxyUpgrader: not an owner"); - } } diff --git a/package-lock.json b/package-lock.json index 9ddfd2d2..ff0f97e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "@solarity/solidity-lib", - "version": "2.6.11", + "version": "2.6.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@solarity/solidity-lib", - "version": "2.6.11", + "version": "2.6.12", "hasInstallScript": true, "license": "MIT", "dependencies": { - "@openzeppelin/contracts": "4.9.2", - "@openzeppelin/contracts-upgradeable": "4.9.2", + "@openzeppelin/contracts": "4.9.5", + "@openzeppelin/contracts-upgradeable": "4.9.5", "@uniswap/v2-core": "1.0.1", "@uniswap/v2-periphery": "1.1.0-beta.0", "@uniswap/v3-core": "1.0.1", @@ -1836,14 +1836,14 @@ } }, "node_modules/@openzeppelin/contracts": { - "version": "4.9.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.9.2.tgz", - "integrity": "sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==" + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.9.5.tgz", + "integrity": "sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==" }, "node_modules/@openzeppelin/contracts-upgradeable": { - "version": "4.9.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz", - "integrity": "sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==" + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.5.tgz", + "integrity": "sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==" }, "node_modules/@pnpm/config.env-replace": { "version": "1.1.0", @@ -10091,14 +10091,14 @@ "optional": true }, "@openzeppelin/contracts": { - "version": "4.9.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.9.2.tgz", - "integrity": "sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==" + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.9.5.tgz", + "integrity": "sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==" }, "@openzeppelin/contracts-upgradeable": { - "version": "4.9.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz", - "integrity": "sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==" + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.5.tgz", + "integrity": "sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==" }, "@pnpm/config.env-replace": { "version": "1.1.0", diff --git a/package.json b/package.json index 89da4d37..22be945c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/solidity-lib", - "version": "2.6.11", + "version": "2.6.12", "license": "MIT", "author": "Distributed Lab", "description": "Solidity Library by Distributed Lab", @@ -29,8 +29,8 @@ "publish-to-npm": "npm run lint-fix && bash ./scripts/publish.sh" }, "dependencies": { - "@openzeppelin/contracts": "4.9.2", - "@openzeppelin/contracts-upgradeable": "4.9.2", + "@openzeppelin/contracts": "4.9.5", + "@openzeppelin/contracts-upgradeable": "4.9.5", "@uniswap/v2-core": "1.0.1", "@uniswap/v2-periphery": "1.1.0-beta.0", "@uniswap/v3-core": "1.0.1", diff --git a/test/contracts-registry/pools/pool-factory/PoolFactory.test.ts b/test/contracts-registry/pools/pool-factory/PoolFactory.test.ts index 15778a03..2d069df2 100644 --- a/test/contracts-registry/pools/pool-factory/PoolFactory.test.ts +++ b/test/contracts-registry/pools/pool-factory/PoolFactory.test.ts @@ -107,7 +107,7 @@ describe("PoolFactory", () => { await contractsRegistry.addContract(await contractsRegistry.POOL_FACTORY_NAME(), OWNER); await contractsRegistry.injectDependencies(await contractsRegistry.POOL_CONTRACTS_REGISTRY_NAME()); - await expect(poolFactory.deployPool()).to.be.revertedWith("AbstractPoolFactory: failed to register contract"); + await expect(poolFactory.deployPool()).to.be.revertedWith("PoolContractsRegistry: not a factory"); }); it("should deploy several pools", async () => { diff --git a/test/contracts-registry/pools/ProxyBeacon.test.ts b/test/proxy/beacon/ProxyBeacon.test.ts similarity index 100% rename from test/contracts-registry/pools/ProxyBeacon.test.ts rename to test/proxy/beacon/ProxyBeacon.test.ts diff --git a/test/proxy/beacon/PublicBeaconProxy.test.ts b/test/proxy/beacon/PublicBeaconProxy.test.ts new file mode 100644 index 00000000..33f263ce --- /dev/null +++ b/test/proxy/beacon/PublicBeaconProxy.test.ts @@ -0,0 +1,41 @@ +import { ethers } from "hardhat"; +import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; +import { expect } from "chai"; +import { Reverter } from "@/test/helpers/reverter"; + +import { PublicBeaconProxy, ProxyBeacon, ERC20Mock } from "@ethers-v6"; + +describe("ProxyBeacon", () => { + const reverter = new Reverter(); + + let OWNER: SignerWithAddress; + + let proxyBeacon: ProxyBeacon; + let token: ERC20Mock; + + before("setup", async () => { + [OWNER] = await ethers.getSigners(); + + const ProxyBeacon = await ethers.getContractFactory("ProxyBeacon"); + const ERC20Mock = await ethers.getContractFactory("ERC20Mock"); + + proxyBeacon = await ProxyBeacon.deploy(); + token = await ERC20Mock.deploy("mock", "mock", 18); + + await reverter.snapshot(); + }); + + afterEach(reverter.revert); + + describe("functions", () => { + it("should get implementation", async () => { + await proxyBeacon.upgradeTo(await token.getAddress()); + + const PublicBeaconProxy = await ethers.getContractFactory("PublicBeaconProxy"); + const proxy: PublicBeaconProxy = await PublicBeaconProxy.deploy(proxyBeacon, "0x"); + + expect(await proxyBeacon.implementation()).to.equal(await token.getAddress()); + expect(await proxy.implementation()).to.equal(await token.getAddress()); + }); + }); +}); diff --git a/test/contracts-registry/ProxyUpgrader.test.ts b/test/proxy/transparent/TransparentProxyUpgrader.test.ts similarity index 50% rename from test/contracts-registry/ProxyUpgrader.test.ts rename to test/proxy/transparent/TransparentProxyUpgrader.test.ts index fbe3e712..f74416b5 100644 --- a/test/contracts-registry/ProxyUpgrader.test.ts +++ b/test/proxy/transparent/TransparentProxyUpgrader.test.ts @@ -3,15 +3,15 @@ import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; import { expect } from "chai"; import { Reverter } from "@/test/helpers/reverter"; -import { ProxyUpgrader, TransparentUpgradeableProxy, ERC20Mock } from "@ethers-v6"; +import { TransparentProxyUpgrader, TransparentUpgradeableProxy, ERC20Mock } from "@ethers-v6"; -describe("ProxyUpgrader", () => { +describe("TransparentProxyUpgrader", () => { const reverter = new Reverter(); let OWNER: SignerWithAddress; let SECOND: SignerWithAddress; - let proxyUpgrader: ProxyUpgrader; + let transparentProxyUpgrader: TransparentProxyUpgrader; let token: ERC20Mock; let proxy: TransparentUpgradeableProxy; @@ -19,12 +19,17 @@ describe("ProxyUpgrader", () => { [OWNER, SECOND] = await ethers.getSigners(); const ERC20Mock = await ethers.getContractFactory("ERC20Mock"); - const ProxyUpgrader = await ethers.getContractFactory("ProxyUpgrader"); + const TransparentProxyUpgrader = await ethers.getContractFactory("TransparentProxyUpgrader"); const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); token = await ERC20Mock.deploy("mock", "mock", 18); - proxyUpgrader = await ProxyUpgrader.deploy(); - proxy = await TransparentUpgradeableProxy.deploy(await token.getAddress(), await proxyUpgrader.getAddress(), "0x"); + + transparentProxyUpgrader = await TransparentProxyUpgrader.deploy(); + proxy = await TransparentUpgradeableProxy.deploy( + await token.getAddress(), + await transparentProxyUpgrader.getAddress(), + "0x", + ); await reverter.snapshot(); }); @@ -34,25 +39,21 @@ describe("ProxyUpgrader", () => { describe("upgrade", () => { it("only owner should upgrade", async () => { await expect( - proxyUpgrader.connect(SECOND).upgrade(await proxy.getAddress(), await proxy.getAddress(), "0x"), - ).to.be.revertedWith("ProxyUpgrader: not an owner"); + transparentProxyUpgrader.connect(SECOND).upgrade(await proxy.getAddress(), await proxy.getAddress(), "0x"), + ).to.be.revertedWith("TransparentProxyUpgrader: not an owner"); }); }); describe("getImplementation", () => { it("should get implementation", async () => { - expect(await proxyUpgrader.getImplementation(await proxy.getAddress())).to.equal(await token.getAddress()); - }); - - it("should not get implementation", async () => { - await expect(proxyUpgrader.getImplementation(await token.getAddress())).to.be.revertedWith( - "ProxyUpgrader: not a proxy", + expect(await transparentProxyUpgrader.getImplementation(await proxy.getAddress())).to.equal( + await token.getAddress(), ); }); - it("only owner should get implementation", async () => { - await expect(proxyUpgrader.connect(SECOND).getImplementation(await proxy.getAddress())).to.be.revertedWith( - "ProxyUpgrader: not an owner", + it("should not get implementation", async () => { + await expect(transparentProxyUpgrader.getImplementation(await token.getAddress())).to.be.revertedWith( + "TransparentProxyUpgrader: not a proxy", ); }); });