-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic 'Helpers' unit tests
- Loading branch information
1 parent
d2c74a3
commit 7dd48ff
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import { Base_Test } from "../../../Base.t.sol"; | ||
import { Helpers } from "./../../../../src/modules/invoice-module/libraries/Helpers.sol"; | ||
import { Types } from "./../../../../src/modules/invoice-module/libraries/Types.sol"; | ||
|
||
contract ComputeNumberOfPayments_Helpers_Test is Base_Test { | ||
function setUp() public virtual override { | ||
Base_Test.setUp(); | ||
} | ||
|
||
function test_ComputeNumberOfPayments_Weekly() external view { | ||
// Create an interval of 11 weeks | ||
uint40 startTime = uint40(block.timestamp); | ||
uint40 endTime = uint40(block.timestamp + 11 weeks); | ||
|
||
// Run the test | ||
uint40 numberOfPayments = | ||
Helpers.computeNumberOfPayments({ recurrence: Types.Recurrence.Weekly, interval: endTime - startTime }); | ||
|
||
// Assert the actual and expected number of payments | ||
assertEq(numberOfPayments, 11); | ||
} | ||
|
||
function test_ComputeNumberOfPayments_Monthly() external view { | ||
// Create an interval of 2 months | ||
uint40 startTime = uint40(block.timestamp); | ||
uint40 endTime = uint40(block.timestamp + 2 * 4 weeks); | ||
|
||
// Run the test | ||
uint40 numberOfPayments = | ||
Helpers.computeNumberOfPayments({ recurrence: Types.Recurrence.Monthly, interval: endTime - startTime }); | ||
|
||
// Assert the actual and expected number of payments | ||
assertEq(numberOfPayments, 2); | ||
} | ||
|
||
function test_ComputeNumberOfPayments_Yearly() external view { | ||
// Create an interval of 3 years | ||
uint40 startTime = uint40(block.timestamp); | ||
uint40 endTime = uint40(block.timestamp + 3 * 48 weeks); | ||
|
||
// Run the test | ||
uint40 numberOfPayments = | ||
Helpers.computeNumberOfPayments({ recurrence: Types.Recurrence.Yearly, interval: endTime - startTime }); | ||
|
||
// Assert the actual and expected number of payments | ||
assertEq(numberOfPayments, 3); | ||
} | ||
} |