diff --git a/foundry.toml b/foundry.toml index e6810b2..c7dd4a8 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,5 +2,11 @@ src = 'src' out = 'out' libs = ['lib'] +gas_reports = ["SendIt"] -# See more config options https://github.com/foundry-rs/foundry/tree/master/config \ No newline at end of file +[rpc_endpoints] +goerli = "${GOERLI_RPC_URL}" +local = "http://127.0.0.1:8545" + +[etherscan] +goerli = { key = "${ETHERSCAN_API_KEY}" } \ No newline at end of file diff --git a/script/NFT.s.sol b/script/NFT.s.sol new file mode 100644 index 0000000..8988183 --- /dev/null +++ b/script/NFT.s.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "forge-std/Script.sol"; +import "../src/NFT.sol"; + +contract MyScript is Script { + // function run() external { + // uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + // vm.startBroadcast(deployerPrivateKey); + // NFT nft = new NFT(); + // vm.stopBroadcast(); + // } + function run() public { + vm.broadcast(); + } +} \ No newline at end of file diff --git a/src/NFT.sol b/src/NFT.sol new file mode 100644 index 0000000..086a5a8 --- /dev/null +++ b/src/NFT.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "solmate/tokens/ERC721.sol"; +import "openzeppelin-contracts/utils/Strings.sol"; + +contract NFT is ERC721 { + uint256 public currentTokenId; + + constructor() ERC721("NFT", "NFT") {} + + function mint(address r, uint256 mintAmount) external { + for(uint256 i; i < mintAmount; i++) { + currentTokenId += 1; + _safeMint(r, currentTokenId); + } + } + + function tokenURI(uint256 id) public view virtual override returns (string memory) { + return Strings.toString(id); + } +} diff --git a/src/SendIt.sol b/src/SendIt.sol index d219f0f..13e3b02 100644 --- a/src/SendIt.sol +++ b/src/SendIt.sol @@ -39,11 +39,11 @@ contract SendIt { ) public { if (isERC1155) { require(ERC1155(contractAddress).balanceOf(msg.sender, tokenIndex) > 0, "Sender is not the token owner, cannot proceed with transfer."); - require(ERC1155(contractAddress).isApprovedForAll(msg.sender, address(this)), "Contract not approved to send token on Sender behalf."); + require(ERC1155(contractAddress).isApprovedForAll(msg.sender, address(this)), "Contract not approved to send tokens on Sender behalf."); ERC1155(contractAddress).safeTransferFrom(msg.sender, recipient, tokenIndex, 1, bytes("")); } else { require(msg.sender == ERC721(contractAddress).ownerOf(tokenIndex), "Sender is not the token owner, cannot proceed with transfer."); - require(ERC721(contractAddress).getApproved(tokenIndex) == address(this), "Contract not approved to send token on Sender behalf."); + require(ERC721(contractAddress).isApprovedForAll(msg.sender, address(this)), "Contract not approved to send tokens on Sender behalf."); ERC721(contractAddress).safeTransferFrom(msg.sender, recipient, tokenIndex); } emit TokenTransfer(contractAddress, tokenIndex, msg.sender, recipient); diff --git a/test/SendIt.t.sol b/test/SendIt.t.sol index c65632c..31f23bc 100644 --- a/test/SendIt.t.sol +++ b/test/SendIt.t.sol @@ -2,17 +2,43 @@ pragma solidity ^0.8.13; import "forge-std/Test.sol"; -import "../src/SendIt.sol"; +import {SendIt} from "../src/SendIt.sol"; +import {NFT} from "../src/NFT.sol"; contract SendItTest is Test { + using stdStorage for StdStorage; SendIt public sendit; + NFT public nft; function setUp() public { sendit = new SendIt(); + nft = new NFT(); } - function testUpdateVault() public { - sendit.updateVault(address(3)); - assertEq(sendit.addressVault(address(0)), address(3)); + function testBulkTransferSucceeds() public { + uint256 amt = 10; + uint256[] memory tokenIndexes = new uint256[](amt); + address[] memory recipients = new address[](amt); + for (uint256 i; i < amt; i++) { + tokenIndexes[i] = i + 1; + recipients[i] = address(1); + } + vm.startPrank(address(5)); + nft.mint(address(5), amt); + nft.setApprovalForAll(address(sendit), true); + sendit.contractBulkTransfer( + address(nft), + tokenIndexes, + recipients, + false + ); + vm.stopPrank(); } + + // function testUpdateVault() public { + // sendit.updateVault(address(3)); + // console.log(address(sendit)); + // // console.log(sendit); + // assertEq(sendit.addressVault(address(2)), address(0)); + // } }