Skip to content

Commit

Permalink
test: RoyaltiesRegistry Contract
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Oct 6, 2023
1 parent 0e8ee9c commit 223b82d
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ contract TestERC1155WithRoyaltyV2981 is
{
uint256 internal constant BASIS_POINTS = 10000;

bytes4 internal constant INTERFACE_ID_GET_RECIPIENTS = 0xfd90e897;

function initialize() public initializer {
__Ownable_init();
}
Expand All @@ -32,6 +34,7 @@ contract TestERC1155WithRoyaltyV2981 is
) public view virtual override(ERC1155Upgradeable, Royalties2981TestImpl) returns (bool) {
return
interfaceId == LibRoyalties2981._INTERFACE_ID_ROYALTIES ||
interfaceId == INTERFACE_ID_GET_RECIPIENTS ||
ERC1155Upgradeable.supportsInterface(interfaceId) ||
Royalties2981TestImpl.supportsInterface(interfaceId);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/marketplace/contracts/mocks/TestRoyaltyInfo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

contract TestRoyaltyInfo {
function royaltyInfo(
uint256 /* _tokenId */,
uint256 /* _salePrice */
) external view returns (address receiver, uint256 royaltyAmount) {
return (msg.sender, 0);
}
}
142 changes: 142 additions & 0 deletions packages/marketplace/test/exchange/RoyaltiesRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,148 @@ describe('RoyaltiesRegistry.sol', function () {
).to.be.deep.eq([user1.address, 1n]);
});

it('should getRoyalties for token with royaltiesType 2 when provider address does not implement getRoyalties', async function () {
const {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
ERC721WithRoyaltyV2981,
ERC20Contract: ProviderContract,
} = await loadFixture(deployFixtures);
await loadFixture(deployFixtures);

await RoyaltiesRegistryAsDeployer.setProviderByToken(
await ERC721WithRoyaltyV2981.getAddress(),
await ProviderContract.getAddress()
);

await RoyaltiesRegistryAsDeployer.forceSetRoyaltiesType(
await ERC721WithRoyaltyV2981.getAddress(),
2
);

expect(
await RoyaltiesRegistryAsUser.getRoyaltiesType(
await ERC721WithRoyaltyV2981.getAddress()
)
).to.be.equal(2);

expect(
await RoyaltiesRegistryAsUser.getRoyalties.staticCall(
await ERC721WithRoyaltyV2981.getAddress(),
1
)
).to.be.deep.eq([]);
});

it('should getRoyalties for token with royaltiesType 3 when token address do not implements royaltyInfo', async function () {
const {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
ERC20Contract,
} = await loadFixture(deployFixtures);
await loadFixture(deployFixtures);

await RoyaltiesRegistryAsDeployer.forceSetRoyaltiesType(
await ERC20Contract.getAddress(),
3
);

expect(
await RoyaltiesRegistryAsUser.getRoyaltiesType(
await ERC20Contract.getAddress()
)
).to.be.equal(3);

expect(
await RoyaltiesRegistryAsUser.getRoyalties.staticCall(
await ERC20Contract.getAddress(),
1
)
).to.be.deep.eq([]);
});

it('should getRoyalties for token with royaltiesType 3 that only implements royaltyInfo', async function () {
const {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
TestRoyaltyInfo,
} = await loadFixture(deployFixtures);
await loadFixture(deployFixtures);

await RoyaltiesRegistryAsDeployer.forceSetRoyaltiesType(
await TestRoyaltyInfo.getAddress(),
3
);

expect(
await RoyaltiesRegistryAsUser.getRoyaltiesType(
await TestRoyaltyInfo.getAddress()
)
).to.be.equal(3);

expect(
await RoyaltiesRegistryAsUser.getRoyalties.staticCall(
await TestRoyaltyInfo.getAddress(),
1
)
).to.be.deep.eq([]);
});

it('should not getRoyalties for token with royaltiesType 3 with partial support when royalties exceed 100%', async function () {
const {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
ERC1155WithRoyalty,
} = await loadFixture(deployFixtures);
await loadFixture(deployFixtures);

await ERC1155WithRoyalty.setRoyalties(1000000);
await RoyaltiesRegistryAsDeployer.forceSetRoyaltiesType(
await ERC1155WithRoyalty.getAddress(),
3
);

expect(
await RoyaltiesRegistryAsUser.getRoyaltiesType(
await ERC1155WithRoyalty.getAddress()
)
).to.be.equal(3);

await expect(
RoyaltiesRegistryAsUser.getRoyalties.staticCall(
await ERC1155WithRoyalty.getAddress(),
1
)
).to.be.revertedWith('Royalties 2981 exceeds 100%');
});

