Skip to content

Commit

Permalink
treasury/tests: Fix LivepeerGovernor tests
Browse files Browse the repository at this point in the history
Initialization was done before RoundsManager was configured
  • Loading branch information
victorges committed Oct 2, 2023
1 parent 245e287 commit c7039b0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
80 changes: 42 additions & 38 deletions deploy/deploy_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,51 +224,13 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
name: "Treasury",
args: []
})
const Treasury: Treasury = await ethers.getContractAt(
"Treasury",
treasury.address
)

await Treasury.initialize(
config.treasury.minDelay,
[], // governor will be added as a proposer later
[constants.AddressZero], // let anyone execute proposals
deployer // temporary admin role for deployer
).then(tx => tx.wait())

const livepeerGovernor = await contractDeployer.deployAndRegister({
contract: "LivepeerGovernor",
name: "LivepeerGovernor",
args: [Controller.address],
proxy: true
})
const LivepeerGovernor: LivepeerGovernor = await ethers.getContractAt(
"LivepeerGovernor",
livepeerGovernor.address
)

await LivepeerGovernor.initialize(
config.livepeerGovernor.initialVotingDelay,
config.livepeerGovernor.initialVotingPeriod,
config.livepeerGovernor.initialProposalThreshold,
config.livepeerGovernor.initialQuorum,
config.livepeerGovernor.quota
).then(tx => tx.wait())

// Now grant proposer and executor roles to governor and renounce deployer admin role
const roles = {
proposer: await Treasury.PROPOSER_ROLE(),
canceller: await Treasury.CANCELLER_ROLE(),
executor: await Treasury.EXECUTOR_ROLE(),
admin: await Treasury.TIMELOCK_ADMIN_ROLE()
}
for (const role of [roles.proposer, roles.canceller, roles.executor]) {
await Treasury.grantRole(role, LivepeerGovernor.address).then(tx =>
tx.wait()
)
}

await Treasury.renounceRole(roles.admin, deployer).then(tx => tx.wait())

// Set BondingManager parameters
const BondingManager: BondingManager = (await ethers.getContractAt(
Expand Down Expand Up @@ -332,6 +294,48 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
}
}

// Initialize Treasury and LivepeerGovernor

const Treasury: Treasury = await ethers.getContractAt(
"Treasury",
treasury.address
)

await Treasury.initialize(
config.treasury.minDelay,
[], // governor will be added as a proposer later
[constants.AddressZero], // let anyone execute proposals
deployer // temporary admin role for deployer
).then(tx => tx.wait())

const LivepeerGovernor: LivepeerGovernor = await ethers.getContractAt(
"LivepeerGovernor",
livepeerGovernor.address
)

await LivepeerGovernor.initialize(
config.livepeerGovernor.initialVotingDelay,
config.livepeerGovernor.initialVotingPeriod,
config.livepeerGovernor.initialProposalThreshold,
config.livepeerGovernor.initialQuorum,
config.livepeerGovernor.quota
).then(tx => tx.wait())

// Now grant proposer and executor roles to governor and renounce deployer admin role
const roles = {
proposer: await Treasury.PROPOSER_ROLE(),
canceller: await Treasury.CANCELLER_ROLE(),
executor: await Treasury.EXECUTOR_ROLE(),
admin: await Treasury.TIMELOCK_ADMIN_ROLE()
}
for (const role of [roles.proposer, roles.canceller, roles.executor]) {
await Treasury.grantRole(role, LivepeerGovernor.address).then(tx =>
tx.wait()
)
}

await Treasury.renounceRole(roles.admin, deployer).then(tx => tx.wait())

// Set TicketBroker parameters
const Broker: TicketBroker = (await ethers.getContractAt(
"TicketBroker",
Expand Down
4 changes: 3 additions & 1 deletion test/integration/LivepeerGovernor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ describe("LivepeerGovernor", () => {
signers = await ethers.getSigners()
proposer = signers[0]

const fixture = await setupIntegrationTest()
const fixture = await setupIntegrationTest({
tags: ["Contracts", "Poll"]
})
controller = await ethers.getContractAt(
"Controller",
fixture.Controller.address
Expand Down

0 comments on commit c7039b0

Please sign in to comment.