proposal-36/test/RelayerRegistry.js

175 lines
8.2 KiB
JavaScript
Raw Normal View History

2023-11-09 17:04:09 +03:00
const { expect, assert } = require("chai");
const { ethers, network, config } = require("hardhat");
const {
resolveAddr,
getRegisterRelayerParams,
deployAndExecuteProposal,
getRelayerRegistryContract,
getRelayerBalance,
2023-11-10 04:23:13 +03:00
getEnsRegistryContract,
2023-11-09 17:04:09 +03:00
governanceAddr,
2023-11-10 04:23:13 +03:00
getManyEth,
2023-11-09 17:04:09 +03:00
} = 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);
});
2023-11-10 04:23:13 +03:00
describe("Restore relayers", async function () {
2023-11-09 17:04:09 +03:00
const blockBeforeProposal32Execution = 18484836;
const unregisteredByMistake = ["reltor.eth", "relayer007.eth", "k-relayer.eth"];
2023-11-10 04:23:13 +03:00
const unregisteredAddrs = [
"0x4750BCfcC340AA4B31be7e71fa072716d28c29C5",
"0xa0109274F53609f6Be97ec5f3052C659AB80f012",
"0xC49415493eB3Ec64a0F13D8AA5056f1CfC4ce35c",
];
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Relayer ENS names links to mistakenly unregistered relayers", async function () {
2023-11-09 17:04:09 +03:00
const maybeUnregisteredAddrs = await Promise.all(unregisteredByMistake.map(resolveAddr));
2023-11-10 04:23:13 +03:00
2023-11-09 17:04:09 +03:00
expect(maybeUnregisteredAddrs.map(ethers.getAddress)).to.deep.equal(unregisteredAddrs);
2023-11-10 04:23:13 +03:00
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Current balance of mistakenly unregistered relayers should be zero", async function () {
const balances = await Promise.all(unregisteredAddrs.map((addr) => getRelayerBalance(addr)));
2023-11-09 17:04:09 +03:00
expect(balances).to.deep.equal([0, 0, 0]);
2023-11-10 04:23:13 +03:00
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Mistakenly unregistered relayers should be really unregistered before proposal", async function () {
2023-11-09 17:04:09 +03:00
const relayerRegistryContract = await getRelayerRegistryContract();
2023-11-10 04:23:13 +03:00
const areWorkers = await Promise.all(unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayer(addr)));
const areRelayers = await Promise.all(
unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayerRegistered(addr, addr)),
);
2023-11-09 17:04:09 +03:00
expect(areWorkers).to.deep.equal([false, false, false]);
expect(areRelayers).to.deep.equal([false, false, false]);
2023-11-10 04:23:13 +03:00
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Should return before-proposal to mistakenly unregistered relayers and register them again", async function () {
const relayerBalancesOld = await Promise.all(
unregisteredAddrs.map((addr) => getRelayerBalance(addr, blockBeforeProposal32Execution)),
);
2023-11-09 17:04:09 +03:00
const { relayerRegistryContract } = await deployAndExecuteProposal();
2023-11-10 04:23:13 +03:00
const relayerBalancesNew = await Promise.all(unregisteredAddrs.map((addr) => getRelayerBalance(addr)));
const areWorkers = await Promise.all(unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayer(addr)));
const areRelayers = await Promise.all(
unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayerRegistered(addr, addr)),
);
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
expect(relayerBalancesNew).to.deep.equal(relayerBalancesOld);
2023-11-09 17:04:09 +03:00
expect(relayerBalancesNew).satisfy((b) => b.every((b) => b < 20000n * 10n ** 18n && b > 10000n * 10n ** 18n));
expect(areWorkers).to.deep.equal([true, true, true]);
expect(areRelayers).to.deep.equal([true, true, true]);
2023-11-10 04:23:13 +03:00
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Should register relayer even if someone steal address as a worker", async function () {
2023-11-09 17:04:09 +03:00
await deployAndExecuteProposal();
const realRelayer = await resolveAddr("torrelayer.eth");
const relayerSigner = await ethers.getImpersonatedSigner(realRelayer);
let relayerRegistryContract = await getRelayerRegistryContract(relayerSigner);
expect(await relayerRegistryContract.isRelayerRegistered(realRelayer, realRelayer)).to.be.equal(true);
const ensWrapperAddr = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
const wrappedEnsDomain = "butterfly-attractor.eth";
const addr = await resolveAddr(wrappedEnsDomain);
await relayerRegistryContract.registerWorker(realRelayer, addr); // Register my address as a worker
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 myRelayerSigner = await ethers.getSigner(addr);
relayerRegistryContract = relayerRegistryContract.connect(myRelayerSigner);
const registerParams = await getRegisterRelayerParams(wrappedEnsDomain);
await expect(relayerRegistryContract.registerPermit(...registerParams)).to.be.revertedWith("cant register again");
const governanceSigner = await ethers.getImpersonatedSigner(governanceAddr);
relayerRegistryContract = relayerRegistryContract.connect(governanceSigner);
await relayerRegistryContract.registerRelayerAdmin(addr, wrappedEnsDomain, 2000n * 10n ** 18n);
expect(await relayerRegistryContract.isRelayer(addr)).to.be.equal(true);
expect(await relayerRegistryContract.isRelayerRegistered(addr, addr)).to.be.equal(true);
expect(await getRelayerBalance(addr)).to.be.equal(2000n * 10n ** 18n);
2023-11-10 04:23:13 +03:00
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Should revert if trying to register existing relayer via Governance", async function () {
2023-11-09 17:04:09 +03:00
const { relayerRegistryContract } = await deployAndExecuteProposal();
const realRelayerDomain = "torrelayer.eth";
const realRelayer = await resolveAddr(realRelayerDomain);
2023-11-10 04:23:13 +03:00
await expect(relayerRegistryContract.registerRelayerAdmin(realRelayer, realRelayerDomain, 1)).to.be.revertedWith(
"cant register again",
);
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Should revert if trying to register relayer with domain that he not own", async function () {
2023-11-09 17:04:09 +03:00
const { relayerRegistryContract } = await deployAndExecuteProposal();
const someDomain = "vitalik.eth";
const me = "0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4";
2023-11-10 04:23:13 +03:00
await expect(relayerRegistryContract.registerRelayerAdmin(me, someDomain, 1)).to.be.revertedWith(
"only ens domain owner",
);
});
2023-11-09 17:04:09 +03:00
2023-11-10 04:23:13 +03:00
it("Admin register function should fail, if called not from Governance", async function () {
2023-11-09 17:04:09 +03:00
await deployAndExecuteProposal();
const me = "0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4";
const meAsSigner = await ethers.getImpersonatedSigner(me);
const relayerRegistryContract = await getRelayerRegistryContract(meAsSigner);
2023-11-10 04:23:13 +03:00
await expect(relayerRegistryContract.registerRelayerAdmin(me, "butterfly-attractor.eth", 1)).to.be.revertedWith(
"only governance",
);
});
it("Proposal execution should not fail, if one relayer can not be registered", async function () {
const relayerEns = "reltor.eth";
const relayerAddr = await resolveAddr("reltor.eth");
const relayerSigner = await ethers.getImpersonatedSigner(relayerAddr);
const me = "0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4";
const ens = await getEnsRegistryContract(relayerSigner);
await getManyEth(relayerAddr);
await ens.setOwner(ethers.namehash(relayerEns), me);
expect(await ens.owner(ethers.namehash(relayerEns))).to.be.equal(me);
const { relayerRegistryContract } = await deployAndExecuteProposal();
await expect(relayerRegistryContract.registerRelayerAdmin(relayerAddr, relayerEns, 1)).to.be.revertedWith(
"only ens domain owner",
);
const areWorkers = await Promise.all(unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayer(addr)));
const areRelayers = await Promise.all(
unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayerRegistered(addr, addr)),
);
expect(relayerAddr).to.be.equal(unregisteredAddrs[0]);
expect(relayerEns).to.be.equal(unregisteredByMistake[0]);
expect(areRelayers).to.deep.equal([false, true, true]);
expect(areWorkers).to.deep.equal([false, true, true]);
});
});
2023-11-09 17:04:09 +03:00
});