-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardhat.config.ts
109 lines (92 loc) · 2.69 KB
/
hardhat.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// @ts-check
require("@nomiclabs/hardhat-waffle");
import "solidity-coverage";
import "hardhat-jest-plugin";
// declaration merging で hre.ethers を生やしているので反映する
import "@nomiclabs/hardhat-ethers";
import { HardhatUserConfig } from "hardhat/config";
import { task } from "hardhat/config";
import { Contract } from "@ethersproject/contracts";
import { HardhatRuntimeEnvironment } from "hardhat/types";
async function getDeployGasUsed(
hre: HardhatRuntimeEnvironment,
contract: Contract
) {
const txReceipt = await hre.ethers.provider.getTransactionReceipt(
contract.deployTransaction.hash
);
return txReceipt.gasUsed.toString();
}
async function getMintGasUsed(
hre: HardhatRuntimeEnvironment,
contract: Contract
) {
const accounts = await hre.ethers.getSigners();
const tx = await contract.functions["mint(address,uint256)"](
accounts[0].address,
1
);
const txReceipt = await hre.ethers.provider.getTransactionReceipt(tx.hash);
return txReceipt.gasUsed.toString();
}
async function getTransferFromGasUsed(
hre: HardhatRuntimeEnvironment,
contract: Contract
) {
const accounts = await hre.ethers.getSigners();
await contract.functions["mint(address,uint256)"](accounts[0].address, 10);
const tx = await contract.functions["transferFrom(address,address,uint256)"](
accounts[0].address,
accounts[1].address,
10
);
const txReceipt = await hre.ethers.provider.getTransactionReceipt(tx.hash);
return txReceipt.gasUsed.toString();
}
task("measure", "deploy/mint/transferFrom のコストを計測").setAction(
async (_, hre) => {
const contractNames = [
"Basic",
"CaseBurnable",
"CaseEnumerable",
"CaseMetadata",
"CasePausable",
];
for (const contractName of contractNames) {
const contract = await hre.ethers.getContractFactory(contractName);
const instance = await contract.deploy();
await instance.deployed();
console.log(contractName);
console.log("deploy", await getDeployGasUsed(hre, instance));
console.log("mint", await getMintGasUsed(hre, instance));
console.log("transferFrom", await getTransferFromGasUsed(hre, instance));
}
}
);
function getAccounts() {
const privateKey = process.env.PRIVATE_KEY;
if (privateKey) {
return [privateKey];
}
}
const config: HardhatUserConfig = {
solidity: {
version: "0.5.17",
settings: {
optimizer: {
enabled: false,
runs: 1000,
},
},
},
networks: {
hardhat: {
hardfork: "muirGlacier",
},
ropsten: {
url: "https://ropsten.infura.io/v3/60d0008ec52149f5a639ba70fc6086df",
// accounts: getAccounts()
},
},
};
export default config;