Skip to content

Commit

Permalink
Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Nov 30, 2023
1 parent dfd6508 commit ea3c4e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 6 additions & 4 deletions packages/plugin-hardhat/test/transparent-admin-initial-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const test = require('ava');
const { ethers, upgrades } = require('hardhat');
const hre = require('hardhat');

const OWNABLE_ABI = ['function owner() view returns (address)'];

test.before(async t => {
t.context.Greeter = await ethers.getContractFactory('Greeter');
});
Expand All @@ -12,7 +14,7 @@ test('initial owner using default signer', async t => {

const proxy = await upgrades.deployProxy(Greeter, ['hello']);
const adminAddress = await upgrades.erc1967.getAdminAddress(await proxy.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);

const defaultSigner = await ethers.provider.getSigner(0);

Expand All @@ -26,7 +28,7 @@ test('initial owner using custom signer', async t => {

const proxy = await upgrades.deployProxy(Greeter, ['hello']);
const adminAddress = await upgrades.erc1967.getAdminAddress(await proxy.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);

t.is(await admin.owner(), customSigner.address);
});
Expand All @@ -38,7 +40,7 @@ test('initial owner using initialOwner option', async t => {

const proxy = await upgrades.deployProxy(Greeter, ['hello'], { initialOwner: initialOwner.address });
const adminAddress = await upgrades.erc1967.getAdminAddress(await proxy.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);

t.is(await admin.owner(), initialOwner.address);
});
Expand All @@ -56,7 +58,7 @@ test('initial owner - no signer in ContractFactory', async t => {

const proxy = await upgrades.deployProxy(Greeter, ['hello'], { initialOwner: initialOwner.address });
const adminAddress = await upgrades.erc1967.getAdminAddress(await proxy.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);

t.is(await admin.owner(), initialOwner.address);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const test = require('ava');

const hre = require('hardhat');
const { ethers, upgrades } = hre;
const testAddress = '0x1E6876a6C2757de611c9F12B23211dBaBd1C9028';

const TEST_ADDRESS = '0x1E6876a6C2757de611c9F12B23211dBaBd1C9028';
const OWNABLE_ABI = ['function owner() view returns (address)'];

test.before(async t => {
t.context.Greeter = await ethers.getContractFactory('Greeter');
Expand All @@ -13,11 +15,11 @@ test('transferProxyAdminOwnership', async t => {
const { Greeter } = t.context;
const greeter = await upgrades.deployProxy(Greeter, ['Hello, Hardhat!'], { kind: 'transparent' });

await upgrades.admin.transferProxyAdminOwnership(await greeter.getAddress(), testAddress);
await upgrades.admin.transferProxyAdminOwnership(await greeter.getAddress(), TEST_ADDRESS);

const adminAddress = await upgrades.erc1967.getAdminAddress(await greeter.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);
const newOwner = await admin.owner();

t.is(newOwner, testAddress);
t.is(newOwner, TEST_ADDRESS);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ const test = require('ava');

const hre = require('hardhat');
const { ethers, upgrades } = hre;
const testAddress = '0x1E6876a6C2757de611c9F12B23211dBaBd1C9028';

const TEST_ADDRESS = '0x1E6876a6C2757de611c9F12B23211dBaBd1C9028';
const OWNABLE_ABI = ['function owner() view returns (address)'];

test('transferProxyAdminOwnership - signer', async t => {
// we need to deploy a proxy so we have a Proxy Admin
const signer = await ethers.provider.getSigner(1);
const Greeter = await ethers.getContractFactory('Greeter', signer);
const greeter = await upgrades.deployProxy(Greeter, ['Hello, Hardhat!'], { kind: 'transparent' });

await upgrades.admin.transferProxyAdminOwnership(await greeter.getAddress(), testAddress, signer);
await upgrades.admin.transferProxyAdminOwnership(await greeter.getAddress(), TEST_ADDRESS, signer);

const adminAddress = await upgrades.erc1967.getAdminAddress(await greeter.getAddress());
const admin = await hre.ethers.getContractAt(['function owner() view returns (address)'], adminAddress);
const admin = await hre.ethers.getContractAt(OWNABLE_ABI, adminAddress);
const newOwner = await admin.owner();

t.is(newOwner, testAddress);
t.is(newOwner, TEST_ADDRESS);
});

0 comments on commit ea3c4e3

Please sign in to comment.