Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Mar 12, 2024
1 parent 2124df4 commit 5212420
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
37 changes: 18 additions & 19 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/TrancheMirror.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";

// Strategy Params
uint256 constant TRANCHE_RESERVE_BASE_AMOUNT = 1000e18 ;
uint256 constant TRANCHE_RESERVE_BASE_IO_RATIO = 242e18;
uint256 constant TRANCHE_RESERVE_BASE_IO_RATIO = 315e18;
uint256 constant SPREAD_RATIO = 101e16;
uint256 constant TRANCHE_EDGE_THRESHOLD = 2e17;
uint256 constant INITIAL_TRANCHE_SPACE = 0;
Expand Down
29 changes: 23 additions & 6 deletions test/TrancheMirrorTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ contract TrancheMirrorTest is TrancheMirrorUtils {
using LibFixedPointDecimalArithmeticOpenZeppelin for uint256;
using LibFixedPointDecimalScale for uint256;

using SafeERC20 for IERC20;
using SafeERC20 for IERC20;

function testSellBuyOrderHappyFork() public {

// Deposit Tokens
{
uint256 depositAmount = 400000e18;
Expand All @@ -39,12 +40,11 @@ contract TrancheMirrorTest is TrancheMirrorUtils {
vm,
address(ORDERBOOK_SUPARSER)
)
);
);
trancheOrder = placeOrder(ORDER_OWNER, bytecode, constants, tokenVaults, tokenVaults);
}
// Take Order
{
// Move external market so the order clears
// Take Sell Order
{
moveExternalPrice(
address(WETH_TOKEN),
address(IEON_TOKEN),
Expand All @@ -58,6 +58,23 @@ contract TrancheMirrorTest is TrancheMirrorUtils {
Vm.Log[] memory entries = vm.getRecordedLogs();
(,distributorTokenOut) = getContextInputOutput(entries);
}
// Take Buy Order
{
// Move external market so the order clears
moveExternalPrice(
address(IEON_TOKEN),
address(WETH_TOKEN),
POLYGON_IEON_HOLDER,
10000000e18,
SELL_ROUTE
);
vm.recordLogs();
takeOrder(trancheOrder, BUY_ROUTE,0,1);

Vm.Log[] memory entries = vm.getRecordedLogs();
(distributorTokenIn,) = getContextInputOutput(entries);
}
assertGe(distributorTokenIn,distributorTokenOut);
}

function giveTestAccountsTokens(IERC20 token, address from, address to, uint256 amount) internal {
Expand Down Expand Up @@ -136,7 +153,7 @@ contract TrancheMirrorTest is TrancheMirrorUtils {
vm.stopPrank();
}

function getContextInputOutput(Vm.Log[] memory entries) public returns(uint256 input, uint256 output){
function getContextInputOutput(Vm.Log[] memory entries) internal pure returns(uint256 input, uint256 output){
for (uint256 j = 0; j < entries.length; j++) {
if (entries[j].topics[0] == keccak256("Context(address,uint256[][])")) {
(, uint256[][] memory context) = abi.decode(entries[j].data, (address, uint256[][]));
Expand Down
3 changes: 2 additions & 1 deletion test/util/TrancheMirrorUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract TrancheMirrorUtils is RainContracts, Test {
using LibFixedPointDecimalArithmeticOpenZeppelin for uint256;
using LibFixedPointDecimalScale for uint256;

uint256 constant FORK_BLOCK_NUMBER = 54140734;
uint256 constant FORK_BLOCK_NUMBER = 54561421;
uint256 constant CONTEXT_VAULT_IO_ROWS = 5;

function selectPolygonFork() internal {
Expand Down Expand Up @@ -135,6 +135,7 @@ contract TrancheMirrorUtils is RainContracts, Test {

function evalDeployedExpression(address expression, bytes32 orderHash, uint256[][] memory context) public view returns (uint256[] memory) {

(orderHash);
FullyQualifiedNamespace namespace =
LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(ORDER_OWNER))), address(ORDERBOOK));

Expand Down

0 comments on commit 5212420

Please sign in to comment.