Skip to content

Commit

Permalink
test(royalty): update tests & add more asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface committed Sep 23, 2024
1 parent dda4afd commit 322a560
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions test/workflows/RoyaltyWorkflows.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ contract RoyaltyWorkflowsTest is BaseTest {

function test_RoyaltyWorkflows_transferToVaultAndSnapshotAndClaimByTokenBatch() public {
// setup IP graph with no snapshot
_setupIpGraph(0);
uint256 numSnapshots = 0;
_setupIpGraph(numSnapshots);

IRoyaltyWorkflows.RoyaltyClaimDetails[] memory claimDetails = new IRoyaltyWorkflows.RoyaltyClaimDetails[](4);
claimDetails[0] = IRoyaltyWorkflows.RoyaltyClaimDetails({
Expand Down Expand Up @@ -79,24 +80,23 @@ contract RoyaltyWorkflowsTest is BaseTest {
amount: (defaultMintingFeeC * defaultCommRevShareC) / royaltyModule.maxPercent() // 500 * 20% = 100
});

address[] memory currencyTokens = new address[](2);
currencyTokens[0] = address(mockTokenA);
currencyTokens[1] = address(mockTokenC);

uint256 claimerBalanceABefore = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCBefore = mockTokenC.balanceOf(u.admin);

(uint256 snapshotId, uint256[] memory amountsClaimed) = royaltyWorkflows
.transferToVaultAndSnapshotAndClaimByTokenBatch({
ancestorIpId: ancestorIpId,
claimer: u.admin,
currencyTokens: currencyTokens,
royaltyClaimDetails: claimDetails
});

uint256 claimerBalanceAAfter = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCAfter = mockTokenC.balanceOf(u.admin);

assertEq(snapshotId, numSnapshots + 1);
assertEq(amountsClaimed.length, 2); // there are 2 currency tokens
assertEq(claimerBalanceAAfter - claimerBalanceABefore, amountsClaimed[0]);
assertEq(claimerBalanceCAfter - claimerBalanceCBefore, amountsClaimed[1]);
assertEq(
claimerBalanceAAfter - claimerBalanceABefore,
defaultMintingFeeA +
Expand All @@ -109,7 +109,6 @@ contract RoyaltyWorkflowsTest is BaseTest {
royaltyModule.maxPercent() // 1000 * 10% * 10% = 10 royalty from grandChildIp
// TODO: should be 20 but MockIPGraph currently only supports single-path calculation
);

assertEq(
claimerBalanceCAfter - claimerBalanceCBefore,
defaultMintingFeeC + (defaultMintingFeeC * defaultCommRevShareC) / royaltyModule.maxPercent() // 500 from from minting fee of childIpC // 500 * 20% = 100 royalty from childIpC
Expand All @@ -118,7 +117,8 @@ contract RoyaltyWorkflowsTest is BaseTest {

function test_RoyaltyWorkflows_transferToVaultAndSnapshotAndClaimBySnapshotBatch() public {
// setup IP graph and takes 3 snapshots of ancestor IP's royalty vault
_setupIpGraph(3);
uint256 numSnapshots = 3;
_setupIpGraph(numSnapshots);

IRoyaltyWorkflows.RoyaltyClaimDetails[] memory claimDetails = new IRoyaltyWorkflows.RoyaltyClaimDetails[](4);
claimDetails[0] = IRoyaltyWorkflows.RoyaltyClaimDetails({
Expand Down Expand Up @@ -150,25 +150,24 @@ contract RoyaltyWorkflowsTest is BaseTest {
amount: (defaultMintingFeeC * defaultCommRevShareC) / royaltyModule.maxPercent() // 500 * 20% = 100
});

address[] memory currencyTokens = new address[](2);
currencyTokens[0] = address(mockTokenA);
currencyTokens[1] = address(mockTokenC);

uint256 claimerBalanceABefore = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCBefore = mockTokenC.balanceOf(u.admin);

(uint256 snapshotId, uint256[] memory amountsClaimed) = royaltyWorkflows
.transferToVaultAndSnapshotAndClaimBySnapshotBatch({
ancestorIpId: ancestorIpId,
claimer: u.admin,
currencyTokens: currencyTokens,
unclaimedSnapshotIds: unclaimedSnapshotIds,
royaltyClaimDetails: claimDetails
});

uint256 claimerBalanceAAfter = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCAfter = mockTokenC.balanceOf(u.admin);

assertEq(snapshotId, numSnapshots + 1);
assertEq(amountsClaimed.length, 2); // there are 2 currency tokens
assertEq(claimerBalanceAAfter - claimerBalanceABefore, amountsClaimed[0]);
assertEq(claimerBalanceCAfter - claimerBalanceCBefore, amountsClaimed[1]);
assertEq(
claimerBalanceAAfter - claimerBalanceABefore,
defaultMintingFeeA +
Expand All @@ -180,7 +179,6 @@ contract RoyaltyWorkflowsTest is BaseTest {
(((defaultMintingFeeA * defaultCommRevShareA) / royaltyModule.maxPercent()) * defaultCommRevShareA) /
royaltyModule.maxPercent() // 1000 * 10% * 10% = 10 royalty from grandChildIp
);

assertEq(
claimerBalanceCAfter - claimerBalanceCBefore,
defaultMintingFeeC + (defaultMintingFeeC * defaultCommRevShareC) / royaltyModule.maxPercent() // 500 from minting fee of childIpC // 500 * 20% = 100 royalty from childIpC
Expand All @@ -189,7 +187,8 @@ contract RoyaltyWorkflowsTest is BaseTest {

function test_RoyaltyWorkflows_snapshotAndClaimByTokenBatch() public {
// setup IP graph with no snapshot
_setupIpGraph(0);
uint256 numSnapshots = 0;
_setupIpGraph(numSnapshots);

address[] memory currencyTokens = new address[](2);
currencyTokens[0] = address(mockTokenA);
Expand All @@ -207,11 +206,14 @@ contract RoyaltyWorkflowsTest is BaseTest {
uint256 claimerBalanceAAfter = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCAfter = mockTokenC.balanceOf(u.admin);

assertEq(snapshotId, numSnapshots + 1);
assertEq(amountsClaimed.length, 2); // there are 2 currency tokens
assertEq(claimerBalanceAAfter - claimerBalanceABefore, amountsClaimed[0]);
assertEq(claimerBalanceCAfter - claimerBalanceCBefore, amountsClaimed[1]);
assertEq(
claimerBalanceAAfter - claimerBalanceABefore,
defaultMintingFeeA + defaultMintingFeeA // 1000 + 1000 from minting fee of childIpA and childIpB
);

assertEq(
claimerBalanceCAfter - claimerBalanceCBefore,
defaultMintingFeeC // 500 from from minting fee of childIpC
Expand All @@ -220,7 +222,8 @@ contract RoyaltyWorkflowsTest is BaseTest {

function test_RoyaltyWorkflows_snapshotAndClaimBySnapshotBatch() public {
// setup IP graph and takes 1 snapshot of ancestor IP's royalty vault
_setupIpGraph(1);
uint256 numSnapshots = 1;
_setupIpGraph(numSnapshots);

address[] memory currencyTokens = new address[](2);
currencyTokens[0] = address(mockTokenA);
Expand All @@ -239,11 +242,14 @@ contract RoyaltyWorkflowsTest is BaseTest {
uint256 claimerBalanceAAfter = mockTokenA.balanceOf(u.admin);
uint256 claimerBalanceCAfter = mockTokenC.balanceOf(u.admin);

assertEq(snapshotId, numSnapshots + 1);
assertEq(amountsClaimed.length, 2); // there are 2 currency tokens
assertEq(claimerBalanceAAfter - claimerBalanceABefore, amountsClaimed[0]);
assertEq(claimerBalanceCAfter - claimerBalanceCBefore, amountsClaimed[1]);
assertEq(
claimerBalanceAAfter - claimerBalanceABefore,
defaultMintingFeeA + defaultMintingFeeA // 1000 + 1000 from minting fee of childIpA and childIpB
);

assertEq(
claimerBalanceCAfter - claimerBalanceCBefore,
defaultMintingFeeC // 500 from from minting fee of childIpC
Expand Down Expand Up @@ -291,7 +297,7 @@ contract RoyaltyWorkflowsTest is BaseTest {
/// - `childIpC`: It has licenseTermsC attached, has 1 parent `ancestorIp`, and has 1 grandchild `grandChildIp`.
/// - `grandChildIp`: It has all 3 license terms attached. It has 3 parents and 1 grandparent IPs.
/// @param numSnapshots The number of snapshots to take of the ancestor IP's royalty vault.
function _setupIpGraph(uint32 numSnapshots) private {
function _setupIpGraph(uint256 numSnapshots) private {
uint256 ancestorTokenId = mockNft.mint(u.admin);
uint256 childTokenIdA = mockNft.mint(u.alice);
uint256 childTokenIdB = mockNft.mint(u.bob);
Expand Down

0 comments on commit 322a560

Please sign in to comment.