108 lines
4.0 KiB
JavaScript
108 lines
4.0 KiB
JavaScript
const { ethers, network } = require("hardhat");
|
|
const contentHash = require('content-hash')
|
|
const { expect, assert } = require("chai");
|
|
const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
|
|
|
|
const tornAddr = "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C";
|
|
const governanceAddr = "0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce";
|
|
async function getManyEth(addr) {
|
|
await network.provider.send("hardhat_setBalance", [
|
|
addr,
|
|
"0x111166630153555558483537",
|
|
]);
|
|
}
|
|
|
|
async function getEnsRegistry(){
|
|
const ensAddr = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
|
|
return await ethers.getContractAt(require("./abi/ensRegistry.abi.json"), ensAddr);
|
|
}
|
|
|
|
async function getEnsResolver(ensName){
|
|
const ensRegistry = await getEnsRegistry();
|
|
const resolverAddr = await ensRegistry.resolver(ethers.namehash(ensName));
|
|
return await ethers.getContractAt(require("./abi/ensResolver.abi.json"), resolverAddr);
|
|
}
|
|
|
|
async function resolveAddr(ensName) {
|
|
if (ethers.isAddress(ensName)) return ensName;
|
|
const ensResolver = await getEnsResolver(ensName);
|
|
|
|
return await ensResolver.addr(ethers.namehash(ensName));
|
|
}
|
|
|
|
async function getTornContract() {
|
|
return await ethers.getContractAt(require("./abi/torn.abi.json"), tornAddr);
|
|
}
|
|
|
|
async function deployAndExecuteProposal() {
|
|
const proposalFactory = await ethers.getContractFactory("Proposal");
|
|
const proposal = await proposalFactory.deploy();
|
|
const deployedProposalAddr = await proposal.getAddress();
|
|
|
|
const bigStakerAddr = "0xAd0dC9b5bf4308Cc26C1d44E1BEB2d30c43Bca1b";
|
|
await getManyEth(bigStakerAddr);
|
|
const stakerSigner = await ethers.getImpersonatedSigner(bigStakerAddr);
|
|
const governanceContract = await ethers.getContractAt(
|
|
require("./abi/governance.abi.json"),
|
|
governanceAddr,
|
|
stakerSigner
|
|
);
|
|
await governanceContract.propose(deployedProposalAddr, "");
|
|
const proposalId = await governanceContract.proposalCount();
|
|
await time.increase(60 * 60);
|
|
await governanceContract.castVote(proposalId, true);
|
|
await time.increase(60 * 60 * 24 * 7 + 60);
|
|
await governanceContract.execute(proposalId);
|
|
await time.increase(60 * 60 * 24 * 4);
|
|
|
|
return governanceContract;
|
|
}
|
|
|
|
describe("Proposal results check", function () {
|
|
beforeEach(async function () {
|
|
await network.provider.request({
|
|
method: "hardhat_reset",
|
|
params: [
|
|
{
|
|
forking: {
|
|
jsonRpcUrl: config.networks.hardhat.forking.url,
|
|
blockNumber: config.networks.hardhat.forking.blockNumber,
|
|
},
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("New ENS names should be registered", async function(){
|
|
await deployAndExecuteProposal();
|
|
const ensRegistry = await getEnsRegistry();
|
|
const swapNode = ethers.namehash("swap.tornadocash.eth");
|
|
const swapSourceNode = ethers.namehash("swap.sources.tornadocash.eth");
|
|
|
|
expect(await ensRegistry.owner(swapNode)).to.be.equal(governanceAddr);
|
|
expect(await ensRegistry.owner(swapSourceNode)).to.be.equal(governanceAddr);
|
|
})
|
|
|
|
it("IPFS contenthashes on ENS should be correct", async function(){
|
|
await deployAndExecuteProposal();
|
|
const swapEns = "swap.tornadocash.eth";
|
|
const swapSourceEns = "swap.sources.tornadocash.eth";
|
|
const swapIpfs = "QmW1UsYYW3L7923uMGcHZ79gFcq9ZGuHSwUJnSkbp8b7FW";
|
|
const swapSourceIpfs = "QmZTwdrDNzFr6TcwUmroNMZ1o7vMdkpWSimkgH5gECDZt2";
|
|
const ensResolver = await getEnsResolver(swapEns);
|
|
|
|
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(swapEns)))).to.be.equal(swapIpfs);
|
|
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(swapSourceEns)))).to.be.equal(swapSourceIpfs);
|
|
})
|
|
|
|
it("Gas expenses should be compensated to me", async function () {
|
|
const tornContract = await getTornContract();
|
|
const me = await resolveAddr("butterfly-attractor.eth");
|
|
const initialTornBalance = await tornContract.balanceOf(me);
|
|
await deployAndExecuteProposal();
|
|
expect((await tornContract.balanceOf(me)) - initialTornBalance).to.be.equal(
|
|
200n * 10n ** 18n
|
|
);
|
|
});
|
|
});
|