diff --git a/src/Mailbomb.sol b/src/Mailbomb.sol index 3047d42..e0ab757 100644 --- a/src/Mailbomb.sol +++ b/src/Mailbomb.sol @@ -13,20 +13,7 @@ chaos ensues until 1000 survivors - the game stops import {ERC721} from "solmate/tokens/ERC721.sol"; import {Owned} from "solmate/auth/Owned.sol"; import {LibString} from "solmate/utils/LibString.sol"; -import {Unaboomer} from "./Unaboomer.sol"; - -error NotEnoughEther(); -error NotOwnerOfToken(); -error MaxSupplyReached(); -error TooMany(); -error NoContract(); -error WrongEtherAmount(); -error MaxAmountReached(); -error NoAdmins(); -error NotAdmin(); -error NoRemoveSelf(); -error NoRemoveDeployer(); -error NotEnoughBombs(); +import {UnaboomerCommon} from "./UnaboomerCommon.sol"; contract Mailbomb is ERC721, Owned { using LibString for uint256; @@ -67,11 +54,17 @@ contract Mailbomb is ERC721, Owned { unchecked { for (uint256 i; i < _amount; i++) { minted++; - _mint(to, minted); + _mint(_to, minted); } } } + /// Burn spent tokens from main contract + function burn(uint256 tokenId) external { + require(msg.sender == address(main), "invalid minter"); + super._burn(tokenId); + } + function totalSupply() public view returns (uint256 supply) { return minted; } diff --git a/src/Unaboomer.sol b/src/Unaboomer.sol index c8548a8..de23585 100644 --- a/src/Unaboomer.sol +++ b/src/Unaboomer.sol @@ -64,7 +64,7 @@ contract Unaboomer is ERC721, Owned { unchecked { for (uint256 i; i < _amount; i++) { minted++; - _mint(to, minted); + _mint(_to, minted); } } } diff --git a/src/UnaboomerCommon.sol b/src/UnaboomerCommon.sol index 811583b..1b143bd 100644 --- a/src/UnaboomerCommon.sol +++ b/src/UnaboomerCommon.sol @@ -52,8 +52,8 @@ contract UnaboomerCommon is Owned { } /// Set contract address for Mailbomb tokens - function setUnaboomerContract(address _address) external onlyOwner { - mailbomb = Unaboomer(_address); + function setMailbombContract(address _address) external onlyOwner { + mailbomb = Mailbomb(_address); } // ========================================================================= @@ -94,14 +94,10 @@ contract UnaboomerCommon is Owned { for (uint256 i; i < tokenIds.length; i++) { require(mailbomb.ownerOf(tokenIds[i]) == msg.sender, "token not owned"); uint256 randomBoomer = uint256(keccak256(abi.encodePacked(tokenIds[i], block.timestamp, msg.sender))) % boomerSupply; - mailbomb._burn(tokenIds[i]); + mailbomb.burn(tokenIds[i]); bool _res = killBoomer(randomBoomer); res[i] = _res; } return res; } - - function supportsInterface(bytes4 interfaceId) public view virtual override (ERC721) returns (bool) { - return super.supportsInterface(interfaceId); - } } \ No newline at end of file diff --git a/test/Unaboomer.t.sol b/test/Unaboomer.t.sol index 717e183..f2c87cb 100644 --- a/test/Unaboomer.t.sol +++ b/test/Unaboomer.t.sol @@ -2,28 +2,34 @@ pragma solidity ^0.8.13; import "forge-std/Test.sol"; +import {UnaboomerCommon} from "../src/UnaboomerCommon.sol"; import {Unaboomer} from "../src/Unaboomer.sol"; import {Mailbomb} from "../src/Mailbomb.sol"; contract UnaboomerTest is Test { + UnaboomerCommon public main; Unaboomer public boomr; Mailbomb public bomb; function setUp() public { + main = new UnaboomerCommon(); boomr = new Unaboomer(); bomb = new Mailbomb(); - bomb.setUnaboomerContract(address(boomr)); + boomr.setMainContract(address(main)); + bomb.setMainContract(address(main)); + main.setUnaboomerContract(address(boomr)); + main.setMailbombContract(address(bomb)); } function testWithdraws() public { - vm.deal(address(boomr), 11 ether); - vm.prank(address(boomr.owner())); - boomr.withdraw(); + vm.deal(address(main), 10 ether); + vm.prank(address(main.owner())); + main.withdraw(); } function testMint() public { hoax(address(1)); - boomr.mint{value: 0.05 ether}(5); + main.radicalizeBoomer{value: 0.05 ether}(5); assertEq(boomr.totalSupply(), 5); assertEq(boomr.tokenDead(1), false); }