Skip to content

Commit

Permalink
Merge branch 'vectorized/pro-220-auction-base' of https://github.com/…
Browse files Browse the repository at this point in the history
…Vectorized/sound-protocol into vectorized/pro-220-auction-base
  • Loading branch information
Vectorized committed Jul 27, 2022
2 parents 69bf024 + 9dc338d commit 37b2a59
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions contracts/SoundCreator/SoundCreatorV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ contract SoundCreatorV1 {
IMetadataModule _metadataModule,
string memory _baseURI,
string memory _contractURI
) external returns (address soundNft) {
) external returns (address soundEdition) {
// todo: if signature provided, pass it to SoundRegistry.register();
// todo: implement extension configurations

// todo: research if we can get any gas savings by using a more minimal version of Clones lib
soundNft = Clones.clone(nftImplementation);
soundEdition = Clones.clone(nftImplementation);

ISoundEditionV1(soundNft).initialize(msg.sender, _name, _symbol, _metadataModule, _baseURI, _contractURI);
ISoundEditionV1(soundEdition).initialize(msg.sender, _name, _symbol, _metadataModule, _baseURI, _contractURI);

// todo: emit event
}
Expand Down
14 changes: 7 additions & 7 deletions tests/SoundCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import "../contracts/SoundCreator/SoundCreatorV1.sol";
contract SoundCreatorTests is TestConfig {
// Tests that the factory deploys
function test_deploysSoundCreator() public {
SoundEditionV1 soundNftImplementation = new SoundEditionV1();
SoundEditionV1 soundEditionImplementation = new SoundEditionV1();
address soundRegistry = address(123);
SoundCreatorV1 _soundCreator = new SoundCreatorV1(address(soundNftImplementation), soundRegistry);
SoundCreatorV1 _soundCreator = new SoundCreatorV1(address(soundEditionImplementation), soundRegistry);

assert(address(_soundCreator) != address(0));

assertEq(address(_soundCreator.soundRegistry()), soundRegistry);
assertEq(address(_soundCreator.nftImplementation()), address(soundNftImplementation));
assertEq(address(_soundCreator.nftImplementation()), address(soundEditionImplementation));
}

// Tests that the factory creates a new sound NFT
function test_createSound() public {
SoundEditionV1 soundNft = SoundEditionV1(
SoundEditionV1 soundEdition = SoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

assert(address(soundNft) != address(0));
assertEq(soundNft.name(), SONG_NAME);
assertEq(soundNft.symbol(), SONG_SYMBOL);
assert(address(soundEdition) != address(0));
assertEq(soundEdition.name(), SONG_NAME);
assertEq(soundEdition.symbol(), SONG_SYMBOL);
}
}
106 changes: 53 additions & 53 deletions tests/SoundNft/metadata.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "openzeppelin/utils/Strings.sol";
import "../TestConfig.sol";
import "../mocks/MockMetadataModule.sol";

contract SoundNft_metadata is TestConfig {
contract SoundEdition_metadata is TestConfig {
event MetadataFrozen(IMetadataModule _metadataModule, string baseURI_, string _contractURI);
event BaseURISet(string baseURI_);
event ContractURISet(string _contractURI);
Expand All @@ -18,58 +18,58 @@ contract SoundNft_metadata is TestConfig {
// Generates tokenURI using baseURI if no metadata module is selected
function test_baseURIWhenNoMetadataModule() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, IMetadataModule(address(0)), BASE_URI, CONTRACT_URI)
);

// mint NFTs
soundNft.mint(2);
soundEdition.mint(2);
uint256 tokenId = 1;

string memory expectedTokenURI = string.concat(BASE_URI, Strings.toString(tokenId));
assertEq(soundNft.tokenURI(tokenId), expectedTokenURI);
assertEq(soundEdition.tokenURI(tokenId), expectedTokenURI);
}

// Should successfully return contract URI for the collection
function test_contractURI() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

assertEq(soundNft.contractURI(), CONTRACT_URI);
assertEq(soundEdition.contractURI(), CONTRACT_URI);
}

// Generate tokenURI using the metadata module
function test_metadataModule() public {
MockMetadataModule metadataModule = new MockMetadataModule();

// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, metadataModule, BASE_URI, CONTRACT_URI)
);

// mint NFTs
soundNft.mint(2);
soundEdition.mint(2);
uint256 tokenId = 1;

string memory expectedTokenURI = "MOCK";
assertEq(soundNft.tokenURI(tokenId), expectedTokenURI);
assertEq(soundEdition.tokenURI(tokenId), expectedTokenURI);
}

function test_tokenURIRevertsWhenTokenIdDoesntExist() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

vm.expectRevert(URIQueryForNonexistentToken.selector);
soundNft.tokenURI(2);
soundEdition.tokenURI(2);
}

function test_setBaseURIRevertsForNonOwner() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

Expand All @@ -78,55 +78,55 @@ contract SoundNft_metadata is TestConfig {
address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert("Ownable: caller is not the owner");
soundNft.setBaseURI(newBaseURI);
soundEdition.setBaseURI(newBaseURI);
}

function test_setBaseURIRevertsWhenMetadataFrozen() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);
// Freeze Metadata
soundNft.freezeMetadata();
soundEdition.freezeMetadata();

string memory newBaseURI = "https://abc.com/";

vm.expectRevert(MetadataIsFrozen.selector);
soundNft.setBaseURI(newBaseURI);
soundEdition.setBaseURI(newBaseURI);
}

function test_setBaseURISuccess() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);
// mint NFTs
soundNft.mint(2);
soundEdition.mint(2);
uint256 tokenId = 1;

string memory newBaseURI = "https://abc.com/";
soundNft.setBaseURI(newBaseURI);
soundEdition.setBaseURI(newBaseURI);

