Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cc903f5
Refactored withdraw from position tx, updated test helper, updated us…
UlyanaAndrukhiv Feb 26, 2026
0788509
Refactored setInsuranceSwapper test helper, updated usages
UlyanaAndrukhiv Feb 26, 2026
d120405
Added boundary conditions tests for interest rate
UlyanaAndrukhiv Mar 9, 2026
8c05412
Added test for extreme utilization on Kink interest curve
UlyanaAndrukhiv Mar 9, 2026
4969faa
Merged with main
UlyanaAndrukhiv Mar 9, 2026
8d2ebff
Merge branch 'lionel/kink-curve-utilization-fix' of github.com:onflow…
UlyanaAndrukhiv Mar 10, 2026
0fce924
Updated tests, merged with utilization fix
UlyanaAndrukhiv Mar 11, 2026
73a18d7
Merged with main
UlyanaAndrukhiv Mar 11, 2026
e71fbc5
Revert FlowActions submodule pointer to correct commit
UlyanaAndrukhiv Mar 11, 2026
8e0dc79
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 16, 2026
e830a9e
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 16, 2026
b17ed95
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 18, 2026
1a8c1b2
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 19, 2026
4818b01
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 19, 2026
e946f62
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
mts1715 Mar 24, 2026
d67ff7e
Updated tests according to changes from main branch
UlyanaAndrukhiv Mar 25, 2026
99c1e78
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 25, 2026
dd2ab4c
Merged with branch main
UlyanaAndrukhiv Mar 26, 2026
9fa3449
Merge branch 'UlianaAndrukhiv/180-interest-rate-testing' of github.co…
UlyanaAndrukhiv Mar 26, 2026
58bf59e
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Mar 30, 2026
3e04bb6
Refactored tests to use getLastPositionId helper
UlyanaAndrukhiv Mar 31, 2026
09e1ed0
Updated test_zero_credit_balance test, updated docs for tests
UlyanaAndrukhiv Mar 31, 2026
3044e31
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
UlyanaAndrukhiv Apr 2, 2026
05d3301
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
zhangchiqing Apr 7, 2026
14ecafd
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
zhangchiqing Apr 8, 2026
df613fa
remove forked mainnet
zhangchiqing Apr 9, 2026
4b8298d
fix ALP model usage
zhangchiqing Apr 9, 2026
023df39
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
zhangchiqing Apr 9, 2026
5d8d6a7
fix tests
zhangchiqing Apr 9, 2026
dacb31c
fix tests
zhangchiqing Apr 10, 2026
78b1104
Merge branch 'main' into UlianaAndrukhiv/180-interest-rate-testing
zhangchiqing Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cadence/contracts/FlowALPModels.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ access(all) contract FlowALPModels {
effectiveDebt: {Type: UFix128}
) {
// Enforce single balance per token invariant: if a type appears in one map, it must not appear in the other.
for collateralType in effectiveCollateral {
for collateralType in effectiveCollateral.keys {
assert(effectiveDebt[collateralType] == nil, message: "cannot construct BalanceSheet: observed both credit and debit balance for \(collateralType.identifier)")
}

Expand Down
11 changes: 7 additions & 4 deletions cadence/tests/adversarial_recursive_withdraw_source_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ fun testRecursiveWithdrawSource() {
//
// In this test, the topUpSource behavior is adversarial: it attempts to re-enter
// the pool during the pull/deposit flow. We expect the transaction to fail.
let withdrawRes = executeTransaction(
"./transactions/flow-alp/epositionadmin/withdraw_from_position.cdc",
[positionID, flowTokenIdentifier, 1500.0, true], // pullFromTopUpSource: true
userAccount
let withdrawRes = withdrawFromPosition(
signer: userAccount,
positionId: positionID,
tokenTypeIdentifier: flowTokenIdentifier,
receiverVaultStoragePath: FLOW_VAULT_STORAGE_PATH,
amount: 1500.0,
pullFromTopUpSource: true
)
Test.expect(withdrawRes, Test.beFailed())

Expand Down
11 changes: 7 additions & 4 deletions cadence/tests/adversarial_type_spoofing_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ fun testMaliciousSource() {
Test.expect(openRes, Test.beSucceeded())

// withdraw 1337 Flow from the position
let withdrawRes = executeTransaction(
"./transactions/flow-alp/epositionadmin/withdraw_from_position.cdc",
[1 as UInt64, flowTokenIdentifier, 1337.0, true],
hackerAccount
let withdrawRes = withdrawFromPosition(
signer: hackerAccount,
positionId: 1,
tokenTypeIdentifier: flowTokenIdentifier,
receiverVaultStoragePath: FLOW_VAULT_STORAGE_PATH,
amount: 1337.0,
pullFromTopUpSource: true
)
Test.expect(withdrawRes, Test.beFailed())

Expand Down
3 changes: 2 additions & 1 deletion cadence/tests/governance_parameters_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fun test_setGovernanceParams_and_exercise_paths() {
// 1) Set insurance swapper
let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down
7 changes: 6 additions & 1 deletion cadence/tests/insurance_collection_formula_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ fun test_collectInsurance_success_fullAmount() {
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 10000.0, beFailed: false)

// configure insurance swapper (1:1 ratio)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(swapperResult, Test.beSucceeded())

// set 10% annual debit rate
Expand Down
53 changes: 44 additions & 9 deletions cadence/tests/insurance_collection_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ fun test_collectInsurance_zeroDebitBalance_returnsNil() {
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 10000.0, beFailed: false)

// configure insurance swapper (1:1 ratio)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(swapperResult, Test.beSucceeded())

// verify initial insurance fund balance is 0
Expand All @@ -112,7 +117,7 @@ fun test_collectInsurance_zeroDebitBalance_returnsNil() {
access(all)
fun test_collectInsurance_insufficientReserves() {
// configure insurance swapper (1:1 ratio)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER, swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
Test.expect(swapperResult, Test.beSucceeded())

// set 90% annual debit rate
Expand Down Expand Up @@ -192,7 +197,12 @@ fun test_collectInsurance_tinyAmount_roundsToZero_returnsNil() {
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 10000.0, beFailed: false)

// configure insurance swapper with very low rate
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(swapperResult, Test.beSucceeded())

// set a very low insurance rate
Expand Down Expand Up @@ -242,7 +252,12 @@ fun test_collectInsurance_success_fullAmount() {
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 10000.0, beFailed: false)

// configure insurance swapper (1:1 ratio)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(swapperResult, Test.beSucceeded())

// set 10% annual debit rate
Expand Down Expand Up @@ -328,10 +343,20 @@ fun test_collectInsurance_multipleTokens() {
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 20000.0, beFailed: false)

// configure insurance swappers for both tokens (both swap to MOET at 1:1)
let moetSwapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
let moetSwapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(moetSwapperResult, Test.beSucceeded())

let flowSwapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER, priceRatio: 1.0)
let flowSwapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(flowSwapperResult, Test.beSucceeded())

// set 10% annual debit rates
Expand Down Expand Up @@ -431,7 +456,12 @@ fun test_collectInsurance_dexOracleSlippageProtection() {

// Oracle says FLOW = 1.0 MOET (already set in setup())
// Configure insurance swapper with price ratio = 0.5 (50% deviation from oracle)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER, priceRatio: 0.5)
let swapperResult = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 0.5,
)
Test.expect(swapperResult, Test.beSucceeded())

// set 10% annual debit rate and 10% insurance rate
Expand All @@ -451,7 +481,12 @@ fun test_collectInsurance_dexOracleSlippageProtection() {
Test.assertEqual(0.0, balanceAfterFailure)

// Now reconfigure swapper with price ratio = 1.0 (matches oracle, 0% deviation)
let swapperResult2 = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult2 = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
swapperInTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(swapperResult2, Test.beSucceeded())

// collect insurance for FLOW - should SUCCEED now
Expand All @@ -472,7 +507,7 @@ fun test_collectInsurance_midPeriodRateChange() {
// configure the protocol FLOW wallet and the insurance swapper
setupMoetVault(PROTOCOL_ACCOUNT, beFailed: false)
mintMoet(signer: PROTOCOL_ACCOUNT, to: PROTOCOL_ACCOUNT.address, amount: 10000.0, beFailed: false)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER, priceRatio: 1.0)
let swapperResult = setInsuranceSwapper(signer: PROTOCOL_ACCOUNT, swapperInTypeIdentifier: FLOW_TOKEN_IDENTIFIER, swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER, priceRatio: 1.0)
Test.expect(swapperResult, Test.beSucceeded())

// set interest curve
Expand Down
22 changes: 14 additions & 8 deletions cadence/tests/insurance_rate_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ access(all)
fun setup() {
deployContracts()
createAndStorePool(signer: PROTOCOL_ACCOUNT, defaultTokenIdentifier: MOET_TOKEN_IDENTIFIER, beFailed: false)

// take snapshot first, then advance time so reset() target is always lower than current height
snapshot = getCurrentBlockHeight()
// move time by 1 second so Test.reset() works properly before each test
Expand All @@ -32,7 +31,8 @@ fun test_setInsuranceRate_withoutEGovernanceEntitlement() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand All @@ -56,7 +56,8 @@ fun test_setInsuranceRate_withEGovernanceEntitlement() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down Expand Up @@ -104,7 +105,8 @@ fun test_setInsuranceRate_rateGreaterThanOne_fails() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand All @@ -131,7 +133,8 @@ fun test_setInsuranceRate_combinedRateExceedsOne_fails() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down Expand Up @@ -164,7 +167,8 @@ fun test_setStabilityFeeRate_combinedRateExceedsOne_fails() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down Expand Up @@ -197,7 +201,8 @@ fun test_setInsuranceRate_rateLessThanZero_fails() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand All @@ -223,7 +228,8 @@ fun test_setInsuranceRate_invalidTokenType_fails() {
// set insurance swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down
24 changes: 16 additions & 8 deletions cadence/tests/insurance_swapper_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ access(all)
fun test_setInsuranceSwapper_success() {
let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand All @@ -39,7 +40,8 @@ fun test_setInsuranceSwapper_updateExistingSwapper_success() {
let initialPriceRatio = 1.0
let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: initialPriceRatio,
)
Test.expect(res, Test.beSucceeded())
Expand All @@ -48,7 +50,8 @@ fun test_setInsuranceSwapper_updateExistingSwapper_success() {
let updatedPriceRatio = 2.0
let updatedRes = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: updatedPriceRatio,
)
Test.expect(updatedRes, Test.beSucceeded())
Expand All @@ -66,7 +69,8 @@ fun test_removeInsuranceSwapper_success() {
// set a swapper
let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down Expand Up @@ -94,7 +98,8 @@ fun test_remove_insuranceSwapper_failed() {
// set a swapper
var res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)
Test.expect(res, Test.beSucceeded())
Expand Down Expand Up @@ -130,7 +135,8 @@ access(all)
fun test_setInsuranceSwapper_withoutEGovernanceEntitlement_fails() {
let res = setInsuranceSwapper(
signer: alice,
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperInTypeIdentifier: MOET_TOKEN_IDENTIFIER,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)

Expand All @@ -148,7 +154,8 @@ fun test_setInsuranceSwapper_invalidTokenTypeIdentifier_fails() {

let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: invalidTokenIdentifier,
swapperInTypeIdentifier: invalidTokenIdentifier,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)

Expand All @@ -166,7 +173,8 @@ fun test_setInsuranceSwapper_emptyTokenTypeIdentifier_fails() {

let res = setInsuranceSwapper(
signer: PROTOCOL_ACCOUNT,
tokenTypeIdentifier: emptyTokenIdentifier,
swapperInTypeIdentifier: emptyTokenIdentifier,
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
priceRatio: 1.0,
)

Expand Down
Loading
Loading