mirror of
https://github.com/tornadocash/tornado-governance
synced 2024-02-02 14:53:55 +01:00
add V3 tests
This commit is contained in:
parent
74f38d68b0
commit
debbd60010
6
config.js
Normal file
6
config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
governance: '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce',
|
||||||
|
TORN: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
|
||||||
|
tornWhale: '0xF977814e90dA44bFA03b6295A0616a897441aceC',
|
||||||
|
forkBlockNumber: 14352372,
|
||||||
|
}
|
@ -7,6 +7,8 @@ require('hardhat-storage-layout')
|
|||||||
require('hardhat-log-remover')
|
require('hardhat-log-remover')
|
||||||
require('hardhat-contract-sizer')
|
require('hardhat-contract-sizer')
|
||||||
|
|
||||||
|
const config = require('./config')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type import('hardhat/config').HardhatUserConfig
|
* @type import('hardhat/config').HardhatUserConfig
|
||||||
*/
|
*/
|
||||||
@ -28,7 +30,7 @@ module.exports = {
|
|||||||
hardhat: {
|
hardhat: {
|
||||||
forking: {
|
forking: {
|
||||||
url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
||||||
blockNumber: 14042331,
|
blockNumber: config.forkBlockNumber,
|
||||||
},
|
},
|
||||||
initialBaseFeePerGas: 5,
|
initialBaseFeePerGas: 5,
|
||||||
},
|
},
|
||||||
|
37
test/utils.js
Normal file
37
test/utils.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* global ethers, network */
|
||||||
|
|
||||||
|
async function setTime(timestamp) {
|
||||||
|
await ethers.provider.send('evm_setNextBlockTimestamp', [timestamp])
|
||||||
|
}
|
||||||
|
|
||||||
|
async function takeSnapshot() {
|
||||||
|
return await ethers.provider.send('evm_snapshot', [])
|
||||||
|
}
|
||||||
|
|
||||||
|
async function revertSnapshot(id) {
|
||||||
|
await ethers.provider.send('evm_revert', [id])
|
||||||
|
}
|
||||||
|
|
||||||
|
async function advanceTime(sec) {
|
||||||
|
const now = (await ethers.provider.getBlock('latest')).timestamp
|
||||||
|
await setTime(now + sec)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSignerFromAddress(address) {
|
||||||
|
await network.provider.request({
|
||||||
|
method: 'hardhat_impersonateAccount',
|
||||||
|
params: [address],
|
||||||
|
})
|
||||||
|
|
||||||
|
let signer = await ethers.provider.getSigner(address)
|
||||||
|
signer.address = signer._address
|
||||||
|
return signer
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
setTime,
|
||||||
|
advanceTime,
|
||||||
|
takeSnapshot,
|
||||||
|
revertSnapshot,
|
||||||
|
getSignerFromAddress,
|
||||||
|
}
|
@ -3,6 +3,7 @@ const { expect } = require('chai')
|
|||||||
const { BigNumber } = require('@ethersproject/bignumber')
|
const { BigNumber } = require('@ethersproject/bignumber')
|
||||||
const { PermitSigner } = require('../../scripts/v1/Permit.js')
|
const { PermitSigner } = require('../../scripts/v1/Permit.js')
|
||||||
const tornConfig = require('torn-token')
|
const tornConfig = require('torn-token')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
const ProposalState = {
|
const ProposalState = {
|
||||||
Pending: 0,
|
Pending: 0,
|
||||||
@ -35,7 +36,7 @@ const duration = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Governance tests', () => {
|
describe('V1 governance tests', () => {
|
||||||
/// NETWORK && DOMAIN
|
/// NETWORK && DOMAIN
|
||||||
let chainId
|
let chainId
|
||||||
let domain
|
let domain
|
||||||
@ -934,7 +935,7 @@ describe('Governance tests', () => {
|
|||||||
{
|
{
|
||||||
forking: {
|
forking: {
|
||||||
jsonRpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
jsonRpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
||||||
blockNumber: process.env.use_latest_block == 'true' ? undefined : 14042331,
|
blockNumber: process.env.use_latest_block == 'true' ? undefined : config.forkBlockNumber,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
@ -5,6 +5,7 @@ const { propose } = require('../../scripts/helper/propose_proposal.js')
|
|||||||
const testcases = require('@ethersproject/testcases')
|
const testcases = require('@ethersproject/testcases')
|
||||||
const seedbase = require('../../resources/hdnode.json')
|
const seedbase = require('../../resources/hdnode.json')
|
||||||
const accountList = require('../../resources/accounts.json')
|
const accountList = require('../../resources/accounts.json')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
describe('V2 governance tests', () => {
|
describe('V2 governance tests', () => {
|
||||||
///// ON-CHAIN CONSTANTS
|
///// ON-CHAIN CONSTANTS
|
||||||
@ -487,7 +488,7 @@ describe('V2 governance tests', () => {
|
|||||||
{
|
{
|
||||||
forking: {
|
forking: {
|
||||||
jsonRpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
jsonRpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
|
||||||
blockNumber: process.env.use_latest_block == 'true' ? undefined : 14042331,
|
blockNumber: process.env.use_latest_block == 'true' ? undefined : config.forkBlockNumber,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
71
test/v3/governance.v3.test.js
Normal file
71
test/v3/governance.v3.test.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
const { ethers } = require('hardhat')
|
||||||
|
const { expect } = require('chai')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
const { getSignerFromAddress, takeSnapshot, revertSnapshot } = require('../utils')
|
||||||
|
|
||||||
|
describe('V3 governance tests', () => {
|
||||||
|
let snapshotId
|
||||||
|
|
||||||
|
//// CONTRACTS
|
||||||
|
let torn = config.TORN
|
||||||
|
let gov
|
||||||
|
|
||||||
|
//// IMPERSONATED ACCOUNTS
|
||||||
|
let tornWhale
|
||||||
|
|
||||||
|
//// HELPER FN
|
||||||
|
let getToken = async (tokenAddress) => {
|
||||||
|
return await ethers.getContractAt('@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20', tokenAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
tornWhale = await getSignerFromAddress(config.tornWhale)
|
||||||
|
|
||||||
|
gov = (await ethers.getContractAt('GovernanceStakingUpgrade', config.governance)).connect(tornWhale)
|
||||||
|
|
||||||
|
snapshotId = await takeSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#lock functionality', () => {
|
||||||
|
it('should be able to lock/unlock torn in governance', async () => {
|
||||||
|
const [sender] = await ethers.getSigners()
|
||||||
|
const value = ethers.utils.parseEther('1000')
|
||||||
|
|
||||||
|
const tornToken = await (await getToken(torn)).connect(tornWhale)
|
||||||
|
await tornToken.transfer(sender.address, value)
|
||||||
|
await tornToken.connect(sender).approve(gov.address, value)
|
||||||
|
|
||||||
|
const ethBalanceBeforeLock = await ethers.provider.getBalance(sender.address)
|
||||||
|
const tokenBalanceBeforeLock = await tornToken.balanceOf(sender.address)
|
||||||
|
let tx = await gov.connect(sender).lockWithApproval(value)
|
||||||
|
|
||||||
|
let receipt = await tx.wait()
|
||||||
|
let txFee = receipt.cumulativeGasUsed.mul(receipt.effectiveGasPrice)
|
||||||
|
const ethBalanceAfterLock = await ethers.provider.getBalance(sender.address)
|
||||||
|
const tokenBalanceAfterLock = await tornToken.balanceOf(sender.address)
|
||||||
|
expect(ethBalanceAfterLock).to.be.equal(ethBalanceBeforeLock.sub(txFee))
|
||||||
|
expect(tokenBalanceAfterLock).to.be.equal(tokenBalanceBeforeLock.sub(value))
|
||||||
|
|
||||||
|
const lockedBalanceAfterLock = await gov.lockedBalance(sender.address)
|
||||||
|
expect(lockedBalanceAfterLock).to.be.equal(value)
|
||||||
|
|
||||||
|
tx = await gov.connect(sender).unlock(value)
|
||||||
|
|
||||||
|
receipt = await tx.wait()
|
||||||
|
txFee = receipt.cumulativeGasUsed.mul(receipt.effectiveGasPrice)
|
||||||
|
const ethBalanceAfterUnlock = await ethers.provider.getBalance(sender.address)
|
||||||
|
const tokenBalanceAfterUnlock = await tornToken.balanceOf(sender.address)
|
||||||
|
expect(ethBalanceAfterUnlock).to.be.equal(ethBalanceAfterLock.sub(txFee))
|
||||||
|
expect(tokenBalanceAfterUnlock).to.be.equal(tokenBalanceBeforeLock)
|
||||||
|
|
||||||
|
const lockedBalanceAfterUnlock = await gov.lockedBalance(sender.address)
|
||||||
|
expect(lockedBalanceAfterUnlock).to.be.equal(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await revertSnapshot(snapshotId)
|
||||||
|
snapshotId = await takeSnapshot()
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user