Skip to content

Commit 57c0dfc

Browse files
authored
Merge pull request #140 from firedancer-io/mjain/use-hex-dumps
codec: use hex dumps for displaying raw bytes instead of octal strings
2 parents 64ebb0b + 4e35045 commit 57c0dfc

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/test_suite/context/codec_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test_suite.context_pb2 as context_pb
22
import fd58
3+
from test_suite.fuzz_interface import encode_hex_compact, decode_hex_compact
34

45

56
def encode_acct_state(acct_state: context_pb.AcctState):
@@ -11,6 +12,10 @@ def encode_acct_state(acct_state: context_pb.AcctState):
1112
if acct_state.owner:
1213
acct_state.owner = fd58.enc32(acct_state.owner)
1314

15+
# Data
16+
if acct_state.data:
17+
acct_state.data = encode_hex_compact(acct_state.data)
18+
1419

1520
def decode_acct_state(acct_state: context_pb.AcctState):
1621
# Pubkey
@@ -20,3 +25,7 @@ def decode_acct_state(acct_state: context_pb.AcctState):
2025
# Owner
2126
if acct_state.owner:
2227
acct_state.owner = fd58.dec32(acct_state.owner)
28+
29+
# Data
30+
if acct_state.data:
31+
acct_state.data = decode_hex_compact(acct_state.data)

src/test_suite/instr/codec_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fd58
22
from test_suite.context.codec_utils import decode_acct_state, encode_acct_state
3+
from test_suite.fuzz_interface import decode_hex_compact, encode_hex_compact
34
import test_suite.invoke_pb2 as invoke_pb
45

56

@@ -11,12 +12,18 @@ def decode_input(instruction_context: invoke_pb.InstrContext):
1112
Args:
1213
- instruction_context (invoke_pb.InstrContext): Instruction context (will be modified).
1314
"""
15+
# Program ID
1416
if instruction_context.program_id:
1517
instruction_context.program_id = fd58.dec32(instruction_context.program_id)
1618

19+
# Accounts
1720
for i in range(len(instruction_context.accounts)):
1821
decode_acct_state(instruction_context.accounts[i])
1922

23+
# Data
24+
if instruction_context.data:
25+
instruction_context.data = decode_hex_compact(instruction_context.data)
26+
2027

2128
def encode_input(instruction_context: invoke_pb.InstrContext):
2229
"""
@@ -26,12 +33,18 @@ def encode_input(instruction_context: invoke_pb.InstrContext):
2633
Args:
2734
- instruction_context (invoke_pb.InstrContext): Instruction context (will be modified).
2835
"""
36+
# Program ID
2937
if instruction_context.program_id:
3038
instruction_context.program_id = fd58.enc32(instruction_context.program_id)
3139

40+
# Accounts
3241
for i in range(len(instruction_context.accounts)):
3342
encode_acct_state(instruction_context.accounts[i])
3443

44+
# Data
45+
if instruction_context.data:
46+
instruction_context.data = encode_hex_compact(instruction_context.data)
47+
3548

3649
def encode_output(instruction_effects: invoke_pb.InstrEffects):
3750
"""
@@ -41,5 +54,12 @@ def encode_output(instruction_effects: invoke_pb.InstrEffects):
4154
Args:
4255
- instruction_effects (invoke_pb.InstrEffects): Instruction effects (will be modified).
4356
"""
57+
# Accounts
4458
for i in range(len(instruction_effects.modified_accounts)):
4559
encode_acct_state(instruction_effects.modified_accounts[i])
60+
61+
# Return data
62+
if instruction_effects.return_data:
63+
instruction_effects.return_data = encode_hex_compact(
64+
instruction_effects.return_data
65+
)

src/test_suite/txn/codec_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fd58
22
from test_suite.context.codec_utils import decode_acct_state, encode_acct_state
3+
from test_suite.fuzz_interface import decode_hex_compact, encode_hex_compact
34
import test_suite.txn_pb2 as txn_pb
45

56

@@ -22,6 +23,13 @@ def decode_sanitized_tx(tx: txn_pb.SanitizedTransaction):
2223
tx.message.recent_blockhash or bytes([0] * 32)
2324
)
2425

26+
# Instructions
27+
for i in range(len(tx.message.instructions)):
28+
if tx.message.instructions[i].data:
29+
tx.message.instructions[i].data = decode_hex_compact(
30+
tx.message.instructions[i].data
31+
)
32+
2533
# Address table lookups
2634
for i in range(len(tx.message.address_table_lookups)):
2735
if tx.message.address_table_lookups[i].account_key:
@@ -49,6 +57,13 @@ def encode_sanitized_tx(tx: txn_pb.SanitizedTransaction):
4957
tx.message.recent_blockhash or bytes([0] * 32)
5058
)
5159

60+
# Instructions
61+
for i in range(len(tx.message.instructions)):
62+
if tx.message.instructions[i].data:
63+
tx.message.instructions[i].data = encode_hex_compact(
64+
tx.message.instructions[i].data
65+
)
66+
5267
# Address table lookups
5368
for i in range(len(tx.message.address_table_lookups)):
5469
if tx.message.address_table_lookups[i].account_key:

0 commit comments

Comments
 (0)