Skip to content

Commit fef8d60

Browse files
committed
fix: minor test fixes
1 parent 56ccb85 commit fef8d60

File tree

7 files changed

+63
-99
lines changed

7 files changed

+63
-99
lines changed

script/Deploy.s.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Script} from "forge-std/Script.sol";
55
import {BatteringRam} from "../src/BatteringRam.sol";
66
import {Catapult} from "../src/Catapult.sol";
77
import {Trebuchet} from "../src/Trebuchet.sol";
8+
import {CatapultNFT} from "../src/CatapultNFT.sol";
89

910
contract DeploySiege is Script {
1011
function run() public {

script/token/DeployMyNFT.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ contract DeployMyNFT is Script {
1111

1212
vm.startBroadcast(deployerPrivateKey);
1313

14-
MyNFT nft = new MyNFT("MyNFT", "MNFT", initialBaseURI);
14+
new MyNFT("MyNFT", "MNFT", initialBaseURI);
1515

1616
vm.stopBroadcast();
1717
}

src/CatapultNFT renamed to src/CatapultNFT.sol

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "@openzeppelin/contracts/utils/Strings.sol";
55

66
/// @notice Modern, minimalist, and gas efficient ERC-721 implementation.
77
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC721.sol)
8-
contract ERC721 {
8+
contract CatapultNFT {
99
using Strings for uint256;
1010
/*//////////////////////////////////////////////////////////////
1111
EVENTS
@@ -29,9 +29,9 @@ contract ERC721 {
2929

3030
uint256 public tokenId;
3131

32-
// function tokenURI(uint256 id) public view virtual returns (string memory){
33-
// return tokenURI(id);
34-
// };
32+
// function tokenURI(uint256 id) public view virtual returns (string memory){
33+
// return tokenURI(id);
34+
// };
3535

3636
/*//////////////////////////////////////////////////////////////
3737
ERC721 BALANCE/OWNER STORAGE
@@ -88,18 +88,13 @@ contract ERC721 {
8888
emit ApprovalForAll(msg.sender, operator, approved);
8989
}
9090

91-
function transferFrom(
92-
address from,
93-
address to,
94-
uint256 id
95-
) public virtual {
91+
function transferFrom(address from, address to, uint256 id) public virtual {
9692
require(from == _ownerOf[id], "WRONG_FROM");
9793

9894
require(to != address(0), "INVALID_RECIPIENT");
9995

10096
require(
101-
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
102-
"NOT_AUTHORIZED"
97+
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id], "NOT_AUTHORIZED"
10398
);
10499

105100
// Underflow of the sender's balance is impossible because we check for
@@ -117,38 +112,29 @@ contract ERC721 {
117112
emit Transfer(from, to, id);
118113
}
119114

120-
function safeTransferFrom(
121-
address from,
122-
address to,
123-
uint256 id
124-
) public virtual {
115+
function safeTransferFrom(address from, address to, uint256 id) public virtual {
125116
transferFrom(from, to, id);
126117

127118
require(
128-
to.code.length == 0 ||
129-
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
130-
ERC721TokenReceiver.onERC721Received.selector,
119+
to.code.length == 0
120+
|| ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "")
121+
== ERC721TokenReceiver.onERC721Received.selector,
131122
"UNSAFE_RECIPIENT"
132123
);
133124
}
134125

135-
function safeTransferFrom(
136-
address from,
137-
address to,
138-
uint256 id,
139-
bytes calldata data
140-
) public virtual {
126+
function safeTransferFrom(address from, address to, uint256 id, bytes calldata data) public virtual {
141127
transferFrom(from, to, id);
142128

143129
require(
144-
to.code.length == 0 ||
145-
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
146-
ERC721TokenReceiver.onERC721Received.selector,
130+
to.code.length == 0
131+
|| ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data)
132+
== ERC721TokenReceiver.onERC721Received.selector,
147133
"UNSAFE_RECIPIENT"
148134
);
149135
}
150136

151-
function tokenURI(uint256 id) public view virtual returns (string memory) {
137+
function tokenURI(uint256 id) public view virtual returns (string memory) {
152138
return string(abi.encodePacked(baseURI, "/", Strings.toString(id), ".json"));
153139
}
154140

@@ -157,10 +143,9 @@ contract ERC721 {
157143
//////////////////////////////////////////////////////////////*/
158144

159145
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
160-
return
161-
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
162-
interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721
163-
interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
146+
return interfaceId == 0x01ffc9a7 // ERC165 Interface ID for ERC165
147+
|| interfaceId == 0x80ac58cd // ERC165 Interface ID for ERC721
148+
|| interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
164149
}
165150

166151
/*//////////////////////////////////////////////////////////////
@@ -209,24 +194,20 @@ contract ERC721 {
209194
_mint(to, id);
210195

211196
require(
212-
to.code.length == 0 ||
213-
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "") ==
214-
ERC721TokenReceiver.onERC721Received.selector,
197+
to.code.length == 0
198+
|| ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "")
199+
== ERC721TokenReceiver.onERC721Received.selector,
215200
"UNSAFE_RECIPIENT"
216201
);
217202
}
218203

219-
function _safeMint(
220-
address to,
221-
uint256 id,
222-
bytes memory data
223-
) internal virtual {
204+
function _safeMint(address to, uint256 id, bytes memory data) internal virtual {
224205
_mint(to, id);
225206

226207
require(
227-
to.code.length == 0 ||
228-
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==
229-
ERC721TokenReceiver.onERC721Received.selector,
208+
to.code.length == 0
209+
|| ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data)
210+
== ERC721TokenReceiver.onERC721Received.selector,
230211
"UNSAFE_RECIPIENT"
231212
);
232213
}
@@ -235,12 +216,7 @@ contract ERC721 {
235216
/// @notice A generic interface for a contract which properly accepts ERC721 tokens.
236217
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC721.sol)
237218
abstract contract ERC721TokenReceiver {
238-
function onERC721Received(
239-
address,
240-
address,
241-
uint256,
242-
bytes calldata
243-
) external virtual returns (bytes4) {
219+
function onERC721Received(address, address, uint256, bytes calldata) external virtual returns (bytes4) {
244220
return ERC721TokenReceiver.onERC721Received.selector;
245221
}
246222
}

src/tokens/MyNFT.sol

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ pragma solidity ^0.8.20;
44
import {ERC721} from "../../lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
55
import {ERC721Enumerable} from "../../lib/openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
66
import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
7-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7+
import {Strings} from "../../lib/openzeppelin-contracts/contracts/utils/Strings.sol";
88

9+
/// @notice EXAMPLE, DO NOT USE THIS CONTRACT IN PRODUCTION
910
contract MyNFT is ERC721, ERC721Enumerable, Ownable {
1011
using Strings for uint256;
1112

1213
uint256 private _nextTokenId;
1314
uint256 public mintPrice = 0.01 ether;
1415
string public baseTokenURI;
1516

16-
constructor(
17-
string memory name,
18-
string memory symbol,
19-
string memory initialBaseURI
20-
) ERC721(name, symbol) Ownable(msg.sender) {
17+
constructor(string memory name, string memory symbol, string memory initialBaseURI)
18+
ERC721(name, symbol)
19+
Ownable(msg.sender)
20+
{
2121
baseTokenURI = initialBaseURI;
2222
}
2323

@@ -45,24 +45,19 @@ contract MyNFT is ERC721, ERC721Enumerable, Ownable {
4545
}
4646

4747
// Override required functions
48-
function _update(
49-
address to,
50-
uint256 tokenId,
51-
address auth
52-
) internal override(ERC721, ERC721Enumerable) returns (address) {
48+
function _update(address to, uint256 tokenId, address auth)
49+
internal
50+
override(ERC721, ERC721Enumerable)
51+
returns (address)
52+
{
5353
return super._update(to, tokenId, auth);
5454
}
5555

56-
function _increaseBalance(
57-
address account,
58-
uint128 value
59-
) internal override(ERC721, ERC721Enumerable) {
56+
function _increaseBalance(address account, uint128 value) internal override(ERC721, ERC721Enumerable) {
6057
super._increaseBalance(account, value);
6158
}
6259

63-
function supportsInterface(
64-
bytes4 interfaceId
65-
) public view override(ERC721, ERC721Enumerable) returns (bool) {
60+
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
6661
return super.supportsInterface(interfaceId);
6762
}
6863
}

src/tokens/MyToken.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity ^0.8.20;
33

44
import {ERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
55

6+
/// @notice EXAMPLE, DO NOT USE THIS CONTRACT IN PRODUCTION
67
contract MyToken is ERC20 {
78
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
89
_mint(msg.sender, initialSupply);

src/tokens/TokenizedVault.sol

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable
77
import {Math} from "../../lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
88
import {IERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
99

10+
/// @notice EXAMPLE, DO NOT USE THIS CONTRACT IN PRODUCTION
1011
contract TokenizedVault is ERC4626, Ownable {
1112
using Math for uint256;
1213

1314
uint256 public managementFee; // Fee represented in basis points (1/10000)
1415
uint256 public constant MAX_FEE = 1000; // Maximum fee of 10% (1000 basis points)
1516
uint256 private constant BASIS_POINTS = 10000;
1617

17-
constructor(
18-
IERC20 asset_,
19-
string memory name_,
20-
string memory symbol_,
21-
uint256 initialFee_
22-
) ERC4626(asset_) ERC20(name_, symbol_) Ownable(msg.sender) {
23-
require(initialFee_ <= MAX_FEE, "Fee too high");
18+
error FeeTooHigh();
19+
20+
constructor(IERC20 asset_, string memory name_, string memory symbol_, uint256 initialFee_)
21+
ERC4626(asset_)
22+
ERC20(name_, symbol_)
23+
Ownable(msg.sender)
24+
{
25+
if (initialFee_ > MAX_FEE) revert FeeTooHigh();
2426
managementFee = initialFee_;
2527
}
2628

2729
function setManagementFee(uint256 newFee) external onlyOwner {
28-
require(newFee <= MAX_FEE, "Fee too high");
30+
if (newFee > MAX_FEE) revert FeeTooHigh();
2931
managementFee = newFee;
3032
}
3133

@@ -35,12 +37,7 @@ contract TokenizedVault is ERC4626, Ownable {
3537
return totalAssetsValue - feeAmount;
3638
}
3739

38-
function _deposit(
39-
address caller,
40-
address receiver,
41-
uint256 assets,
42-
uint256 shares
43-
) internal virtual override {
40+
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual override {
4441
super._deposit(caller, receiver, assets, shares);
4542

4643
// Transfer management fee to owner
@@ -50,13 +47,11 @@ contract TokenizedVault is ERC4626, Ownable {
5047
}
5148
}
5249

53-
function _withdraw(
54-
address caller,
55-
address receiver,
56-
address owner_,
57-
uint256 assets,
58-
uint256 shares
59-
) internal virtual override {
50+
function _withdraw(address caller, address receiver, address owner_, uint256 assets, uint256 shares)
51+
internal
52+
virtual
53+
override
54+
{
6055
super._withdraw(caller, receiver, owner_, assets, shares);
6156

6257
// Apply fee on withdrawal

test/token/TokenizedVault.t.sol

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ contract TokenizedVaultTest is Test {
3131
asset = new MockERC20();
3232

3333
// Deploy vault
34-
vault = new TokenizedVault(
35-
IERC20(address(asset)),
36-
"Vault Token",
37-
"vTKN",
38-
INITIAL_FEE
39-
);
34+
vault = new TokenizedVault(IERC20(address(asset)), "Vault Token", "vTKN", INITIAL_FEE);
4035

4136
// Transfer initial tokens to users
4237
asset.transfer(user1, INITIAL_DEPOSIT);
@@ -70,7 +65,7 @@ contract TokenizedVaultTest is Test {
7065
uint256 shares = vault.deposit(depositAmount, user1);
7166

7267
uint256 expectedAssets = vault.previewRedeem(shares);
73-
uint256 withdrawnAssets = vault.withdraw(expectedAssets, user1, user1);
68+
uint256 withdrawnAssets = vault.redeem(shares, user1, user1);
7469

7570
assertEq(withdrawnAssets, expectedAssets);
7671
assertEq(vault.balanceOf(user1), 0);
@@ -97,9 +92,10 @@ contract TokenizedVaultTest is Test {
9792
assertEq(vault.managementFee(), newFee);
9893
}
9994

100-
function testFailSetManagementFeeTooHigh() public {
95+
function testSetManagementFeeTooHigh() public {
10196
uint256 tooHighFee = 1100; // 11%
102-
vm.expectRevert("Fee too high");
97+
98+
vm.expectRevert(TokenizedVault.FeeTooHigh.selector);
10399
vault.setManagementFee(tooHighFee);
104100
}
105101
}

0 commit comments

Comments
 (0)