add tests layout

This commit is contained in:
Drygin 2022-02-24 13:54:13 +03:00
parent 24bb042a64
commit eabb8c1fbc
8 changed files with 127 additions and 58 deletions

View File

@ -1,4 +1,4 @@
# Tornado smart contract data aggregator
# Tornado smart contract data aggregator
[![Build Status](https://github.com/tornadocash/tornado-aggregator/workflows/build/badge.svg)](https://github.com/tornadocash/tornado-aggregator/actions)

10
config.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
governance: '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce',
instanceRegistry: '0xB20c66C4DE72433F3cE747b58B86830c459CA911',
router: '0xd90e2f925DA726b50C4Ed8D0Fb90Ad053324F31b',
singletonFactory: '0xce0042B868300000d44A59004Da54A005ffdcf9f',
singletonFactoryVerboseWrapper: '0xCEe71753C9820f063b38FDbE4cFDAf1d3D928A80',
salt: '0x0000000000000000000000000000000000000000000000000000000047941987',
TORN: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
tornWhale: '0xF977814e90dA44bFA03b6295A0616a897441aceC',
}

View File

@ -45,6 +45,6 @@
"dependencies": {
"tornado-anonymity-mining": "^1.0.0",
"tornado-governance": "v1.0.0",
"torn-token": "^1.0.0"
"torn-token": "^1.0.4"
}
}

22
scripts/deploy.js Normal file
View File

@ -0,0 +1,22 @@
const { ethers } = require('hardhat')
const config = require('../config')
async function main() {
const [deployer] = await ethers.getSigners()
console.log('Deploying contracts with the account:', deployer.address)
console.log('Account balance:', (await deployer.getBalance()).toString())
const AggregatorFactory = await ethers.getContractFactory('Aggregator')
const aggregator = await AggregatorFactory.deploy()
console.log('Aggregator address:', aggregator.address)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})

View File

@ -1,55 +0,0 @@
// This module is used only for tests
function send(method, params = []) {
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-undef
web3.currentProvider.send(
{
jsonrpc: '2.0',
id: Date.now(),
method,
params,
},
(err, res) => {
return err ? reject(err) : resolve(res)
},
)
})
}
const takeSnapshot = async () => {
return await send('evm_snapshot')
}
const traceTransaction = async (tx) => {
return await send('debug_traceTransaction', [tx, {}])
}
const revertSnapshot = async (id) => {
await send('evm_revert', [id])
}
const mineBlock = async (timestamp) => {
await send('evm_mine', [timestamp])
}
const increaseTime = async (seconds) => {
await send('evm_increaseTime', [seconds])
}
const minerStop = async () => {
await send('miner_stop', [])
}
const minerStart = async () => {
await send('miner_start', [])
}
module.exports = {
takeSnapshot,
revertSnapshot,
mineBlock,
minerStop,
minerStart,
increaseTime,
traceTransaction,
}

39
test/aggregator.test.js Normal file
View File

@ -0,0 +1,39 @@
const hre = require('hardhat')
const { ethers, waffle } = hre
const { loadFixture } = waffle
const { expect } = require('chai')
const { BigNumber } = require('@ethersproject/bignumber')
const config = require('../config')
const { getSignerFromAddress, minewait } = require('./utils')
describe('Aggregator Tests', () => {
async function fixture() {
const [sender] = await ethers.getSigners()
const tornWhale = await getSignerFromAddress(config.tornWhale)
const gov = await ethers.getContractAt('Governance', config.governance)
const tornToken = await ethers.getContractAt(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20',
config.TORN,
)
// deploy Aggregator
const AggregatorFactory = await ethers.getContractFactory('Aggregator')
const aggregator = await AggregatorFactory.deploy()
return {
sender,
tornWhale,
gov,
tornToken,
aggregator,
}
}
it('Should have initialized all successfully', async function () {
const { aggregator } = await loadFixture(fixture)
expect(aggregator.address).to.exist
})
})

43
test/utils.js Normal file
View File

@ -0,0 +1,43 @@
/* 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
}
async function minewait(time) {
await ethers.provider.send('evm_increaseTime', [time])
await ethers.provider.send('evm_mine', [])
}
module.exports = {
setTime,
advanceTime,
takeSnapshot,
revertSnapshot,
getSignerFromAddress,
minewait,
}

View File

@ -8891,6 +8891,16 @@ torn-token@^1.0.0:
ethereumjs-util "^7.0.3"
web3 "^1.2.11"
torn-token@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/torn-token/-/torn-token-1.0.6.tgz#66cde5f85b611033918c807b4a8d9d4e5bb3fcfc"
integrity sha512-ilCS7fN+JM2O8l1Iw5cEWXyiQQg8GxEeYYvqALJcn5cO6qSpD+xJb3Dji4EHXa1Yu1OBd/19ktWNvUkWNvuAaQ==
dependencies:
"@openzeppelin/contracts" "^3.1.0"
eth-sig-util "^2.5.3"
ethereumjs-util "^7.0.3"
web3 "^1.2.11"
tornado-anonymity-mining@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/tornado-anonymity-mining/-/tornado-anonymity-mining-1.0.0.tgz#179485e97ec83665ffce72f0813168bc513e26e3"
@ -8904,7 +8914,7 @@ tornado-anonymity-mining@^1.0.0:
web3 "^1.2.11"
websnark "git+https://github.com/tornadocash/websnark.git#86a526718cd6f6f5d31bdb1fe26a9ec8819f633e"
tornado-governance@v1.0.0:
tornado-governance@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/tornado-governance/-/tornado-governance-1.0.0.tgz#eb3632a9a8a2b480f69e26a6e6b91a606fbbc334"
integrity sha512-4WPkdOgZGoR8aWYAiaC4c/NgtiEU8XwN6xpyQMo0GcoVjmJRNlZBbGY7WAqMX0Yvohc1p4JPZOyZaEEBFaVodA==