diff --git a/packages/plugin-hardhat/test/transparent-admin-initial-owner.js b/packages/plugin-hardhat/test/transparent-admin-initial-owner.js index ad6c173bf..7d9751bcb 100644 --- a/packages/plugin-hardhat/test/transparent-admin-initial-owner.js +++ b/packages/plugin-hardhat/test/transparent-admin-initial-owner.js @@ -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'); }); @@ -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); @@ -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); }); @@ -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); }); @@ -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); }); diff --git a/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-happy-path.js b/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-happy-path.js index 5682345d9..185e6f9fa 100644 --- a/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-happy-path.js +++ b/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-happy-path.js @@ -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'); @@ -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); }); diff --git a/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-signer.js b/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-signer.js index c52a3a3a8..b50015801 100644 --- a/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-signer.js +++ b/packages/plugin-hardhat/test/transparent-transfer-admin-ownership-signer.js @@ -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('transferProxyAdminOwnership - signer', async t => { // we need to deploy a proxy so we have a Proxy Admin @@ -10,11 +12,11 @@ test('transferProxyAdminOwnership - signer', async t => { 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); });