Skip to content

Commit

Permalink
chore: Add code coverage for CustomFractionalFeeAssessor (#13278)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
Signed-off-by: Bilyana Gospodinova <[email protected]>
  • Loading branch information
Neeharika-Sompalli authored and bilyana-gospodinova committed Jun 13, 2024
1 parent 830a147 commit 2e8e783
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private Map<AccountID, Long> filteredByExemptions(
* @param fractionalFee the fractional fee
* @return the amount owned to be paid as fractional custom fee
*/
private long amountOwed(final long givenUnits, @NonNull final FractionalFee fractionalFee) {
public long amountOwed(final long givenUnits, @NonNull final FractionalFee fractionalFee) {
final var numerator = fractionalFee.fractionalAmountOrThrow().numerator();
final var denominator = fractionalFee.fractionalAmountOrThrow().denominator();
var nominalFee = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ public void assessRoyaltyFees(
}
}
}
// We check this outside the for loop above because a sender should only be marked as paid royalty, after
// assessing
// all the fees for the given token. If a sender is sending multiple NFTs of the same token, royalty fee
// should be paid only once.
// We don't want to charge the fallback fee for each nft transfer, if the receiver has already
// paid it for this token. This should be added only once per token transfer, so this is
// added here.
// paid it for this token.

if (exchangedValue.isEmpty()) {
// Receiver pays fallback fees
result.addToRoyaltiesPaid(Pair.of(receiver, tokenId));
} else {
// Sender effectively pays percent royalties
// Sender effectively pays percent royalties. Here we don't check isPayerExempt because
// the sender could be exempt for one fee on token, but not other fees(if any) on the same token.
result.addToRoyaltiesPaid(Pair.of(sender, tokenId));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setUp() {
@Test
void delegatesToHbarWhenDenomIsNull() {
result = new AssessmentResult(List.of(nftTransferList), List.of());
final var hbarFee = withFixedFee(hbarFixedFee, otherCollector);
final var hbarFee = withFixedFee(hbarFixedFee, otherCollector, false);
final var feeMeta = withCustomFeeMeta(List.of(hbarFee), TokenType.FUNGIBLE_COMMON);

subject.assessFixedFees(feeMeta, payer, result);
Expand All @@ -88,7 +88,7 @@ void delegatesToHbarWhenDenomIsNull() {
@Test
void delegatesToHtsWhenDenomIsNonNull() {
result = new AssessmentResult(List.of(nftTransferList), List.of());
final var hbarFee = withFixedFee(htsFixedFee, otherCollector);
final var hbarFee = withFixedFee(htsFixedFee, otherCollector, false);
final var feeMeta = withCustomFeeMeta(List.of(hbarFee), TokenType.FUNGIBLE_COMMON);

subject.assessFixedFees(feeMeta, payer, result);
Expand All @@ -99,7 +99,7 @@ void delegatesToHtsWhenDenomIsNonNull() {
@Test
void fixedCustomFeeExemptIsOk() {
result = new AssessmentResult(List.of(nftTransferList), List.of());
final var hbarFee = withFixedFee(htsFixedFee, payer);
final var hbarFee = withFixedFee(htsFixedFee, payer, false);
final var feeMeta = withCustomFeeMeta(List.of(hbarFee), TokenType.FUNGIBLE_COMMON);

subject.assessFixedFees(feeMeta, payer, result);
Expand All @@ -109,7 +109,7 @@ void fixedCustomFeeExemptIsOk() {
@Test
void exemptsAssessmentWhenSenderSameAsCollector() {
result = new AssessmentResult(List.of(nftTransferList), List.of());
final var hbarFee = withFixedFee(htsFixedFee, payer);
final var hbarFee = withFixedFee(htsFixedFee, payer, false);
final var feeMeta = withCustomFeeMeta(List.of(hbarFee), TokenType.FUNGIBLE_COMMON);

subject.assessFixedFees(feeMeta, payer, result);
Expand All @@ -119,7 +119,7 @@ void exemptsAssessmentWhenSenderSameAsCollector() {
@Test
void ignoresIfPayerExempt() {
result = new AssessmentResult(List.of(nftTransferList), List.of());
final var hbarFee = withFixedFee(htsFixedFee, payer);
final var hbarFee = withFixedFee(htsFixedFee, payer, false);
final var feeMeta = withCustomFeeMeta(List.of(hbarFee), TokenType.FUNGIBLE_COMMON);

subject.assessFixedFee(feeMeta, payer, hbarFee, result);
Expand Down
Loading

0 comments on commit 2e8e783

Please sign in to comment.