add distinct 721 and 1155 sample contracts and tests

master
lza_menace 2 years ago
parent 923d0ff04e
commit c1c58ce115

@ -2,15 +2,10 @@
pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import "../src/NFT.sol";
import "../src/sampleERC721.sol";
import "../src/sampleERC1155.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();
}

@ -1,22 +0,0 @@
// 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);
}
}

@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {ERC1155} from "openzeppelin-contracts/token/ERC1155/ERC1155.sol";
import {Strings} from "openzeppelin-contracts/utils/Strings.sol";
import {Counters} from "openzeppelin-contracts/utils/Counters.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
contract NFT1155 is ERC1155, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC1155("") {}
function mint(uint256 id, uint256 amount) external {
_mint(msg.sender, id, amount, "");
}
}

@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {ERC721} from "openzeppelin-contracts/token/ERC721/ERC721.sol";
import {Strings} from "openzeppelin-contracts/utils/Strings.sol";
import {Counters} from "openzeppelin-contracts/utils/Counters.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
contract NFT721 is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("NFT", "NFT") {}
function mint(uint256 amount) external {
for (uint256 i; i < amount; i++) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_safeMint(msg.sender, tokenId);
}
}
}

@ -3,19 +3,24 @@ pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {SendIt} from "../src/SendIt.sol";
import {NFT} from "../src/NFT.sol";
import {NFT721} from "../src/sampleERC721.sol";
import {NFT1155} from "../src/sampleERC1155.sol";
contract SendItTest is Test {
using stdStorage for StdStorage;
SendIt public sendit;
NFT public nft;
NFT721 public nft721;
NFT1155 public nft1155;
function setUp() public {
sendit = new SendIt();
nft = new NFT();
nft721 = new NFT721();
nft1155 = new NFT1155();
}
function testBulkTransferSucceeds() public {
// Tokens
function test721BulkTransferSuccess() public {
uint256 amt = 20;
uint256 fee = sendit.usageFee();
uint256 val = fee * amt;
@ -27,10 +32,10 @@ contract SendItTest is Test {
}
vm.deal(address(5), 1 ether);
vm.startPrank(address(5));
nft.mint(address(5), amt);
nft.setApprovalForAll(address(sendit), true);
nft721.mint(amt);
nft721.setApprovalForAll(address(sendit), true);
sendit.contractBulkTransfer{value: val}(
address(nft),
address(nft721),
tokenIndexes,
recipients,
false
@ -38,44 +43,45 @@ contract SendItTest is Test {
vm.stopPrank();
}
function testSingleTransfer() public {
nft.mint(address(5), 20);
vm.startPrank(address(5));
for (uint256 i; i < 20; i++) {
nft.safeTransferFrom(address(5), address(1), i + 1);
}
vm.stopPrank();
}
function testUpdateVault() public {
vm.prank(address(1));
sendit.updateVault(address(3));
assertEq(sendit.addressVault(address(1)), address(3));
}
function testTokenOwnerCanSend() public {
function testFail721NonTokenOwnerCanSend() public {
uint256 amt = 1;
uint256 fee = sendit.usageFee();
uint256 val = fee * amt;
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);
}
tokenIndexes[0] = 23;
recipients[0] = address(1);
vm.deal(address(5), 1 ether);
vm.startPrank(address(5));
nft.mint(address(5), amt);
nft721.mint(amt);
// vm.stopPrank();
nft.setApprovalForAll(address(sendit), true);
nft721.setApprovalForAll(address(sendit), true);
sendit.contractBulkTransfer{value: val}(
address(nft),
address(nft721),
tokenIndexes,
recipients,
false
);
}
function test1155BulkTransferSuccess() public {
//
}
// meta
function testUpdateVault() public {
vm.prank(address(1));
sendit.updateVault(address(3));
assertEq(sendit.addressVault(address(1)), address(3));
}
// admin
// TODO
// only token owner can bulk transfer
// can only proceed after approval set
// only owner can updateFee

Loading…
Cancel
Save