string memory expectedTokenURI = string.concat(newBaseURI, Strings.toString(tokenId));
assertEq(soundNft.tokenURI(tokenId), expectedTokenURI);
assertEq(soundEdition.tokenURI(tokenId), expectedTokenURI);
}

function test_setBaseURIEmitsEvent() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

string memory newBaseURI = "https://abc.com/";

vm.expectEmit(false, false, false, true);
emit BaseURISet(newBaseURI);
soundNft.setBaseURI(newBaseURI);
soundEdition.setBaseURI(newBaseURI);
}

function test_setContractURIRevertsForNonOwner() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

Expand All @@ -135,51 +135,51 @@ contract SoundNft_metadata is TestConfig {
address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert("Ownable: caller is not the owner");
soundNft.setContractURI(newContractURI);
soundEdition.setContractURI(newContractURI);
}

function test_setContractURIRevertsWhenMetadataFrozen() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);
// Freeze Metadata
soundNft.freezeMetadata();
soundEdition.freezeMetadata();

string memory newContractURI = "https://abc.com/";

vm.expectRevert(MetadataIsFrozen.selector);
soundNft.setContractURI(newContractURI);
soundEdition.setContractURI(newContractURI);
}

function test_setContractURISuccess() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

string memory newContractURI = "https://abc.com/";
soundNft.setContractURI(newContractURI);
soundEdition.setContractURI(newContractURI);

assertEq(soundNft.contractURI(), newContractURI);
assertEq(soundEdition.contractURI(), newContractURI);
}

function test_setContractURIEmitsEvent() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

string memory newContractURI = "https://abc.com/";

vm.expectEmit(false, false, false, true);
emit ContractURISet(newContractURI);
soundNft.setContractURI(newContractURI);
soundEdition.setContractURI(newContractURI);
}

function test_setMetadataModuleRevertsForNonOwner() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

Expand All @@ -188,94 +188,94 @@ contract SoundNft_metadata is TestConfig {
address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert("Ownable: caller is not the owner");
soundNft.setMetadataModule(newMetadataModule);
soundEdition.setMetadataModule(newMetadataModule);
}

function test_setMetadataModuleRevertsWhenMetadataFrozen() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);
// Freeze Metadata
soundNft.freezeMetadata();
soundEdition.freezeMetadata();

MockMetadataModule newMetadataModule = new MockMetadataModule();

vm.expectRevert(MetadataIsFrozen.selector);
soundNft.setMetadataModule(newMetadataModule);
soundEdition.setMetadataModule(newMetadataModule);
}

function test_setMetadataModuleSuccess() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, IMetadataModule(address(0)), BASE_URI, CONTRACT_URI)
);
// mint NFTs
soundNft.mint(2);
soundEdition.mint(2);
uint256 tokenId = 1;

MockMetadataModule newMetadataModule = new MockMetadataModule();
soundNft.setMetadataModule(newMetadataModule);
soundEdition.setMetadataModule(newMetadataModule);

string memory expectedTokenURI = "MOCK";
assertEq(soundNft.tokenURI(tokenId), expectedTokenURI);
assertEq(soundEdition.tokenURI(tokenId), expectedTokenURI);
}

function test_setMetadataModuleEmitsEvent() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, IMetadataModule(address(0)), BASE_URI, CONTRACT_URI)
);

MockMetadataModule newMetadataModule = new MockMetadataModule();

vm.expectEmit(false, false, false, true);
emit MetadataModuleSet(newMetadataModule);
soundNft.setMetadataModule(newMetadataModule);
soundEdition.setMetadataModule(newMetadataModule);
}

function test_freezeMetadataRevertsForNonOwner() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

address caller = getRandomAccount(1);
vm.prank(caller);
vm.expectRevert("Ownable: caller is not the owner");
soundNft.freezeMetadata();
soundEdition.freezeMetadata();
}

function test_freezeMetadataRevertsIfAlreadyFrozen() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);
soundNft.freezeMetadata();
soundEdition.freezeMetadata();

vm.expectRevert(MetadataIsFrozen.selector);
soundNft.freezeMetadata();
soundEdition.freezeMetadata();
}

function test_freezeMetadataSuccess() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

soundNft.freezeMetadata();
soundEdition.freezeMetadata();

assertEq(soundNft.isMetadataFrozen(), true);
assertEq(soundEdition.isMetadataFrozen(), true);
}

function test_freezeMetadataEmitsEvent() public {
// deploy new sound contract
MockSoundEditionV1 soundNft = MockSoundEditionV1(
MockSoundEditionV1 soundEdition = MockSoundEditionV1(
soundCreator.createSound(SONG_NAME, SONG_SYMBOL, METADATA_MODULE, BASE_URI, CONTRACT_URI)
);

vm.expectEmit(false, false, false, true);
emit MetadataFrozen(METADATA_MODULE, BASE_URI, CONTRACT_URI);
soundNft.freezeMetadata();
soundEdition.freezeMetadata();
}
}
4 changes: 2 additions & 2 deletions tests/TestConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ contract TestConfig is Test {
// Set up called before each test
function setUp() public {
// Deploy SoundEdition implementation
MockSoundEditionV1 soundNftImplementation = new MockSoundEditionV1();
MockSoundEditionV1 soundEditionImplementation = new MockSoundEditionV1();

// todo: deploy registry here
address soundRegistry = address(123);

soundCreator = new SoundCreatorV1(address(soundNftImplementation), soundRegistry);
soundCreator = new SoundCreatorV1(address(soundEditionImplementation), soundRegistry);
}

// Returns a random address funded with ETH
Expand Down

0 comments on commit 37b2a59

Please sign in to comment.