fix tests & remove fucking bugged hardhat fixtures
This commit is contained in:
parent
c9eb84d312
commit
491cfc20be
@ -1,22 +1,34 @@
|
|||||||
const { loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
|
|
||||||
const { expect, assert } = require("chai");
|
const { expect, assert } = require("chai");
|
||||||
const { ethers, network, config } = require("hardhat");
|
const { ethers, network, config } = require("hardhat");
|
||||||
const {
|
const {
|
||||||
sendMinimalStakeAmount,
|
sendMinimalStakeAmount,
|
||||||
resolveAddr,
|
resolveAddr,
|
||||||
getEnsRegistryContract,
|
getEnsRegistryContract,
|
||||||
getOldRelayerRegistryContractFixture,
|
getOldRelayerRegistryContract,
|
||||||
getRegisterRelayerParams,
|
getRegisterRelayerParams,
|
||||||
getManyEth,
|
getManyEth,
|
||||||
deployAndExecuteFixture,
|
deployAndExecuteProposal,
|
||||||
unregisterRelayer,
|
unregisterRelayer,
|
||||||
getRelayerRegistryContract,
|
getRelayerRegistryContract,
|
||||||
} = require("./utils");
|
} = require("./utils");
|
||||||
|
|
||||||
describe("Registry update", function () {
|
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 () {
|
it("Implementation address should be updated", async function () {
|
||||||
await loadFixture(getOldRelayerRegistryContractFixture);
|
const { relayerRegistryProxyAddr, deployedRegistryAddr } = await deployAndExecuteProposal();
|
||||||
const { relayerRegistryProxyAddr, deployedRegistryAddr } = await loadFixture(deployAndExecuteFixture);
|
|
||||||
const implementation = await ethers.provider.getStorage(
|
const implementation = await ethers.provider.getStorage(
|
||||||
relayerRegistryProxyAddr,
|
relayerRegistryProxyAddr,
|
||||||
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
|
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
|
||||||
@ -30,13 +42,13 @@ describe("Registry update", function () {
|
|||||||
it("Uregister relayer function should work", async function () {
|
it("Uregister relayer function should work", async function () {
|
||||||
const testRelayerAddr = await resolveAddr("first-relayer.eth");
|
const testRelayerAddr = await resolveAddr("first-relayer.eth");
|
||||||
|
|
||||||
const relayerRegistryOldContract = await loadFixture(getOldRelayerRegistryContractFixture);
|
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
|
||||||
let isRelayer = await relayerRegistryOldContract.isRelayer(testRelayerAddr);
|
let isRelayer = await relayerRegistryOldContract.isRelayer(testRelayerAddr);
|
||||||
let isRelayerRegistered = await relayerRegistryOldContract.isRelayerRegistered(testRelayerAddr, testRelayerAddr);
|
let isRelayerRegistered = await relayerRegistryOldContract.isRelayerRegistered(testRelayerAddr, testRelayerAddr);
|
||||||
expect(isRelayer).to.equal(true);
|
expect(isRelayer).to.equal(true);
|
||||||
expect(isRelayerRegistered).to.equal(true);
|
expect(isRelayerRegistered).to.equal(true);
|
||||||
|
|
||||||
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
||||||
await unregisterRelayer(testRelayerAddr);
|
await unregisterRelayer(testRelayerAddr);
|
||||||
|
|
||||||
isRelayer = await relayerRegistryContract.isRelayer(testRelayerAddr);
|
isRelayer = await relayerRegistryContract.isRelayer(testRelayerAddr);
|
||||||
@ -48,7 +60,7 @@ describe("Registry update", function () {
|
|||||||
|
|
||||||
it("Unregistered relayer should have zero balance", async function () {
|
it("Unregistered relayer should have zero balance", async function () {
|
||||||
const testRelayerAddr = await resolveAddr("first-relayer.eth");
|
const testRelayerAddr = await resolveAddr("first-relayer.eth");
|
||||||
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
||||||
await unregisterRelayer(testRelayerAddr);
|
await unregisterRelayer(testRelayerAddr);
|
||||||
|
|
||||||
const relayerBalance = await relayerRegistryContract.getRelayerBalance(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 () {
|
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");
|
const me = await resolveAddr("🦋️-effect.eth");
|
||||||
await getManyEth(me);
|
await getManyEth(me);
|
||||||
@ -70,10 +82,10 @@ describe("Registry update", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Tornado router address should be valid", async 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 oldRegistryRouterAddress = await relayerRegistryOldContract.tornadoRouter();
|
||||||
|
|
||||||
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
||||||
expect(await relayerRegistryContract.tornadoRouter()).to.equal(oldRegistryRouterAddress);
|
expect(await relayerRegistryContract.tornadoRouter()).to.equal(oldRegistryRouterAddress);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -90,7 +102,7 @@ describe("Registry update", function () {
|
|||||||
]);
|
]);
|
||||||
const oldData = await callAggr();
|
const oldData = await callAggr();
|
||||||
|
|
||||||
await loadFixture(deployAndExecuteFixture);
|
await deployAndExecuteProposal();
|
||||||
await unregisterRelayer(testRelayer);
|
await unregisterRelayer(testRelayer);
|
||||||
|
|
||||||
const newData = await callAggr();
|
const newData = await callAggr();
|
||||||
@ -113,14 +125,14 @@ describe("Registry update", function () {
|
|||||||
].map(resolveAddr),
|
].map(resolveAddr),
|
||||||
);
|
);
|
||||||
|
|
||||||
const relayerRegistryOldContract = await loadFixture(getOldRelayerRegistryContractFixture);
|
const relayerRegistryOldContract = await getOldRelayerRegistryContract();
|
||||||
let areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.isRelayer(r)));
|
let areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.isRelayer(r)));
|
||||||
let balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.getRelayerBalance(r)));
|
let balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryOldContract.getRelayerBalance(r)));
|
||||||
|
|
||||||
expect(areRegistered).satisfy((v) => v.every((v) => v === true));
|
expect(areRegistered).satisfy((v) => v.every((v) => v === true));
|
||||||
expect(balances).satisfy((v) => v.every((v) => v >= 0n));
|
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)));
|
areRegistered = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.isRelayer(r)));
|
||||||
balances = await Promise.all(cheatingRelayers.map((r) => relayerRegistryContract.getRelayerBalance(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 () {
|
it("Unregistered relayers can register again", async function () {
|
||||||
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
|
const { relayerRegistryContract } = await deployAndExecuteProposal();
|
||||||
const relayerEns = "moon-relayer.eth";
|
const relayerEns = "moon-relayer.eth";
|
||||||
const unregisteredRelayer = await resolveAddr(relayerEns);
|
const unregisteredRelayer = await resolveAddr(relayerEns);
|
||||||
const toStake = await sendMinimalStakeAmount(unregisteredRelayer);
|
const toStake = await sendMinimalStakeAmount(unregisteredRelayer);
|
||||||
@ -158,7 +170,7 @@ describe("Registry update", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Registering relayer with wrapped ENS domain should revert", async 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 relayerWrappedEns = "butterfly-attractor.eth";
|
||||||
const registerParams = await getRegisterRelayerParams(relayerWrappedEns);
|
const registerParams = await getRegisterRelayerParams(relayerWrappedEns);
|
||||||
const [relayer] = await ethers.getSigners();
|
const [relayer] = await ethers.getSigners();
|
||||||
@ -168,31 +180,20 @@ describe("Registry update", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("After ENS domain unwrapping owner can register relayer", async function () {
|
it("After ENS domain unwrapping owner can register relayer", async function () {
|
||||||
const { relayerRegistryProxyAddr } = await loadFixture(deployAndExecuteFixture);
|
await deployAndExecuteProposal();
|
||||||
const ensWrapperAddr = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
|
const ensWrapperAddr = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
|
||||||
const wrappedEnsDomain = "butterfly-attractor.eth";
|
const wrappedEnsDomain = "butterfly-attractor.eth";
|
||||||
const addr = await resolveAddr(wrappedEnsDomain);
|
const addr = await resolveAddr(wrappedEnsDomain);
|
||||||
const ensContract = await getEnsRegistryContract();
|
|
||||||
const wrapperContract = await ethers.getContractAt(require("./abi/ensWrapper.abi.json"), ensWrapperAddr);
|
const wrapperContract = await ethers.getContractAt(require("./abi/ensWrapper.abi.json"), ensWrapperAddr);
|
||||||
const labelhash = ethers.keccak256(ethers.toUtf8Bytes(wrappedEnsDomain.split(".")[0]));
|
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);
|
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 relayerSigner = await ethers.getSigner(addr);
|
||||||
const relayerRegistry = await ethers.getContractAt(
|
const relayerRegistryContract = await getRelayerRegistryContract(relayerSigner);
|
||||||
require("./abi/relayerRegistry.abi.json"),
|
|
||||||
relayerRegistryProxyAddr,
|
|
||||||
relayerSigner,
|
|
||||||
);
|
|
||||||
const registerParams = await getRegisterRelayerParams(wrappedEnsDomain);
|
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 { ethers, network } = require("hardhat");
|
||||||
const { time, loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
|
const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
|
||||||
const { keccak256, toUtf8Bytes } = require("ethers");
|
|
||||||
|
|
||||||
const ensAddr = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
|
const ensAddr = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
|
||||||
const relayerRegistryProxyAddr = "0x58E8dCC13BE9780fC42E8723D8EaD4CF46943dF2";
|
const relayerRegistryProxyAddr = "0x58E8dCC13BE9780fC42E8723D8EaD4CF46943dF2";
|
||||||
const tornAddr = "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C";
|
const tornAddr = "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C";
|
||||||
@ -90,7 +88,7 @@ async function getRelayerRegistryContract(signer) {
|
|||||||
return await ethers.getContractAt("RelayerRegistry", relayerRegistryProxyAddr, signer);
|
return await ethers.getContractAt("RelayerRegistry", relayerRegistryProxyAddr, signer);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOldRelayerRegistryContractFixture() {
|
async function getOldRelayerRegistryContract() {
|
||||||
return await ethers.getContractAt(require("./abi/relayerRegistryOld.abi.json"), relayerRegistryProxyAddr);
|
return await ethers.getContractAt(require("./abi/relayerRegistryOld.abi.json"), relayerRegistryProxyAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ async function getManyEth(addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendMinimalStakeAmount(addr, additionalStake = 0n) {
|
async function sendMinimalStakeAmount(addr, additionalStake = 0n) {
|
||||||
const { relayerRegistryContract } = await loadFixture(deployAndExecuteFixture);
|
const relayerRegistryContract = await getRelayerRegistryContract();
|
||||||
const minRelayerStakeAmount = await relayerRegistryContract.minStakeAmount();
|
const minRelayerStakeAmount = await relayerRegistryContract.minStakeAmount();
|
||||||
const governanceSigner = await ethers.getImpersonatedSigner(governanceAddr);
|
const governanceSigner = await ethers.getImpersonatedSigner(governanceAddr);
|
||||||
const tornContract = await ethers.getContractAt(require("./abi/torn.abi.json"), tornAddr, governanceSigner);
|
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;
|
return minRelayerStakeAmount + additionalStake;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deployAndExecuteFixture() {
|
async function deployAndExecuteProposal() {
|
||||||
const RelayerRegistryFactory = await ethers.getContractFactory("RelayerRegistry");
|
const RelayerRegistryFactory = await ethers.getContractFactory("RelayerRegistry");
|
||||||
const constructorArgs = [
|
const constructorArgs = [
|
||||||
tornAddr,
|
tornAddr,
|
||||||
@ -158,12 +156,12 @@ async function unregisterRelayer(ensNameOrAddress) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
sendMinimalStakeAmount,
|
sendMinimalStakeAmount,
|
||||||
getEnsRegistryContract,
|
getEnsRegistryContract,
|
||||||
getOldRelayerRegistryContractFixture,
|
getOldRelayerRegistryContract,
|
||||||
getRelayerRegistryContract,
|
getRelayerRegistryContract,
|
||||||
getPermitSignature,
|
getPermitSignature,
|
||||||
resolveAddr,
|
resolveAddr,
|
||||||
getManyEth,
|
getManyEth,
|
||||||
unregisterRelayer,
|
unregisterRelayer,
|
||||||
deployAndExecuteFixture,
|
deployAndExecuteProposal,
|
||||||
getRegisterRelayerParams,
|
getRegisterRelayerParams,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user