-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from bancorprotocol/voucher-immutability
Voucher immutability
- Loading branch information
Showing
14 changed files
with
168 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { DeployedContracts, InstanceName, execute, setDeploymentMetadata, upgradeProxy } from '../../../utils/Deploy'; | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
|
||
/** | ||
* @dev voucher immutability upgrade - replace minter role with controller role | ||
*/ | ||
const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironment) => { | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
await upgradeProxy({ | ||
name: InstanceName.Voucher, | ||
from: deployer, | ||
args: [] | ||
}); | ||
|
||
const controller = await DeployedContracts.CarbonController.deployed(); | ||
|
||
// Set the carbon controller address in the voucher contract | ||
await execute({ | ||
name: InstanceName.Voucher, | ||
methodName: 'setController', | ||
args: [controller.address], | ||
from: deployer | ||
}); | ||
|
||
return true; | ||
}; | ||
|
||
export default setDeploymentMetadata(__filename, func); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { ProxyAdmin, Voucher } from '../../../components/Contracts'; | ||
import { DeployedContracts, describeDeployment, getNamedSigners } from '../../../utils/Deploy'; | ||
import { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
|
||
/** | ||
* @dev Voucher immutability upgrade - replace minter role with controller | ||
*/ | ||
describeDeployment(__filename, () => { | ||
let proxyAdmin: ProxyAdmin; | ||
let voucher: Voucher; | ||
let deployer: SignerWithAddress; | ||
|
||
beforeEach(async () => { | ||
({ deployer } = await getNamedSigners()); | ||
proxyAdmin = await DeployedContracts.ProxyAdmin.deployed(); | ||
voucher = await DeployedContracts.Voucher.deployed(); | ||
}); | ||
|
||
it('should deploy and configure the voucher contract', async () => { | ||
expect(await proxyAdmin.getProxyAdmin(voucher.address)).to.equal(proxyAdmin.address); | ||
expect(await voucher.version()).to.equal(2); | ||
}); | ||
|
||
it('voucher implementation should be initialized', async () => { | ||
const implementationAddress = await proxyAdmin.getProxyImplementation(voucher.address); | ||
const voucherImpl: Voucher = await ethers.getContractAt('Voucher', implementationAddress); | ||
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) | ||
const tx = await voucherImpl.initialize(true, '1', '1', { gasLimit: 6000000 }); | ||
await expect(tx.wait()).to.be.reverted; | ||
}); | ||
|
||
it("admin shouldn't be able to change controller address", async () => { | ||
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) | ||
const tx = await voucher.connect(deployer).setController(deployer.address, { gasLimit: 6000000 }); | ||
await expect(tx.wait()).to.be.reverted; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.