Skip to content

Commit df20ef9

Browse files
test: Fuzzed BPS shares test added
1 parent 54ef64b commit df20ef9

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/ATokenVaultRevenueSplitterOwner.t.sol

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,80 @@ contract ATokenVaultRevenueSplitterOwnerTest is Test {
543543
assertLe(address(revenueSplitterOwner).balance, recipients.length - 1);
544544
}
545545

546+
function test_splitRevenue_distributesRevenueToAllRecipientsAccordingToTheirShares_FuzzShares(
547+
uint16 fuzzShareI
548+
) public {
549+
recipients.pop();
550+
assertEq(recipients.length, 2);
551+
552+
fuzzShareI = uint16(bound(fuzzShareI, 1, 10_000 - 1));
553+
uint16 fuzzShareII = 10_000 - fuzzShareI;
554+
555+
recipients[0].shareInBps = fuzzShareI;
556+
recipients[1].shareInBps = fuzzShareII;
557+
558+
// Redeploys the splitter with the new recipients configuration
559+
revenueSplitterOwner = new ATokenVaultRevenueSplitterOwner(address(vault), owner, recipients);
560+
561+
uint256 amountToSplit = 100_000;
562+
MockDAI assetToSplit = new MockDAI();
563+
564+
assertEq(assetToSplit.balanceOf(address(revenueSplitterOwner)), 0);
565+
assertEq(assetToSplit.balanceOf(address(recipientI)), 0);
566+
assertEq(assetToSplit.balanceOf(address(recipientII)), 0);
567+
assertEq(assetToSplit.balanceOf(address(recipientIII)), 0); // Not set as recipient
568+
569+
assetToSplit.mint(address(revenueSplitterOwner), amountToSplit);
570+
571+
assertEq(assetToSplit.balanceOf(address(revenueSplitterOwner)), amountToSplit);
572+
573+
address[] memory assetsToSplit = new address[](1);
574+
assetsToSplit[0] = address(assetToSplit);
575+
576+
revenueSplitterOwner.splitRevenue(assetsToSplit);
577+
578+
assertEq(assetToSplit.balanceOf(address(recipientI)), amountToSplit * fuzzShareI / 10_000);
579+
assertEq(assetToSplit.balanceOf(address(recipientII)), amountToSplit * fuzzShareII / 10_000);
580+
assertEq(assetToSplit.balanceOf(address(recipientIII)), 0); // Not set as recipient
581+
582+
// The remaining unsplit amount is capped to the be strictly less than the number of recipients
583+
assertLe(assetToSplit.balanceOf(address(revenueSplitterOwner)), recipients.length - 1);
584+
}
585+
586+
function test_splitRevenue_distributesRevenueToAllRecipientsAccordingToTheirShares_FuzzShares_NativeCurrency(
587+
uint16 fuzzShareI
588+
) public {
589+
recipients.pop();
590+
assertEq(recipients.length, 2);
591+
592+
fuzzShareI = uint16(bound(fuzzShareI, 1, 10_000 - 1));
593+
uint16 fuzzShareII = 10_000 - fuzzShareI;
594+
595+
recipients[0].shareInBps = fuzzShareI;
596+
recipients[1].shareInBps = fuzzShareII;
597+
598+
// Redeploys the splitter with the new recipients configuration
599+
revenueSplitterOwner = new ATokenVaultRevenueSplitterOwner(address(vault), owner, recipients);
600+
601+
uint256 amountToSplit = 100_000;
602+
603+
assertEq(address(revenueSplitterOwner).balance, 0);
604+
assertEq(address(recipientI).balance, 0);
605+
assertEq(address(recipientII).balance, 0);
606+
assertEq(address(recipientIII).balance, 0); // Not set as recipient
607+
608+
vm.deal(address(revenueSplitterOwner), amountToSplit);
609+
610+
assertEq(address(revenueSplitterOwner).balance, amountToSplit);
611+
612+
revenueSplitterOwner.splitRevenue();
613+
614+
assertEq(address(recipientI).balance, amountToSplit * fuzzShareI / 10_000);
615+
assertEq(address(recipientII).balance, amountToSplit * fuzzShareII / 10_000);
616+
assertEq(address(recipientIII).balance, 0); // Not set as recipient
617+
618+
// The remaining unsplit amount is capped to the be strictly less than the number of recipients
619+
assertLe(address(revenueSplitterOwner).balance, recipients.length - 1);
620+
}
621+
546622
}

0 commit comments

Comments
 (0)