proposal-32/test/RelayerRegistry.js

200 lines
8.5 KiB
JavaScript

const { expect, assert } = require("chai");
const { ethers, network, config } = require("hardhat");
const {
sendMinimalStakeAmount,
resolveAddr,
getEnsRegistryContract,
getOldRelayerRegistryContract,
getRegisterRelayerParams,
getManyEth,
deployAndExecuteProposal,
unregisterRelayer,
getRelayerRegistryContract,
} = require("./utils");
describe("Registry update", 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("Implementation address should be updated", async function () {
const { relayerRegistryProxyAddr, deployedRegistryAddr } = await deployAndExecuteProposal();
const implementation = await ethers.provider.getStorage(
relayerRegistryProxyAddr,
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
);
const [implementationAddr] = new ethers.AbiCoder().decode(["address"], implementation);
expect(implementationAddr).to.equal(deployedRegistryAddr);
});
describe("Unregister relayer", function () {
it("Uregister relayer function should work", async function () {
const testRelayerAddr = await resolveAddr("first-relayer.eth");
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
let isRelayer = await relayerRegistryOldContract.isRelayer(testRelayerAddr);
let isRelayerRegistered = await relayerRegistryOldContract.isRelayerRegistered(testRelayerAddr, testRelayerAddr);
expect(isRelayer).to.equal(true);
expect(isRelayerRegistered).to.equal(true);
const { relayerRegistryContract } = await deployAndExecuteProposal();
await unregisterRelayer(testRelayerAddr);
isRelayer = await relayerRegistryContract.isRelayer(testRelayerAddr);
isRelayerRegistered = await relayerRegistryContract.isRelayerRegistered(testRelayerAddr, testRelayerAddr);
expect(isRelayer).to.equal(false);
expect(isRelayerRegistered).to.equal(false);
});
it("Unregistered relayer should have zero balance", async function () {
const testRelayerAddr = await resolveAddr("first-relayer.eth");
const { relayerRegistryContract } = await deployAndExecuteProposal();
await unregisterRelayer(testRelayerAddr);
const relayerBalance = await relayerRegistryContract.getRelayerBalance(testRelayerAddr);
expect(relayerBalance).to.equal(0);
});
it("Unregister function should revert if called not by Governance", async function () {
const { relayerRegistryContract } = await deployAndExecuteProposal();
const me = await resolveAddr("🦋️-effect.eth");
await getManyEth(me);
const meAsSigner = await ethers.getImpersonatedSigner(me);
const testRelayerAddr = await resolveAddr("first-relayer.eth");
const relayerRegistryWithMeAsSigner = relayerRegistryContract.connect(meAsSigner);
await expect(relayerRegistryWithMeAsSigner.unregisterRelayer(testRelayerAddr)).to.be.revertedWith(
"only governance",
);
});
it("Tornado router address should be valid", async function () {
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
const oldRegistryRouterAddress = await relayerRegistryOldContract.tornadoRouter();
const { relayerRegistryContract } = await deployAndExecuteProposal();
expect(await relayerRegistryContract.tornadoRouter()).to.equal(oldRegistryRouterAddress);
});
it("Aggregator contract data for unregistered relayers should be valid", async function () {
const aggregatorAddr = "0xE8F47A78A6D52D317D0D2FFFac56739fE14D1b49";
const aggregatorContract = await ethers.getContractAt(require("./abi/aggregator.abi.json"), aggregatorAddr);
const notRelayer = "🦋️-effect.eth";
const testRelayer = "first-relayer.eth";
const callAggr = async () =>
await aggregatorContract.relayersData([notRelayer, testRelayer].map(ethers.namehash), [
"mainnet-tornado",
"bsc-tornado",
]);
const oldData = await callAggr();
await deployAndExecuteProposal();
await unregisterRelayer(testRelayer);
const newData = await callAggr();
assert.deepEqual(oldData[0], newData[0]);
expect(oldData[1][1]).to.greaterThan(500n * 10n ** 18n);
expect(newData[1][1]).to.equal(0);
expect(oldData[1][2]).to.equal(true);
expect(newData[1][2]).to.equal(false);
});
it("Cheating relayers should be unregistered", async function () {
const cheatingRelayers = await Promise.all(
[
"available-reliable-relayer.eth",
"0xtornadocash.eth",
"0xtorn365.eth",
"tornrelayers.eth",
"moon-relayer.eth",
].map(resolveAddr),
);
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
let areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.isRelayer(r)));
let balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.getRelayerBalance(r)));
expect(areRegistered).satisfy((v) => v.every((v) => v === true));
expect(balances).satisfy((v) => v.every((v) => v >= 0n));
const { relayerRegistryContract } = await deployAndExecuteProposal();
areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.isRelayer(r)));
balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.getRelayerBalance(r)));
expect(areRegistered).satisfy((v) => v.every((v) => v === false));
expect(balances).satisfy((v) => v.every((v) => v === 0n));
});
});
it("Unregistered relayers can register again", async function () {
const { relayerRegistryContract } = await deployAndExecuteProposal();
const relayerEns = "moon-relayer.eth";
const unregisteredRelayer = await resolveAddr(relayerEns);
const toStake = await sendMinimalStakeAmount(unregisteredRelayer);
const relayerSigner = await ethers.getImpersonatedSigner(unregisteredRelayer);
await relayerRegistryContract.connect(relayerSigner).register(relayerEns, toStake, []);
const isRelayerRegistered = await relayerRegistryContract.isRelayerRegistered(
unregisteredRelayer,
unregisteredRelayer,
);
const relayerBalance = await relayerRegistryContract.getRelayerBalance(unregisteredRelayer);
expect(isRelayerRegistered).to.be.equal(true);
expect(relayerBalance).to.be.equal(toStake);
});
describe("Fix ENS owner checks", async function () {
it("ENS owner of wrapped domain should be a wrapper", async function () {
const wrappedDomain = "butterfly-attractor.eth";
const realOwner = await resolveAddr(wrappedDomain);
const ensRegistry = await getEnsRegistryContract();
const wrapperOwner = await ensRegistry.owner(ethers.namehash(wrappedDomain));
expect(wrapperOwner).to.be.not.equal(realOwner);
});
it("Registering relayer with wrapped ENS domain should revert", async function () {
const { relayerRegistryContract } = await deployAndExecuteProposal();
const relayerWrappedEns = "butterfly-attractor.eth";
const registerParams = await getRegisterRelayerParams(relayerWrappedEns);
const [relayer] = await ethers.getSigners();
const relayerRegistry = relayerRegistryContract.connect(relayer);
await expect(relayerRegistry.registerPermit(...registerParams)).to.be.revertedWith("only unwrapped ens domains");
});
it("After ENS domain unwrapping owner can register relayer", async function () {
await deployAndExecuteProposal();
const ensWrapperAddr = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
const wrappedEnsDomain = "butterfly-attractor.eth";
const addr = await resolveAddr(wrappedEnsDomain);
const wrapperContract = await ethers.getContractAt(require("./abi/ensWrapper.abi.json"), ensWrapperAddr);
const labelhash = ethers.keccak256(ethers.toUtf8Bytes(wrappedEnsDomain.split(".")[0]));
await wrapperContract.unwrapETH2LD(labelhash, addr, addr);
const relayerSigner = await ethers.getSigner(addr);
const relayerRegistryContract = await getRelayerRegistryContract(relayerSigner);
const registerParams = await getRegisterRelayerParams(wrappedEnsDomain);
await relayerRegistryContract.registerPermit(...registerParams);
expect(await relayerRegistryContract.isRelayerRegistered(addr, addr)).to.be.equal(true);
});
});
});