From 1c21b158c4c6002e2272e597e798a89eb8c3baf3 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Tue, 27 Dec 2022 01:01:26 -0800 Subject: [PATCH] cleanup --- src/Mailbomb.sol | 10 +--------- src/Main.sol | 3 ++- src/Unaboomer.sol | 18 +++++------------- test/Unaboomer.t.sol | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/Mailbomb.sol b/src/Mailbomb.sol index a6dd2d3..bc105d0 100644 --- a/src/Mailbomb.sol +++ b/src/Mailbomb.sol @@ -1,15 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; - -/******* Mint Mechanics -.00 per unaboomer (BOOMR) - 10k supply -.02 per bomb (BOMB) - infinite supply -BOMB holders can randomly mail bombs to other owners -1 BOMB kills 1 BOOMR - BOOMR image switches to explosion after being bombed -chaos ensues until 1000 survivors - the game stops -********/ - import {ERC1155} from "solmate/tokens/ERC1155.sol"; import {Owned} from "solmate/auth/Owned.sol"; import {LibString} from "solmate/utils/LibString.sol"; @@ -48,6 +39,7 @@ contract Mailbomb is ERC1155, Owned { // Modifiers // ========================================================================= + /// Only main address can mint modifier onlyMain { require(msg.sender == address(main), "invalid minter"); _; diff --git a/src/Main.sol b/src/Main.sol index 050f246..85d5938 100644 --- a/src/Main.sol +++ b/src/Main.sol @@ -91,13 +91,14 @@ contract Main is Owned { uint256[] memory tokensKilled ) { require(_amount <= mailbomb.balanceOf(msg.sender, 1), "not enough bombs"); + require(_amount <= unaboomer.totalSupply(), "not enough supply"); bool[] memory res = new bool[](_amount); uint256[] memory killed = new uint256[](_amount); uint256 boomerSupply = unaboomer.totalSupply(); for (uint256 i; i < _amount; i++) { uint256 randomBoomer = uint256(keccak256(abi.encodePacked(i, block.timestamp, msg.sender))) % boomerSupply; bool dud = unaboomer.tokenDead(randomBoomer); - unaboomer.kill(randomBoomer); + unaboomer.die(randomBoomer); res[i] = dud; killed[i] = randomBoomer; } diff --git a/src/Unaboomer.sol b/src/Unaboomer.sol index 9fe82f3..7fd11f7 100644 --- a/src/Unaboomer.sol +++ b/src/Unaboomer.sol @@ -1,15 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; - -/******* Mint Mechanics -.00 per unaboomer (BOOMR) - 10k supply -.02 per bomb (BOMB) - infinite supply -BOMB holders can randomly mail bombs to other owners -1 BOMB kills 1 BOOMR - BOOMR image switches to explosion after being bombed -chaos ensues until 1000 survivors - the game stops -********/ - import {ERC721A} from "erc721a/ERC721A.sol"; import {Owned} from "solmate/auth/Owned.sol"; import {LibString} from "solmate/utils/LibString.sol"; @@ -58,7 +49,8 @@ contract Unaboomer is ERC721A, Owned { // ========================================================================= // Modifiers // ========================================================================= - + + /// Only main address can mint modifier onlyMain { require(msg.sender == address(main), "invalid minter"); _; @@ -75,8 +67,8 @@ contract Unaboomer is ERC721A, Owned { } /// Toggle token state from living to dead - function kill(uint256 tokenId) external onlyMain { - require(tokenId <= totalSupply(), "invalid token id"); + function die(uint256 tokenId) external onlyMain { + require(tokenId < totalSupply(), "invalid token id"); if (tokenDead[tokenId] == false) { killCount++; tokenDead[tokenId] = true; @@ -84,7 +76,7 @@ contract Unaboomer is ERC721A, Owned { } function tokenURI(uint256 _tokenId) public view override returns (string memory) { - if (tokenDead[_tokenId]) { + if (tokenDead[_tokenId] == true) { return string(abi.encodePacked(deadURI, _tokenId.toString(), ".json")); } else { return string(abi.encodePacked(aliveURI, _tokenId.toString(), ".json")); diff --git a/test/Unaboomer.t.sol b/test/Unaboomer.t.sol index a483e0f..902968c 100644 --- a/test/Unaboomer.t.sol +++ b/test/Unaboomer.t.sol @@ -51,6 +51,34 @@ contract UnaboomerTest is Test { console.log(boomr.killCount()); } - // function testX() public {} - + function testKilling() public { + address t = address(1); + startHoax(t); + main.assembleBombs{value: .1 ether}(10); + vm.expectRevert(bytes("not enough supply")); + main.sendBombs(10); + main.radicalizeBoomers{value: .1 ether}(10); + main.sendBombs(10); + assertEq(bomb.balanceOf(t, 1), 20); + } + + function testFailDirectFunctions() public { + address t = address(1); + startHoax(t); + boomr.radicalize(t, 10); + boomr.die(1); + bomb.create(t, 10); + bomb.explode(t, 10); + } + + function testURILogic() public { + address t = address(1); + boomr.setAliveURI('ipfs://alive/'); + boomr.setDeadURI('ipfs://dead/'); + startHoax(t); + main.radicalizeBoomers{value: .01 ether}(1); + assertEq(boomr.tokenURI(0), 'ipfs://alive/0.json'); + main.sendBombs(1); + assertEq(boomr.tokenURI(0), 'ipfs://dead/0.json'); + } }