Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(solana): priority fees support [LIVE-11792] #225

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ devices = ["nanos", "nanox", "nanos+", "stax", "flex"]
[use_cases]
use_test_keys = "TEST_PUBLIC_KEY=1"
dbg_use_test_keys = "DEBUG=1 TEST_PUBLIC_KEY=1"
testing_dbg_use_test_keys = "DEBUG=1 TESTING=1 TEST_PUBLIC_KEY=1"
tdejoigny-ledger marked this conversation as resolved.
Show resolved Hide resolved

[tests]
pytest_directory = "./test/python/"
39 changes: 34 additions & 5 deletions test/python/apps/solana_cmd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


PROGRAM_ID_SYSTEM = "11111111111111111111111111111111"
PROGRAM_ID_COMPUTE_BUDGET = "ComputeBudget111111111111111111111111111111"

# Fake blockhash so this example doesn't need a network connection. It should be queried from the cluster in normal use.
FAKE_RECENT_BLOCKHASH = "11111111111111111111111111111111"
Expand All @@ -31,6 +32,11 @@ class SystemInstruction(IntEnum):
TransferWithSeed = 0x11
UpgradeNonceAccount = 0x12

class ComputeBudgetInstructionType(IntEnum):
RequestUnits = 0x00
RequestHeapFrame = 0x01
SetComputeUnitLimit = 0x02
SetComputeUnitPrice = 0x03

class MessageHeader:
def __init__(self, num_required_signatures: int, num_readonly_signed_accounts: int, num_readonly_unsigned_accounts: int):
Expand Down Expand Up @@ -69,6 +75,18 @@ def __init__(self, from_pubkey: bytes, to_pubkey: bytes, amount: int):
self.accounts = [AccountMeta(from_pubkey, True, True), AccountMeta(to_pubkey, False, True)]
self.data = (SystemInstruction.Transfer).to_bytes(4, byteorder='little') + (amount).to_bytes(8, byteorder='little')

class ComputeBudgetInstructionSetComputeUnitLimit(Instruction):
def __init__(self, units: int):
self.program_id = base58.b58decode(PROGRAM_ID_COMPUTE_BUDGET)
self.accounts = []
self.data = (ComputeBudgetInstructionType.SetComputeUnitLimit).to_bytes(1, byteorder='little') + (units).to_bytes(4, byteorder='little')

class ComputeBudgetInstructionSetComputeUnitPrice(Instruction):
def __init__(self, microLamports: int):
self.program_id = base58.b58decode(PROGRAM_ID_COMPUTE_BUDGET)
self.accounts = []
self.data = (ComputeBudgetInstructionType.SetComputeUnitPrice).to_bytes(1, byteorder='little') + (microLamports).to_bytes(8, byteorder='little')

# Cheat as we only support 1 SystemInstructionTransfer currently
# TODO add support for multiple transfers and other instructions if the needs arises
class CompiledInstruction:
Expand Down Expand Up @@ -99,12 +117,22 @@ class Message:
compiled_instructions: List[CompiledInstruction]

def __init__(self, instructions: List[Instruction]):
# Cheat as we only support 1 SystemInstructionTransfer currently
# Cheat as we only support 1 SystemInstructionTransfer currently and compute budget only
# TODO add support for multiple transfers and other instructions if the needs arises
self.header = MessageHeader(2, 0, 1)
self.account_keys = [instructions[0].from_pubkey, instructions[0].to_pubkey, instructions[0].program_id]
self.account_keys = []
for instruction in instructions:
if hasattr(instruction, "from_pubkey") and hasattr(instruction, "to_pubkey"):
self.account_keys = [instruction.from_pubkey, instruction.to_pubkey] + self.account_keys
if instruction.program_id not in self.account_keys:
self.account_keys.append(instruction.program_id)
self.compiled_instructions = []
for instruction in instructions:
accountIndexes = []
if hasattr(instruction, "from_pubkey") and hasattr(instruction, "to_pubkey"):
accountIndexes = [self.account_keys.index(instruction.from_pubkey), self.account_keys.index(instruction.to_pubkey)]
self.compiled_instructions.append(CompiledInstruction(self.account_keys.index(instruction.program_id), accountIndexes, instruction.data))
self.header = MessageHeader(2, 0, len(self.account_keys) - 2)
self.recent_blockhash = base58.b58decode(FAKE_RECENT_BLOCKHASH)
self.compiled_instructions = [CompiledInstruction(2, [0, 1], instructions[0].data)]

def serialize(self) -> bytes:
serialized: bytes = self.header.serialize()
Expand All @@ -113,5 +141,6 @@ def serialize(self) -> bytes:
serialized += account_key
serialized += self.recent_blockhash
serialized += len(self.compiled_instructions).to_bytes(1, byteorder='little')
serialized += self.compiled_instructions[0].serialize()
for instruction in self.compiled_instructions:
serialized += instruction.serialize()
return serialized
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading