You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.7 KiB
Solidity

2 years ago
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
2 years ago
import {ShipIt} from "../src/ShipIt.sol";
import {NFT721} from "../src/sampleERC721.sol";
import {NFT1155} from "../src/sampleERC1155.sol";
2 years ago
2 years ago
contract ShipItTest is Test {
using stdStorage for StdStorage;
2 years ago
ShipIt public shipit;
NFT721 public nft721;
NFT1155 public nft1155;
2 years ago
function setUp() public {
2 years ago
shipit = new ShipIt();
nft721 = new NFT721();
nft1155 = new NFT1155();
2 years ago
}
// Tokens
function test721BulkTransferSuccess() public {
2 years ago
uint256 amt = 20;
2 years ago
uint256 fee = shipit.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);
}
vm.deal(address(5), 1 ether);
vm.startPrank(address(5));
nft721.mint(amt);
2 years ago
nft721.setApprovalForAll(address(shipit), true);
shipit.erc721BulkTransfer{value: val}(
address(nft721),
recipients,
tokenIndexes
);
2 years ago
// assert balances
2 years ago
}
function testFail721NonTokenOwnerCanSend() public {
2 years ago
uint256 amt = 1;
2 years ago
uint256 fee = shipit.usageFee();
2 years ago
uint256 val = fee * amt;
uint256[] memory tokenIndexes = new uint256[](amt);
address[] memory recipients = new address[](amt);
2 years ago
tokenIndexes[0] = 1;
recipients[0] = address(1);
2 years ago
vm.deal(address(5), 1 ether);
2 years ago
vm.deal(address(3), 1 ether);
2 years ago
vm.startPrank(address(5));
nft721.mint(amt);
2 years ago
nft721.setApprovalForAll(address(shipit), true);
2 years ago
vm.stopPrank();
vm.prank(address(3));
shipit.erc721BulkTransfer{value: val}(
address(nft721),
2 years ago
recipients,
tokenIndexes
2 years ago
);
}
function test1155BulkTransferSuccess() public {
2 years ago
uint256 amt = 10;
2 years ago
uint256 fee = shipit.usageFee();
2 years ago
uint256 val = fee * amt;
address[] memory recipients = new address[](2);
uint256[] memory tokenIndexes = new uint256[](2);
uint256[] memory amounts = new uint256[](2);
recipients[0] = address(11);
recipients[1] = address(11);
tokenIndexes[0] = 1;
tokenIndexes[1] = 5;
amounts[0] = amt;
amounts[1] = amt;
vm.deal(address(50), 1 ether);
vm.startPrank(address(50));
2 years ago
nft1155.mint(1, amt);
nft1155.mint(5, amt);
2 years ago
nft1155.setApprovalForAll(address(shipit), true);
shipit.erc1155BulkTransfer{value: val}(
2 years ago
address(nft1155),
recipients,
tokenIndexes,
amounts
2 years ago
);
assertEq(nft1155.balanceOf(address(11), 1), 10);
assertEq(nft1155.balanceOf(address(11), 5), 10);
2 years ago
}
function testFail1155NonTokenOwnerCanSend() public {
uint256 amt = 1;
2 years ago
uint256 fee = shipit.usageFee();
2 years ago
uint256 val = fee * amt;
address[] memory recipients = new address[](amt);
uint256[] memory tokenIndexes = new uint256[](amt);
uint256[] memory amounts = new uint256[](amt);
2 years ago
tokenIndexes[0] = 1;
recipients[0] = address(1);
amounts[0] = amt;
2 years ago
vm.deal(address(5), 1 ether);
2 years ago
vm.deal(address(3), 1 ether);
2 years ago
vm.startPrank(address(5));
nft1155.mint(1, amt);
2 years ago
nft1155.setApprovalForAll(address(shipit), true);
2 years ago
vm.stopPrank();
2 years ago
vm.prank(address(3));
shipit.erc1155BulkTransfer{value: val}(
2 years ago
address(nft1155),
recipients,
tokenIndexes,
amounts
2 years ago
);
}
// meta
function testUpdateVault() public {
vm.prank(address(1));
2 years ago
shipit.updateVault(address(3));
assertEq(shipit.addressVault(address(1)), address(3));
}
// admin
2 years ago
function testOwnerCanWithdraw() public {
2 years ago
address owner = shipit.owner();
vm.deal(address(shipit), 1 ether);
2 years ago
vm.deal(owner, 1 ether);
vm.deal(address(20), 2 ether);
vm.prank(owner);
2 years ago
shipit.transferOwnership(address(20));
2 years ago
vm.prank(address(20));
2 years ago
shipit.withdraw();
2 years ago
vm.startPrank(address(30));
vm.expectRevert();
2 years ago
shipit.withdraw();
2 years ago
}
2 years ago
function testOwnerCanUpdateFee() public {
2 years ago
address owner = shipit.owner();
2 years ago
vm.deal(owner, 1 ether);
vm.prank(owner);
2 years ago
shipit.updateFee(0.1 ether);
assertEq(shipit.usageFee(), 0.1 ether);
2 years ago
vm.startPrank(address(1));
vm.expectRevert();
2 years ago
shipit.updateFee(0.25 ether);
2 years ago
}
2 years ago
}