Skip to content

Commit

Permalink
add event and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xble committed Feb 8, 2024
1 parent ecf8b20 commit cc0cb51
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/party/EZPartyBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { ProposalStorage } from "contracts/proposals/ProposalStorage.sol";
import { ERC721Receiver } from "contracts/tokens/ERC721Receiver.sol";

contract EZPartyBuilder is ERC721Receiver {
event EZPartyCreated(Party indexed party, address host, address[] initialMembers);

error PartyAlreadyCreated();

address payable immutable TREASURY;
Expand Down Expand Up @@ -103,6 +105,8 @@ contract EZPartyBuilder is ERC721Receiver {
}
}
}

emit EZPartyCreated(party, host, initialMembers);
}

receive() external payable {}
Expand Down
49 changes: 49 additions & 0 deletions test/party/EZPartyBuilder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { PartyNFTRenderer } from "contracts/renderers/PartyNFTRenderer.sol";
import { MetadataProvider } from "contracts/renderers/MetadataProvider.sol";

contract EZPartyBuilderTest is SetupPartyHelper {
event EZPartyCreated(Party indexed party, address host, address[] initialMembers);

EZPartyBuilder builder;
BondingCurveAuthority bondingCurveAuthority;
MetadataProvider metadataProvider;
Expand Down Expand Up @@ -61,6 +63,12 @@ contract EZPartyBuilderTest is SetupPartyHelper {
true
);

vm.expectEmit(true, true, true, true);
emit EZPartyCreated(
Party(payable(computeCreateAddress(address(partyFactory), 2))),
host,
initialMembers
);
Party party = builder.createPartyAndDistributeMemberships{ value: initialPrice }(
host,
initialMembers,
Expand All @@ -69,6 +77,9 @@ contract EZPartyBuilderTest is SetupPartyHelper {
imageUri
);

// Check host has already created a party
assertEq(builder.hasAlreadyCreatedParty(host), true);

// Check each member received a card
assertEq(party.ownerOf(1), host);
assertEq(party.ownerOf(2), initialMembers[0]);
Expand All @@ -85,5 +96,43 @@ contract EZPartyBuilderTest is SetupPartyHelper {
assertEq(metadata.image, imageUri);
}

function test_createPartyAndDistributeMemberships_revertsIfHostAlreadyCreatedParty() public {
address host = _randomAddress();

address[] memory initialMembers = new address[](3);
initialMembers[0] = _randomAddress();
initialMembers[1] = _randomAddress();
initialMembers[2] = _randomAddress();

string memory partyName = "John John John";
string memory partySymbol = "JJJ";
string memory imageUri = "www.johnjohnjohn.com";

uint256 initialPrice = bondingCurveAuthority.getPriceToBuy(
0,
4,
50_000,
uint80(0.001 ether),
true
);

builder.createPartyAndDistributeMemberships{ value: initialPrice }(
host,
initialMembers,
partyName,
partySymbol,
imageUri
);

vm.expectRevert(abi.encodeWithSelector(EZPartyBuilder.PartyAlreadyCreated.selector));
builder.createPartyAndDistributeMemberships{ value: initialPrice }(
host,
initialMembers,
partyName,
partySymbol,
imageUri
);
}

receive() external payable {}
}

0 comments on commit cc0cb51

Please sign in to comment.