Skip to content

Commit 9cc27b8

Browse files
authored
refactor: test deferred migrate bond loan specific suites (#1307)
Signed-off-by: Marcos Serradilla Diez <marcos@io.builders>
1 parent d0c5cd0 commit 9cc27b8

23 files changed

Lines changed: 6215 additions & 6480 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hashgraph/asset-tokenization-contracts": patch
3+
---
4+
5+
test: migrate all IAsset integration suites onto one reconfigurable shared fixture (deployAssetMockCtx), eliminating the redundant per-file token deploys (BBND-1876). Test-only — no contract behaviour change; test run ~5 min → ~1 min and the coverage run roughly halved.

packages/ats/contracts/contracts/test/mocks/MockDiamondCut.sol

Lines changed: 139 additions & 72 deletions
Large diffs are not rendered by default.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.8.0 <0.9.0;
3+
4+
import { ILoan } from "../../facets/loan/ILoan.sol";
5+
import { ITransferByPartition } from "../../facets/transferByPartition/ITransferByPartition.sol";
6+
7+
/**
8+
* @title MockLoanHolding
9+
* @author Asset Tokenization Studio Team
10+
* @notice Configurable test stand-in for a loan holding asset that the
11+
* LoansPortfolio facet reads from at runtime.
12+
* @dev Exposes exactly the two call surfaces the portfolio invokes:
13+
* `getLoanDetails()` (collateral classification + performance status)
14+
* and `balanceOfByPartition(...)` (ownership balance). Only the
15+
* fields the portfolio reads are configurable; all other struct
16+
* members return their type defaults.
17+
*/
18+
contract MockLoanHolding is ITransferByPartition {
19+
uint256 internal _totalCollateralValue;
20+
ILoan.PerformanceStatus internal _performanceStatus;
21+
mapping(bytes32 partition => mapping(address holder => uint256)) internal _balances;
22+
23+
/**
24+
* @notice Sets the collateral value and performance classification.
25+
* @param totalCollateralValue_ Total collateral backing the loan.
26+
* @param performanceStatus_ Current repayment performance category.
27+
*/
28+
function setLoanState(uint256 totalCollateralValue_, ILoan.PerformanceStatus performanceStatus_) external {
29+
_totalCollateralValue = totalCollateralValue_;
30+
_performanceStatus = performanceStatus_;
31+
}
32+
33+
/**
34+
* @notice Sets the token balance for a given partition and holder.
35+
* @param _partition Partition identifier.
36+
* @param _holder Address of the token holder.
37+
* @param _amount Raw token balance to assign.
38+
*/
39+
function setBalance(bytes32 _partition, address _holder, uint256 _amount) external {
40+
_balances[_partition][_holder] = _amount;
41+
}
42+
43+
/**
44+
* @notice Minimal transfer-by-partition stub for the LoansPortfolio withdraw path.
45+
* @dev Decrements `msg.sender`'s balance and increments the recipient's balance
46+
* in `_partition`. Reverts with `InvalidPartition` when `msg.sender` holds
47+
* fewer tokens than `value`. Intended solely for test scenarios where the
48+
* portfolio withdraws loan holdings.
49+
* @param _partition Source partition.
50+
* @param _basicTransferInfo Recipient address and token amount.
51+
* @param _data Additional data (forwarded to the event, otherwise unused).
52+
* @return The partition identifier (`_partition`).
53+
*/
54+
function transferByPartition(
55+
bytes32 _partition,
56+
BasicTransferInfo calldata _basicTransferInfo,
57+
bytes calldata _data
58+
) external returns (bytes32) {
59+
address from = msg.sender;
60+
address to = _basicTransferInfo.to;
61+
uint256 value = _basicTransferInfo.value;
62+
63+
if (_balances[_partition][from] < value) {
64+
revert InvalidPartition(from, _partition);
65+
}
66+
67+
_balances[_partition][from] -= value;
68+
_balances[_partition][to] += value;
69+
70+
emit TransferByPartition(_partition, from, from, to, value, _data, "");
71+
72+
return _partition;
73+
}
74+
75+
/**
76+
* @notice No-op stub required by `ITransferByPartition`.
77+
* @dev The real initialiser is never called on the mock; this exists solely
78+
* to satisfy the interface.
79+
*/
80+
function initializeTransferByPartition() external {}
81+
82+
/**
83+
* @notice Returns the loan details with configurable fields populated.
84+
* @dev Only `collateral.totalCollateralValue` and
85+
* `loanPerformanceStatus.performanceStatus` carry the values set
86+
* via `setLoanState`; all other struct members return zero / their
87+
* type default, matching the portfolio's read pattern.
88+
* @return loanDetailsData_ LoanDetailsData struct.
89+
*/
90+
function getLoanDetails() external view returns (ILoan.LoanDetailsData memory loanDetailsData_) {
91+
loanDetailsData_.collateral.totalCollateralValue = _totalCollateralValue;
92+
loanDetailsData_.loanPerformanceStatus.performanceStatus = _performanceStatus;
93+
}
94+
95+
/**
96+
* @notice Returns the configured token balance for a partition and holder.
97+
* @param _partition Partition identifier.
98+
* @param _holder Address of the token holder.
99+
* @return The balance previously set via `setBalance`.
100+
*/
101+
function balanceOfByPartition(bytes32 _partition, address _holder) external view returns (uint256) {
102+
return _balances[_partition][_holder];
103+
}
104+
}

packages/ats/contracts/test/contracts/integration/controlList/controlList.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export function controlListTests(getCtx: () => AssetMockCtx): void {
7676
);
7777
});
7878

79+
it("GIVEN an account without controlList role WHEN removeFromControlList THEN transaction fails with AccountHasNoRole", async () => {
80+
await expect(asset.connect(signer_B).removeFromControlList(signer_C.address)).to.be.revertedWithCustomError(
81+
asset,
82+
"AccountHasNoRole",
83+
);
84+
});
85+
7986
it("GIVEN a paused Token WHEN addToControlList THEN transaction fails with IsPaused", async () => {
8087
await grantRoleAndPauseToken(asset, ATS_ROLES.ROLE_CONTROL_LIST, signer_A, signer_B, signer_C.address);
8188

0 commit comments

Comments
 (0)