From 853ab3df3942de0401211e25afab5c89eb64429b Mon Sep 17 00:00:00 2001 From: skynetcap <100323448+skynetcap@users.noreply.github.com> Date: Sat, 9 Dec 2023 11:39:14 -0800 Subject: [PATCH] OBv2: Update tests PHX: Add OB test --- openbook/src/test/java/OpenBookTest.java | 4 +++- phoenix/src/test/java/PhoenixTest.java | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/openbook/src/test/java/OpenBookTest.java b/openbook/src/test/java/OpenBookTest.java index 5b82e91..832a2c3 100644 --- a/openbook/src/test/java/OpenBookTest.java +++ b/openbook/src/test/java/OpenBookTest.java @@ -1,5 +1,6 @@ import com.mmorrell.openbook.manager.OpenBookManager; import com.mmorrell.openbook.model.BookSide; +import com.mmorrell.openbook.model.LeafNode; import com.mmorrell.openbook.model.NodeTag; import com.mmorrell.openbook.model.OpenBookMarket; import com.mmorrell.openbook.program.OpenbookProgram; @@ -13,6 +14,7 @@ import org.p2p.solanaj.utils.ByteUtils; import java.io.IOException; +import java.util.Comparator; import java.util.List; @Slf4j @@ -64,7 +66,7 @@ public void orderBookTest() throws RpcException, IOException { log.info("Leaf node: {}", anyNode); }); log.info("Bids:"); - bookSide.getLeafNodes().forEach(leafNode -> { + bookSide.getLeafNodes().stream().sorted(Comparator.comparingDouble(LeafNode::getPrice).reversed()).forEach(leafNode -> { // log.info("Leaf: {}", leafNode); // log.info("Hex: {}", ByteUtils.bytesToHex(leafNode.getKey())); log.info("Price: {}, Size: {}, Trader: {}", leafNode.getPrice(), leafNode.getQuantity(), diff --git a/phoenix/src/test/java/PhoenixTest.java b/phoenix/src/test/java/PhoenixTest.java index ed2a662..408b38f 100644 --- a/phoenix/src/test/java/PhoenixTest.java +++ b/phoenix/src/test/java/PhoenixTest.java @@ -99,7 +99,7 @@ public void placeMultiplePostOnlyOrdersTest() throws IOException, RpcException { List bidsToPlace = new ArrayList<>(); for (int i = 0; i < 20; i++) { - double price = 59.00 + (i * 0.01); + double price = 73 + (i * 0.01); bidsToPlace.add( CondensedPhoenixOrder.builder() .sizeInBaseLots(market.convertSizeToNumBaseLots(0.001)) @@ -110,7 +110,7 @@ public void placeMultiplePostOnlyOrdersTest() throws IOException, RpcException { List asksToPlace = new ArrayList<>(); for (int i = 0; i < 20; i++) { - double price = 60 + (i * 0.01); + double price = 74 + (i * 0.01); asksToPlace.add( CondensedPhoenixOrder.builder() .sizeInBaseLots(market.convertSizeToNumBaseLots(0.001)) @@ -674,6 +674,14 @@ public void phoenixPlaceLimitOrderTest() throws IOException, RpcException, Inter } } + @Test + public void orderBookTest() throws RpcException { + byte[] data = client.getApi().getAccountInfo(SOL_USDC_MARKET).getDecodedData(); + PhoenixMarket market = PhoenixMarket.readPhoenixMarket(data); + + log.info("OB: {}", market.getBidListSanitized()); + } + private String getDiscriminator(String input) { Keccak keccak = new Keccak(256); keccak.update(PhoenixProgram.PHOENIX_PROGRAM_ID.toByteArray());