From d40a0492d73161afb0f1fdda93a2188827fafe14 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Tue, 19 Mar 2024 22:00:22 +0000 Subject: [PATCH] Strengthen tests --- .gas-snapshot | 22 +++++++++++----------- test/DN420.t.sol | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 200333d..8bf28f5 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -164,19 +164,19 @@ DN420OnlyERC20Test:testTransferFromInsufficientBalanceReverts(address,uint256,ui DN420OnlyERC20Test:testTransferInsufficientBalanceReverts() (gas: 67140) DN420OnlyERC20Test:testTransferInsufficientBalanceReverts(address,uint256,uint256) (runs: 258, μ: 68173, ~: 68227) DN420OnlyERC20Test:test__codesize() (gas: 26885) -DN420Test:testERC1155Methods(uint256) (runs: 258, μ: 4350728, ~: 4584934) -DN420Test:testERC1155MethodsSelfTransfers(uint256) (runs: 258, μ: 2352430, ~: 2068336) +DN420Test:testERC1155Methods(uint256) (runs: 258, μ: 4346596, ~: 4601179) +DN420Test:testERC1155MethodsSelfTransfers(uint256) (runs: 258, μ: 2546320, ~: 2685708) DN420Test:testFindOwnedIds() (gas: 2651260) DN420Test:testMintNext() (gas: 2126914) -DN420Test:testMintToNonERC155RecipientReverts(uint256) (runs: 258, μ: 914483, ~: 799285) -DN420Test:testMintToRevertingERC155RecipientReverts(uint256) (runs: 258, μ: 1458154, ~: 981686) -DN420Test:testMintToZeroReverts(uint256) (runs: 258, μ: 742464, ~: 665153) -DN420Test:testMixed(uint256) (runs: 258, μ: 10537405, ~: 6419873) -DN420Test:testSafeBatchTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 2284301, ~: 2182469) -DN420Test:testSafeTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 1752377, ~: 1475201) -DN420Test:testTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 2882201, ~: 2868451) -DN420Test:testTransferMixedReverts(uint256) (runs: 258, μ: 4563582, ~: 3427133) -DN420Test:test__codesize() (gas: 65521) +DN420Test:testMintToNonERC155RecipientReverts(uint256) (runs: 258, μ: 899013, ~: 798557) +DN420Test:testMintToRevertingERC155RecipientReverts(uint256) (runs: 258, μ: 1453715, ~: 982568) +DN420Test:testMintToZeroReverts(uint256) (runs: 258, μ: 742100, ~: 665294) +DN420Test:testMixed(uint256) (runs: 258, μ: 10547010, ~: 6465435) +DN420Test:testSafeBatchTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 2238368, ~: 2182182) +DN420Test:testSafeTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 1784409, ~: 1475200) +DN420Test:testTransferFromToERC1155Recipient(uint256) (runs: 258, μ: 2881452, ~: 2868451) +DN420Test:testTransferMixedReverts(uint256) (runs: 258, μ: 4214140, ~: 3287831) +DN420Test:test__codesize() (gas: 66295) MappingsTest:testAddressPairMapSetAndGet(address[2],address[2],uint256,uint256) (runs: 258, μ: 45763, ~: 47075) MappingsTest:testBitmapSetAndGet(uint256) (runs: 258, μ: 453208, ~: 413769) MappingsTest:testBitmapSetAndGet(uint256,uint256,bool,bool) (runs: 258, μ: 25592, ~: 26270) diff --git a/test/DN420.t.sol b/test/DN420.t.sol index 8f40e16..78390e4 100644 --- a/test/DN420.t.sol +++ b/test/DN420.t.sol @@ -237,9 +237,13 @@ contract DN420Test is SoladyTest { } vm.prank(_ALICE); dn.setApprovalForAll(address(this), true); + + uint88 aliceAux = uint88(_random()); + dn.setAux(_ALICE, aliceAux); _testERC1155Methods(); _testERC1155Methods2(); _testERC1155Methods3(); + assertEq(dn.getAux(_ALICE), aliceAux); } function _testERC1155Methods() internal { @@ -383,8 +387,11 @@ contract DN420Test is SoladyTest { vm.prank(_ALICE); dn.setApprovalForAll(address(this), true); + uint88 aliceAux = uint88(_random()); + dn.setAux(_ALICE, aliceAux); _testERC1155MethodsSelfTransfers(); _testERC1155MethodsSelfTransfers2(); + assertEq(dn.getAux(_ALICE), aliceAux); } function _testERC1155MethodsSelfTransfers() internal { @@ -896,6 +903,17 @@ contract DN420Test is SoladyTest { uint256 amount = _bound(_random(), 1, 10) * _WAD; dn.mint(from, amount, ""); + uint88 fromAux = uint88(_random()); + dn.setAux(from, fromAux); + _testTransferMixedReverts(from); + _testTransferMixedReverts2(from); + _testTransferMixedReverts3(from); + assertEq(dn.getAux(from), fromAux); + } + + function _testTransferMixedReverts(address from) internal { + uint256 amount = dn.balanceOf(from); + if (_random() % 4 == 0) { vm.expectRevert(DN420.TransferToZeroAddress.selector); dn.mint(address(0), _random(), ""); @@ -934,7 +952,9 @@ contract DN420Test is SoladyTest { _safeTransferFromNFT(to, to, from, 1); } } + } + function _testTransferMixedReverts2(address from) internal { if (_random() % 4 == 0) { uint256 id = _bound(_random(), 0, 256); while (dn.owns(from, id)) id = _bound(_random(), 0, 256); @@ -951,7 +971,9 @@ contract DN420Test is SoladyTest { vm.expectRevert(DN420.TransferFromIncorrectOwner.selector); dn.safeBatchTransferFromNFTs(from, from, to, ids); } + } + function _testTransferMixedReverts3(address from) internal { if (_random() % 2 == 0) { address to = _random() % 2 == 0 ? from : _randomNonZeroAddress(); uint256[] memory ids = dn.findOwnedIds(from);