Skip to content

Commit

Permalink
test: move strategy tests into dedicated folders
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Dec 8, 2023
1 parent c2b6126 commit 4167050
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 188 deletions.
6 changes: 4 additions & 2 deletions test/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "forge-std/Test.sol";

// Global test configuration for Portfolio
import "./Configuration.sol";
import "./strategies/NormalConfiguration.sol";
import "./strategies/NormalStrategy/NormalConfiguration.sol";

// Test helper types
import { deploy as deployCoin, Coin } from "./utils/CoinType.sol";
Expand Down Expand Up @@ -120,7 +120,9 @@ contract Setup is ISetup, Test, ERC1155TokenReceiver {
vm.label(_subjects.positionRenderer, "position-renderer");

_subjects.portfolio = address(
new Portfolio(_subjects.weth, _subjects.registry, _subjects.positionRenderer)
new Portfolio(
_subjects.weth, _subjects.registry, _subjects.positionRenderer
)
);
vm.label(_subjects.portfolio, "portfolio");

Expand Down
185 changes: 0 additions & 185 deletions test/TestG3MCreatePool.t.sol

This file was deleted.

78 changes: 78 additions & 0 deletions test/strategies/G3M/TestG3MAllocate.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.4;

import "../../Setup.sol";

contract TestG3MCreatePool is Setup {
using FixedPointMathLib for *;

address controller = address(0);
uint256 reserveX = 18_600 ether;
uint256 startWeightX = 0.75 ether;
uint256 endWeightX = 0.75 ether;
uint256 startUpdate = block.timestamp;
uint256 endUpdate = block.timestamp;
uint256 initialPrice = 1937.5 ether;

function deployTokens(
IPortfolio subject,
bool createPair
) internal returns (MockERC20 token0, MockERC20 token1) {
token0 = new MockERC20("tkn", "tkn", 18);
token1 = new MockERC20("tkn", "tkn", 18);
token0.mint(address(this), type(uint256).max);
token0.approve(address(subject), type(uint256).max);
token1.mint(address(this), type(uint256).max);
token1.approve(address(subject), type(uint256).max);

if (createPair) {
subject.createPair(address(token0), address(token1));
}
}

function test_G3M_allocate() public {
(MockERC20 token0, MockERC20 token1) = deployTokens(subject(), true);

(bytes memory strategyData, uint256 initialX, uint256 initialY) =
G3MStrategy(g3mStrategy()).getStrategyData(
abi.encode(
controller,
reserveX,
startWeightX,
endWeightX,
startUpdate,
endUpdate,
initialPrice
)
);

uint64 poolId = subject().createPool(
0,
initialX,
initialY,
100,
0,
address(0),
g3mStrategy(),
strategyData
);

uint128 liquidity = 100 ether;
(uint256 deltaAsset, uint256 deltaQuote) = subject().allocate(
false,
address(this),
poolId,
liquidity,
type(uint128).max,
type(uint128).max
);

assertEq(
ERC1155(address(subject())).balanceOf(address(this), poolId),
liquidity - BURNED_LIQUIDITY
);

assertEq(token0.balanceOf(address(subject())), deltaAsset);
assertEq(token1.balanceOf(address(subject())), deltaQuote);
}
}
63 changes: 63 additions & 0 deletions test/strategies/G3M/TestG3MCreatePool.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.4;

import "../../Setup.sol";

contract TestG3MCreatePool is Setup {
using FixedPointMathLib for *;

function deployTokens(
IPortfolio subject,
bool createPair
) internal returns (MockERC20 token0, MockERC20 token1) {
token0 = new MockERC20("tkn", "tkn", 18);
token1 = new MockERC20("tkn", "tkn", 18);
token0.mint(address(this), type(uint256).max);
token0.approve(address(subject), type(uint256).max);
token1.mint(address(this), type(uint256).max);
token1.approve(address(subject), type(uint256).max);

if (createPair) {
subject.createPair(address(token0), address(token1));
}
}

function test_G3M_createPool() public {
deployTokens(subject(), true);

address controller = address(0);
uint256 reserveX = 18_600 ether;
uint256 startWeightX = 0.75 ether;
uint256 endWeightX = 0.75 ether;
uint256 startUpdate = block.timestamp;
uint256 endUpdate = block.timestamp;
uint256 initialPrice = 1937.5 ether;

(bytes memory strategyData, uint256 initialX, uint256 initialY) =
G3MStrategy(g3mStrategy()).getStrategyData(
abi.encode(
controller,
reserveX,
startWeightX,
endWeightX,
startUpdate,
endUpdate,
initialPrice
)
);

uint64 poolId = subject().createPool(
0,
initialX,
initialY,
100,
0,
address(0),
g3mStrategy(),
strategyData
);

assertEq(subject().getSpotPrice(poolId), initialPrice);
assertEq(subject().getStrategy(poolId), g3mStrategy());
}
}
Loading

0 comments on commit 4167050

Please sign in to comment.