fix tests & remove fucking bugged hardhat fixtures

This commit is contained in:
ButterflyEffect 2023-10-26 10:00:04 +00:00
parent c9eb84d312
commit 491cfc20be
2 changed files with 39 additions and 40 deletions

@ -1,22 +1,34 @@
const { loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { expect, assert } = require("chai");
const { ethers, network, config } = require("hardhat");
const {
sendMinimalStakeAmount,
resolveAddr,
getEnsRegistryContract,
getOldRelayerRegistryContractFixture,
getOldRelayerRegistryContract,
getRegisterRelayerParams,
getManyEth,
deployAndExecuteFixture,
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 () {
await loadFixture(getOldRelayerRegistryContractFixture);
const { relayerRegistryProxyAddr, deployedRegistryAddr } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryProxyAddr, deployedRegistryAddr } = await deployAndExecuteProposal();
const implementation = await ethers.provider.getStorage(
relayerRegistryProxyAddr,
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
@ -30,13 +42,13 @@ describe("Registry update", function () {
it("Uregister relayer function should work", async function () {
const testRelayerAddr = await resolveAddr("first-relayer.eth");
const relayerRegistryOldContract = await loadFixture(getOldRelayerRegistryContractFixture);
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 loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
await unregisterRelayer(testRelayerAddr);
isRelayer = await relayerRegistryContract.isRelayer(testRelayerAddr);
@ -48,7 +60,7 @@ describe("Registry update", function () {
it("Unregistered relayer should have zero balance", async function () {
const testRelayerAddr = await resolveAddr("first-relayer.eth");
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
await unregisterRelayer(testRelayerAddr);
const relayerBalance = await relayerRegistryContract.getRelayerBalance(testRelayerAddr);
@ -56,7 +68,7 @@ describe("Registry update", function () {
});
it("Unregister function should revert if called not by Governance", async function () {
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
const me = await resolveAddr("🦋️-effect.eth");
await getManyEth(me);
@ -70,10 +82,10 @@ describe("Registry update", function () {
});
it("Tornado router address should be valid", async function () {
const relayerRegistryOldContract = await loadFixture(getOldRelayerRegistryContractFixture);
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
const oldRegistryRouterAddress = await relayerRegistryOldContract.tornadoRouter();
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
expect(await relayerRegistryContract.tornadoRouter()).to.equal(oldRegistryRouterAddress);
});
@ -90,7 +102,7 @@ describe("Registry update", function () {
]);
const oldData = await callAggr();
await loadFixture(deployAndExecuteFixture);
await deployAndExecuteProposal();
await unregisterRelayer(testRelayer);
const newData = await callAggr();
@ -113,14 +125,14 @@ describe("Registry update", function () {
].map(resolveAddr),
);
const relayerRegistryOldContract = await loadFixture(getOldRelayerRegistryContractFixture);
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 loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.isRelayer(r)));
balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.getRelayerBalance(r)));
@ -130,7 +142,7 @@ describe("Registry update", function () {
});
it("Unregistered relayers can register again", async function () {
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
const relayerEns = "moon-relayer.eth";
const unregisteredRelayer = await resolveAddr(relayerEns);
const toStake = await sendMinimalStakeAmount(unregisteredRelayer);
@ -158,7 +170,7 @@ describe("Registry update", function () {
});
it("Registering relayer with wrapped ENS domain should revert", async function () {
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const { relayerRegistryContract } = await deployAndExecuteProposal();
const relayerWrappedEns = "butterfly-attractor.eth";
const registerParams = await getRegisterRelayerParams(relayerWrappedEns);
const [relayer] = await ethers.getSigners();
@ -168,31 +180,20 @@ describe("Registry update", function () {
});
it("After ENS domain unwrapping owner can register relayer", async function () {
const { relayerRegistryProxyAddr } = await loadFixture(deployAndExecuteFixture);
await deployAndExecuteProposal();
const ensWrapperAddr = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
const wrappedEnsDomain = "butterfly-attractor.eth";
const addr = await resolveAddr(wrappedEnsDomain);
const ensContract = await getEnsRegistryContract();
const wrapperContract = await ethers.getContractAt(require("./abi/ensWrapper.abi.json"), ensWrapperAddr);
const labelhash = ethers.keccak256(ethers.toUtf8Bytes(wrappedEnsDomain.split(".")[0]));
console.log(await ensContract.owner(ethers.namehash(wrappedEnsDomain)));
console.log(await ethers.provider.getBlockNumber());
await wrapperContract.unwrapETH2LD(labelhash, addr, addr);
console.log(await ensContract.owner(ethers.namehash(wrappedEnsDomain)));
console.log(await ethers.provider.getBlockNumber());
console.log(await network.provider.send("evm_mine"));
console.log(await ethers.provider.getBlockNumber());
const [relayerSigner] = await ethers.getSigners();
const relayerRegistry = await ethers.getContractAt(
require("./abi/relayerRegistry.abi.json"),
relayerRegistryProxyAddr,
relayerSigner,
);
const relayerSigner = await ethers.getSigner(addr);
const relayerRegistryContract = await getRelayerRegistryContract(relayerSigner);
const registerParams = await getRegisterRelayerParams(wrappedEnsDomain);
await relayerRegistry.registerPermit(...registerParams);
await relayerRegistryContract.registerPermit(...registerParams);
expect(await relayerRegistry.isRelayerRegistered(addr, addr)).to.be.equal(true);
expect(await relayerRegistryContract.isRelayerRegistered(addr, addr)).to.be.equal(true);
});
});
});

@ -1,7 +1,5 @@
const { ethers, network } = require("hardhat");
const { time, loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { keccak256, toUtf8Bytes } = require("ethers");
const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const ensAddr = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
const relayerRegistryProxyAddr = "0x58E8dCC13BE9780fC42E8723D8EaD4CF46943dF2";
const tornAddr = "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C";
@ -90,7 +88,7 @@ async function getRelayerRegistryContract(signer) {
return await ethers.getContractAt("RelayerRegistry", relayerRegistryProxyAddr, signer);
}
async function getOldRelayerRegistryContractFixture() {
async function getOldRelayerRegistryContract() {
return await ethers.getContractAt(require("./abi/relayerRegistryOld.abi.json"), relayerRegistryProxyAddr);
}
@ -99,7 +97,7 @@ async function getManyEth(addr) {
}
async function sendMinimalStakeAmount(addr, additionalStake = 0n) {
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
const relayerRegistryContract = await getRelayerRegistryContract();
const minRelayerStakeAmount = await relayerRegistryContract.minStakeAmount();
const governanceSigner = await ethers.getImpersonatedSigner(governanceAddr);
const tornContract = await ethers.getContractAt(require("./abi/torn.abi.json"), tornAddr, governanceSigner);
@ -108,7 +106,7 @@ async function sendMinimalStakeAmount(addr, additionalStake = 0n) {
return minRelayerStakeAmount + additionalStake;
}
async function deployAndExecuteFixture() {
async function deployAndExecuteProposal() {
const RelayerRegistryFactory = await ethers.getContractFactory("RelayerRegistry");
const constructorArgs = [
tornAddr,
@ -158,12 +156,12 @@ async function unregisterRelayer(ensNameOrAddress) {
module.exports = {
sendMinimalStakeAmount,
getEnsRegistryContract,
getOldRelayerRegistryContractFixture,
getOldRelayerRegistryContract,
getRelayerRegistryContract,
getPermitSignature,
resolveAddr,
getManyEth,
unregisterRelayer,
deployAndExecuteFixture,
deployAndExecuteProposal,
getRegisterRelayerParams,
};