Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/mocks/MockStrategies.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ access(all) contract MockStrategies {
}

init() {
self.IssuerStoragePath = StoragePath(identifier: "FlowYieldVaultsStrategyComposerIssuer_\(self.account.address)")!
self.IssuerStoragePath = StoragePath(identifier: "MockStrategiesComposerIssuer_\(self.account.address)")!

let initialCollateralType = Type<@FlowToken.Vault>()

Expand Down
15 changes: 13 additions & 2 deletions cadence/tests/PMStrategiesV1_syWFLOWv_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import "FlowYieldVaults"
import "PMStrategiesV1"
import "FlowYieldVaultsClosedBeta"

import "test_helpers.cdc"

/// Fork test for PMStrategiesV1 syWFLOWv strategy — validates the full YieldVault lifecycle
/// (create, deposit, withdraw, close) against real mainnet state.
///
Expand Down Expand Up @@ -55,6 +53,11 @@ access(all) var syWFLOWvYieldVaultID: UInt64 = 0

/* --- Test Helpers --- */

access(all)
fun _executeScript(_ path: String, _ args: [AnyStruct]): Test.ScriptResult {
return Test.executeScript(Test.readFile(path), args)
}

access(all)
fun _executeTransactionFile(_ path: String, _ args: [AnyStruct], _ signers: [Test.TestAccount]): Test.TransactionResult {
let txn = Test.Transaction(
Expand All @@ -66,6 +69,14 @@ fun _executeTransactionFile(_ path: String, _ args: [AnyStruct], _ signers: [Tes
return Test.executeTransaction(txn)
}

access(all)
fun equalAmounts(a: UFix64, b: UFix64, tolerance: UFix64): Bool {
if a > b {
return a - b <= tolerance
}
return b - a <= tolerance
}

/* --- Setup --- */

access(all) fun setup() {
Expand Down
2 changes: 0 additions & 2 deletions cadence/tests/rebalance_scenario1_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ fun test_RebalanceYieldVaultScenario1() {

log("[TEST] Initial yield vault balance: \(yieldVaultBalance ?? 0.0)")

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

testSnapshot = getCurrentBlockHeight()
Expand All @@ -147,7 +146,6 @@ fun test_RebalanceYieldVaultScenario1() {
let yieldTokensBefore = getAutoBalancerBalance(id: yieldVaultIDs![0]) ?? 0.0
let currentValueBefore = getAutoBalancerCurrentValue(id: yieldVaultIDs![0]) ?? 0.0

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: false, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: false, beFailed: false)

yieldVaultBalance = getYieldVaultBalance(address: user.address, yieldVaultID: yieldVaultIDs![0])
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_scenario2_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fun test_RebalanceYieldVaultScenario2() {

log("[TEST] Initial yield vault balance: \(yieldVaultBalance ?? 0.0)")

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

for index, yieldTokenPrice in yieldPriceIncreases {
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_scenario3a_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fun test_RebalanceYieldVaultScenario3A() {
message: "Expected MOET debt to be \(expectedDebtValues[0]) but got \(debtBefore)"
)

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

// Debug: Log position details
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_scenario3b_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fun test_RebalanceYieldVaultScenario3B() {
message: "Expected MOET debt to be \(expectedDebtValues[0]) but got \(debtBefore)"
)

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

let yieldTokensAfterFlowPriceIncrease = getAutoBalancerBalance(id: yieldVaultIDs![0])!
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_scenario3c_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fun test_RebalanceYieldVaultScenario3C() {
message: "Expected MOET debt to be \(expectedDebtValues[0]) but got \(debtBefore)"
)

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

let yieldTokensAfterFlowPriceIncrease = getAutoBalancerBalance(id: yieldVaultIDs![0])!
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_scenario3d_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fun test_RebalanceYieldVaultScenario3D() {
message: "Expected MOET debt to be \(expectedDebtValues[0]) but got \(debtBefore)"
)

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

let yieldTokensAfterFlowPriceDecrease = getAutoBalancerBalance(id: yieldVaultIDs![0])!
Expand Down
4 changes: 1 addition & 3 deletions cadence/tests/rebalance_scenario4_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ fun test_RebalanceLowCollateralHighYieldPrices() {
log(" FLOW collateral: \(collateralBefore) FLOW (value: \(collateralBefore * flowPriceDecrease) MOET @ $\(flowPriceDecrease)/FLOW)")
log(" MOET debt: \(debtBefore) MOET")

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

let ytAfterFlowDrop = getAutoBalancerBalance(id: yieldVaultIDs![0])!
Expand Down Expand Up @@ -258,8 +257,7 @@ fun test_RebalanceHighCollateralLowYieldPrices() {
message: "Expected health to remain above \(SOLVENT_HEALTH_FLOOR) after 20% FLOW price drop, got \(healthBeforeRebalance)")

// Rebalance to restore health to the strategy target.
log("[Scenario5] Rebalancing position and yield vault...")
rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
log("[Scenario5] Rebalancing position...")
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

let ytAfterFlowDrop = getAutoBalancerBalance(id: yieldVaultIDs![0])!
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/rebalance_yield_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ fun test_RebalanceYieldVaultScenario2() {

log("[TEST] Initial yield vault balance: \(yieldVaultBalance ?? 0.0)")

rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)
rebalancePosition(signer: protocolAccount, pid: pid, force: true, beFailed: false)

for index, yieldTokenPrice in yieldPriceIncreases {
Expand Down
7 changes: 2 additions & 5 deletions cadence/tests/tracer_strategy_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,8 @@ fun test_RebalanceYieldVaultSucceedsAfterCollateralPriceIncrease() {

log("Yield token balance before rebalance: \(yieldTokensBefore)")

// Rebalance the YieldVault to adjust the Yield tokens based on the new collateral price
// Force both yield vault and position to rebalance
rebalanceYieldVault(signer: flowYieldVaultsAccount, id: yieldVaultIDs![0], force: true, beFailed: false)

// Position ID is hardcoded to 1 here since this is the first yield vault created,
// Position health increased because FLOW collateral is worth more; drawDown brings it back to target.
// Position ID is hardcoded to 1 here since this is the first yield vault created,
// if there is a better way to get the position ID, please let me know
rebalancePosition(signer: protocolAccount, pid: positionID, force: true, beFailed: false)

Expand Down
Loading
Loading