Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Aug 25, 2024
1 parent 6c5cc3c commit c8437a2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tranche/tranche-space.rain
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ scenarios:
# selling RED for it, then the amount is the INPUT.
amount-is-output: 0
io-ratio-expr: '''linear-growth'
io-ratio-base: 10
io-ratio-base: 9
io-ratio-growth: 0.5
tranche-size-expr: '''exponential-growth'
tranche-size-base: 1
Expand All @@ -201,7 +201,7 @@ scenarios:
# If the market is outside the chart then set this to 0.
initial-tranche-space: 0
post-action: '''post-action-constant'
io-ratio-current: 0.1
io-ratio-current: 10
post-action-tranche: '''post-action-tranche-linear'
scenarios:
prod:
Expand Down
68 changes: 68 additions & 0 deletions test/TrancheSpaceTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,74 @@ contract TrancheSpaceTest is StrategyTests {
iOrderBook = IOrderBookV4(address(uint160(bytes20(orderBook))));
}

function testSuccessiveInitTranches() public {

LibStrategyDeployment.StrategyDeploymentV4 memory strategy = LibStrategyDeployment.StrategyDeploymentV4(
"",
"",
0,
0,
10e18,
10e18,
0,
0,
"src/tranche/tranche-space.rain",
"src/settings.yml",
"",
"flare-sell",
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml"
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);


// Tranche 0
{
vm.recordLogs();
takeExternalOrder(order, strategy.inputTokenIndex, strategy.outputTokenIndex, new SignedContextV1[](0));

Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 102009999999999997;
uint256 expectedTrancheRatio = 10e18;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
}

// Tranche 1
{
vm.recordLogs();
takeExternalOrder(order, strategy.inputTokenIndex, strategy.outputTokenIndex, new SignedContextV1[](0));

Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 98123904761904758;
uint256 expectedTrancheRatio = 10.5e18;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
}

// Tranche 2
{
vm.recordLogs();
takeExternalOrder(order, strategy.inputTokenIndex, strategy.outputTokenIndex, new SignedContextV1[](0));

Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 94600364545454541;
uint256 expectedTrancheRatio = 11e18;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
}
}

function testTrancheSpaceShynessExternalFlare() public {

uint256 expectedRatio = 1e18;
Expand Down

0 comments on commit c8437a2

Please sign in to comment.