Skip to content

Commit

Permalink
Make SoundEditionCreated event more buffed (#219)
Browse files Browse the repository at this point in the history
* Make SoundEditionCreated event more buffed

* Buff event even more
  • Loading branch information
Vectorized committed Sep 16, 2022
1 parent 7a2e1ee commit 56c0b17
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 73 deletions.
2 changes: 1 addition & 1 deletion contracts/core/SoundCreatorV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract SoundCreatorV1 is ISoundCreatorV1, Ownable {

OwnableRoles(soundEdition).transferOwnership(msg.sender);

emit SoundEditionCreated(soundEdition, msg.sender);
emit SoundEditionCreated(soundEdition, msg.sender, initData, contracts, data, results);
}

/**
Expand Down
17 changes: 14 additions & 3 deletions contracts/core/interfaces/ISoundCreatorV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ interface ISoundCreatorV1 {

/**
* @dev Emitted when an edition is created.
* @param soundEdition the address of the edition.
* @param deployer The address of the deployer.
* @param soundEdition The address of the edition.
* @param deployer The address of the deployer.
* @param initData The calldata to initialize SoundEdition via `abi.encodeWithSelector`.
* @param contracts The list of contracts called.
* @param data The list of calldata created via `abi.encodeWithSelector`
* @param results The results of calling the contracts. Use `abi.decode` to decode them.
*/
event SoundEditionCreated(address indexed soundEdition, address indexed deployer);
event SoundEditionCreated(
address indexed soundEdition,
address indexed deployer,
bytes initData,
address[] contracts,
bytes[] data,
bytes[] results
);

/**
* @dev Emitted when the edition implementation address is set.
Expand Down
170 changes: 101 additions & 69 deletions tests/core/SoundCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import { OwnableRoles } from "solady/auth/OwnableRoles.sol";
import { TestConfig } from "../TestConfig.sol";

contract SoundCreatorTests is TestConfig {
event SoundEditionCreated(address indexed soundEdition, address indexed deployer);
event SoundEditionCreated(
address indexed soundEdition,
address indexed deployer,
bytes initData,
address[] contracts,
bytes[] data,
bytes[] results
);

event SoundEditionImplementationSet(address newImplementation);

uint96 constant PRICE = 1 ether;
Expand Down Expand Up @@ -130,11 +138,17 @@ contract SoundCreatorTests is TestConfig {
address[] memory contracts = new address[](6);
bytes[] memory data = new bytes[](6);

FixedPriceSignatureMinter signatureMinter;
MerkleDropMinter merkleMinter;
RangeEditionMinter rangeMinter;

// Deploy the registry and minters.
ISoundFeeRegistry feeRegistry = ISoundFeeRegistry(address(1));
FixedPriceSignatureMinter signatureMinter = new FixedPriceSignatureMinter(feeRegistry);
MerkleDropMinter merkleMinter = new MerkleDropMinter(feeRegistry);
RangeEditionMinter rangeMinter = new RangeEditionMinter(feeRegistry);
{
ISoundFeeRegistry feeRegistry = ISoundFeeRegistry(address(1));
signatureMinter = new FixedPriceSignatureMinter(feeRegistry);
merkleMinter = new MerkleDropMinter(feeRegistry);
rangeMinter = new RangeEditionMinter(feeRegistry);
}

// Deploy the implementation of the edition.
SoundEditionV1 editionImplementation = new SoundEditionV1();
Expand All @@ -153,59 +167,78 @@ contract SoundCreatorTests is TestConfig {

// Populate the data:
// First, we have to call the {grantRoles} on the `soundEditionAddress`.
data[0] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(signatureMinter),
editionImplementation.MINTER_ROLE()
);
data[1] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(merkleMinter),
editionImplementation.MINTER_ROLE()
);
data[2] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(rangeMinter),
editionImplementation.MINTER_ROLE()
);
// Then, we have to call the {createEditionMint} on the minters.
data[3] = abi.encodeWithSelector(
signatureMinter.createEditionMint.selector,
soundEditionAddress,
price0,
SIGNER,
EDITION_MAX_MINTABLE,
START_TIME,
END_TIME,
AFFILIATE_FEE_BPS
);
data[4] = abi.encodeWithSelector(
merkleMinter.createEditionMint.selector,
soundEditionAddress,
bytes32(uint256(123456)), // Merkle root hash.
price1,
START_TIME,
END_TIME,
AFFILIATE_FEE_BPS,
EDITION_MAX_MINTABLE,
5 // Max mintable per account.
);
data[5] = abi.encodeWithSelector(
rangeMinter.createEditionMint.selector,
soundEditionAddress,
price2,
START_TIME,
START_TIME + 1, // Closing time
END_TIME,
AFFILIATE_FEE_BPS,
10, // Max mintable lower.
20, // Max mintable upper.
5 // Max mintable per account.
);
{
data[0] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(signatureMinter),
editionImplementation.MINTER_ROLE()
);
data[1] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(merkleMinter),
editionImplementation.MINTER_ROLE()
);
data[2] = abi.encodeWithSelector(
editionImplementation.grantRoles.selector,
address(rangeMinter),
editionImplementation.MINTER_ROLE()
);
}

// Check that the creation event is emitted.
vm.expectEmit(true, true, true, true);
emit SoundEditionCreated(soundEditionAddress, address(this));
// Then, we have to call the {createEditionMint} on the minters.
{
data[3] = abi.encodeWithSelector(
signatureMinter.createEditionMint.selector,
soundEditionAddress,
price0,
SIGNER,
EDITION_MAX_MINTABLE,
START_TIME,
END_TIME,
AFFILIATE_FEE_BPS
);
data[4] = abi.encodeWithSelector(
merkleMinter.createEditionMint.selector,
soundEditionAddress,
bytes32(uint256(123456)), // Merkle root hash.
price1,
START_TIME,
END_TIME,
AFFILIATE_FEE_BPS,
EDITION_MAX_MINTABLE,
5 // Max mintable per account.
);
data[5] = abi.encodeWithSelector(
rangeMinter.createEditionMint.selector,
soundEditionAddress,
price2,
START_TIME,
START_TIME + 1, // Closing time
END_TIME,
AFFILIATE_FEE_BPS,
10, // Max mintable lower.
20, // Max mintable upper.
5 // Max mintable per account.
);
}

{
bytes[] memory expectedResults = new bytes[](6);
expectedResults[3] = abi.encode(signatureMinter.nextMintId());
expectedResults[4] = abi.encode(merkleMinter.nextMintId());
expectedResults[5] = abi.encode(rangeMinter.nextMintId());

// Check that the creation event is emitted.
vm.expectEmit(true, true, true, true);
emit SoundEditionCreated(
soundEditionAddress,
address(this),
_makeInitData(),
contracts,
data,
expectedResults
);
}

// Call the create function.
(, bytes[] memory results) = _createSoundEditionWithCalls(salt, contracts, data);
Expand Down Expand Up @@ -259,14 +292,8 @@ contract SoundCreatorTests is TestConfig {
test_createSoundAndMintsRevertForArrayLengthsMismatch(0, 1, salt);
}

// For avoiding the stack too deep error.
function _createSoundEditionWithCalls(
bytes32 salt,
address[] memory contracts,
bytes[] memory data
) internal returns (address soundEdition, bytes[] memory results) {
(soundEdition, results) = soundCreator.createSoundAndMints(
salt,
function _makeInitData() internal pure returns (bytes memory) {
return
abi.encodeWithSelector(
SoundEditionV1.initialize.selector,
SONG_NAME,
Expand All @@ -280,9 +307,14 @@ contract SoundCreatorTests is TestConfig {
EDITION_MAX_MINTABLE,
EDITION_CUTOFF_TIME,
FLAGS
),
contracts,
data
);
);
}

function _createSoundEditionWithCalls(
bytes32 salt,
address[] memory contracts,
bytes[] memory data
) internal returns (address soundEdition, bytes[] memory results) {
(soundEdition, results) = soundCreator.createSoundAndMints(salt, _makeInitData(), contracts, data);
}
}

0 comments on commit 56c0b17

Please sign in to comment.