Skip to content

Commit

Permalink
Add suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Jul 29, 2022
1 parent ef21e2e commit 1285ea7
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 117 deletions.
4 changes: 2 additions & 2 deletions contracts/modules/Minters/EditionMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract EditionMinter {
error MintControllerNotFound();

/// @dev A mint controller is already assigned to this edition.
error MintControllerAlreadyExists();
error MintControllerAlreadyExists(address controller);

/// @dev Emitted when the mint `controller` for `edition` is changed.
event MintControllerUpdated(address indexed edition, address indexed controller);
Expand All @@ -45,7 +45,7 @@ abstract contract EditionMinter {
///
/// - The `edition` must not have a controller.
function _createEditionMintController(address edition) internal {
if (_controllers[edition] != address(0)) revert MintControllerAlreadyExists();
if (_controllers[edition] != address(0)) revert MintControllerAlreadyExists(_controllers[edition]);
_controllers[edition] = msg.sender;
emit MintControllerUpdated(edition, msg.sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract FixedPricePermissionedSaleMinter is EditionMinter {
using ECDSA for bytes32;
error WrongEtherValue();

error MintOutOfStock();
error SoldOut();

error InvalidSignature();

Expand Down Expand Up @@ -67,12 +67,12 @@ contract FixedPricePermissionedSaleMinter is EditionMinter {
bytes calldata signature
) public payable {
EditionMintData storage data = editionMintData[edition];
if ((data.totalMinted += quantity) > data.maxMinted) revert MintOutOfStock();
if (data.price * quantity != msg.value) revert MintWithWrongEtherValue();
if ((data.totalMinted += quantity) > data.maxMinted) revert SoldOut();
if (data.price * quantity != msg.value) revert WrongEtherValue();

bytes32 hash = keccak256(abi.encode(msg.sender, edition));
hash = hash.toEthSignedMessageHash();
if (hash.recover(signature) != data.signer) revert MintWithInvalidSignature();
if (hash.recover(signature) != data.signer) revert InvalidSignature();

ISoundEditionV1(edition).mint{ value: msg.value }(edition, quantity);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/modules/Minters/FixedPricePublicSaleMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "../../SoundEdition/ISoundEditionV1.sol";
contract FixedPricePublicSaleMinter is EditionMinter {
error WrongEtherValue();

error OutOfStock();
error SoldOut();

error MintNotStarted();

Expand Down Expand Up @@ -69,8 +69,8 @@ contract FixedPricePublicSaleMinter is EditionMinter {

function mint(address edition, uint32 quantity) public payable {
EditionMintData storage data = editionMintData[edition];
if ((data.totalMinted += quantity) > data.maxMinted) revert MintOutOfStock();
if (data.price * quantity != msg.value) revert MintWithWrongEtherValue();
if ((data.totalMinted += quantity) > data.maxMinted) revert SoldOut();
if (data.price * quantity != msg.value) revert WrongEtherValue();
if (block.timestamp < data.startTime) revert MintNotStarted();
if (data.endTime < block.timestamp) revert MintHasEnded();
ISoundEditionV1(edition).mint{ value: msg.value }(edition, quantity);
Expand Down
99 changes: 99 additions & 0 deletions tests/modules/Minters/EditionMinter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
pragma solidity ^0.8.15;

import "../../TestConfig.sol";
import "../../../contracts/SoundEdition/SoundEditionV1.sol";
import "../../../contracts/SoundCreator/SoundCreatorV1.sol";
import "../../../contracts/modules/Minters/FixedPricePublicSaleMinter.sol";

contract EditionMinterTests is TestConfig, EditionMinter {
function createEditionMintController(address edition) external {
_createEditionMintController(edition);
}

function deleteEditionMintController(address edition) external {
_deleteEditionMintController(edition);
}

function test_createEditionMintControllerEmitsEvent(address edition) external {
address controller = getRandomAccount(1);
vm.expectEmit(false, false, false, true);
emit MintControllerUpdated(address(edition), controller);
vm.prank(controller);
this.createEditionMintController(address(edition));
}

function test_createEditionMintControllerChangesController(address edition) external {
address controller = getRandomAccount(1);
assertEq(this.editionMintController(edition), address(0));
vm.prank(controller);
this.createEditionMintController(address(edition));
assertEq(this.editionMintController(edition), controller);
}

function test_createEditionMintControllerRevertsWhenAlreadyExists(address edition) external {
address controller0 = getRandomAccount(0);
address controller1 = getRandomAccount(1);
vm.prank(controller0);
this.createEditionMintController(address(edition));
vm.expectRevert(abi.encodeWithSelector(EditionMinter.MintControllerAlreadyExists.selector, controller0));
vm.prank(controller0);
this.createEditionMintController(address(edition));
vm.prank(controller1);
vm.expectRevert(abi.encodeWithSelector(EditionMinter.MintControllerAlreadyExists.selector, controller0));
this.createEditionMintController(address(edition));
}

function test_setEditionMintControllerEmitsEvent(address edition) external {
address controller0 = getRandomAccount(0);
address controller1 = getRandomAccount(1);
vm.prank(controller0);
this.createEditionMintController(address(edition));
vm.expectEmit(false, false, false, true);
emit MintControllerUpdated(address(edition), controller1);
vm.prank(controller0);
this.setEditionMintController(address(edition), controller1);
}

function test_setEditionMintControllerChangesController(address edition) external {
address controller0 = getRandomAccount(0);
address controller1 = getRandomAccount(1);
vm.prank(controller0);
this.createEditionMintController(address(edition));
vm.prank(controller0);
this.setEditionMintController(address(edition), controller1);
assertEq(this.editionMintController(edition), controller1);
}

function test_deleteEditionMintControllerEmitsEvent(address edition) external {
address controller = getRandomAccount(0);
vm.prank(controller);
this.createEditionMintController(address(edition));
vm.expectEmit(false, false, false, true);
emit MintControllerUpdated(address(edition), address(0));
vm.prank(controller);
this.deleteEditionMintController(address(edition));
}

function test_deleteEditionMintRevertsIfCallerUnauthorized(address edition) public {
address controller0 = getRandomAccount(0);
address controller1 = getRandomAccount(1);
vm.prank(controller0);
this.createEditionMintController(address(edition));

vm.prank(controller1);
vm.expectRevert(EditionMinter.MintControllerUnauthorized.selector);
this.deleteEditionMintController(address(edition));
}

function test_deleteEditionMintRevertsIfMintEditionDoesNotExist(address edition0, address edition1) public {
vm.assume(edition0 != edition1);

address controller = getRandomAccount(0);
vm.prank(controller);
this.createEditionMintController(address(edition0));

vm.prank(controller);
vm.expectRevert(EditionMinter.MintControllerNotFound.selector);
this.deleteEditionMintController(address(edition1));
}
}
40 changes: 5 additions & 35 deletions tests/modules/Minters/FixedPricePermissionedSaleMinter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,6 @@ contract FixedPricePermissionedSaleMinterTests is TestConfig {
minter.createEditionMint(address(edition), PRICE, _signerAddress(), MAX_MINTED);
}

function test_createEditionMintRevertsIfMintEditionExists() public {
(SoundEditionV1 edition, FixedPricePermissionedSaleMinter minter) = _createEditionAndMinter();

vm.expectRevert(EditionMinter.MintControllerAlreadyExists.selector);
minter.createEditionMint(address(edition), PRICE, _signerAddress(), MAX_MINTED);
}

function test_deleteEditionMintRevertsIfCallerUnauthorized() public {
(SoundEditionV1 edition, FixedPricePermissionedSaleMinter minter) = _createEditionAndMinter();

address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert(EditionMinter.MintControllerUnauthorized.selector);
minter.deleteEditionMint(address(edition));

minter.setEditionMintController(address(edition), caller);
vm.prank(caller);
minter.deleteEditionMint(address(edition));
}

function test_deleteEditionMintRevertsIfMintEditionDoesNotExist() public {
(SoundEditionV1 edition, FixedPricePermissionedSaleMinter minter) = _createEditionAndMinter();

minter.deleteEditionMint(address(edition));

vm.expectRevert(EditionMinter.MintControllerNotFound.selector);

minter.deleteEditionMint(address(edition));
}

function test_mintWithoutCorrectSignatureReverts() public {
(SoundEditionV1 edition, FixedPricePermissionedSaleMinter minter) = _createEditionAndMinter();

Expand All @@ -100,7 +70,7 @@ contract FixedPricePermissionedSaleMinterTests is TestConfig {
vm.prank(caller);
minter.mint{ value: PRICE }(address(edition), 1, sig);

vm.expectRevert(FixedPricePermissionedSaleMinter.MintWithInvalidSignature.selector);
vm.expectRevert(FixedPricePermissionedSaleMinter.InvalidSignature.selector);
minter.mint{ value: PRICE }(address(edition), 1, sig);
}

Expand All @@ -111,25 +81,25 @@ contract FixedPricePermissionedSaleMinterTests is TestConfig {
bytes memory sig = _getSignature(caller, address(edition));

vm.prank(caller);
vm.expectRevert(FixedPricePermissionedSaleMinter.MintWithWrongEtherValue.selector);
vm.expectRevert(FixedPricePermissionedSaleMinter.WrongEtherValue.selector);
minter.mint{ value: PRICE * 2 }(address(edition), 1, sig);
}

function test_mintDuringOutOfStockReverts() public {
function test_mintWhenSoldOutReverts() public {
(SoundEditionV1 edition, FixedPricePermissionedSaleMinter minter) = _createEditionAndMinter();

address caller = getRandomAccount(1);
bytes memory sig = _getSignature(caller, address(edition));

vm.prank(caller);
vm.expectRevert(FixedPricePermissionedSaleMinter.MintOutOfStock.selector);
vm.expectRevert(FixedPricePermissionedSaleMinter.SoldOut.selector);
minter.mint{ value: PRICE * (MAX_MINTED + 1) }(address(edition), MAX_MINTED + 1, sig);

vm.prank(caller);
minter.mint{ value: PRICE * MAX_MINTED }(address(edition), MAX_MINTED, sig);

vm.prank(caller);
vm.expectRevert(FixedPricePermissionedSaleMinter.MintOutOfStock.selector);
vm.expectRevert(FixedPricePermissionedSaleMinter.SoldOut.selector);
minter.mint{ value: PRICE }(address(edition), 1, sig);
}

Expand Down
77 changes: 4 additions & 73 deletions tests/modules/Minters/FixedPricePublicSaleMinter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ contract FixedPricePublicSaleMinterTests is TestConfig {
uint32 maxMinted
);

event MintControllerUpdated(address indexed edition, address indexed controller);

function _createEditionAndMinter() internal returns (SoundEditionV1 edition, FixedPricePublicSaleMinter minter) {
edition = SoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
Expand All @@ -51,73 +49,6 @@ contract FixedPricePublicSaleMinterTests is TestConfig {
minter.createEditionMint(address(edition), PRICE, START_TIME, END_TIME, MAX_MINTED);
}

function test_createEditionMintEmitsMintControllerUpdatedEvent() public {
SoundEditionV1 edition = SoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

FixedPricePublicSaleMinter minter = new FixedPricePublicSaleMinter();

vm.expectEmit(false, false, false, true);

emit MintControllerUpdated(address(edition), edition.owner());

minter.createEditionMint(address(edition), PRICE, START_TIME, END_TIME, MAX_MINTED);
}

function test_createEditionMintRevertsIfMintEditionExists() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

vm.expectRevert(EditionMinter.MintControllerAlreadyExists.selector);

minter.createEditionMint(address(edition), PRICE, START_TIME, END_TIME, MAX_MINTED);
}

function test_deleteEditionMintEmitsMintControllerUpdatedEvent() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

vm.expectEmit(false, false, false, true);

emit MintControllerUpdated(address(edition), address(0));

minter.deleteEditionMint(address(edition));
}

function test_setEditionMintControllerEmitsMintControllerUpdatedEvent() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

vm.expectEmit(false, false, false, true);

address newController = getRandomAccount(1);

emit MintControllerUpdated(address(edition), newController);

minter.setEditionMintController(address(edition), newController);
}

function test_deleteEditionMintRevertsIfCallerUnauthorized() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert(EditionMinter.MintControllerUnauthorized.selector);
minter.deleteEditionMint(address(edition));

minter.setEditionMintController(address(edition), caller);
vm.prank(caller);
minter.deleteEditionMint(address(edition));
}

function test_deleteEditionMintRevertsIfMintEditionDoesNotExist() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

minter.deleteEditionMint(address(edition));

vm.expectRevert(EditionMinter.MintControllerNotFound.selector);

minter.deleteEditionMint(address(edition));
}

function test_mintBeforeStartTimeReverts() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

Expand Down Expand Up @@ -148,21 +79,21 @@ contract FixedPricePublicSaleMinterTests is TestConfig {
minter.mint{ value: PRICE }(address(edition), 1);
}

function test_mintDuringOutOfStockReverts() public {
function test_mintWhenSoldOutReverts() public {
(SoundEditionV1 edition, FixedPricePublicSaleMinter minter) = _createEditionAndMinter();

vm.warp(START_TIME);

address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert(FixedPricePublicSaleMinter.MintOutOfStock.selector);
vm.expectRevert(FixedPricePublicSaleMinter.SoldOut.selector);
minter.mint{ value: PRICE * (MAX_MINTED + 1) }(address(edition), MAX_MINTED + 1);

vm.prank(caller);
minter.mint{ value: PRICE * MAX_MINTED }(address(edition), MAX_MINTED);

vm.prank(caller);
vm.expectRevert(FixedPricePublicSaleMinter.MintOutOfStock.selector);
vm.expectRevert(FixedPricePublicSaleMinter.SoldOut.selector);
minter.mint{ value: PRICE }(address(edition), 1);
}

Expand All @@ -173,7 +104,7 @@ contract FixedPricePublicSaleMinterTests is TestConfig {

address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert(FixedPricePublicSaleMinter.MintWithWrongEtherValue.selector);
vm.expectRevert(FixedPricePublicSaleMinter.WrongEtherValue.selector);
minter.mint{ value: PRICE * 2 }(address(edition), 1);
}

Expand Down

0 comments on commit 1285ea7

Please sign in to comment.