Skip to content

Commit

Permalink
Merge pull request #17 from skynetcap/1.31.0-staging
Browse files Browse the repository at this point in the history
1.31.0 staging
  • Loading branch information
skynetcap authored Sep 21, 2024
2 parents a67d3dd + df50fd9 commit b9f4983
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 172 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Bonfida.
<dependency>
<groupId>com.mmorrell</groupId>
<artifactId>solanaj-programs</artifactId>
<version>1.30.3</version>
<version>1.31.0</version>
</dependency>
```
Or just one dependency:
```xml
<dependency>
<groupId>com.mmorrell</groupId>
<artifactId>phoenix</artifactId>
<version>1.30.3</version>
<version>1.31.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion bonfida/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>solanaj-programs</artifactId>
<groupId>com.mmorrell</groupId>
<version>1.30.5</version>
<version>1.31.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
28 changes: 7 additions & 21 deletions bonfida/src/test/java/BonfidaTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import com.mmorrell.bonfida.manager.NamingManager;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.*;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.rpc.Cluster;
import org.p2p.solanaj.rpc.RpcClient;
import org.p2p.solanaj.rpc.types.AccountInfo;

Expand All @@ -11,29 +10,23 @@
import java.util.Optional;
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

// Ignored since too many GPAs for free build server.
@Ignore
public class BonfidaTest {

private static final Logger LOGGER = Logger.getLogger(BonfidaTest.class.getName());
private final RpcClient rpcClient = new RpcClient("https://rpc.ankr.com/solana");
private final RpcClient rpcClient = new RpcClient(Cluster.MAINNET);
private final NamingManager namingManager = new NamingManager(rpcClient);
private static final String DOMAIN_NAME = ".sol"; // testdomainname.sol
private final PublicKey skynetMainnetPubkey = new PublicKey("skynetDj29GH6o6bAqoixCpDuYtWqi1rm8ZNx1hB3vq");
private final PublicKey bonfidaPubkey = new PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR");
private static final PublicKey NAME_PROGRAM_ID = new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX");

@BeforeClass
@BeforeAll
public static void beforeClass() throws InterruptedException {
// Prevent RPCPool rate limit
Thread.sleep(2000L);
}

@Test
@Ignore
public void retrieveNameFromRegistry() {
// getAccountInfo
AccountInfo testAccountInfo = namingManager.getAccountInfo(new PublicKey("BVk1qg1y9AJ3LkfWCpr8FkDXZZcu7muAyVgbTBDbqDwZ"));
Expand Down Expand Up @@ -91,6 +84,7 @@ public void getPublicKeyBySolDomainTest() {
}

@Test
@Disabled
public void resolveTest() {
LOGGER.info("Looking up domain for: " + skynetMainnetPubkey.toBase58());
Optional<String> domainName = namingManager.getDomainNameByPubkey(skynetMainnetPubkey);
Expand All @@ -110,13 +104,5 @@ public void resolveTest() {
);

assertTrue(sbfWallet.isPresent());

// // Confirm it matches sbf.sol
// assertEquals(
// sbfWallet.get(),
// "sbf"
// );
//
// LOGGER.info("2NoEcR9cC7Rn6bP9rBpky6B1eP9syyPf8FXRaf1myChv = " + sbfWallet.get() + ".sol");
}
}
2 changes: 1 addition & 1 deletion magiceden/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>solanaj-programs</artifactId>
<groupId>com.mmorrell</groupId>
<version>1.30.5</version>
<version>1.31.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion mango/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>solanaj-programs</artifactId>
<groupId>com.mmorrell</groupId>
<version>1.30.5</version>
<version>1.31.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
9 changes: 4 additions & 5 deletions mango/src/test/java/MangoTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import com.mmorrell.mango.manager.MangoManager;
import com.mmorrell.mango.model.*;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.*;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.rpc.Cluster;
import org.p2p.solanaj.rpc.RpcClient;
Expand All @@ -11,7 +10,7 @@
import java.util.Base64;
import java.util.logging.Logger;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class MangoTest {

Expand Down Expand Up @@ -186,7 +185,7 @@ public void getMangoGroupAndMarginAccountTest() {
}

@Test
@Ignore
@Disabled
public void mangoV3Test() {
final MangoPerpGroup mangoPerpGroup = devnetMangoManager.getMangoPerpGroup(
PublicKey.valueOf("ECAikQUnS8HGLnzGrqEYA6Daz8nRRu9GsbfLbwMfK23P")
Expand Down Expand Up @@ -240,7 +239,7 @@ public void mangoV3Test() {
}

@Test
@Ignore
@Disabled
public void mangoV3PerpAccountTest() {
final MangoPerpGroup mangoPerpGroup = devnetMangoManager.getMangoPerpGroup(
PublicKey.valueOf("ECAikQUnS8HGLnzGrqEYA6Daz8nRRu9GsbfLbwMfK23P")
Expand Down
2 changes: 1 addition & 1 deletion metaplex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>solanaj-programs</artifactId>
<groupId>com.mmorrell</groupId>
<version>1.30.5</version>
<version>1.31.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
7 changes: 3 additions & 4 deletions metaplex/src/test/java/MetaplexTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import com.mmorrell.metaplex.manager.MetaplexManager;
import com.mmorrell.metaplex.model.Metadata;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.*;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.rpc.Cluster;
import org.p2p.solanaj.rpc.RpcClient;

import java.util.Optional;
import java.util.logging.Logger;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MetaplexTest {

Expand All @@ -18,7 +17,7 @@ public class MetaplexTest {
private final RpcClient rpcClient = new RpcClient(Cluster.MAINNET);
private final MetaplexManager metaplexManager = new MetaplexManager(rpcClient);

@BeforeClass
@BeforeAll
public static void beforeClass() throws InterruptedException {
// Prevent RPCPool rate limit
Thread.sleep(2000L);
Expand Down
2 changes: 1 addition & 1 deletion openbook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>solanaj-programs</artifactId>
<groupId>com.mmorrell</groupId>
<version>1.30.5</version>
<version>1.31.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
122 changes: 116 additions & 6 deletions openbook/src/test/java/OpenBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import com.mmorrell.openbook.program.OpenbookProgram;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Base58;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.*;
import org.p2p.solanaj.core.Account;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.core.Transaction;
Expand All @@ -28,9 +27,7 @@
import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

@Slf4j
public class OpenBookTest {
Expand All @@ -43,7 +40,18 @@ public class OpenBookTest {
private final OpenBookManager openBookManager = new OpenBookManager(client);
private static final String PRIVATE_KEY_FILE = "mikeDBaJgkicqhZcoYDBB4dRwZFFJCThtWCYD7A9FAH.json";

/**
* Sets up the test environment, adding a delay before each test.
*
* @throws InterruptedException if the thread is interrupted during sleep
*/
@BeforeEach
public void setUp() throws InterruptedException {
Thread.sleep(2000); // 1.5 seconds delay
}

@Test
@Disabled
public void openBookV2Test() throws RpcException {
final List<ProgramAccount> markets = client.getApi().getProgramAccountsBase64(
OpenbookProgram.OPENBOOK_V2_PROGRAM_ID,
Expand Down Expand Up @@ -106,7 +114,7 @@ public void getOBv2MarketWithBooksTest() {
}

@Test
@Ignore
@Disabled
public void eventHeapTest() throws RpcException, IOException {
byte[] data = client.getApi().getAccountInfo(new PublicKey("GY5HKym4yKNUpdHpBBiqLB3DHbrNKhLHDFTSLPK8AbFX"))
.getDecodedData();
Expand Down Expand Up @@ -134,6 +142,7 @@ public void openBookEventHeapOutEventsTest() {
}

@Test
@Disabled // Ignored due to usage of PRIVATE_KEY_FILE
public void openBookOpenOrdersAccountTest() throws RpcException, IOException {
Optional<OpenBookOpenOrdersAccount> openBookOpenOrdersAccount = openBookManager.getOpenOrdersAccount(
new PublicKey("G1hKFxyM3qNCd1nnjnuvydw6VjCowVp5Jm6w1mwyWH4r")
Expand All @@ -148,6 +157,7 @@ public void openBookOpenOrdersAccountTest() throws RpcException, IOException {
}

@Test
@Disabled // Ignored due to usage of PRIVATE_KEY_FILE
public void consumeEventsTest() throws IOException, RpcException {
Account tradingAccount = Account.fromJson(
Resources.toString(Resources.getResource(PRIVATE_KEY_FILE), Charset.defaultCharset())
Expand Down Expand Up @@ -197,6 +207,7 @@ public void consumeEventsTest() throws IOException, RpcException {
}

@Test
@Disabled // Ignored due to usage of PRIVATE_KEY_FILE
public void consumeEventsAllMarketsTest() throws IOException, RpcException, InterruptedException {
Account tradingAccount = Account.fromJson(
Resources.toString(Resources.getResource(PRIVATE_KEY_FILE), Charset.defaultCharset())
Expand Down Expand Up @@ -246,6 +257,7 @@ public void consumeEventsAllMarketsTest() throws IOException, RpcException, Inte
}

@Test
@Disabled // Ignored due to usage of PRIVATE_KEY_FILE
public void consumeEventsOpenBookManagerTest() throws IOException {
Account tradingAccount = Account.fromJson(
Resources.toString(Resources.getResource(PRIVATE_KEY_FILE), Charset.defaultCharset())
Expand All @@ -265,4 +277,102 @@ public void consumeEventsOpenBookManagerTest() throws IOException {
log.info("No events found to consume.");
}
}

/**
* Tests the retrieval of a specific market by its public key.
*/
@Test
public void testGetSpecificMarket() {
PublicKey marketId = PublicKey.valueOf("C3YPL3kYCSYKsmHcHrPWx1632GUXGqi2yMXJbfeCc57q");
Optional<OpenBookMarket> market = openBookManager.getMarket(marketId, false, false);
assertTrue(market.isPresent(), "Market should be present");
assertEquals(marketId, market.get().getMarketId(), "Market ID should match");
assertNotNull(market.get().getName(), "Market name should not be null");
}

/**
* Tests the retrieval of all markets and verifies that the list is not empty.
*/
@Test
public void testGetAllMarkets() {
List<OpenBookMarket> markets = openBookManager.getOpenBookMarkets();
assertFalse(markets.isEmpty(), "Markets list should not be empty");
assertTrue(markets.size() > 1, "Markets list should contain more than one market");
}

/**
* Tests the retrieval of the event heap for a specific market and verifies its contents.
*/
@Test
public void testGetEventHeapForMarket() {
PublicKey marketId = PublicKey.valueOf("3w9Z8FPRuSTbrGQLPhRDEQzSRYyhXzuiqmFVaku5Rjb2");
Optional<OpenBookMarket> market = openBookManager.getMarket(marketId, true, false);
assertTrue(market.isPresent(), "Market should be present");
Optional<OpenBookEventHeap> eventHeap = openBookManager.getEventHeap(market.get().getEventHeap());
assertTrue(eventHeap.isPresent(), "Event heap should be present");
assertNotNull(eventHeap.get().getFillEvents(), "Fill events should not be null");
}

/**
* Tests the retrieval of open orders account for a specific public key.
*/
@Test
public void testGetOpenOrdersAccount() {
PublicKey ooa = PublicKey.valueOf("KTmdiqkZvNXocarMothBs6PZZFN6Q9vzryLiSuxV2Ef");
Optional<OpenBookOpenOrdersAccount> account = openBookManager.getOpenOrdersAccount(ooa);
assertTrue(account.isPresent(), "Open Orders Account should be present");

}

/**
* Tests the retrieval of the best bid and ask prices for a specific market.
*/
@Test
public void testGetBestBidAskForMarket() {
PublicKey marketId = PublicKey.valueOf("3w9Z8FPRuSTbrGQLPhRDEQzSRYyhXzuiqmFVaku5Rjb2");
Optional<OpenBookMarket> market = openBookManager.getMarket(marketId, false, true);
assertTrue(market.isPresent(), "Market should be present");
assertFalse(market.get().getBidOrders().isEmpty(), "Bid orders should not be empty");
assertFalse(market.get().getAskOrders().isEmpty(), "Ask orders should not be empty");
}

/**
* Tests the calculation of the spread for a specific market.
*/
@Test
public void testCalculateSpreadForMarket() {
PublicKey marketId = PublicKey.valueOf("3w9Z8FPRuSTbrGQLPhRDEQzSRYyhXzuiqmFVaku5Rjb2");
Optional<OpenBookMarket> market = openBookManager.getMarket(marketId, false, true);
assertTrue(market.isPresent(), "Market should be present");
assertFalse(market.get().getBidOrders().isEmpty(), "Bid orders should not be empty");
assertFalse(market.get().getAskOrders().isEmpty(), "Ask orders should not be empty");
double bestBidPrice = market.get().getBidOrders().get(0).getPrice();
double bestAskPrice = market.get().getAskOrders().get(0).getPrice();
double spread = bestAskPrice - bestBidPrice;
assertTrue(spread > 0, "Spread should be greater than zero");
}

/**
* Tests the retrieval of market depth for a specific market.
*/
@Test
public void testGetMarketDepth() {
PublicKey marketId = PublicKey.valueOf("3w9Z8FPRuSTbrGQLPhRDEQzSRYyhXzuiqmFVaku5Rjb2");
Optional<OpenBookMarket> market = openBookManager.getMarket(marketId, false, true);
assertTrue(market.isPresent(), "Market should be present");
assertTrue(market.get().getBidOrders().size() > 0, "Bid orders should be greater than zero");
assertTrue(market.get().getAskOrders().size() > 0, "Ask orders should be greater than zero");
}

/**
* Tests the consumption of events for a specific market.
*/
@Test
@Disabled // This test requires a valid Account object and may modify blockchain state
public void testConsumeEvents() throws IOException {
PublicKey marketId = PublicKey.valueOf("C3YPL3kYCSYKsmHcHrPWx1632GUXGqi2yMXJbfeCc57q");
Account caller = Account.fromJson(Files.toString(new File("path/to/account.json"), Charset.defaultCharset()));
Optional<String> result = openBookManager.consumeEvents(caller, marketId, 10, null);
assertTrue(result.isPresent(), "Consume events should return a transaction ID");
}
}
Loading

0 comments on commit b9f4983

Please sign in to comment.