-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests and mocks to get 100% coverage
Also some small improvementes to the contract
- Loading branch information
Andres Adjimann
committed
Aug 22, 2024
1 parent
85e4a44
commit 1e9d2d9
Showing
12 changed files
with
545 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.26; | ||
|
||
import {NFTCollection} from "../nft-collection/NFTCollection.sol"; | ||
|
||
|
||
contract NFTCollectionMock is NFTCollection { | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor(address _collectionOwner, address _initialTrustedForwarder) { | ||
_transferOwnership(_collectionOwner); | ||
_setTrustedForwarder(_initialTrustedForwarder); | ||
} | ||
|
||
function NFTCollection_init( | ||
address _collectionOwner, | ||
string memory _initialBaseURI, | ||
string memory _name, | ||
string memory _symbol, | ||
address payable _mintTreasury, | ||
address _signAddress, | ||
address _initialTrustedForwarder, | ||
address _allowedToExecuteMint, | ||
uint256 _maxSupply, | ||
MintingDefaults memory _mintingDefaults | ||
) external { | ||
__NFTCollection_init( | ||
_collectionOwner, | ||
_initialBaseURI, | ||
_name, | ||
_symbol, | ||
_mintTreasury, | ||
_signAddress, | ||
_initialTrustedForwarder, | ||
_allowedToExecuteMint, | ||
_maxSupply, | ||
_mintingDefaults | ||
); | ||
} | ||
|
||
/** | ||
* @notice ERC2771 compatible msg.sender getter | ||
* @return sender msg.sender | ||
*/ | ||
function msgSender(address) external view returns (address) { | ||
return super._msgSender(); | ||
} | ||
|
||
/** | ||
* @notice ERC2771 compatible msg.data getter | ||
* @return msg.data | ||
*/ | ||
function msgData(address) external view returns (bytes calldata) { | ||
return super._msgData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
// solhint-disable one-contract-per-file | ||
pragma solidity 0.8.26; | ||
|
||
contract ReenterMock { | ||
struct MintArgs { | ||
CollectionInterface target; | ||
address wallet; | ||
uint256 amount; | ||
uint256 signatureId; | ||
bytes signature; | ||
} | ||
|
||
struct AllowedArgs { | ||
CollectionInterface target; | ||
address minterToken; | ||
} | ||
|
||
MintArgs public mintArgs; | ||
AllowedArgs public allowedArgs; | ||
|
||
function mintReenter( | ||
CollectionInterface _target, | ||
address _wallet, | ||
uint256 _amount, | ||
uint256 _signatureId, | ||
bytes calldata _signature | ||
) external { | ||
mintArgs = MintArgs({target : _target, wallet : _wallet, amount : _amount, signatureId : _signatureId, signature : _signature}); | ||
_target.mint(_wallet, _amount, _signatureId, _signature); | ||
} | ||
|
||
function setAllowedExecuteMintReenter(CollectionInterface _target, address _minterToken) external { | ||
allowedArgs = AllowedArgs({target : _target, minterToken : _minterToken}); | ||
_target.setAllowedExecuteMint(_minterToken); | ||
} | ||
|
||
// reenter setAllowedExecuteMint | ||
function decimals() external returns (uint256) { | ||
allowedArgs.target.setAllowedExecuteMint(allowedArgs.minterToken); | ||
return 12; | ||
} | ||
|
||
// reenter mint | ||
function transferFrom( | ||
address, | ||
address, | ||
uint256 | ||
) external { | ||
mintArgs.target.mint(mintArgs.wallet, mintArgs.amount, mintArgs.signatureId, mintArgs.signature); | ||
} | ||
|
||
} | ||
|
||
interface CollectionInterface { | ||
function mint( | ||
address _wallet, | ||
uint256 _amount, | ||
uint256 _signatureId, | ||
bytes calldata _signature | ||
) external; | ||
|
||
function setAllowedExecuteMint(address _minterToken) external; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1e9d2d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report