Skip to content

Commit

Permalink
chore: add fuzz test for rebalance
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithsomraaj committed Oct 1, 2024
1 parent 22c9cdb commit 430d698
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ update:; forge update
# Build & test
build :; FOUNDRY_PROFILE=production forge build
build-sizes :; FOUNDRY_PROFILE=production forge build --sizes
test-vvv :; forge test --match-test test_superVault_rebalance_assetNotSupported --evm-version cancun -vvvv
test-vvv :; forge test --match-test testFuzz_superVault_rebalance --evm-version cancun -vvv
ftest :; forge test --evm-version cancun
coverage :; forge coverage --evm-version cancun --report lcov
clean :; forge clean
Expand Down
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = true

[fuzz]
runs = 200
32 changes: 32 additions & 0 deletions test/SuperVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,38 @@ contract SuperVaultTest is ProtocolActions {
assertEq(SuperVault(payable(superVaultAddress)).refundReceiver(), deployer);
}

//////////////////////////////////////////////////////////////
// FUZZ TESTS //
//////////////////////////////////////////////////////////////

function testFuzz_superVault_rebalance(uint256 finalWeightsOne) public {
uint256 finalWeightsOne = bound(finalWeightsOne, 1000, 9000);
uint256 finalWeightsTwo = 10_000 - finalWeightsOne;

vm.startPrank(deployer);
SOURCE_CHAIN = ETH;

uint256 amount = 10_000e6;
// Perform a direct deposit to the SuperVault
_directDeposit(SUPER_VAULT_ID1, amount);

_assertSuperPositionsSplitAccordingToWeights(ETH);

// Test case 1
uint256[] memory finalIndexes = new uint256[](2);
finalIndexes[0] = 1;
finalIndexes[1] = 2;

uint256[] memory finalWeightsTargets = new uint256[](2);
finalWeightsTargets[0] = finalWeightsOne;
finalWeightsTargets[1] = finalWeightsTwo;

uint256[] memory indexesRebalanceFrom = new uint256[](1);
indexesRebalanceFrom[0] = 0;

_performRebalance(finalIndexes, finalWeightsTargets, indexesRebalanceFrom);
}

//////////////////////////////////////////////////////////////
// INTERNAL HELPERS //
//////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 430d698

Please sign in to comment.