@@ -85,6 +85,9 @@ access(all) var flowVaultID: UInt64 = 0
8585access (all ) var wbtcVaultID : UInt64 = 0
8686access (all ) var wethVaultID : UInt64 = 0
8787
88+ /// Relative tolerance used in all balance assertions (1%).
89+ access (all ) let tolerancePct : UFix64 = 0.01
90+
8891/* --- Helpers --- */
8992
9093access (all )
@@ -442,7 +445,7 @@ access(all) fun testDepositToFUSDEVYieldVault_WFLOW() {
442445 Test .beSucceeded ()
443446 )
444447 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [flowUser .address , flowVaultID ]).returnValue ! as ! UFix64 ? )!
445- Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : 0.1 ),
448+ Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : ( before + depositAmount ) * tolerancePct ),
446449 message : " WFLOW deposit: expected ~" .concat ((before + depositAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
447450 log (" WFLOW vault balance after deposit: " .concat (after .toString ()))
448451}
@@ -456,7 +459,7 @@ access(all) fun testWithdrawFromFUSDEVYieldVault_WFLOW() {
456459 Test .beSucceeded ()
457460 )
458461 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [flowUser .address , flowVaultID ]).returnValue ! as ! UFix64 ? )!
459- Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : 0.1 ),
462+ Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : ( before - withdrawAmount ) * tolerancePct ),
460463 message : " WFLOW withdraw: expected ~" .concat ((before - withdrawAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
461464 log (" WFLOW vault balance after withdrawal: " .concat (after .toString ()))
462465}
@@ -476,7 +479,7 @@ access(all) fun testCloseFUSDEVYieldVault_WFLOW() {
476479 // After close the debt is fully repaid (closePosition would have reverted otherwise).
477480 // Assert that the collateral returned is within 5% of the vault NAV before close,
478481 // accounting for UniV3 swap fees and any pre-supplement collateral sold to cover shortfall.
479- Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore / 20.0 ),
482+ Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore * tolerancePct ),
480483 message : " WFLOW close: expected ~" .concat (vaultBalBefore .toString ()).concat (" FLOW returned, collateralBefore=" ).concat (collateralBefore .toString ()).concat (" collateralAfter=" ).concat (collateralAfter .toString ()))
481484 log (" WFLOW yield vault closed successfully, collateral returned: " .concat (collateralAfter .toString ()))
482485}
@@ -513,7 +516,7 @@ access(all) fun testDepositToFUSDEVYieldVault_WBTC() {
513516 Test .beSucceeded ()
514517 )
515518 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [wbtcUser .address , wbtcVaultID ]).returnValue ! as ! UFix64 ? )!
516- Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : 0.000005 ),
519+ Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : ( before + depositAmount ) * tolerancePct ),
517520 message : " WBTC deposit: expected ~" .concat ((before + depositAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
518521 log (" WBTC vault balance after deposit: " .concat (after .toString ()))
519522}
@@ -527,7 +530,7 @@ access(all) fun testWithdrawFromFUSDEVYieldVault_WBTC() {
527530 Test .beSucceeded ()
528531 )
529532 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [wbtcUser .address , wbtcVaultID ]).returnValue ! as ! UFix64 ? )!
530- Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : 0.000005 ),
533+ Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : ( before - withdrawAmount ) * tolerancePct ),
531534 message : " WBTC withdraw: expected ~" .concat ((before - withdrawAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
532535 log (" WBTC vault balance after withdrawal: " .concat (after .toString ()))
533536}
@@ -547,7 +550,7 @@ access(all) fun testCloseFUSDEVYieldVault_WBTC() {
547550 let collateralAfter = (_executeScript (" ../scripts/tokens/get_balance.cdc" , [wbtcUser .address , wbtcBalancePath ]).returnValue ! as ! UFix64 ? ) ?? 0.0
548551 // After close the debt is fully repaid (closePosition would have reverted otherwise).
549552 // Assert that the collateral returned is within 5% of the vault NAV before close.
550- Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore / 20.0 ),
553+ Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore * tolerancePct ),
551554 message : " WBTC close: expected ~" .concat (vaultBalBefore .toString ()).concat (" WBTC returned, collateralBefore=" ).concat (collateralBefore .toString ()).concat (" collateralAfter=" ).concat (collateralAfter .toString ()))
552555 log (" WBTC yield vault closed successfully, collateral returned: " .concat (collateralAfter .toString ()))
553556}
@@ -584,7 +587,7 @@ access(all) fun testDepositToFUSDEVYieldVault_WETH() {
584587 Test .beSucceeded ()
585588 )
586589 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [wethUser .address , wethVaultID ]).returnValue ! as ! UFix64 ? )!
587- Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : 0.00005 ),
590+ Test .assert (equalAmounts (a : after , b : before + depositAmount , tolerance : ( before + depositAmount ) * tolerancePct ),
588591 message : " WETH deposit: expected ~" .concat ((before + depositAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
589592 log (" WETH vault balance after deposit: " .concat (after .toString ()))
590593}
@@ -598,7 +601,7 @@ access(all) fun testWithdrawFromFUSDEVYieldVault_WETH() {
598601 Test .beSucceeded ()
599602 )
600603 let after = (_executeScript (" ../scripts/flow-yield-vaults/get_yield_vault_balance.cdc" , [wethUser .address , wethVaultID ]).returnValue ! as ! UFix64 ? )!
601- Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : 0.00005 ),
604+ Test .assert (equalAmounts (a : after , b : before - withdrawAmount , tolerance : ( before - withdrawAmount ) * tolerancePct ),
602605 message : " WETH withdraw: expected ~" .concat ((before - withdrawAmount ).toString ()).concat (" , got " ).concat (after .toString ()))
603606 log (" WETH vault balance after withdrawal: " .concat (after .toString ()))
604607}
@@ -618,7 +621,7 @@ access(all) fun testCloseFUSDEVYieldVault_WETH() {
618621 let collateralAfter = (_executeScript (" ../scripts/tokens/get_balance.cdc" , [wethUser .address , wethBalancePath ]).returnValue ! as ! UFix64 ? ) ?? 0.0
619622 // After close the debt is fully repaid (closePosition would have reverted otherwise).
620623 // Assert that the collateral returned is within 5% of the vault NAV before close.
621- Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore / 20.0 ),
624+ Test .assert (equalAmounts (a : collateralAfter , b : collateralBefore + vaultBalBefore , tolerance : vaultBalBefore * tolerancePct ),
622625 message : " WETH close: expected ~" .concat (vaultBalBefore .toString ()).concat (" WETH returned, collateralBefore=" ).concat (collateralBefore .toString ()).concat (" collateralAfter=" ).concat (collateralAfter .toString ()))
623626 log (" WETH yield vault closed successfully, collateral returned: " .concat (collateralAfter .toString ()))
624627}
@@ -710,12 +713,12 @@ access(all) fun testCloseFUSDEVVaultWithExcessYieldTokens_WFLOW() {
710713 )
711714 Test .expect (vaultBalAfterCreate , Test .beSucceeded ())
712715 let vaultBal = vaultBalAfterCreate .returnValue ! as ! UFix64 ?
713- Test .assert (vaultBal ! = nil && vaultBal ! > 0.0 ,
714- message : " Expected positive vault balance after create, got: \( vaultBal ?? 0.0 ) " )
716+ Test .assert (equalAmounts ( a : vaultBal ! , b : collateralAmount , tolerance : collateralAmount * tolerancePct ) ,
717+ message : " Expected vault balance ~ \( collateralAmount ) after create, got: \( vaultBal ?? 0.0 ) " )
715718 log (" Vault balance (FLOW collateral value): \( vaultBal ! ) " )
716719
717720 let abBalBefore = _autoBalancerBalance (vaultID )
718- Test .assert (abBalBefore ! = nil && abBalBefore ! > 0.0 ,
721+ Test .assert (abBalBefore ! > 0.0 ,
719722 message : " Expected positive AutoBalancer balance after vault creation, got: \( abBalBefore ?? 0.0 ) " )
720723 log (" AutoBalancer FUSDEV balance before injection: \( abBalBefore ! ) " )
721724
0 commit comments