Skip to content

Commit

Permalink
Improve hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sembrestels committed Oct 19, 2023
1 parent 945fc56 commit a892a59
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
12 changes: 7 additions & 5 deletions pkg/abc-template/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require("@nomicfoundation/hardhat-ethers");
require("@nomicfoundation/hardhat-verify");
require("@nomicfoundation/hardhat-toolbox");

const ALCHEMY_ID = 'ln15qqnK7vEODFKXum9YOeFOFZxUfkIh' //process.env.ALCHEMY_ID;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: {
Expand All @@ -16,17 +18,17 @@ module.exports = {
networks: {
hardhat: {
forking: {
url: "https://opt-mainnet.g.alchemy.com/v2/<API-KEY>"
url: `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`
}
},
gnosis: {
url: "https://rpc.gnosischain.com/",
},
optimism: {
url: "https://opt-mainnet.g.alchemy.com/v2/<API-KEY>"
url: `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`
}
},
etherscan: {
apiKey: "<API-KEY>"
}
// etherscan: {
// apiKey: "<API-KEY>"
// }
};
5 changes: 4 additions & 1 deletion pkg/abc-template/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "hardhat-project",
"name": "abc-template",
"scripts": {
"test": "hardhat test test/AbcTemplate.test.ts"
},
"dependencies": {
"@aragon/os": "^4.4.0",
"@aragon/templates-shared": "^1.0.1",
Expand Down
60 changes: 42 additions & 18 deletions pkg/abc-template/test/AbcTemplate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { assert } = require("chai");
const { ethers, network } = require("hardhat");

// Optimism:
Expand All @@ -12,38 +13,61 @@ const pct = (n) => BigInt(n) * BigInt(10 ** 16);
const wad = (n) => BigInt(n) * BigInt(10 ** 18);

describe("AbcTemplate contract", function () {
it("Deployment should work", async function () {
const [owner] = await ethers.getSigners();

let signer, abcTemplate, reserveToken;

before(async function () {
const daiHolder = '0x2de373887b9742162c9a5885ddb5debea8e4486d'
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [daiHolder],
});
const signer = await ethers.getSigner(daiHolder);

const abcTemplate = await ethers.deployContract("AbcTemplate", [
daoFactory,
_ens,
_miniMeFactory,
_aragonID,
_formula
]);

const reserveToken = new ethers.Contract(_reserveToken, ["function approve(address spender, uint256 value) public returns (bool)"], signer);
signer = await ethers.getSigner(daiHolder);
reserveToken = new ethers.Contract(_reserveToken, [
"function approve(address spender, uint256 value) public returns (bool)",
"function balanceOf(address account) external view returns (uint256)",
"function allowance(address owner, address spender) external view returns (uint256)"
], signer);
});

await reserveToken.approve(await abcTemplate.getAddress(), wad(3n * 10n ** 18n));
it("Deployment should work", async function () {
abcTemplate = await ethers.deployContract("AbcTemplate", [
daoFactory,
_ens,
_miniMeFactory,
_aragonID,
_formula
]);
// abcTemplate = await ethers.getContractAt("AbcTemplate", "0x18F575dfDcE7Dd0E0bF5fA95dEE1F002fA19fa5D");
});

await abcTemplate.connect(signer).newTokenAndInstance(
it('New DAO without reserve balance should work', async function () {
await abcTemplate.newTokenAndInstance(
"Token Name",
"TKN",
"daoname",
[owner.address],
[signer.address],
[wad(1)],
[pct(50), pct(15), 7 * 24 * 60 * 60],
[pct(1), pct(2), _reserveToken, 20e4, wad(3n * 10n ** 18n)],
{ from : daiHolder }
[pct(1), pct(2), _reserveToken, 20e4, 0]
);

});

xit('New DAO with reserve balance should work', async function () { // FIXME: It works on Optimism, but not on Hardhat
await (await reserveToken.approve(await abcTemplate.getAddress(), wad(3))).wait();
assert.isAtLeast(await reserveToken.balanceOf(signer.address), wad(3));
assert.equal(await reserveToken.allowance(signer.address, await abcTemplate.getAddress()), wad(3));

await abcTemplate.newTokenAndInstance(
"Token Name",
"TKN",
"daoname2",
[signer.address],
[wad(1)],
[pct(50), pct(15), 7 * 24 * 60 * 60],
[pct(1), pct(2), _reserveToken, 20e4, wad(3)],
{ gasLimit: 30000000 }
);
});
});

0 comments on commit a892a59

Please sign in to comment.