Skip to content

Commit

Permalink
Make rentEpoch a string because its too big to be a long ...
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-james committed Oct 23, 2024
1 parent 559a781 commit 21f8ee5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,14 @@ class GetAccountInfoContractTest extends SolanaClientIntegrationTestBase
@Test
void shouldGetAccountInfo()
{
// {
// "jsonrpc": "2.0",
// "result": {
// "context": {
// "apiVersion": "1.18.25",
// "slot": 733
// },
// "value": {
// "data": [
// "",
// "base64"
// ],
// "executable": false,
// "lamports": 1000000000,
// "owner": "11111111111111111111111111111111",
// "rentEpoch": 18446744073709551615,
// "space": 0
// }
// },
// "id": 8
// }


final var accountInfo = Waiter.waitFor(Condition.isNotNull(() -> api.getAccountInfo(account)));
final var accountInfo = Waiter.waitFor(Condition.isNotNull(() -> api.getAccountInfo(payerAccount)));

assertThat(accountInfo.getOwner()).isEqualTo("11111111111111111111111111111111");
assertThat(accountInfo.getData().get(0)).isEqualTo("");
assertThat(accountInfo.getData().get(1)).isEqualTo("base64");
assertThat(accountInfo.getLamports()).isEqualTo(1000000000);
assertThat(accountInfo.getLamports()).isEqualTo(600000L);
assertThat(accountInfo.isExecutable()).isEqualTo(false);
assertThat(accountInfo.getRentEpoch()).isEqualTo(0);
assertThat(accountInfo.getRentEpoch()).isEqualTo("18446744073709551615");
assertThat(accountInfo.getSpace()).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,25 @@
import com.lmax.solana4j.assertion.Condition;
import com.lmax.solana4j.assertion.Waiter;
import com.lmax.solana4j.client.api.SolanaApi;
import com.lmax.solana4j.domain.Sol;
import com.lmax.solana4j.util.TestKeyPairGenerator;
import org.junit.jupiter.api.BeforeEach;

import java.math.BigDecimal;

public class SolanaClientIntegrationTestBase extends IntegrationTestBase
{
// associated token account public key : 4swkJXi9iwk1sRB4QAk4ZmX1WCWfpP9ButmqCfkEyaqC
// multisig account public key : 13SkCFWQiqAN4YTdH3SxNoUNL4RvcxCxMXXQxpJue1UW
// nonce account public key : 6qS7fCwPYCSJ6msth7h1AB6g8aGe6rro1agHAamM4rAM
// payer account public key : EjmK3LTW8oBSJp14zvQ55PMvPJCuQwRrnjd17P4vrQYo
// token account public key : Ad1xH9GUwv8AgsMvGzPmxvgKyht3u2yEseztCqQGH6aJ
// token mint public key : 876uAwedRmXAxH2uuxcDwJ49gMyCemWZUz73m2L7NZVn
// found in shared/src/test-support/resources/testcontainers/accounts
protected final String associatedTokenAccount = "4swkJXi9iwk1sRB4QAk4ZmX1WCWfpP9ButmqCfkEyaqC";
protected final String multiSigAccount = "13SkCFWQiqAN4YTdH3SxNoUNL4RvcxCxMXXQxpJue1UW";
protected final String nonceAccount = "6qS7fCwPYCSJ6msth7h1AB6g8aGe6rro1agHAamM4rAM";
protected final String payerAccount = "EjmK3LTW8oBSJp14zvQ55PMvPJCuQwRrnjd17P4vrQYo";
protected final String tokenAccount = "Ad1xH9GUwv8AgsMvGzPmxvgKyht3u2yEseztCqQGH6aJ";
protected final String tokenMintAccount = "876uAwedRmXAxH2uuxcDwJ49gMyCemWZUz73m2L7NZVn";

protected SolanaApi api;
protected String account;

@BeforeEach
void moreSetup()
{
api = new SolanaJsonRpcClient(rpcUrl, true);

Waiter.waitFor(Condition.isTrue(() -> api.getSlot() > 35));

final var testKeyPair = TestKeyPairGenerator.generateSolanaKeyPair();
account = testKeyPair.getPublicKeyBase58();

api.requestAirdrop(testKeyPair.getPublicKeyBase58(), new Sol(BigDecimal.ONE).lamports());

Waiter.waitFor(Condition.isEqualTo(1000000000L, () -> api.getBalance(account)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface AccountInfo
*
* @return the rent epoch number
*/
long getRentEpoch();
String getRentEpoch();

/**
* Returns the amount of space, in bytes, allocated to the account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ public interface AccountInfoParsedData
*
* @return the rent epoch number
*/
long getRentEpoch();
String getRentEpoch();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ static final class AccountInfoValueDTO implements AccountInfo
{
private final long lamports;
private final String owner;
private final List<String> data; // Base64 encoded
private final List<String> data;
private final boolean executable;
private final long rentEpoch;
private final String rentEpoch;
private final int space;

@JsonCreator
Expand All @@ -67,9 +67,7 @@ static final class AccountInfoValueDTO implements AccountInfo
this.owner = owner;
this.data = unmodifiableList(data);
this.executable = executable;
// TODO: suspicious
// solana rpc uses unsigned longs which can overflow javas long object, this is a small workaround
this.rentEpoch = Long.parseUnsignedLong(rentEpoch) < 0 ? 0 : Long.parseLong(rentEpoch);
this.rentEpoch = rentEpoch;
this.space = space;
}

Expand Down Expand Up @@ -98,7 +96,7 @@ public boolean isExecutable()
}

@Override
public long getRentEpoch()
public String getRentEpoch()
{
return rentEpoch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static final class AccountInfoValueParsedDataDTO implements AccountInfoParsedDat
{
private final long lamports;
private final String owner;
private final Map<String, Object> data; // JSON encoded
private final Map<String, Object> data;
private final boolean executable;
private final long rentEpoch;
private final String rentEpoch;

@JsonCreator
AccountInfoValueParsedDataDTO(
Expand All @@ -63,8 +63,7 @@ static final class AccountInfoValueParsedDataDTO implements AccountInfoParsedDat
this.owner = owner;
this.data = data;
this.executable = executable;
// Solana rpc uses unsigned longs which can overflow javas long object, this is a small workaround
this.rentEpoch = Long.parseUnsignedLong(rentEpoch) < 0 ? 0 : Long.parseLong(rentEpoch);
this.rentEpoch = rentEpoch;
}

@Override
Expand Down Expand Up @@ -115,7 +114,7 @@ public boolean isExecutable()
}

@Override
public long getRentEpoch()
public String getRentEpoch()
{
return rentEpoch;
}
Expand Down

0 comments on commit 21f8ee5

Please sign in to comment.