-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from anticlimactic/migration-revoke-tests
test: add migration, revoke tests
- Loading branch information
Showing
5 changed files
with
137 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
import {StrategyFixture} from "./utils/StrategyFixture.sol"; | ||
|
||
// NOTE: if the name of the strat or file changes this needs to be updated | ||
import {Strategy} from "../Strategy.sol"; | ||
|
||
contract StrategyMigrationTest is StrategyFixture { | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
// TODO: Add tests that show proper migration of the strategy to a newer one | ||
// Use another copy of the strategy to simmulate the migration | ||
// Show that nothing is lost. | ||
function testMigration(uint256 _amount) public { | ||
vm_std_cheats.assume(_amount > 0.1 ether && _amount < 10e18); | ||
|
||
// Deposit to the vault and harvest | ||
vm_std_cheats.prank(user); | ||
want.approve(address(vault), _amount); | ||
vm_std_cheats.prank(user); | ||
vault.deposit(_amount); | ||
skip(1); | ||
strategy.harvest(); | ||
assertEq(strategy.estimatedTotalAssets(), _amount); | ||
|
||
// Migrate to a new strategy | ||
vm_std_cheats.prank(strategist); | ||
address newStrategyAddr = deployStrategy(address(vault)); | ||
vault.migrateStrategy(address(strategy), newStrategyAddr); | ||
assertEq(Strategy(newStrategyAddr).estimatedTotalAssets(), _amount); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.12; | ||
|
||
import {StrategyFixture} from "./utils/StrategyFixture.sol"; | ||
|
||
contract StrategyRevokeTest is StrategyFixture { | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function testRevokeStrategyFromVault(uint256 _amount) public { | ||
vm_std_cheats.assume(_amount > 0.1 ether && _amount < 10e18); | ||
|
||
// Deposit to the vault and harvest | ||
vm_std_cheats.prank(user); | ||
want.approve(address(vault), _amount); | ||
vm_std_cheats.prank(user); | ||
vault.deposit(_amount); | ||
skip(1); | ||
strategy.harvest(); | ||
assertEq(strategy.estimatedTotalAssets(), _amount); | ||
|
||
// In order to pass these tests, you will need to implement prepareReturn. | ||
// TODO: uncomment the following lines. | ||
// vault.revokeStrategy(address(strategy)); | ||
// skip(1); | ||
// strategy.harvest(); | ||
// assertEq(want.balanceOf(address(vault)), _amount); | ||
} | ||
|
||
function testRevokeStrategyFromStrategy(uint256 _amount) public { | ||
vm_std_cheats.assume(_amount > 0.1 ether && _amount < 10e18); | ||
|
||
vm_std_cheats.prank(user); | ||
want.approve(address(vault), _amount); | ||
vm_std_cheats.prank(user); | ||
vault.deposit(_amount); | ||
skip(1); | ||
strategy.harvest(); | ||
assertEq(strategy.estimatedTotalAssets(), _amount); | ||
|
||
strategy.setEmergencyExit(); | ||
skip(1); | ||
strategy.harvest(); | ||
assertEq(want.balanceOf(address(vault)), _amount); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters