Created
October 18, 2023 14:53
-
-
Save agostbiro/c5b0f273b0a21abdbaa159cf9e269260 to your computer and use it in GitHub Desktop.
Hardhat Network `eth_sendTransaction` performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Performance test for Hardhat Network with the `eth_sendTransaction` method. Reports the elapsed time for 1000 calls. | |
To run: | |
1. Check out the Hardhat repo: `git clone https://github.com/NomicFoundation/hardhat/` | |
2. `cd hardhat` | |
3. `yarn` | |
4. `cd packages/hardhat-core` | |
5. `yarn build` | |
6. `node send-transaction.js` | |
To see a flame chart: | |
1. `npm install clinic -g` | |
2. From `package/hardhat-core`: `clinic flame -- node send-transaction.js` | |
*/ | |
const { | |
bufferToHex, | |
privateToAddress, | |
toBuffer, | |
} = require("@nomicfoundation/ethereumjs-util"); | |
const { defaultHardhatNetworkParams } = require("./internal/core/config/default-config"); | |
const { HardhatNetworkProvider } = require("./internal/hardhat-network/provider/provider"); | |
const {ModulesLogger} = require("./internal/hardhat-network/provider/modules/logger"); | |
const DEFAULT_HARDFORK = "shanghai"; | |
const DEFAULT_CHAIN_ID = 123; | |
const DEFAULT_NETWORK_ID = 234; | |
const DEFAULT_BLOCK_GAS_LIMIT = 6000000n; | |
const DEFAULT_ALLOW_UNLIMITED_CONTRACT_SIZE = false; | |
const DEFAULT_MEMPOOL_CONFIG = { | |
order: "priority", | |
}; | |
const DEFAULT_MINING_CONFIG = { | |
auto: true, | |
interval: 0, | |
mempool: DEFAULT_MEMPOOL_CONFIG, | |
}; | |
const DEFAULT_ACCOUNTS = [ | |
{ | |
privateKey: | |
"0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109", | |
balance: 10n ** 21n, | |
}, | |
{ | |
privateKey: | |
"0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd10a", | |
balance: 10n ** 21n, | |
}, | |
{ | |
privateKey: | |
"0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd10b", | |
balance: 10n ** 21n, | |
}, | |
{ | |
privateKey: | |
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", | |
balance: 10n ** 21n, | |
}, | |
]; | |
const DEFAULT_ACCOUNTS_ADDRESSES = DEFAULT_ACCOUNTS.map((account) => | |
bufferToHex(privateToAddress(toBuffer(account.privateKey))).toLowerCase() | |
); | |
(async () => { | |
const logger = new ModulesLogger(false); | |
const provider = new HardhatNetworkProvider({ | |
hardfork: DEFAULT_HARDFORK, | |
chainId: DEFAULT_CHAIN_ID, | |
networkId: DEFAULT_NETWORK_ID, | |
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT, | |
initialBaseFeePerGas: undefined, | |
minGasPrice: 0n, | |
throwOnTransactionFailures: true, | |
throwOnCallFailures: true, | |
automine: DEFAULT_MINING_CONFIG.auto, | |
intervalMining: DEFAULT_MINING_CONFIG.interval, | |
mempoolOrder: DEFAULT_MINING_CONFIG.mempool.order, | |
chains: defaultHardhatNetworkParams.chains, | |
genesisAccounts: DEFAULT_ACCOUNTS, | |
allowUnlimitedContractSize: DEFAULT_ALLOW_UNLIMITED_CONTRACT_SIZE, | |
forkConfig: undefined, | |
coinbase: undefined, | |
allowBlocksWithSameTimestamp: false, | |
enableTransientStorage: false, | |
}, logger); | |
const n = 1; | |
const value = `0x${n.toString(16)}`; | |
const start = Date.now(); | |
for (let i = 0; i < 1000; i++) { | |
await provider.request({ | |
method: "eth_sendTransaction", | |
params: [{ | |
from: DEFAULT_ACCOUNTS_ADDRESSES[0], | |
to: DEFAULT_ACCOUNTS_ADDRESSES[1], | |
value, | |
}] | |
}); | |
} | |
const end = Date.now(); | |
return end - start; | |
})().then((delta) => console.log(`${delta} ms`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment