From 36d0a9fb9c1f974a4e2dab32b7a635d96a4c03be Mon Sep 17 00:00:00 2001 From: malteish Date: Mon, 25 Sep 2023 10:54:12 +0200 Subject: [PATCH] add test for PaymentSplitter --- test/PaymentSplitter.t.sol | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/PaymentSplitter.t.sol diff --git a/test/PaymentSplitter.t.sol b/test/PaymentSplitter.t.sol new file mode 100644 index 00000000..d695707d --- /dev/null +++ b/test/PaymentSplitter.t.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.13; + +import "../lib/forge-std/src/Test.sol"; +import "./resources/FakePaymentToken.sol"; +import "@openzeppelin/contracts/finance/PaymentSplitter.sol"; + +contract paymentSplitterTest is Test { + FakePaymentToken token; + + function setUp() public { + token = new FakePaymentToken(1000e18, 18); + } + + function testFixedSplit() public { + address[] memory payees = new address[](2); + payees[0] = address(0x1); + payees[1] = address(0x2); + uint256[] memory shares = new uint256[](2); + shares[0] = 8; // 80% + shares[1] = 2; // 20% + PaymentSplitter splitter = new PaymentSplitter(payees, shares); + + // send 100 tokens to the splitter + token.transfer(address(splitter), 100e18); + + // pull share for address 1 + assertEq(token.balanceOf(payees[0]), 0); + splitter.release(token, payees[0]); + assertEq(token.balanceOf(payees[0]), 80e18); + + // pull share for address 2 + assertEq(token.balanceOf(payees[1]), 0); + splitter.release(token, payees[1]); + assertEq(token.balanceOf(payees[1]), 20e18); + } +}