Skip to content

Commit

Permalink
feat(world-modules): add gas reports to ERC721Module (#1966)
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Morpheus authored Nov 30, 2023
1 parent 1077c7f commit 72df3d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@
"name": "transferFrom",
"gasUsed": 130250
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113956
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87965
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101835
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169433
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169704
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143638
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136798
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
Expand Down
47 changes: 47 additions & 0 deletions packages/world-modules/test/ERC721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
vm.assume(owner != address(0));

_expectMintEvent(owner, id);
startGasReport("mint");
token.mint(owner, id);
endGasReport();

assertEq(token.balanceOf(owner), 1);
assertEq(token.ownerOf(id), owner);
Expand All @@ -182,7 +184,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
assertEq(token.balanceOf(owner), 1, "after mint");

_expectBurnEvent(owner, id);
startGasReport("burn");
token.burn(id);
endGasReport();

assertEq(token.balanceOf(owner), 0, "after burn");

Expand All @@ -207,7 +211,10 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.mint(owner, tokenId);

vm.prank(owner);

startGasReport("transferFrom");
token.transferFrom(owner, to, tokenId);
endGasReport();

assertEq(token.balanceOf(owner), 0);
assertEq(token.balanceOf(to), 1);
Expand All @@ -221,7 +228,11 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {

vm.prank(owner);
_expectApprovalEvent(owner, spender, id);

startGasReport("approve");
token.approve(spender, id);
endGasReport();

assertEq(token.getApproved(id), spender);
}

Expand All @@ -230,7 +241,11 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {

vm.prank(owner);
_expectApprovalForAllEvent(owner, operator, approved);

startGasReport("setApprovalForAll");
token.setApprovalForAll(operator, approved);
endGasReport();

assertEq(token.isApprovedForAll(owner, operator), approved);
}

Expand Down Expand Up @@ -276,7 +291,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.setApprovalForAll(operator, true);

vm.prank(operator);
startGasReport("safeTransferFrom");
token.safeTransferFrom(from, to, id);
endGasReport();

assertEq(token.getApproved(id), address(0));
assertEq(token.ownerOf(id), to);
Expand Down Expand Up @@ -340,7 +357,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
_assumeEOA(to);
vm.assume(to != address(0));

startGasReport("safeMint");
token.safeMint(to, id);
endGasReport();

assertEq(token.ownerOf(id), to);
assertEq(token.balanceOf(to), 1);
Expand Down Expand Up @@ -577,4 +596,32 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
vm.expectRevert(abi.encodeWithSelector(ERC721NonexistentToken.selector, id));
token.ownerOf(id);
}

function testMintGas() public {
testMint(1e18, address(0xABCD));
}

function testBurnGas() public {
testBurn(1e18, address(0xABCD));
}

function testTransferFromGas() public {
testTransferFrom(address(0xABCD), address(0xBEEF), 1e18);
}

function testApproveGas() public {
testApprove(address(0xABCD), 1e18, address(0xBEEF));
}

function testApproveAllGas() public {
testApproveAll(address(0xABCD), address(0xBEEF), true);
}

function testSafeTransferFromToEOAGas() public {
testSafeTransferFromToEOA(1, address(0xABCD), address(0xBEEF), address(0xDEFE));
}

function testSafeMintToEOAGas() public {
testSafeMintToEOA(1, address(0xABCD));
}
}

0 comments on commit 72df3d3

Please sign in to comment.