diff --git a/.gas-snapshot b/.gas-snapshot index e0f37d5..7a7493e 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -145,27 +145,28 @@ DN404Test:test__codesize() (gas: 61620) DN404ZeroIndexedTest:testBatchNFTLog() (gas: 326053) DN404ZeroIndexedTest:testBurnOnTransfer(uint32,address) (runs: 270, μ: 255124, ~: 255124) DN404ZeroIndexedTest:testFnSelectorNotRecognized() (gas: 6268) -DN404ZeroIndexedTest:testInitialize(uint32,address) (runs: 272, μ: 109068, ~: 113108) +DN404ZeroIndexedTest:testInitialize(uint32,address) (runs: 272, μ: 109048, ~: 113108) DN404ZeroIndexedTest:testMintAndBurn() (gas: 343030) -DN404ZeroIndexedTest:testMintAndBurn2() (gas: 280268) +DN404ZeroIndexedTest:testMintAndBurn2() (gas: 280290) DN404ZeroIndexedTest:testMintNext() (gas: 701766) -DN404ZeroIndexedTest:testMintNextContiguous(uint256) (runs: 272, μ: 559796, ~: 516666) -DN404ZeroIndexedTest:testMintOnTransfer(uint32,address) (runs: 270, μ: 269705, ~: 269705) -DN404ZeroIndexedTest:testMixed(bytes32) (runs: 272, μ: 577183, ~: 498226) -DN404ZeroIndexedTest:testNameAndSymbol(string,string) (runs: 272, μ: 205773, ~: 206176) +DN404ZeroIndexedTest:testMintNextContiguous(uint256) (runs: 272, μ: 568584, ~: 524801) +DN404ZeroIndexedTest:testMintOnTransfer(uint32,address) (runs: 270, μ: 269727, ~: 269727) +DN404ZeroIndexedTest:testMixed(bytes32) (runs: 272, μ: 564213, ~: 505534) +DN404ZeroIndexedTest:testNameAndSymbol(string,string) (runs: 272, μ: 205728, ~: 206131) DN404ZeroIndexedTest:testNumAliasesOverflowReverts() (gas: 40944) DN404ZeroIndexedTest:testOwnedIds() (gas: 347336) -DN404ZeroIndexedTest:testOwnedIds(uint256) (runs: 272, μ: 261162, ~: 284431) -DN404ZeroIndexedTest:testPermit2() (gas: 455270) -DN404ZeroIndexedTest:testRegisterAndResolveAlias(address,address) (runs: 272, μ: 120044, ~: 120191) -DN404ZeroIndexedTest:testSetAndGetAux(address,uint88) (runs: 272, μ: 21987, ~: 22272) +DN404ZeroIndexedTest:testOwnedIds(uint256) (runs: 272, μ: 263381, ~: 286216) +DN404ZeroIndexedTest:testPermit2() (gas: 455292) +DN404ZeroIndexedTest:testRegisterAndResolveAlias(address,address) (runs: 272, μ: 120191, ~: 120191) +DN404ZeroIndexedTest:testSetAndGetAux(address,uint88) (runs: 272, μ: 22004, ~: 22289) DN404ZeroIndexedTest:testSetAndGetOperatorApprovals(address,address,bool) (runs: 272, μ: 129643, ~: 119840) -DN404ZeroIndexedTest:testSetAndGetSkipNFT() (gas: 708368) -DN404ZeroIndexedTest:testTokenURI(string,uint256) (runs: 272, μ: 156264, ~: 156411) +DN404ZeroIndexedTest:testSetAndGetSkipNFT() (gas: 708390) +DN404ZeroIndexedTest:testTokenURI(string,uint256) (runs: 272, μ: 156286, ~: 156433) DN404ZeroIndexedTest:testTransferWithMirrorEvent() (gas: 409821) DN404ZeroIndexedTest:testTransfersAndBurns() (gas: 485767) -DN404ZeroIndexedTest:testWrapAround(uint32,uint256) (runs: 272, μ: 380944, ~: 388042) -DN404ZeroIndexedTest:test__codesize() (gas: 61169) +DN404ZeroIndexedTest:testWrapAround(uint32,uint256) (runs: 272, μ: 380053, ~: 387951) +DN404ZeroIndexedTest:testWrapNFTIdEquivalence(uint256,uint256,bool) (runs: 272, μ: 1379, ~: 1418) +DN404ZeroIndexedTest:test__codesize() (gas: 61415) DN420OnlyERC20Test:testApprove() (gas: 35770) DN420OnlyERC20Test:testApprove(address,uint256) (runs: 272, μ: 30882, ~: 31321) DN420OnlyERC20Test:testBurn() (gas: 49034) diff --git a/test/DN404ZeroIndexed.t.sol b/test/DN404ZeroIndexed.t.sol index 0143565..c0c874f 100644 --- a/test/DN404ZeroIndexed.t.sol +++ b/test/DN404ZeroIndexed.t.sol @@ -809,4 +809,40 @@ contract DN404ZeroIndexedTest is SoladyTest { } } } + + function testWrapNFTIdEquivalence(uint256 id, uint256 idLimit, bool useOneIndexed) public { + id = _bound(id, 0, 0xffff); + idLimit = _bound(idLimit, 0, 0xff); + // if (useOneIndexed) while (id == 0) id = _random(); + uint256 original = _wrapNFTIdOrigina(id, idLimit, useOneIndexed); + assertEq(_wrapNFTId(id, idLimit, useOneIndexed), original); + } + + function _wrapNFTIdOrigina(uint256 id, uint256 idLimit, bool useOneIndexed) + internal + pure + returns (uint256) + { + if (useOneIndexed) { + return id <= idLimit ? id : 1; + } else { + return id < idLimit ? id : 0; + } + } + + function _wrapNFTId(uint256 id, uint256 idLimit, bool useOneIndexed) + internal + pure + returns (uint256 result) + { + result = useOneIndexed ? 1 : 0; + /// @solidity memory-safe-assembly + assembly { + result := + or( + mul(or(mul(iszero(gt(id, idLimit)), id), gt(id, idLimit)), result), + mul(mul(lt(id, idLimit), id), iszero(result)) + ) + } + } }