Skip to content

Commit

Permalink
Complete GetLatestBlockhashContractTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-james committed Nov 1, 2024
1 parent d362d8c commit 64c6d02
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.lmax.solana4j.client.jsonrpc;

import com.lmax.solana4j.client.api.SolanaClientOptionalParams;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

// https://solana.com/docs/rpc/http/getlatestblockhash
class GetLatestBlockhashContractTest extends SolanaClientIntegrationTestBase
{
@Test
void shouldGetLatestBlockhash() throws SolanaJsonRpcClientException
{
// {
// "jsonrpc" : "2.0",
// "result" : {
// "context" : {
// "apiVersion" : "2.0.14",
// "slot" : 117
// },
// "value" : {
// "blockhash" : "8hmtSxyZRLcXEwpVZyaeniQJevxQkLje3mLgFvyToWLs",
// "lastValidBlockHeight" : 267
// }
// },
// "id" : 4
// }
final var latestBlockhash = api.getLatestBlockhash().getResponse();
assertThat(latestBlockhash.getBlockhashBase58()).isNotBlank();
assertThat(latestBlockhash.getLastValidBlockHeight()).isGreaterThan(0);
}

@Test
void shouldReturnErrorForMinContextSlotNotReached() throws SolanaJsonRpcClientException
{
final SolanaClientOptionalParams optionalParams = new SolanaJsonRpcClientOptionalParams();
optionalParams.addParam("minContextSlot", 10000000000L);

final var response = api.getLatestBlockhash(optionalParams);

assertThat(response.isSuccess()).isFalse();
assertThat(response.getError().getErrorCode()).isEqualTo(-32016L);
assertThat(response.getError().getErrorMessage()).isEqualTo("Minimum context slot has not been reached");
}
}

0 comments on commit 64c6d02

Please sign in to comment.