mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
/* global ethers */
|
|
const { expect, should } = require('chai')
|
|
should()
|
|
|
|
const { poseidonHash2, toFixedHex, takeSnapshot, revertSnapshot } = require('../src/utils')
|
|
|
|
const MERKLE_TREE_HEIGHT = 5
|
|
const MerkleTree = require('fixed-merkle-tree')
|
|
|
|
const { deposit, transact, withdraw, merge } = require('../src/index')
|
|
|
|
describe('TornadoPool', () => {
|
|
let snapshotId, tornadoPool
|
|
|
|
/* prettier-ignore */
|
|
before(async function () {
|
|
const Verifier2 = await ethers.getContractFactory('Verifier2')
|
|
const verifier2 = await Verifier2.deploy()
|
|
await verifier2.deployed()
|
|
|
|
const Verifier16 = await ethers.getContractFactory('Verifier16')
|
|
const verifier16 = await Verifier16.deploy()
|
|
await verifier16.deployed()
|
|
|
|
const tree = new MerkleTree(MERKLE_TREE_HEIGHT, [], { hashFunction: poseidonHash2 })
|
|
const root = await tree.root()
|
|
|
|
const Pool = await ethers.getContractFactory('TornadoPool')
|
|
tornadoPool = await Pool.deploy(verifier2.address, verifier16.address, toFixedHex(root))
|
|
|
|
snapshotId = await takeSnapshot()
|
|
})
|
|
|
|
it('should deposit, transact and withdraw', async function () {
|
|
const utxo1 = await deposit({ tornadoPool })
|
|
const utxo2 = await transact({ tornadoPool, utxo: utxo1 })
|
|
|
|
const recipient = '0xc2Ba33d4c0d2A92fb4f1a07C273c5d21E688Eb48'
|
|
await withdraw({ tornadoPool, utxo: utxo2, recipient })
|
|
|
|
let bal = await ethers.provider.getBalance(recipient)
|
|
expect(bal).to.be.gt(0)
|
|
})
|
|
|
|
it('should work with 16 inputs', async function () {
|
|
const utxo1 = await merge({tornadoPool})
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await revertSnapshot(snapshotId)
|
|
snapshotId = await takeSnapshot()
|
|
})
|
|
})
|