Skip to content

Commit

Permalink
measure gas
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Feb 2, 2022
1 parent 50dcb15 commit 3b389f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 737 deletions.
29 changes: 0 additions & 29 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
import "@nomiclabs/hardhat-ethers"
import "hardhat-gas-reporter"

export default {
paths: {
artifacts: "build/artifacts",
cache: "build/cache",
sources: "contracts",
},
solidity: {
compilers: [{ version: "0.8.6" }],
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
hardhat: {
// allowUnlimitedContractSize: true,
},
},
namedAccounts: {
deployer: 0,
},
mocha: {
timeout: 2000000,
},
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"eslint-plugin-prettier": "^4.0.0",
"ethers": "^5.5.2",
"hardhat": "^2.8.0",
"hardhat-gas-reporter": "^1.0.6",
"rimraf": "^3.0.2",
"solc": "^0.8.11",
"ts-node": "^10.4.0",
Expand Down
27 changes: 8 additions & 19 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,11 @@ function solCompile(contractSource: string) {
},
},
},
}),
{ import: findImports }
})
)
)
}

function findImports(importPath: string) {
if (importPath === "@rari-capital/solmate/src/utils/SSTORE2.sol") {
return {
contents: readFileSync(
path.join(__dirname, "../node_modules", importPath),
{
encoding: "utf8",
flag: "r",
}
),
}
} else {
return { error: "File not found" }
}
}

describe("end-to-end test suite", () => {
const cases = readdirSync(path.join(__dirname, "cases"), {
withFileTypes: true,
Expand Down Expand Up @@ -111,9 +94,13 @@ describe("end-to-end test suite", () => {

const [signer] = await ethers.getSigners()
const factory = new ethers.ContractFactory(abi, bytecode, signer)
const deploymentData = factory.interface.encodeDeploy()
const gas = await ethers.provider.estimateGas({ data: deploymentData })
contract = await factory.deploy()

console.log("Successfully deployed template contract")
console.log(
`Successfully deployed template contract (gas cost: ${gas})`
)
})

const [, outputExtension] = templateFile.name.split(".")
Expand Down Expand Up @@ -146,7 +133,9 @@ describe("end-to-end test suite", () => {
)

it(`renders correctly for inputs #${inputIndex}`, async () => {
const gas = await contract.estimateGas.render(input)
const result = await contract.render(input)
console.log(`Gas for rendering input #${inputIndex}: ${gas}`)
expect(result).to.equal(expectedOutput)
})

Expand Down
Loading

0 comments on commit 3b389f4

Please sign in to comment.