Skip to content

Commit

Permalink
Add a lot more tests covering SolanaAccounts, including those that pl…
Browse files Browse the repository at this point in the history
…ug tiny bugs found, especially around the number of unsignedReadOnly accounts in the transaction, when those accounts are in lookup tables
  • Loading branch information
ml-james committed Sep 2, 2024
1 parent 70fe46c commit e082ec2
Show file tree
Hide file tree
Showing 5 changed files with 674 additions and 129 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/lmax/solana4j/encoding/SolanaAccounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ public int getCountUnsignedReadOnly()
return countUnsignedReadOnly;
}

static Accounts create(final List<TransactionInstruction> instructions, final TransactionInstruction.AccountReference payerReference)
static Accounts create(final List<TransactionInstruction> instructions, final PublicKey payer)
{
return create(instructions, payerReference, List.of());
return create(instructions, payer, List.of());
}

static Accounts create(
final List<TransactionInstruction> instructions,
final TransactionInstruction.AccountReference payerReference,
final PublicKey payer,
final List<AddressLookupTable> addressLookupTables)
{
final var payerReference = new SolanaAccountReference(payer, true, true, false);
final var allAccountReferences = mergeAccountReferences(instructions, payerReference);

final var lookupAccounts = LookupAccounts.create(allAccountReferences, addressLookupTables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
class SolanaInnerTransactionBuilder implements InnerTransactionBuilder
{
private final List<TransactionInstruction> innerInstructions = new ArrayList<>();

private TransactionInstruction.AccountReference payerReference = new SolanaAccountReference(Solana.account(new byte[32]), true, true, false);
private PublicKey payer = Solana.account(new byte[32]);

@Override
public InnerTransactionBuilder instructions(final Consumer<TransactionBuilder> builder)
Expand All @@ -34,15 +33,15 @@ public InnerTransactionBuilder instructions(final Consumer<TransactionBuilder> b
@Override
public InnerTransactionBuilder payer(final PublicKey payer)
{
payerReference = new SolanaAccountReference(payer, true, true, false);
this.payer = payer;
return this;
}

@Override
public InnerInstructions build()
{
final ByteBuffer innerTransactionBytes = ByteBuffer.allocate(Solana.MAX_MESSAGE_SIZE);
final Accounts accounts = SolanaAccounts.create(innerInstructions, payerReference);
final Accounts accounts = SolanaAccounts.create(innerInstructions, payer);
final SolanaMessageWriterLegacy writer = new SolanaMessageWriterLegacy(accounts, new SolanaBlockhash(new byte[32]), innerInstructions);

writer.write(innerTransactionBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public SealedMessageBuilder seal() throws BufferOverflowException
throw new IllegalStateException("Solana transaction incomplete; payer has not been specified.");
}

final SolanaAccountReference payerReference = new SolanaAccountReference(this.payer, true, true, false);

final var accounts = SolanaAccounts.create(instructions, payerReference);
final var accounts = SolanaAccounts.create(instructions, payer);

final var writer = new SolanaMessageWriterLegacy(accounts, this.recent, this.instructions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public SealedMessageBuilder seal() throws BufferOverflowException
throw new IllegalStateException("Solana transaction incomplete; payer has not been specified.");
}

final SolanaAccountReference payerReference = new SolanaAccountReference(this.payer, true, true, false);
final Accounts accounts = SolanaAccounts.create(instructions, payerReference, accountLookups);
final Accounts accounts = SolanaAccounts.create(instructions, payer, accountLookups);

final var writer = new SolanaMessageWriterV0(recentBlockhash, instructions, accounts);

Expand Down
Loading

0 comments on commit e082ec2

Please sign in to comment.