Skip to content

Commit a379178

Browse files
committed
minor fixes
1 parent e6c6b42 commit a379178

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

cadence/tests/insurance_collection_formula_test.cdc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fun test_collectInsurance_success_fullAmount() {
4343
// LP deposits MOET (creates credit balance, provides borrowing liquidity)
4444
createPosition(admin: PROTOCOL_ACCOUNT, signer: lp, amount: 10000.0, vaultStoragePath: MOET.VaultStoragePath, pushToDrawDownSink: false)
4545

46-
// setup borrower with enough FLOW so MOET debit > MOET credit × (1 − pFeeRate).
47-
// MOET credit = 10000, pFeeRate = 0.15 → threshold = 8500.
48-
// 15000 FLOW × 0.8 CF / 1.3 target health ≈ 9231 MOET debit. 9231 > 8500
46+
// setup borrower with FLOW collateral
47+
// With 0.8 CF and 1.3 target health: 15000 FLOW collateral allows borrowing ~9231 MOET
48+
// borrow = (collateral * price * CF) / targetHealth = (15000 * 1.0 * 0.8) / 1.3 ≈ 9230.77
4949
let borrower = Test.createAccount()
5050
setupMoetVault(borrower, beFailed: false)
5151
transferFlowTokens(to: borrower, amount: 15000.0)
@@ -116,16 +116,7 @@ fun test_collectInsurance_success_fullAmount() {
116116
// protocolFee = 970.808555393 - 887.170667 = 83.637888393 MOET
117117
// insuranceAmt = 83.637888393 × 0.1 / 0.15 ≈ 55.758 MOET
118118
//
119-
// NOTE:
120-
// We intentionally do not use `equalWithinVariance` with `defaultUFixVariance` here.
121-
// The default variance is designed for deterministic math, but insurance collection
122-
// depends on block timestamps, which can differ slightly between test runs.
123-
// A larger, time-aware tolerance is required.
124-
let tolerance = 0.001
125119
let expectedCollectedAmount = 55.758
126-
let diff = expectedCollectedAmount > collectedInsuranceAmount
127-
? expectedCollectedAmount - collectedInsuranceAmount
128-
: collectedInsuranceAmount - expectedCollectedAmount
129120

130-
Test.assert(diff < tolerance, message: "Insurance collected should be around \(expectedCollectedAmount) but current \(collectedInsuranceAmount)")
121+
Test.assert(equalWithinVariance(expectedCollectedAmount, collectedInsuranceAmount, 0.001), message: "Insurance collected should be around \(expectedCollectedAmount) but current \(collectedInsuranceAmount)")
131122
}

cadence/tests/stability_collection_formula_test.cdc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fun test_collectStability_success_fullAmount() {
4343
// LP deposits MOET (creates credit balance, provides borrowing liquidity)
4444
createPosition(admin: PROTOCOL_ACCOUNT, signer: lp, amount: 10000.0, vaultStoragePath: MOET.VaultStoragePath, pushToDrawDownSink: false)
4545

46-
// setup borrower with enough FLOW so MOET debit > MOET credit × (1 − pFeeRate).
47-
// MOET credit = 10000, stabilityFeeRate = 0.1 → pFeeRate = 0.1, threshold = 9000.
48-
// 15000 FLOW × 0.8 CF / 1.3 target health ≈ 9231 MOET debit. 9231 > 9000
46+
// setup borrower with FLOW collateral
47+
// With 0.8 CF and 1.3 target health: 15000 FLOW collateral allows borrowing ~9231 MOET
48+
// borrow = (collateral * price * CF) / targetHealth = (15000 * 1.0 * 0.8) / 1.3 ≈ 9230.77
4949
let borrower = Test.createAccount()
5050
setupMoetVault(borrower, beFailed: false)
5151
transferFlowTokens(to: borrower, amount: 15000.0)
@@ -109,12 +109,6 @@ fun test_collectStability_success_fullAmount() {
109109
// protocolFee ≈ 29.0656 MOET
110110
// stabilityAmt = 29.0656 × 0.1 / 0.1 = 29.065637485 MOET (all to stability since insuranceRate=0)
111111
//
112-
// NOTE: block timestamps vary slightly between runs, so we use a 0.5 MOET tolerance.
113-
let tolerance = 0.001
114112
let expectedCollectedAmount = 29.065
115-
let diff = expectedCollectedAmount > collectedAmount
116-
? expectedCollectedAmount - collectedAmount
117-
: collectedAmount - expectedCollectedAmount
118-
119-
Test.assert(diff < tolerance, message: "Stability collected should be around \(expectedCollectedAmount) but current \(collectedAmount)")
113+
Test.assert(equalWithinVariance(expectedCollectedAmount, collectedAmount, 0.001), message: "Stability collected should be around \(expectedCollectedAmount) but current \(collectedAmount)")
120114
}

0 commit comments

Comments
 (0)