Skip to content

Commit e3093d9

Browse files
committed
contracts: upgrade hardhat and improve UT efficiency
1 parent f84dfeb commit e3093d9

File tree

11 files changed

+228
-208
lines changed

11 files changed

+228
-208
lines changed

contracts/hardhat.config.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import type { HardhatUserConfig } from "hardhat/config";
22

3+
import hardhatEthers from "@nomicfoundation/hardhat-ethers";
4+
import hardhatNetworkHelpers from "@nomicfoundation/hardhat-network-helpers";
35
import hardhatToolboxMochaEthersPlugin from "@nomicfoundation/hardhat-toolbox-mocha-ethers";
46

57
const config: HardhatUserConfig = {
6-
/*
7-
* In Hardhat 3, plugins are defined as part of the Hardhat config instead of
8-
* being based on the side-effect of imports.
9-
*
10-
* Note: A `hardhat-toolbox` like plugin for Hardhat 3 hasn't been defined yet,
11-
* so this list is larger than what you would normally have.
12-
*/
13-
plugins: [hardhatToolboxMochaEthersPlugin],
8+
plugins: [hardhatEthers, hardhatNetworkHelpers, hardhatToolboxMochaEthersPlugin],
149
solidity: {
1510
profiles: {
1611
default: {

contracts/package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"name": "neox-governance",
3-
"type": "module",
43
"version": "1.0.0",
4+
"type": "module",
55
"devDependencies": {
6-
"@nomicfoundation/hardhat-ethers": "^4.0.0-next.21",
7-
"@nomicfoundation/hardhat-ignition": "^3.0.0-next.21",
8-
"@nomicfoundation/hardhat-toolbox-mocha-ethers": "^3.0.0-next.21",
6+
"@nomicfoundation/hardhat-ethers": "^4.0.2",
7+
"@nomicfoundation/hardhat-ignition": "^3.0.3",
8+
"@nomicfoundation/hardhat-network-helpers": "^3.0.1",
9+
"@nomicfoundation/hardhat-toolbox-mocha-ethers": "^3.0.0",
910
"@types/chai": "^4.3.20",
1011
"@types/chai-as-promised": "^8.0.2",
1112
"@types/mocha": "^10.0.10",
12-
"@types/node": "^22.16.0",
13-
"chai": "^5.2.0",
13+
"@types/node": "^22.18.10",
14+
"chai": "^5.3.3",
1415
"ethers": "^6.15.0",
1516
"forge-std": "github:foundry-rs/forge-std#v1.9.4",
16-
"hardhat": "^3.0.0-next.21",
17-
"mocha": "^11.7.1",
17+
"hardhat": "^3.0.7",
18+
"mocha": "^11.7.4",
1819
"typescript": "~5.8.0"
1920
},
2021
"dependencies": {
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
import { expect } from "chai";
22
import { ERRORS } from "./helpers/errors.js";
3-
import { ethers, allocGenesis } from "./helpers/setup.js";
3+
import { ethers, networkHelpers, allocGenesis } from "./helpers/setup.js";
44

55
describe("CommitteeMultiSig", function () {
66

7-
let signers: any;
7+
let MultiSig: any, MockCaller: any;
8+
let signers: any, snapshot: any;
89

9-
beforeEach(async function () {
10+
before(async function () {
1011
signers = await ethers.getSigners();
1112
await allocGenesis();
13+
MultiSig = await ethers.deployContract("CommitteeMultiSig");
14+
MockCaller = await ethers.deployContract("MockMultiSig");
15+
snapshot = await networkHelpers.takeSnapshot();
1216
});
1317

14-
describe("execute", function () {
15-
let MultiSig: any, Mock: any;
16-
17-
beforeEach(async function () {
18-
MultiSig = await ethers.deployContract("CommitteeMultiSig");
19-
Mock = await ethers.deployContract("MockMultiSig");
20-
});
18+
afterEach(async function () {
19+
await snapshot.restore();
20+
});
2121

22+
describe("execute", function () {
2223
it("Should revert if the sender is not a miner", async function () {
2324
await expect(
24-
MultiSig.connect(signers[7]).execute(Mock.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
25+
MultiSig.connect(signers[7]).execute(MockCaller.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
2526
).to.be.revertedWithCustomError(MultiSig, ERRORS.NOT_MINER);
2627
});
2728

2829
it("Should not execute method when threshold is not met", async function () {
2930
await expect(
30-
MultiSig.connect(signers[0]).execute(Mock.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
31-
).not.to.be.reverted(ethers);
31+
MultiSig.connect(signers[0]).execute(MockCaller.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
32+
).not.to.be.revert(ethers);
3233

33-
expect(await Mock.v()).to.eq(0);
34+
expect(await MockCaller.v()).to.eq(0);
3435
});
3536

3637
it("Should execute method when threshold is met", async function () {
3738
for (let i = 0; i < 3; i++) {
3839
await expect(
39-
MultiSig.connect(signers[i]).execute(Mock.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
40-
).not.to.be.reverted(ethers);
40+
MultiSig.connect(signers[i]).execute(MockCaller.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
41+
).not.to.be.revert(ethers);
4142
}
42-
expect(await Mock.v()).to.eq(0);
43+
expect(await MockCaller.v()).to.eq(0);
4344

4445
await expect(
45-
MultiSig.connect(signers[3]).execute(Mock.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
46-
).not.to.be.reverted(ethers);
47-
expect(await Mock.v()).to.eq(1);
46+
MultiSig.connect(signers[3]).execute(MockCaller.target, "0xa1b2ca7d0000000000000000000000000000000000000000000000000000000000000001")
47+
).not.to.be.revert(ethers);
48+
expect(await MockCaller.v()).to.eq(1);
4849
});
4950
});
5051
});

contracts/test/GovProxyUpgradeable.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,29 @@ import { expect } from "chai";
44
const { ethers } = await network.connect();
55

66
describe("GovProxyUpgradeable", function () {
7+
8+
let Mock: any;
9+
10+
before(async function () {
11+
Mock = await ethers.deployContract("MockGovProxyUpgradeable");
12+
});
13+
714
it("Should prevent implementation contract from initialization", async function () {
8-
const mockGovProxyUpgradeable = await ethers.deployContract("MockGovProxyUpgradeable");
9-
await expect(mockGovProxyUpgradeable.initialize()).to.be.reverted(ethers);
15+
await expect(Mock.initialize()).to.be.revert(ethers);
1016
expect(
1117
await ethers.provider.send("eth_getStorageAt", [
12-
await mockGovProxyUpgradeable.getAddress(),
18+
await Mock.getAddress(),
1319
"0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00",
1420
"latest"]
1521
)
1622
).to.eq("0x000000000000000000000000000000000000000000000000ffffffffffffffff");
1723
});
1824

1925
it("Should prevent implementation contract from reinitialization", async function () {
20-
const mockGovProxyUpgradeable = await ethers.deployContract("MockGovProxyUpgradeable");
21-
await expect(mockGovProxyUpgradeable.reinitialize()).to.be.reverted(ethers);
26+
await expect(Mock.reinitialize()).to.be.revert(ethers);
2227
expect(
2328
await ethers.provider.send("eth_getStorageAt", [
24-
await mockGovProxyUpgradeable.getAddress(),
29+
await Mock.getAddress(),
2530
"0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00",
2631
"latest"]
2732
)

contracts/test/GovReward.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
import { expect } from "chai";
2-
import { SYS_SETTINGS, ethers, allocGenesis } from "./helpers/setup.js";
2+
import { SYS_SETTINGS, ethers, networkHelpers, allocGenesis } from "./helpers/setup.js";
33

44
describe("GovReward", function () {
55

6-
beforeEach(async function () {
6+
let MockCaller: any;
7+
let snapshot: any;
8+
9+
before(async function () {
710
await allocGenesis();
11+
MockCaller = await ethers.deployContract("MockFallback");
12+
snapshot = await networkHelpers.takeSnapshot();
13+
});
14+
15+
afterEach(async function () {
16+
await snapshot.restore();
817
});
918

1019
describe("fallback", function () {
11-
let Mock: any;
12-
13-
beforeEach(async function () {
14-
Mock = await ethers.deployContract("MockFallback");
15-
});
16-
1720
it("Should revert if the selector is not 0xffffffff", async function () {
1821
await expect(
19-
Mock.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xfffffffe")
20-
).to.be.reverted(ethers);
22+
MockCaller.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xfffffffe")
23+
).to.be.revert(ethers);
2124
});
2225

2326
it("Should revert if the declared gaslimit is lower than 21000", async function () {
2427
await expect(
25-
Mock.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xffffffff")
26-
).to.be.reverted(ethers);
28+
MockCaller.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xffffffff")
29+
).to.be.revert(ethers);
2730
});
2831

2932
it("Should consume gas as expected", async function () {
3033
await expect(
31-
Mock.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xffffffff0000000000005208")
32-
).not.to.be.reverted(ethers);
34+
MockCaller.call_fallback(SYS_SETTINGS.REWARD_PROXY, "0xffffffff0000000000005208")
35+
).not.to.be.revert(ethers);
3336
});
3437
});
3538
});

0 commit comments

Comments
 (0)