mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
refactor tests
This commit is contained in:
parent
3cae4c9817
commit
d374e28f69
@ -3,7 +3,7 @@ const { ethers, waffle } = hre
|
|||||||
const { loadFixture } = waffle
|
const { loadFixture } = waffle
|
||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
|
|
||||||
const { poseidonHash2, toFixedHex } = require('../src/utils')
|
const { poseidonHash2 } = require('../src/utils')
|
||||||
const Utxo = require('../src/utxo')
|
const Utxo = require('../src/utxo')
|
||||||
|
|
||||||
const MERKLE_TREE_HEIGHT = 5
|
const MERKLE_TREE_HEIGHT = 5
|
||||||
@ -14,7 +14,6 @@ const { Keypair } = require('../src/keypair')
|
|||||||
|
|
||||||
describe('TornadoPool', function () {
|
describe('TornadoPool', function () {
|
||||||
this.timeout(20000)
|
this.timeout(20000)
|
||||||
let gov, messenger
|
|
||||||
|
|
||||||
async function deploy(contractName, ...args) {
|
async function deploy(contractName, ...args) {
|
||||||
const Factory = await ethers.getContractFactory(contractName)
|
const Factory = await ethers.getContractFactory(contractName)
|
||||||
@ -23,51 +22,47 @@ describe('TornadoPool', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fixture() {
|
async function fixture() {
|
||||||
;[, gov] = await ethers.getSigners()
|
|
||||||
const verifier2 = await deploy('Verifier2')
|
const verifier2 = await deploy('Verifier2')
|
||||||
const verifier16 = await deploy('Verifier16')
|
const verifier16 = await deploy('Verifier16')
|
||||||
|
|
||||||
const tree = new MerkleTree(MERKLE_TREE_HEIGHT, [], { hashFunction: poseidonHash2 })
|
const tree = new MerkleTree(MERKLE_TREE_HEIGHT, [], { hashFunction: poseidonHash2 })
|
||||||
const root = await tree.root()
|
|
||||||
|
|
||||||
const Pool = await ethers.getContractFactory('TornadoPool')
|
/** @type {TornadoPool} */
|
||||||
const tornadoPoolImpl = await Pool.deploy(verifier2.address, verifier16.address)
|
const tornadoPool = await deploy('TornadoPool', verifier2.address, verifier16.address)
|
||||||
|
await tornadoPool.initialize(tree.root())
|
||||||
|
return { tornadoPool }
|
||||||
|
}
|
||||||
|
|
||||||
const OVM_Messenger = await ethers.getContractFactory('MockOVM_CrossDomainMessenger')
|
async function fixtureUpgradeable() {
|
||||||
messenger = await OVM_Messenger.deploy(gov.address)
|
const { tornadoPool } = await loadFixture(fixture)
|
||||||
await messenger.deployed()
|
const [, gov] = await ethers.getSigners()
|
||||||
|
const messenger = await deploy('MockOVM_CrossDomainMessenger', gov.address)
|
||||||
const CrossChainUpgradeableProxy = await ethers.getContractFactory('CrossChainUpgradeableProxy')
|
const proxy = await deploy(
|
||||||
const proxy = await CrossChainUpgradeableProxy.deploy(
|
'CrossChainUpgradeableProxy',
|
||||||
tornadoPoolImpl.address,
|
tornadoPool.address,
|
||||||
gov.address,
|
gov.address,
|
||||||
[],
|
[],
|
||||||
messenger.address,
|
messenger.address,
|
||||||
)
|
)
|
||||||
await proxy.deployed()
|
|
||||||
|
|
||||||
|
const TornadoPool = await ethers.getContractFactory('TornadoPool')
|
||||||
/** @type {TornadoPool} */
|
/** @type {TornadoPool} */
|
||||||
const tornadoPool = Pool.attach(proxy.address)
|
const tornadoPoolProxied = TornadoPool.attach(proxy.address)
|
||||||
|
await tornadoPoolProxied.initialize(await tornadoPool.currentRoot())
|
||||||
|
|
||||||
await tornadoPool.initialize(toFixedHex(root))
|
return { tornadoPool: tornadoPoolProxied, proxy, gov, messenger }
|
||||||
return { tornadoPool }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Upgradeability tests', () => {
|
describe('Upgradeability tests', () => {
|
||||||
let tornadoPool, proxy
|
|
||||||
before(async () => {
|
|
||||||
;({ tornadoPool } = await loadFixture(fixture))
|
|
||||||
const CrossChainUpgradeableProxy = await ethers.getContractFactory('CrossChainUpgradeableProxy')
|
|
||||||
proxy = CrossChainUpgradeableProxy.attach(tornadoPool.address)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('admin should be gov', async () => {
|
it('admin should be gov', async () => {
|
||||||
|
const { proxy, messenger, gov } = await loadFixture(fixtureUpgradeable)
|
||||||
const { data } = await proxy.populateTransaction.admin()
|
const { data } = await proxy.populateTransaction.admin()
|
||||||
const { result } = await messenger.callStatic.execute(proxy.address, data)
|
const { result } = await messenger.callStatic.execute(proxy.address, data)
|
||||||
expect('0x' + result.slice(26)).to.be.equal(gov.address.toLowerCase())
|
expect('0x' + result.slice(26)).to.be.equal(gov.address.toLowerCase())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non admin cannot call', async () => {
|
it('non admin cannot call', async () => {
|
||||||
|
const { proxy } = await loadFixture(fixtureUpgradeable)
|
||||||
await expect(proxy.admin()).to.be.revertedWith(
|
await expect(proxy.admin()).to.be.revertedWith(
|
||||||
"Transaction reverted: function selector was not recognized and there's no fallback function",
|
"Transaction reverted: function selector was not recognized and there's no fallback function",
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user