From 0f7ca6d72b3ec8a03156e560f02210b9242cb6e2 Mon Sep 17 00:00:00 2001 From: legendaryKnight1 Date: Wed, 26 Jul 2023 18:33:29 +0100 Subject: [PATCH 1/2] Update Unit test of ERC721ACH for gas estimation for minting nfts --- test/ERC721ACH.t.sol | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/ERC721ACH.t.sol b/test/ERC721ACH.t.sol index 8348e25..f8a3126 100644 --- a/test/ERC721ACH.t.sol +++ b/test/ERC721ACH.t.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.15; + +import "forge-std/console.sol"; import {Vm} from "forge-std/Vm.sol"; import {DSTest} from "ds-test/test.sol"; import {ERC721ACHMock} from "./utils/ERC721ACHMock.sol"; @@ -144,4 +146,43 @@ contract ERC721ACHTest is DSTest { address(erc721Mock.isApprovedForAllHook()) ); } + + function test_gasEstimateForSingleMint() public { + address buyer = address(0x1111); + console.logString( + "=====================gas estimation for minting single NFT==========================" + ); + uint originGasLeft; + uint gasDelta; + originGasLeft = gasleft(); + erc721Mock.mint(buyer, 1); + gasDelta = originGasLeft - gasleft() - 100; + console.log("gasDelta: %d", gasDelta); + } + + function test_gasEstimateForMint2NFTs() public { + address buyer = address(0x1111); + console.logString( + "=====================gas estimation for minting 2 NFT==========================" + ); + uint originGasLeft; + uint gasDelta; + originGasLeft = gasleft(); + erc721Mock.mint(buyer, 2); + gasDelta = originGasLeft - gasleft() - 100; + console.log("gasDelta: %d", gasDelta); + } + + function test_gasEstimateForMint3NFTs() public { + address buyer = address(0x1111); + console.logString( + "=====================gas estimation for minting 3 NFT==========================" + ); + uint originGasLeft; + uint gasDelta; + originGasLeft = gasleft(); + erc721Mock.mint(buyer, 3); + gasDelta = originGasLeft - gasleft() - 100; + console.log("gasDelta: %d", gasDelta); + } } From 347f75a921259f7b9cbe2c514edc5dc64df035cb Mon Sep 17 00:00:00 2001 From: legendaryKnight1 Date: Wed, 26 Jul 2023 18:34:12 +0100 Subject: [PATCH 2/2] update foundary configure to get gas estimation for gas reports --- foundry.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/foundry.toml b/foundry.toml index e6810b2..069113c 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,5 +2,6 @@ src = 'src' out = 'out' libs = ['lib'] +gas_reports = ["ERC721ACHMock"] # See more config options https://github.com/foundry-rs/foundry/tree/master/config \ No newline at end of file