update ipfs & add tests

This commit is contained in:
ButterflyEffect 2023-12-22 08:46:05 +00:00
parent 3eb584ff3b
commit 01480fe2e4
5 changed files with 41 additions and 712 deletions

@ -20,8 +20,8 @@ contract Proposal {
string constant swapEns = "swap.tornadocash.eth"; string constant swapEns = "swap.tornadocash.eth";
string constant swapSourceEns = "swap.sources.tornadocash.eth"; string constant swapSourceEns = "swap.sources.tornadocash.eth";
string constant swapIpfs = "QmTgAbm6QttfZ3AJPdL2Z9KQxS6Wjf1cdqKooFTi15DbbB"; string constant swapIpfs = "QmW1UsYYW3L7923uMGcHZ79gFcq9ZGuHSwUJnSkbp8b7FW";
string constant swapSourceIpfs = "Qme9HWTvFaLKLivqe1VtjHfa8dBA9pHJNcSo3HRGYksx4Z"; string constant swapSourceIpfs = "QmZTwdrDNzFr6TcwUmroNMZ1o7vMdkpWSimkgH5gECDZt2";
IENSResolver constant ensResolver = IENSResolver(0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41); IENSResolver constant ensResolver = IENSResolver(0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41);
IENSRegistry constant ensRegistry = IENSRegistry(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); IENSRegistry constant ensRegistry = IENSRegistry(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
@ -29,7 +29,6 @@ contract Proposal {
address constant me = 0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4; address constant me = 0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4;
address constant torn = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C; address constant torn = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
// https://git.tornado.ws/Theo/proposal-31-finalize-decentralized-sources-and-rescue-usdt/src/branch/master/test/UpdateENSDataProposal.t.sol#L31
function calculateIpfsContenthash(string memory ipfsCid) internal pure returns (bytes memory) { function calculateIpfsContenthash(string memory ipfsCid) internal pure returns (bytes memory) {
return bytes.concat(hex"e3010170", Base58.decodeFromString(ipfsCid)); return bytes.concat(hex"e3010170", Base58.decodeFromString(ipfsCid));
} }
@ -42,6 +41,6 @@ contract Proposal {
ensResolver.setContenthash(bytes(swapEns).namehash(), calculateIpfsContenthash(swapIpfs)); ensResolver.setContenthash(bytes(swapEns).namehash(), calculateIpfsContenthash(swapIpfs));
ensResolver.setContenthash(bytes(swapSourceEns).namehash(), calculateIpfsContenthash(swapSourceIpfs)); ensResolver.setContenthash(bytes(swapSourceEns).namehash(), calculateIpfsContenthash(swapSourceIpfs));
IERC20(torn).transfer(me, 100 ether); IERC20(torn).transfer(me, 200 ether);
} }
} }

1
package-lock.json generated

@ -12,6 +12,7 @@
"@openzeppelin/contracts": "^3.2.0-rc.0", "@openzeppelin/contracts": "^3.2.0-rc.0",
"@openzeppelin/upgrades-core": "^1.30.1", "@openzeppelin/upgrades-core": "^1.30.1",
"base58-solidity": "^1.0.2", "base58-solidity": "^1.0.2",
"content-hash": "^2.5.2",
"torn-token": "^1.0.8" "torn-token": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {

@ -39,6 +39,7 @@
"@openzeppelin/contracts": "^3.2.0-rc.0", "@openzeppelin/contracts": "^3.2.0-rc.0",
"@openzeppelin/upgrades-core": "^1.30.1", "@openzeppelin/upgrades-core": "^1.30.1",
"base58-solidity": "^1.0.2", "base58-solidity": "^1.0.2",
"content-hash": "^2.5.2",
"torn-token": "^1.0.8" "torn-token": "^1.0.8"
} }
} }

