update func names, add test

master
lza_menace 2 years ago
parent d947a5c8cd
commit ec9962bb85

@ -58,13 +58,13 @@ contract Mailbomb is ERC1155, Owned {
// =========================================================================
/// Mint tokens from main contract
function mint(address _to, uint256 _amount) external payable onlyMain {
function create(address _to, uint256 _amount) external payable onlyMain {
bombsAssembled += _amount;
super._mint(_to, 1, _amount, "");
}
/// Burn spent tokens from main contract
function burn(address _from, uint256 _amount) external onlyMain {
function explode(address _from, uint256 _amount) external onlyMain {
super._burn(_from, 1, _amount);
}

@ -69,7 +69,7 @@ contract Unaboomer is ERC721, Owned {
// =========================================================================
/// Mint tokens from main contract
function mint(address _to, uint256 _amount) external payable onlyMain {
function radicalize(address _to, uint256 _amount) external payable onlyMain {
require(minted + _amount <= MAX_SUPPLY, "supply reached");
unchecked {
for (uint256 i; i < _amount; i++) {

@ -72,31 +72,36 @@ contract UnaboomerCommon is Owned {
/// Radicalize a boomer to become a Unaboomer - start with 2 bombs
function radicalizeBoomers(uint256 _amount) external payable missionNotCompleted {
require(msg.value >= _amount * boomerPrice, "not enough ether");
unaboomer.mint(msg.sender, _amount);
mailbomb.mint(msg.sender, _amount * 2);
unaboomer.radicalize(msg.sender, _amount);
mailbomb.create(msg.sender, _amount * 2);
}
/// Assemble additional mailbombs to kill targets
function assembleBombs(uint256 _amount) external payable missionNotCompleted {
require(msg.value >= _amount * bombPrice, "not enough ether");
mailbomb.mint(msg.sender, _amount);
mailbomb.create(msg.sender, _amount);
}
/// Send N bombs to pseudo-random Unaboomer tokenIds to kill them.
/// If the Unaboomer is already dead, the bomb is considered a dud.
/// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value
/// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds
function sendBombs(uint256 _amount) external missionNotCompleted returns (bool[] memory results) {
function sendBombs(uint256 _amount) external missionNotCompleted returns (
bool[] memory results,
uint256[] memory tokensKilled
) {
require(_amount <= mailbomb.balanceOf(msg.sender, 1), "not enough bombs");
bool[] memory res = new bool[](_amount);
uint256 boomerSupply = unaboomer.totalSupply();
uint256[] memory killed = new uint256[](_amount);
for (uint256 i; i < _amount; i++) {
uint256 boomerSupply = unaboomer.totalSupply();
uint256 randomBoomer = uint256(keccak256(abi.encodePacked(i, block.timestamp, msg.sender))) % boomerSupply;
bool dud = unaboomer.tokenDead(randomBoomer);
unaboomer.kill(randomBoomer);
res[i] = dud;
killed[i] = randomBoomer;
}
mailbomb.burn(msg.sender, _amount);
return res;
mailbomb.explode(msg.sender, _amount);
return (res, killed);
}
}

@ -22,103 +22,36 @@ contract UnaboomerTest is Test {
}
function testBasicMechanics() public {
address t = address(3);
address t2 = address(4);
startHoax(t);
address t1 = address(1);
address t2 = address(2);
// mint 20 boomers - should have 20 BOOMR and 40 BOMB
hoax(t1);
main.radicalizeBoomers{value: .2 ether}(20);
assertEq(boomr.totalSupply(), 20);
assertEq(boomr.balanceOf(t1), 20);
assertEq(bomb.bombsAssembled(), 40);
assertEq(bomb.balanceOf(t, 1), 40);
assertEq(bomb.balanceOf(t1, 1), 40);
// mint 20 more bombs - should have 60 BOMB
hoax(t1);
main.assembleBombs{value: .2 ether}(20);
assertEq(bomb.bombsAssembled(), 60);
assertEq(bomb.balanceOf(t, 1), 60);
stopHoax();
vm.prank(t2);
main.assembleBombs{value: .2 ether}(20);
assertEq(bomb.bombsAssembled(), 80);
assertEq(bomb.balanceOf(t2, 1), 20);
assertEq(bomb.balanceOf(t1, 1), 60);
// mint 20 more boomers as other address - supplies should line up
hoax(t2);
main.radicalizeBoomers{value: .2 ether}(20);
assertEq(boomr.totalSupply(), 40);
assertEq(boomr.balanceOf(t2), 20);
assertEq(bomb.bombsAssembled(), 100);
assertEq(bomb.balanceOf(t2, 1), 40);
// sending bombs should change supplies
hoax(t1);
(bool[] memory res, uint256[] memory killed) = main.sendBombs(60);
for (uint256 i; i < res.length; i++) {
console.log(res[i]);
console.log(killed[i]);
}
}
// function testWithdraws() public {
// vm.deal(address(main), 10 ether);
// vm.prank(address(main.owner()));
// main.withdraw();
// }
// function testMint() public {
// hoax(address(1));
// main.radicalizeBoomers{value: 0.05 ether}(5);
// assertEq(boomr.totalSupply(), 5);
// assertEq(boomr.tokenDead(1), false);
// }
// src/Mailbomb.sol: function withdraw() external onlyOwner {
// src/Mailbomb.sol: function setBaseURI(string calldata _baseURI) external onlyOwner {
// src/Mailbomb.sol: /// Set main contract address for executing functions
// src/Mailbomb.sol: function setMainContract(address _address) external onlyOwner {
// src/Mailbomb.sol: function mint(address _to, uint256 _amount) external payable {
// src/Mailbomb.sol: function burn(uint256 tokenId) external {
// src/Mailbomb.sol: function totalSupply() public view returns (uint256 supply) {
// src/Mailbomb.sol: function tokenURI(uint256 _tokenId) public view override returns (string memory) {
// src/Mailbomb.sol: function supportsInterface(bytes4 interfaceId) public view virtual override (ERC721) returns (bool) {
// src/UnaboomerCommon.sol: function withdraw() external onlyOwner {
// src/UnaboomerCommon.sol: function setBombPrice(uint256 _price) external onlyOwner {
// src/UnaboomerCommon.sol: function setBoomerPrice(uint256 _price) external onlyOwner {
// src/UnaboomerCommon.sol: function setUnaboomerContract(address _address) external onlyOwner {
// src/UnaboomerCommon.sol: function setMailbombContract(address _address) external onlyOwner {
// src/UnaboomerCommon.sol: function radicalizeBoomers(uint256 _amount) external payable missionNotCompleted {
// src/UnaboomerCommon.sol: function assembleBombs(uint256 _amount) external payable missionNotCompleted {
// src/UnaboomerCommon.sol: function sendBombs(uint256[] calldata tokenIds) external missionNotCompleted returns (bool[] memory results) {
// function testX() public {}
// =========================================================================
// Unaboomer
// =========================================================================
// function testWithdrawUnaboomer() public {}
// function testUnaboomerSetters() public {
// string memory aliveURI = 'ipfs://xxxx/';
// string memory deadURI = 'ipfs://yyyy/';
// boomr.setAliveURI(aliveURI);
// boomr.setDeadURI(deadURI);
// assertEq(boomr.aliveURI(), aliveURI);
// assertEq(boomr.deadURI(), deadURI);
// }
// function testUnaboomerMainMint() public {
// startHoax(address(3));
// main.radicalizeBoomers{value: .1 ether}(10);
// assertEq(boomr.totalSupply(), 10);
// assertEq(bomb.totalSupply(), 20);
// }
// function testUnaboomerMainKill() public {
// startHoax(address(3));
// main.radicalizeBoomers{value: .01 ether}(1);
// uint256[] memory bombs = new uint256[](2);
// bombs[0] = 1;
// bombs[1] = 2;
// main.sendBombs(bombs);
// vm.expectRevert(bytes("not enough bombs"));
// main.sendBombs(bombs);
// main.radicalizeBoomers{value: .01 ether}(1);
// main.sendBombs(bombs);
// }
// function testUnaboomerSupply() public {}
// function testUnaboomerTokenURIs() public {}
// function testUnaboomerDirectMint() public {
// startHoax(address(5));
// vm.expectRevert(bytes("invalid minter"));
// boomr.mint(address(5), 2);
// }
// function testUnaboomerDirectKill() public {
// startHoax(address(5));
// main.radicalizeBoomers{value: .05 ether}(5);
// vm.expectRevert(bytes("invalid minter"));
// boomr.kill(1);
// }
}

Loading…
Cancel
Save