-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andrew Redden <[email protected]>
- Loading branch information
1 parent
0771896
commit a2d9d81
Showing
5 changed files
with
161 additions
and
36 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
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
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
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,46 @@ | ||
import "starport-test/StarPortTest.sol"; | ||
import {BorrowerEnforcer} from "starport-core/enforcers/BorrowerEnforcer.sol"; | ||
import {ConduitTransfer, ConduitItemType} from "seaport-types/src/conduit/lib/ConduitStructs.sol"; | ||
|
||
import "forge-std/console.sol"; | ||
|
||
contract TestBorrowerEnforcer is StarPortTest { | ||
function testBERevertAdditionalTransfers() external { | ||
ConduitTransfer[] memory additionalTransfers = new ConduitTransfer[](1); | ||
additionalTransfers[0] = ConduitTransfer({ | ||
token: address(0), | ||
amount: 0, | ||
to: address(0), | ||
from: address(0), | ||
identifier: 0, | ||
itemType: ConduitItemType.ERC20 | ||
}); | ||
|
||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
BorrowerEnforcer.Details memory details = BorrowerEnforcer.Details({loan: loan}); | ||
vm.expectRevert(BorrowerEnforcer.InvalidAdditionalTransfer.selector); | ||
borrowerEnforcer.validate(additionalTransfers, loan, abi.encode(details)); | ||
} | ||
|
||
function testBERevertInvalidLoanTerms() external { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
|
||
BorrowerEnforcer.Details memory details = BorrowerEnforcer.Details({loan: loan}); | ||
details.loan.borrower = lender.addr; | ||
vm.expectRevert(BorrowerEnforcer.InvalidLoanTerms.selector); | ||
borrowerEnforcer.validate(new ConduitTransfer[](0), generateDefaultLoanTerms(), abi.encode(details)); | ||
} | ||
|
||
function testBEValidLoanTerms() external view { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
borrowerEnforcer.validate(new ConduitTransfer[](0), loan, abi.encode(BorrowerEnforcer.Details({loan: loan}))); | ||
} | ||
|
||
function testBEValidLoanTermsAnyIssuer() external view { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
BorrowerEnforcer.Details memory details = BorrowerEnforcer.Details({loan: loan}); | ||
details.loan.issuer = address(0); | ||
|
||
borrowerEnforcer.validate(new ConduitTransfer[](0), loan, abi.encode(BorrowerEnforcer.Details({loan: loan}))); | ||
} | ||
} |
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,61 @@ | ||
import "starport-test/StarPortTest.sol"; | ||
import {LenderEnforcer} from "starport-core/enforcers/LenderEnforcer.sol"; | ||
import {ConduitTransfer, ConduitItemType} from "seaport-types/src/conduit/lib/ConduitStructs.sol"; | ||
|
||
import "forge-std/console.sol"; | ||
|
||
contract TestLenderEnforcer is StarPortTest { | ||
function testLERevertAdditionalTransfersFromLender() external { | ||
ConduitTransfer[] memory additionalTransfers = new ConduitTransfer[](1); | ||
additionalTransfers[0] = ConduitTransfer({ | ||
token: address(0), | ||
amount: 0, | ||
to: address(0), | ||
from: lender.addr, | ||
identifier: 0, | ||
itemType: ConduitItemType.ERC20 | ||
}); | ||
|
||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
|
||
vm.expectRevert(LenderEnforcer.InvalidAdditionalTransfer.selector); | ||
lenderEnforcer.validate(additionalTransfers, loan, abi.encode(LenderEnforcer.Details({loan: loan}))); | ||
} | ||
|
||
function testLERevertInvalidLoanTerms() external { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
|
||
LenderEnforcer.Details memory details = LenderEnforcer.Details({loan: loan}); | ||
details.loan.custodian = borrower.addr; | ||
vm.expectRevert(LenderEnforcer.InvalidLoanTerms.selector); | ||
|
||
lenderEnforcer.validate(new ConduitTransfer[](0), generateDefaultLoanTerms(), abi.encode(details)); | ||
} | ||
|
||
function testLEValidLoanTermsWithAdditionalTransfers() external view { | ||
ConduitTransfer[] memory additionalTransfers = new ConduitTransfer[](1); | ||
additionalTransfers[0] = ConduitTransfer({ | ||
token: address(0), | ||
amount: 0, | ||
to: address(0), | ||
from: address(0), | ||
identifier: 0, | ||
itemType: ConduitItemType.ERC20 | ||
}); | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
lenderEnforcer.validate(additionalTransfers, loan, abi.encode(LenderEnforcer.Details({loan: loan}))); | ||
} | ||
|
||
function testLEValidLoanTerms() external view { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
lenderEnforcer.validate(new ConduitTransfer[](0), loan, abi.encode(LenderEnforcer.Details({loan: loan}))); | ||
} | ||
|
||
function testLEValidLoanTermsAnyBorrower() external view { | ||
LoanManager.Loan memory loan = generateDefaultLoanTerms(); | ||
LenderEnforcer.Details memory details = LenderEnforcer.Details({loan: loan}); | ||
details.loan.borrower = address(0); | ||
|
||
lenderEnforcer.validate(new ConduitTransfer[](0), loan, abi.encode(LenderEnforcer.Details({loan: loan}))); | ||
} | ||
} |