Skip to content

Commit

Permalink
Strengthen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Mar 19, 2024
1 parent 4e8728f commit d40a049
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
22 changes: 11 additions & 11 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/DN420.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(), "");
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d40a049

Please sign in to comment.