Skip to content

Commit

Permalink
Merge pull request #11 from ethereum-push-notification-service/7_prox…
Browse files Browse the repository at this point in the history
…yAdmin_inclusion

included proxyAdmin
  • Loading branch information
zaryab2000 authored Feb 13, 2024
2 parents 2e57ed4 + 2671405 commit 2ba73e7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
5 changes: 5 additions & 0 deletions contracts/PushBravoAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity >=0.6.0 <0.7.0;

import "@openzeppelin/contracts/proxy/ProxyAdmin.sol";

contract PushBravoAdmin is ProxyAdmin {}
3 changes: 2 additions & 1 deletion contracts/PushBravoProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol";
contract PushBravoProxy is TransparentUpgradeableProxy {
constructor(
address _logic,
address _proxyAdmin,
address _admin,
address _timelock,
address _push,
Expand All @@ -18,7 +19,7 @@ contract PushBravoProxy is TransparentUpgradeableProxy {
payable
TransparentUpgradeableProxy(
_logic,
_admin,
_proxyAdmin,
abi.encodeWithSignature(
"initialize(address,address,address,uint256,uint256,uint256)",
_admin,
Expand Down
27 changes: 24 additions & 3 deletions scripts/deployGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
await logic.waitForDeployment();
console.log("logic deployed on", logic.target);
console.log("verifying logic");
await logic.deploymentTransaction().wait(6);
await logic.deploymentTransaction().wait(4);

try {
await hre.run("verify:verify", {
Expand All @@ -34,7 +34,7 @@ async function main() {

console.log("timelock deployed to:", timelock.target);
console.log("verifying timelock");
await timelock.deploymentTransaction().wait(6);
await timelock.deploymentTransaction().wait(4);

try {
await hre.run("verify:verify", {
Expand All @@ -45,9 +45,29 @@ async function main() {
console.log("Verification failed :", error);
}

console.log("deploying proxy Admin");

const proxyAdmin = await ethers.deployContract("PushBravoAdmin");
console.log("proxyAdmin deployed to:", proxyAdmin.target);

console.log("verifying proxy Admin");
await proxyAdmin.deploymentTransaction().wait(4);
try {
await hre.run("verify:verify", {
address: proxyAdmin.target,
constructorArguments: [],
contract:"contracts/PushBravoAdmin.sol:PushBravoAdmin"
});
} catch (error) {
console.log("Verification failed :", error);
}


console.log("deploying proxy");

const proxy = await ethers.deployContract("PushBravoProxy", [
logic.target,
proxyAdmin.target,
_admin,
timelock.target,
_push,
Expand All @@ -60,12 +80,13 @@ async function main() {
console.log("proxy deployed to:", proxy.target);

console.log("verifying proxy");
await proxy.deploymentTransaction().wait(6);
await proxy.deploymentTransaction().wait(4);
try {
await hre.run("verify:verify", {
address: proxy.target,
constructorArguments: [
logic.target,
proxyAdmin.target,
_admin,
timelock.target,
_push,
Expand Down
57 changes: 47 additions & 10 deletions test/GovernorBravo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
describe("Governor Bravo", function () {
async function deployFixtures() {
const [owner, otherAccount, owner2] = await ethers.getSigners();
const { governorBravo, timelock, pushToken, governorBravoProxy } =
const { governorBravo, timelock, pushToken, proxyAdmin } =
await setupGovernorBravo();

return {
Expand All @@ -33,7 +33,7 @@ describe("Governor Bravo", function () {
governorBravo,
timelock,
pushToken,
governorBravoProxy,
proxyAdmin,
};
}

Expand All @@ -45,11 +45,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();

await GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -65,11 +70,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -83,6 +93,7 @@ describe("Governor Bravo", function () {
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -101,11 +112,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -119,6 +135,7 @@ describe("Governor Bravo", function () {
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -137,11 +154,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand All @@ -157,6 +179,7 @@ describe("Governor Bravo", function () {
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
addresses[0],
addresses[1],
addresses[2],
Expand Down Expand Up @@ -197,11 +220,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate,
proxyAdmin.target,
addresses[0],
addresses[2],
ethers.zeroPadBytes("0x", 20),
Expand All @@ -220,11 +248,16 @@ describe("Governor Bravo", function () {
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
const addresses = (await ethers.getSigners()).slice(3);
const governorBravoDelegate = await GovernorBravoDelegate.deploy();
await expect(
GovernorBravoDelegator.deploy(
governorBravoDelegate,
proxyAdmin.target,
addresses[0],
ethers.zeroPadBytes("0x", 20),
addresses[2],
Expand Down Expand Up @@ -416,7 +449,6 @@ describe("Governor Bravo", function () {
governorBravo.connect(otherAccount).cancel(proposalId)
).to.be.revertedWith("GovernorBravo::cancel: proposer above threshold");
});

});

describe("Vote", function () {
Expand Down Expand Up @@ -774,33 +806,38 @@ describe("Governor Bravo", function () {
});

it("Invalid address", async function () {
const { governorBravo, owner2 } = await loadFixture(deployFixtures);
const { governorBravo, owner, proxyAdmin } = await loadFixture(
deployFixtures
);
const GovernorBravoDelegator = await ethers.getContractFactory(
"PushBravoProxy"
);
const governorBravoDelegator = GovernorBravoDelegator.attach(
await governorBravo.getAddress()
);
await expect(
governorBravoDelegator.connect(owner2).upgradeTo(ethers.ZeroAddress)
proxyAdmin
.connect(owner)
.upgrade(governorBravoDelegator, ethers.ZeroAddress)
).to.be.revertedWith(
"UpgradeableProxy: new implementation is not a contract"
);
});

it("Happy path", async function () {
const { governorBravo, owner2 } = await loadFixture(deployFixtures);
const { governorBravo, owner, proxyAdmin } = await loadFixture(
deployFixtures
);
const GovernorBravoDelegator = await ethers.getContractFactory(
"PushBravoProxy"
);
const governorBravoDelegator = GovernorBravoDelegator.attach(
await governorBravo.getAddress()
);
await governorBravoDelegator
.connect(owner2)
.upgradeTo(governorBravo.target);
await expect(
governorBravoDelegator.connect(owner2).upgradeTo(governorBravo.target)
proxyAdmin
.connect(owner)
.upgrade(governorBravoDelegator.target, governorBravo.target)
).to.be.fulfilled;
});
});
Expand Down
8 changes: 6 additions & 2 deletions test/governanceHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const setupGovernorBravo = async function setupGovernorBravo() {
const GovernorBravoDelegator = await ethers.getContractFactory(
"PushBravoProxy"
);
const GovernorBravoProxyAdmin = await ethers.getContractFactory(
"PushBravoAdmin"
);
const GovernorBravoDelegate = await ethers.getContractFactory(
"GovernorBravoDelegate"
);
Expand All @@ -126,16 +129,17 @@ const setupGovernorBravo = async function setupGovernorBravo() {
await pushToken.delegate(owner);

const governorBravoDelegate = await GovernorBravoDelegate.deploy();
const proxyAdmin = await GovernorBravoProxyAdmin.deploy();
let governorBravo = await GovernorBravoDelegator.deploy(
governorBravoDelegate.target,
proxyAdmin.target,
owner,
timelock,
pushToken,
5760,
100,
500000n * 10n ** 18n
);
await governorBravo.connect(owner).changeAdmin(owner2.address);

governorBravo = GovernorBravoDelegate.attach(
await governorBravo.getAddress()
Expand All @@ -161,7 +165,7 @@ const setupGovernorBravo = async function setupGovernorBravo() {
await timelock.executeTransaction(timelock, 0, "", txData, eta);

await governorBravo.acceptTimelockOwnership();
return { governorBravo, timelock, pushToken };
return { governorBravo, timelock, pushToken,proxyAdmin };
};

const getTypedDomain = async function getTypedDomain(address, chainId) {
Expand Down

0 comments on commit 2ba73e7

Please sign in to comment.