it('should getRoyalties for token with royaltiesType 3 with partial support', async function () {
const {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
ERC1155WithRoyalty,
} = await loadFixture(deployFixtures);
await loadFixture(deployFixtures);

await RoyaltiesRegistryAsDeployer.forceSetRoyaltiesType(
await ERC1155WithRoyalty.getAddress(),
3
);

expect(
await RoyaltiesRegistryAsUser.getRoyaltiesType(
await ERC1155WithRoyalty.getAddress()
)
).to.be.equal(3);

expect(
await RoyaltiesRegistryAsUser.getRoyalties.staticCall(
await ERC1155WithRoyalty.getAddress(),
1
)
).to.be.deep.eq([]);
});

it('should getRoyalties for token with royaltiesType 4', async function () {
const {
RoyaltiesRegistryAsUser,
Expand Down
20 changes: 20 additions & 0 deletions packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ async function deploy() {
);
await ERC721WithRoyalty.waitForDeployment();

const TestERC1155WithRoyaltyFactory = await ethers.getContractFactory(
'TestERC1155WithRoyaltyV2981'
);
const ERC1155WithRoyalty = await upgrades.deployProxy(
TestERC1155WithRoyaltyFactory,
[],
{
initializer: 'initialize',
}
);
await ERC1155WithRoyalty.waitForDeployment();

const TestRoyaltyInfoFactory = await ethers.getContractFactory(
'TestRoyaltyInfo'
);
const TestRoyaltyInfo = await TestRoyaltyInfoFactory.deploy();
await TestRoyaltyInfo.waitForDeployment();

const ERC20ContractFactory = await ethers.getContractFactory('TestERC20');
const ERC20Contract = await ERC20ContractFactory.deploy();
await ERC20Contract.waitForDeployment();
Expand Down Expand Up @@ -137,6 +155,8 @@ async function deploy() {
RoyaltiesRegistryAsUser,
ERC721WithRoyaltyV2981,
ERC721WithRoyalty,
ERC1155WithRoyalty,
TestRoyaltyInfo,
RoyaltiesProvider,
ERC1271Contract,
deployer,
Expand Down

1 comment on commit 223b82d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

95.81%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts/exchange
   Exchange.sol95.65%96.67%93.75%95.65%173, 63
   ExchangeCore.sol98.73%96.15%100%100%64
   OrderValidator.sol98.21%96.15%100%100%41
   WhiteList.sol97.67%93.75%100%100%63
packages/marketplace/contracts/exchange/libraries
   LibFill.sol100%100%100%100%
   LibMath.sol100%100%100%100%
packages/marketplace/contracts/interfaces
   IAssetMatcher.sol100%100%100%100%
   IOrderValidator.sol100%100%100%100%
   IRoyaltiesProvider.sol100%100%100%100%
   IWhiteList.sol100%100%100%100%
packages/marketplace/contracts/lib-asset
   LibAsset.sol100%100%100%100%
packages/marketplace/contracts/lib-bp
   BpLibrary.sol100%100%100%100%
packages/marketplace/contracts/lib-order
   LibOrder.sol100%100%100%100%
packages/marketplace/contracts/lib-part
   LibPart.sol100%100%100%100%
packages/marketplace/contracts/royalties
   IERC2981.sol100%100%100%100%
   LibRoyalties2981.sol100%100%100%100%
packages/marketplace/contracts/royalties-registry
   IMultiRoyaltyRecipients.sol100%100%100%100%
   RoyaltiesRegistry.sol95.04%87.50%100%97.30%166–167, 170–171, 244, 60
packages/marketplace/contracts/transfer-manager
   TransferExecutor.sol100%100%100%100%
   TransferManager.sol82.91%72.41%100%87.50%137, 190, 199, 206–207, 207, 207–208, 212, 220, 227–228, 252, 269, 273–275, 275, 275–277, 282–283, 306, 310–311, 62
packages/marketplace/contracts/transfer-manager/interfaces
   IRoyaltyUGC.sol100%100%100%100%
   ITransferExecutor.sol100%100%100%100%
   ITransferManager.sol100%100%100%100%

Please sign in to comment.