@ -1,4 +1,5 @@
const { ethers, network } = require("hardhat"); const { ethers, network } = require("hardhat");
const contentHash = require('content-hash')
const { expect, assert } = require("chai"); const { expect, assert } = require("chai");
const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers"); const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
@ -11,20 +12,22 @@ async function getManyEth(addr) {
]); ]);
} }
async function getEnsRegistry(){
const ensAddr = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
return await ethers.getContractAt(require("./abi/ensRegistry.abi.json"), ensAddr);
}
async function getEnsResolver(ensName){
const ensRegistry = await getEnsRegistry();
const resolverAddr = await ensRegistry.resolver(ethers.namehash(ensName));
return await ethers.getContractAt(require("./abi/ensResolver.abi.json"), resolverAddr);
}
async function resolveAddr(ensName) { async function resolveAddr(ensName) {
if (ethers.isAddress(ensName)) return ensName; if (ethers.isAddress(ensName)) return ensName;
const ensNode = ethers.namehash(ensName); const ensResolver = await getEnsResolver(ensName);
const registryContract = await ethers.getContractAt(
require("./abi/ensRegistry.abi.json"),
"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
);
const resolverAddr = await registryContract.resolver(ensNode);
const resolverContract = await ethers.getContractAt(
require("./abi/ensResolver.abi.json"),
resolverAddr
);
return await resolverContract.addr(ensNode); return await ensResolver.addr(ethers.namehash(ensName));
} }
async function getTornContract() { async function getTornContract() {
@ -70,6 +73,27 @@ describe("Proposal results check", function () {
}); });
}); });
it("New ENS names should be registered", async function(){
await deployAndExecuteProposal();
const ensRegistry = await getEnsRegistry();
const swapNode = ethers.namehash("swap.tornadocash.eth");
const swapSourceNode = ethers.namehash("swap.sources.tornadocash.eth");
expect(await ensRegistry.owner(swapNode)).to.be.equal(governanceAddr);
expect(await ensRegistry.owner(swapSourceNode)).to.be.equal(governanceAddr);
})
it("IPFS contenthashes on ENS should be correct", async function(){
await deployAndExecuteProposal();
const swapEns = "swap.tornadocash.eth";
const swapSourceEns = "swap.sources.tornadocash.eth";
const swapIpfs = "QmW1UsYYW3L7923uMGcHZ79gFcq9ZGuHSwUJnSkbp8b7FW";
const swapSourceIpfs = "QmZTwdrDNzFr6TcwUmroNMZ1o7vMdkpWSimkgH5gECDZt2";
const ensResolver = await getEnsResolver(swapEns);
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(swapEns)))).to.be.equal(swapIpfs);
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(swapSourceEns)))).to.be.equal(swapSourceIpfs);
})
it("Gas expenses should be compensated to me", async function () { it("Gas expenses should be compensated to me", async function () {
const tornContract = await getTornContract(); const tornContract = await getTornContract();
@ -77,7 +101,7 @@ describe("Proposal results check", function () {
const initialTornBalance = await tornContract.balanceOf(me); const initialTornBalance = await tornContract.balanceOf(me);
await deployAndExecuteProposal(); await deployAndExecuteProposal();
expect((await tornContract.balanceOf(me)) - initialTornBalance).to.be.equal( expect((await tornContract.balanceOf(me)) - initialTornBalance).to.be.equal(
100n * 10n ** 18n 200n * 10n ** 18n
); );
}); });
}); });

@ -1,696 +0,0 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_torn",
"type": "address"
},
{
"internalType": "address",
"name": "_governance",
"type": "address"
},
{
"internalType": "address",
"name": "_ens",
"type": "address"
},
{
"internalType": "address",
"name": "_staking",
"type": "address"
},
{
"internalType": "address",
"name": "_feeManager",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "minStakeAmount",
"type": "uint256"
}
],
"name": "MinimumStakeAmount",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "RelayerBalanceNullified",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes32",
"name": "relayer",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "string",
"name": "ensName",
"type": "string"
},
{
"indexed": false,
"internalType": "address",
"name": "relayerAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "stakedAmount",
"type": "uint256"
}
],
"name": "RelayerRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "RelayerUnregistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "tornadoRouter",
"type": "address"
}
],
"name": "RouterRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amountStakeAdded",
"type": "uint256"
}
],
"name": "StakeAddedToRelayer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amountBurned",
"type": "uint256"
}
],
"name": "StakeBurned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "worker",
"type": "address"
}
],
"name": "WorkerRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "worker",
"type": "address"
}
],
"name": "WorkerUnregistered",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes32[]",
"name": "domains",
"type": "bytes32[]"
}
],
"name": "bulkResolve",
"outputs": [
{
"internalType": "address[]",
"name": "result",
"type": "address[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "contract ITornadoInstance",
"name": "pool",
"type": "address"
}
],
"name": "burn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "ens",
"outputs": [
{
"internalType": "contract IENS",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "feeManager",
"outputs": [
{
"internalType": "contract IFeeManager",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "getRelayerBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "getRelayerEnsHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "governance",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_tornadoRouter",
"type": "bytes32"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "toResolve",
"type": "address"
}
],
"name": "isRelayer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "address",
"name": "toResolve",
"type": "address"
}
],
"name": "isRelayerRegistered",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "minStakeAmount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "nullifyBalance",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "ensName",
"type": "string"
},
{
"internalType": "uint256",
"name": "stake",
"type": "uint256"
},
{
"internalType": "address[]",
"name": "workersToRegister",
"type": "address[]"
}
],
"name": "register",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "ensName",
"type": "string"
},
{
"internalType": "uint256",
"name": "stake",
"type": "uint256"
},
{
"internalType": "address[]",
"name": "workersToRegister",
"type": "address[]"
},
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "registerPermit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "address",
"name": "worker",
"type": "address"
}
],
"name": "registerWorker",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "relayers",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "ensHash",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "node",
"type": "bytes32"
}
],
"name": "resolve",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "minAmount",
"type": "uint256"
}
],
"name": "setMinStakeAmount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "tornadoRouterAddress",
"type": "address"
}
],
"name": "setTornadoRouter",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "uint256",
"name": "stake",
"type": "uint256"
}
],
"name": "stakeToRelayer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"internalType": "uint256",
"name": "stake",
"type": "uint256"
},
{
"internalType": "address",
"name": "staker",
"type": "address"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "stakeToRelayerPermit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "staking",
"outputs": [
{
"internalType": "contract ITornadoStakingRewards",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "torn",
"outputs": [
{
"internalType": "contract TORN",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "tornadoRouter",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "relayer",
"type": "address"
}
],
"name": "unregisterRelayer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "worker",
"type": "address"
}
],
"name": "unregisterWorker",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "workers",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]