175 lines
8.2 KiB
JavaScript
175 lines
8.2 KiB
JavaScript
const { expect, assert } = require("chai");
|
|
const { ethers, network, config } = require("hardhat");
|
|
const {
|
|
resolveAddr,
|
|
getRegisterRelayerParams,
|
|
deployAndExecuteProposal,
|
|
getRelayerRegistryContract,
|
|
getRelayerBalance,
|
|
getEnsRegistryContract,
|
|
governanceAddr,
|
|
getManyEth,
|
|
} = 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("Restore relayers", async function () {
|
|
const blockBeforeProposal32Execution = 18484836;
|
|
const unregisteredByMistake = ["reltor.eth", "relayer007.eth", "k-relayer.eth"];
|
|
const unregisteredAddrs = [
|
|
"0x4750BCfcC340AA4B31be7e71fa072716d28c29C5",
|
|
"0xa0109274F53609f6Be97ec5f3052C659AB80f012",
|
|
"0xC49415493eB3Ec64a0F13D8AA5056f1CfC4ce35c",
|
|
];
|
|
|
|
it("Relayer ENS names links to mistakenly unregistered relayers", async function () {
|
|
const maybeUnregisteredAddrs = await Promise.all(unregisteredByMistake.map(resolveAddr));
|
|
|
|
expect(maybeUnregisteredAddrs.map(ethers.getAddress)).to.deep.equal(unregisteredAddrs);
|
|
});
|
|
|
|
it("Current balance of mistakenly unregistered relayers should be zero", async function () {
|
|
const balances = await Promise.all(unregisteredAddrs.map((addr) => getRelayerBalance(addr)));
|
|
|
|
expect(balances).to.deep.equal([0, 0, 0]);
|
|
});
|
|
|
|
it("Mistakenly unregistered relayers should be really unregistered before proposal", async function () {
|
|
const relayerRegistryContract = await getRelayerRegistryContract();
|
|
const areWorkers = await Promise.all(unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayer(addr)));
|
|
const areRelayers = await Promise.all(
|
|
unregisteredAddrs.map((addr) => relayerRegistryContract.isRelayerRegistered(addr, addr)),
|
|
);
|
|
|
|
expect(areWorkers).to.deep.equal([false, false, false]);
|
|
expect(areRelayers).to.deep.equal([false, false, false]);
|
|
});
|
|
|
|
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)),
|
|
);
|
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
|
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)),
|
|
);
|
|
|
|
expect(relayerBalancesNew).to.deep.equal(relayerBalancesOld);
|
|
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]);
|
|
});
|
|
|
|
it("Should register relayer even if someone steal address as a worker", async function () {
|
|
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);
|
|
});
|
|
|
|
it("Should revert if trying to register existing relayer via Governance", async function () {
|
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
|
const realRelayerDomain = "torrelayer.eth";
|
|
const realRelayer = await resolveAddr(realRelayerDomain);
|
|
|
|
await expect(relayerRegistryContract.registerRelayerAdmin(realRelayer, realRelayerDomain, 1)).to.be.revertedWith(
|
|
"cant register again",
|
|
);
|
|
});
|
|
|
|
it("Should revert if trying to register relayer with domain that he not own", async function () {
|
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
|
const someDomain = "vitalik.eth";
|
|
const me = "0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4";
|
|
|
|
await expect(relayerRegistryContract.registerRelayerAdmin(me, someDomain, 1)).to.be.revertedWith(
|
|
"only ens domain owner",
|
|
);
|
|
});
|
|
|
|
it("Admin register function should fail, if called not from Governance", async function () {
|
|
await deployAndExecuteProposal();
|
|
const me = "0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4";
|
|
const meAsSigner = await ethers.getImpersonatedSigner(me);
|
|
const relayerRegistryContract = await getRelayerRegistryContract(meAsSigner);
|
|
|
|
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]);
|
|
});
|
|
});
|
|
});
|