instances/test/all.test.js
T-Hax 3863e951d8 fork tested
Signed-off-by: T-Hax <>
2023-04-14 19:16:26 +00:00

189 lines
5.6 KiB
JavaScript

const hre = require('hardhat')
const config = require('../config')
const { ethers, waffle } = hre
const { loadFixture } = waffle
const { expect } = require('chai')
const { minewait } = require('./utils')
const { BigNumber } = require('@ethersproject/bignumber')
describe('Tests', () => {
let governanceSigner, proposer
let minimalFactory, proposalFactory, governance, torn
before(async () => {
minimalFactory = await (
await ethers.getContractFactory('MinimalInstanceFactory')
).deploy(config.verifier, config.hasher, config.merkleTreeHeight)
let gasUsed = await ethers.provider.estimateGas(minimalFactory.deployTransaction.data.toString())
console.log(`\nManaged to deploy the MinimalInstanceFactory. Gas used: ${gasUsed} 🏭\n`)
proposalFactory = await (
await ethers.getContractFactory('InstanceProposalFactory')
).deploy(
config.governance,
minimalFactory.address,
config.instanceRegistry,
config.UniswapV3Factory,
config.WETH,
config.TWAPSlotsMin,
)
gasUsed = await ethers.provider.estimateGas(minimalFactory.deployTransaction.data.toString())
console.log(`\nManaged to deploy the InstanceProposalFactory. Gas used: ${gasUsed} 🏭\n`)
await hre.network.provider.request({
method: 'hardhat_impersonateAccount',
params: [config.governance],
})
await hre.network.provider.request({
method: 'hardhat_setBalance',
params: [config.governance, ethers.utils.parseUnits('10').toHexString()],
})
governanceSigner = await ethers.getSigner(config.governance)
governance = await ethers.getContractAt(
'tornado-governance/contracts/v1/Governance.sol:Governance',
config.governance,
governanceSigner,
)
console.log('\nManaged to setup self-signing governance (just like IRL). 🏛️\n')
torn = await ethers.getContractAt('torn-token/contracts/TORN.sol:TORN', config.TORN, governanceSigner)
proposer = (await ethers.getSigners())[0]
const fundAmount = (await torn.balanceOf(governance.address)).div(2)
await expect(() => torn.transfer(proposer.address, fundAmount)).to.changeTokenBalance(
torn,
proposer,
fundAmount,
)
console.log(`\nFunded proposer with ${fundAmount.div(BigNumber.from(10).pow(18))} TORN 🌪️\n`)
})
it('Test the entire instance creation process.', async () => {
let response = await proposalFactory.createProposalContract(
[config.LUSD],
// This should work fine
[3000, 100000],
// This should work fine
[18, 3921],
[[ethers.utils.parseUnits('10000'), ethers.utils.parseUnits('1000'), ethers.utils.parseUnits('100')]],
// This should work fine
[[100, 100, 100, 312]],
3,
)
console.log('\nManaged to deploy an LUSD proposal factory. 🏭\n')
let receipt = await response.wait()
const proposalContractLUSD = await ethers.getContractAt(
'InstanceAdditionProposal',
receipt.events[0].args[0],
)
expect((await proposalContractLUSD.getAllDataToAdd()).length).to.equal(3)
let denominations = [
ethers.utils.parseUnits('1000'),
ethers.utils.parseUnits('100'),
ethers.utils.parseUnits('10'),
]
response = await proposalFactory.createProposalContract(
[config.RETH, config.LUSD],
// This should work fine
[500, 3000, 100000],
// This too
[18, 18, 3921],
[denominations, denominations],
// This should work fine
[
[100, 100, 100, 312],
[300, 300, 300, 312],
],
6,
)
console.log('\nManaged to deploy a RETH + LUSD proposal factory. 🏭\n')
receipt = await response.wait()
const proposalContractRETHLUSD = await ethers.getContractAt(
'InstanceAdditionProposal',
receipt.events[0].args[0],
)
const addedData = await proposalContractRETHLUSD.getAllDataToAdd()
expect(addedData.length).to.equal(6)
await expect(
proposalFactory.createProposalContract(
[config.RETH, config.FRXETH],
// Should be reverted because of frxeth
[500, 3000],
[18, 18, 3921],
[denominations, denominations],
[
[100, 100, 100, 312],
[100, 100, 100, 312],
],
6,
),
).to.be.reverted
console.log('\nInsufficient cardinality frxETH reverted. 🦄\n')
console.log('Starting proposal process on former proposal...\n')
governance = governance.connect(proposer)
torn = torn.connect(proposer)
const proposerBalance = await torn.balanceOf(proposer.address)
await torn.approve(governance.address, proposerBalance)
await expect(() => governance.lockWithApproval(proposerBalance)).to.changeTokenBalance(
torn,
proposer,
proposerBalance.mul('-1'),
)
await expect(governance.propose(proposalContractRETHLUSD.address, 'Add some random tokens.')).to.not.be
.reverted
const proposalId = await governance.latestProposalIds(proposer.address)
console.log(`\nSuccessfully proposed proposal with id ${proposalId}. 📜\n`)
const votingDelay = await governance.VOTING_DELAY()
// Mine the time necessary for the proposal to finish
await minewait(votingDelay.toNumber())
await expect(governance.castVote(proposalId, true)).to.not.be.reverted
const delay = await governance.EXECUTION_DELAY()
const period = await governance.VOTING_PERIOD()
// Mine the time necessary for the proposal to finish
await minewait(delay.add(period.add('43200')).toNumber())
await expect(governance.execute(proposalId)).to.not.be.reverted
console.log('\n Successfully executed the proposal! 🥳\n')
})
})