Skip to content

Commit

Permalink
Updated test cases according to proxy admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Zartaj0 committed Feb 12, 2024
1 parent c00d9ba commit 2671405
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
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 2671405

Please sign in to comment.