|
| 1 | +#/ 自动生成pom |
| 2 | +# 自动生成config |
| 3 | + |
| 4 | +HardhatConfigData = '''require('@nomiclabs/hardhat-waffle'); |
| 5 | +require('@nomiclabs/hardhat-web3'); |
| 6 | +require('dotenv').config(); |
| 7 | +
|
| 8 | +const fs = require('fs'); |
| 9 | +const path = require('path'); |
| 10 | +
|
| 11 | +// const INFURA_PROJECT_ID = '719d739434254b88ac95d53e2b6ac997'; |
| 12 | +
|
| 13 | +const argv = require('yargs/yargs')() |
| 14 | + .env('') |
| 15 | + .options({{ |
| 16 | + ci: {{ |
| 17 | + type: 'boolean', |
| 18 | + default: false, |
| 19 | + }}, |
| 20 | + coverage: {{ |
| 21 | + type: 'boolean', |
| 22 | + default: false, |
| 23 | + }}, |
| 24 | + gas: {{ |
| 25 | + alias: 'enableGasReport', |
| 26 | + type: 'boolean', |
| 27 | + default: false, |
| 28 | + }}, |
| 29 | + mode: {{ |
| 30 | + alias: 'compileMode', |
| 31 | + type: 'string', |
| 32 | + choices: ['production', 'development'], |
| 33 | + default: 'development', |
| 34 | + }}, |
| 35 | + compiler: {{ |
| 36 | + alias: 'compileVersion', |
| 37 | + type: 'string', |
| 38 | + default: '0.8.9', |
| 39 | + }}, |
| 40 | + coinmarketcap: {{ |
| 41 | + alias: 'coinmarketcapApiKey', |
| 42 | + type: 'string', |
| 43 | + }}, |
| 44 | + }}) |
| 45 | + .argv; |
| 46 | +
|
| 47 | +require('@nomiclabs/hardhat-truffle5'); |
| 48 | +
|
| 49 | +if (argv.enableGasReport) {{ |
| 50 | + require('hardhat-gas-reporter'); |
| 51 | +}} |
| 52 | +
|
| 53 | +for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {{ |
| 54 | + require(path.join(__dirname, 'hardhat', f)); |
| 55 | +}} |
| 56 | +
|
| 57 | +const withOptimizations = argv.enableGasReport || argv.compileMode === 'production'; |
| 58 | +
|
| 59 | +/** |
| 60 | + * @type import('hardhat/config').HardhatUserConfig |
| 61 | + */ |
| 62 | +module.exports = {{ |
| 63 | + solidity: {{ |
| 64 | + version: argv.compiler, |
| 65 | + settings: {{ |
| 66 | + optimizer: {{ |
| 67 | + enabled: withOptimizations, |
| 68 | + runs: 200, |
| 69 | + }}, |
| 70 | + }}, |
| 71 | + }}, |
| 72 | + defaultNetwork: 'testRpc', |
| 73 | + networks: {{ |
| 74 | + hardhat: {{ |
| 75 | + loggingEnabled: true, |
| 76 | + blockGasLimit: 10000000, |
| 77 | + allowUnlimitedContractSize: !withOptimizations, |
| 78 | + }}, |
| 79 | + testRpc: {{ |
| 80 | + url: process.env.TEST_RPC, |
| 81 | + // gas:10000000, |
| 82 | + accounts: {{ |
| 83 | + mnemonic: process.env.MNEMONIC_STR, |
| 84 | + path: 'm/44\\\'/60\\\'/0\\\'/0', |
| 85 | + initialIndex: {idx}, |
| 86 | + count: 10, |
| 87 | + passphrase: '', |
| 88 | + }}, |
| 89 | + }}, |
| 90 | + }}, |
| 91 | + mocha: {{ |
| 92 | + timeout: 100000, |
| 93 | + reporter: 'mochawesome', |
| 94 | + reporterOptions: {{ |
| 95 | + reportFilename: '[status]-{contractName}-report', |
| 96 | + }}, |
| 97 | + }}, |
| 98 | +
|
| 99 | +}}; |
| 100 | +
|
| 101 | +if (argv.coverage) {{ |
| 102 | + require('solidity-coverage'); |
| 103 | + module.exports.networks.hardhat.initialBaseFeePerGas = 0; |
| 104 | +}} |
| 105 | +''' |
| 106 | +ContractList = [ |
| 107 | + "AccessControl", |
| 108 | + "AccessControlEnum", |
| 109 | + "Ownable", |
| 110 | + "CrossChainEnabled", |
| 111 | + "PaymentSplitter", |
| 112 | + "VestingWallet", |
| 113 | + "GovernorCompatibilityBravo", |
| 114 | + "GovernorComp", |
| 115 | + "GovernorERC721Mock", |
| 116 | + "GovernorPreventLateQuorum", |
| 117 | + "GovernorTimelockCompound", |
| 118 | + "GovernorTimelockControl", |
| 119 | + "GovernorVotesQuorumFraction", |
| 120 | + "GovernorWithParams", |
| 121 | + "Governor", |
| 122 | + "TimelockController", |
| 123 | + "Votes", |
| 124 | + "ERC2771Context", |
| 125 | + "MinimalForwarder", |
| 126 | + "BeaconProxy", |
| 127 | + "UpgradeableBeacon", |
| 128 | + "Clones", |
| 129 | + "ERC1967Proxy", |
| 130 | + "ProxyAdmin", |
| 131 | + "TransparentUpgradeableProxy", |
| 132 | + "Initializable", |
| 133 | + "UUPSUpgradeable", |
| 134 | + "Pausable", |
| 135 | + "PullPayment", |
| 136 | + "ReentrancyGuard", |
| 137 | + "ERC1155", |
| 138 | + "ERC1155Burnable", |
| 139 | + "ERC1155Pausable", |
| 140 | + "ERC1155Supply", |
| 141 | + "ERC1155URIStorage", |
| 142 | + "ERC1155PresetMinterPauser", |
| 143 | + "ERC1155Holder", |
| 144 | + "ERC20Test", |
| 145 | + "ERC20Permit", |
| 146 | + "ERC20Burnable", |
| 147 | + "ERC20Capped", |
| 148 | + "ERC20FlashMint", |
| 149 | + "ERC20Pausable", |
| 150 | + "ERC20Snapshot", |
| 151 | + "ERC20Votes", |
| 152 | + "ERC20VotesComp", |
| 153 | + "ERC20Wrapper", |
| 154 | + "ERC20PresetFixedSupply", |
| 155 | + "ERC20PresetMinterPauser", |
| 156 | + "SafeERC20", |
| 157 | + "TokenTimelock", |
| 158 | + "ERC721", |
| 159 | + "ERC721Enumerable", |
| 160 | + "ERC721Burnable", |
| 161 | + "ERC721Pausable", |
| 162 | + "ERC721Royalty", |
| 163 | + "ERC721URIStorage", |
| 164 | + "ERC721Votes", |
| 165 | + "ERC721PresetMinterPauserAutoId", |
| 166 | + "ERC721Holder", |
| 167 | + "ERC777", |
| 168 | + "ERC777PresetFixedSupply", |
| 169 | + "Address", |
| 170 | + "Arrays", |
| 171 | + "Strings", |
| 172 | + "Checkpoints", |
| 173 | + "Context", |
| 174 | + "Counters", |
| 175 | + "Create2", |
| 176 | + "EIP712", |
| 177 | + "ECDSA", |
| 178 | + "MerkleProof", |
| 179 | + "SignatureChecker", |
| 180 | + "ConditionalEscrow", |
| 181 | + "Escrow", |
| 182 | + "RefundEscrow", |
| 183 | + "ERC165", |
| 184 | + "ERC165Checker", |
| 185 | + "ERC165Storage", |
| 186 | + "ERC1820Implementer", |
| 187 | + "Math", |
| 188 | + "SafeCast", |
| 189 | + "SafeMath", |
| 190 | + "SignedMath", |
| 191 | + "SignedSafeMath", |
| 192 | + "MulticallToken", |
| 193 | + "StorageSlot", |
| 194 | + "BitMap", |
| 195 | + "DoubleEndedQueue", |
| 196 | + "EnumerableMap", |
| 197 | + "EnumerableSet", |
| 198 | + "TimersBlockNumber", |
| 199 | + "TimersTimestamp" |
| 200 | +] |
| 201 | +def auto_hardhat_config(contractName,idx): |
| 202 | + fileName = "hardhat.config.{contractName}.js".format(contractName = contractName) |
| 203 | + with open(fileName,'w') as f: |
| 204 | + f.write(HardhatConfigData.format(contractName = contractName,idx = idx)) |
| 205 | + |
| 206 | +def auto_cmd(contractName): |
| 207 | + f''' |
| 208 | + {contractName} => |
| 209 | + "test:{contractName}": "hardhat test --config ./hardhat.config.{contractName}.js --grep \"Contract: {contractName} \"", |
| 210 | + :param contractName: |
| 211 | + :return: |
| 212 | + ''' |
| 213 | + return '''"test:{contractName}": "hardhat test --config ./hardhat.config.{contractName}.js --network testRpc --grep \\\"Contract: {contractName} \\\"",'''.format( |
| 214 | + contractName = contractName |
| 215 | + ) |
| 216 | + |
| 217 | +def main_config(): |
| 218 | + for idx in range(0,len(ContractList)): |
| 219 | + data = ContractList[idx] |
| 220 | + print(idx,data,idx % 5 *10) |
| 221 | + auto_hardhat_config(data,idx % 5 *10) |
| 222 | + |
| 223 | +def main_cmd(): |
| 224 | + for contractName in ContractList: |
| 225 | + print(auto_cmd(contractName)) |
| 226 | + |
| 227 | +if __name__ == '__main__': |
| 228 | + main_cmd() |
0 commit comments