Skip to content

Commit

Permalink
Merge pull request #2 from h20liquidity/2024-04-09-test-suite
Browse files Browse the repository at this point in the history
reorganize dirs
  • Loading branch information
thedavidmeister authored Apr 10, 2024
2 parents acee011 + 0f8d772 commit 8ea5c07
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 9 deletions.
10 changes: 5 additions & 5 deletions test/src/StrategyTests.t.sol → src/StrategyTests.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;
import "test/abstract/OrderBookTestUtils.sol";
import {LibStrategyDeployment} from "test/lib/LibStrategyDeployment.sol";
import {LibComposeOrders} from "test/lib/LibComposeOrder.sol";
import "src/abstract/OrderBookStrategyTest.sol";
import {LibStrategyDeployment} from "src/lib/LibStrategyDeployment.sol";
import {LibComposeOrders} from "src/lib/LibComposeOrder.sol";

contract StrategyTests is OrderBookTestUtils {
contract StrategyTests is OrderBookStrategyTest {

function checkStrategyCalculations(LibStrategyDeployment.StrategyDeployment memory strategy) internal {
address inputToken;
Expand All @@ -30,7 +30,7 @@ contract StrategyTests is OrderBookTestUtils {
OrderV2 memory order;
{
(bytes memory bytecode, uint256[] memory constants) = PARSER.parse(
LibComposeOrders.getComposedOrder(vm, strategy.strategyFile, strategy.strategyScenario)
LibComposeOrders.getComposedOrder(vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath)
);
order = placeOrder(ORDER_OWNER, bytecode, constants, strategy.inputVaults, strategy.outputVaults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/ut
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import {IRouteProcessor} from "src/interface/IRouteProcessor.sol";

abstract contract OrderBookTestUtils is Test {
abstract contract OrderBookStrategyTest is Test {
using SafeERC20 for IERC20;
using Strings for address;

Expand Down
6 changes: 3 additions & 3 deletions test/lib/LibComposeOrder.sol → src/lib/LibComposeOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ library LibComposeOrders {
using Strings for address;
using Strings for uint256;

function getComposedOrder(Vm vm, string memory filePath, string memory scenario)
function getComposedOrder(Vm vm, string memory filePath, string memory scenario, string memory buildPath, string memory manifestPath)
internal
returns (bytes memory trancheOrder)
{
string[] memory ffi = new string[](16);
ffi[0] = "nix";
ffi[1] = "develop";
ffi[2] = "./lib/h20.test-std/lib/rain.orderbook";
ffi[2] = buildPath;
ffi[3] = "--command";
ffi[4] = "cargo";
ffi[5] = "run";
ffi[6] = "--manifest-path";
ffi[7] = "./lib/h20.test-std/lib/rain.orderbook/Cargo.toml";
ffi[7] = manifestPath;
ffi[8] = "--package";
ffi[9] = "rain_orderbook_cli";
ffi[10] = "order";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ library LibStrategyDeployment {
uint256 expectedAmount;
string strategyFile;
string strategyScenario;
string buildPath;
string manifestPath;
IO[] inputVaults;
IO[] outputVaults;
}
Expand Down
75 changes: 75 additions & 0 deletions test/DeployedStrategyTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;
import "src/StrategyTests.sol";

/// @title DeployedStrategyTest
/// @notice The contract inherits StrategyTests.sol.
/// DISP and OrderBook contracts need to be intiliazed as part of the setup for
/// running the tests available in StrategyTests.sol.
/// This is how the inheriting repo that has the test suite as a dependency is expected
/// to initialize the suite for a particular fork.
contract DeployedStrategyTest is StrategyTests {

// Inheriting contract defines the fork block number.
uint256 constant FORK_BLOCK_NUMBER = 196561436;

// Inheriting contract defines fork selection.
function selectFork() internal {
uint256 fork = vm.createFork(vm.envString("RPC_URL_ARBITRUM"));
vm.selectFork(fork);
vm.rollFork(FORK_BLOCK_NUMBER);
}

// Inheriting contract initializes the contracts on the fork.
function setUp() public {
selectFork();
PARSER = IParserV1(0x22410e2a46261a1B1e3899a072f303022801C764);
ORDERBOOK = IOrderBookV3(0x90CAF23eA7E507BB722647B0674e50D8d6468234);
ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0xf382cbF44901cD26D14B247F4EA7260ee8041157);
EXPRESSION_DEPLOYER = IExpressionDeployerV3(0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76);
ROUTE_PROCESSOR = IRouteProcessor(address(0x09bD2A33c47746fF03b86BCe4E885D03C74a8E8C));
EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427);
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88);
ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C);
}

// Inheriting contract tests OrderBook strategy with test suite.
function testDeployedStrategy() public {

// Input vaults
IO[] memory inputVaults = new IO[](1);
IO memory inputVault = IO(address(0x6d3AbB80c3CBAe0f60ba274F36137298D8571Fbe), 18, 1);
inputVaults[0] = inputVault;

// Output vaults
IO[] memory outputVaults = new IO[](1);
IO memory outputVault = IO(address(0x667f41fF7D9c06D2dd18511b32041fC6570Dc468), 18, 1);
outputVaults[0] = outputVault;

// Expected calculations context
uint256 expectedRatio = 2e18;
uint256 expectedAmountOutputMax = 1e18;

// Init params for the strategy
LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
"",
"",
0,
0,
0,
0,
expectedRatio,
expectedAmountOutputMax,
"test/strategies/arbitrum-order.rain",
"arbitrum-order-simulations",
"./lib/rain.orderbook",
"./lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
);

// Assert strategy calculations
checkStrategyCalculations(strategy);
}

}
73 changes: 73 additions & 0 deletions test/strategies/arbitrum-order.rain
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
networks:
arbitrum-one:
rpc: https://arbitrum.llamarpc.com
chain-id: 42161
network-id: 42161
currency: ETH

subgraphs:
arbitrum-one: https://api.thegraph.com/subgraphs/name/h20liquidity/arbitrum-0x90caf23e

orderbooks:
arbitrum-one:
address: 0x90CAF23eA7E507BB722647B0674e50D8d6468234
network: arbitrum-one
subgraph: arbitrum-one

deployers:
arbitrum-one:
address: 0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76
network: arbitrum-one

tokens:
arbitrum-one-red:
network: arbitrum-one
address: 0x6d3AbB80c3CBAe0f60ba274F36137298D8571Fbe
arbitrum-one-blue:
network: arbitrum-one
address: 0x667f41fF7D9c06D2dd18511b32041fC6570Dc468


orders:
arbitrum-order:
inputs:
- token: arbitrum-one-red
vault-id: 0xeede83a4244afae4fef82c8f5b97df1f18bfe3193e65ba02052e37f6171b334b
outputs:
- token: arbitrum-one-blue
vault-id: 0xeede83a4244afae4fef82c8f5b97df1f18bfe3193e65ba02052e37f6171b334b

scenarios:
arbitrum-order-simulations:
network: arbitrum-one
deployer: arbitrum-one
orderbook: arbitrum-one
runs: 100
bindings:
max-output: 1e18
io-ratio: 2e18

charts:
arbitrum-simulation:
scenario: arbitrum-order-simulations
plots:
$ amount vs ratio:
marks:
- type: line
options:
x: 0.0
y: 0.1

deployments:
buy-order:
scenario: arbitrum-order-simulations
order: arbitrum-order

---
#max-output !OrderBook max output
#io-ratio !OrderBook order ratio
#calculate-io
_ _: max-output io-ratio;

#handle-io
:;

0 comments on commit 8ea5c07

Please sign in to comment.