Skip to content

Commit eeb73d9

Browse files
jordanschalmclaude
andcommitted
Use existing createPosition helper in rounding test
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6cb689d commit eeb73d9

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

cadence/tests/available_balance_rounding_test.cdc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import "FlowALPModels"
66
import "test_helpers.cdc"
77

88
// Tests that availableBalance rounds DOWN when converting from UFix128 to UFix64.
9-
// This is critical: rounding up could return a value that, if withdrawn/borrowed,
10-
// would violate the position's minimum health factor.
9+
// Rounding up could return a value that, if withdrawn/borrowed, would violate the position's minimum health factor.
1110
//
1211
// Token setup:
1312
// FLOW: collateralFactor=0.8, borrowFactor=1.0, price=1.0
1413
// MOET: collateralFactor=1.0, borrowFactor=1.0, price=1.0 (default token)
1514
//
1615
// Scenario:
1716
// Deposit 100 FLOW (no debt). Available MOET borrow = 80 / 1.1 = 72.72727272727...
18-
// UFix64 round-down: 72.72727272
17+
// UFix64 round-down: 72.72727272
1918
// UFix64 round-half-up: 72.72727273 (incorrect — would breach minHealth)
2019

2120
access(all) let user = Test.createAccount()
@@ -78,7 +77,8 @@ fun beforeEach() {
7877
access(all)
7978
fun test_availableBalance_rounds_down() {
8079
// Open position: deposit 100 FLOW, no auto-borrow
81-
let pid = openPosition(flowAmount: 100.0)
80+
createPosition(admin: PROTOCOL_ACCOUNT, signer: user, amount: 100.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
81+
let pid = getLastPositionId()
8282

8383
// availableBalance for MOET (no MOET credit, so this is the pure borrow path)
8484
let available = getAvailableBalance(
@@ -100,7 +100,8 @@ fun test_availableBalance_rounds_down() {
100100
// ---------------------------------------------------------------------------
101101
access(all)
102102
fun test_borrowing_full_availableBalance_succeeds() {
103-
let pid = openPosition(flowAmount: 100.0)
103+
createPosition(admin: PROTOCOL_ACCOUNT, signer: user, amount: 100.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
104+
let pid = getLastPositionId()
104105

105106
let available = getAvailableBalance(
106107
pid: pid,
@@ -125,16 +126,3 @@ fun test_borrowing_full_availableBalance_succeeds() {
125126
message: "Health after borrowing full availableBalance should be >= 1.1, got \(health)")
126127
}
127128

128-
// --- helpers ---
129-
130-
access(self)
131-
fun openPosition(flowAmount: UFix64): UInt64 {
132-
let openRes = _executeTransaction(
133-
"../transactions/flow-alp/position/create_position.cdc",
134-
[flowAmount, FLOW_VAULT_STORAGE_PATH, false],
135-
user
136-
)
137-
Test.expect(openRes, Test.beSucceeded())
138-
return getLastPositionId()
139-
}
140-

0 commit comments

Comments
 (0)