Migrate proxy folder to ethersjs (#4746)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
Renan Souza
2023-11-29 21:51:08 +00:00
committed by GitHub
parent c35057978f
commit ae69142379
13 changed files with 785 additions and 856 deletions

View File

@ -1,24 +1,28 @@
const { ethers } = require('hardhat');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const shouldBehaveLikeProxy = require('../Proxy.behaviour');
const shouldBehaveLikeTransparentUpgradeableProxy = require('./TransparentUpgradeableProxy.behaviour');
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
async function fixture() {
const [owner, other, ...accounts] = await ethers.getSigners();
contract('TransparentUpgradeableProxy', function (accounts) {
const [owner, ...otherAccounts] = accounts;
const implementation = await ethers.deployContract('DummyImplementation');
// `undefined`, `null` and other false-ish opts will not be forwarded.
const createProxy = async function (logic, initData, opts = undefined) {
const { address, transactionHash } = await TransparentUpgradeableProxy.new(
logic,
owner,
initData,
...[opts].filter(Boolean),
);
const instance = await ITransparentUpgradeableProxy.at(address);
return { ...instance, transactionHash };
const createProxy = function (logic, initData, opts = undefined) {
return ethers.deployContract('TransparentUpgradeableProxy', [logic, owner, initData], opts);
};
shouldBehaveLikeProxy(createProxy, otherAccounts);
shouldBehaveLikeTransparentUpgradeableProxy(createProxy, owner, otherAccounts);
return { nonContractAddress: owner, owner, other, accounts, implementation, createProxy };
}
describe('TransparentUpgradeableProxy', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
shouldBehaveLikeProxy();
// createProxy, owner, otherAccounts
shouldBehaveLikeTransparentUpgradeableProxy();
});