@@ -113,3 +113,64 @@ func TestData_DataBytesOrJSONFromBytes(t *testing.T) {
113113 out := dataBytesOrJSON .GetBinary ()
114114 assert .Equal (t , in , out )
115115}
116+
117+ // TestParsedTransactionMeta_Decode guards issue #284: the jsonParsed
118+ // and binary encodings return the same UiTransactionStatusMeta shape
119+ // on the wire, so every field on TransactionMeta must also decode
120+ // cleanly onto ParsedTransactionMeta. The fixture carries every trailing
121+ // field that was historically dropped (status, rewards, loadedAddresses,
122+ // returnData, computeUnitsConsumed) plus the parsed inner-instructions
123+ // shape that distinguishes this path from the binary one.
124+ func TestParsedTransactionMeta_Decode (t * testing.T ) {
125+ in := []byte (`{
126+ "err": null,
127+ "fee": 5000,
128+ "preBalances": [1000000, 0],
129+ "postBalances": [994000, 1000],
130+ "innerInstructions": [{
131+ "index": 0,
132+ "instructions": [{
133+ "program": "system",
134+ "programId": "11111111111111111111111111111111",
135+ "parsed": {"type":"transfer","info":{"lamports":1}},
136+ "stackHeight": 1
137+ }]
138+ }],
139+ "preTokenBalances": [],
140+ "postTokenBalances": [],
141+ "logMessages": ["Program 11111111111111111111111111111111 invoke [1]"],
142+ "status": {"Ok": null},
143+ "rewards": [{
144+ "pubkey": "4ejjNYBbaETZyqaiK8aDj2BWER8LKHgDcCnRrPC22YGg",
145+ "lamports": 10,
146+ "postBalance": 1000010,
147+ "rewardType": "Fee"
148+ }],
149+ "loadedAddresses": {
150+ "writable": ["4ejjNYBbaETZyqaiK8aDj2BWER8LKHgDcCnRrPC22YGg"],
151+ "readonly": ["11111111111111111111111111111111"]
152+ },
153+ "returnData": {
154+ "programId": "11111111111111111111111111111111",
155+ "data": ["", "base64"]
156+ },
157+ "computeUnitsConsumed": 150
158+ }` )
159+
160+ var got ParsedTransactionMeta
161+ assert .NoError (t , stdjson .Unmarshal (in , & got ))
162+
163+ assert .Equal (t , uint64 (5000 ), got .Fee )
164+ assert .Len (t , got .InnerInstructions , 1 )
165+ assert .Equal (t , "system" , got .InnerInstructions [0 ].Instructions [0 ].Program )
166+
167+ // Fields that were missing before the #284 fix — regression guards.
168+ assert .Len (t , got .Rewards , 1 )
169+ assert .Equal (t , int64 (10 ), got .Rewards [0 ].Lamports )
170+ assert .Len (t , got .LoadedAddresses .Writable , 1 )
171+ assert .Len (t , got .LoadedAddresses .ReadOnly , 1 )
172+ assert .Equal (t , solana .MustPublicKeyFromBase58 ("11111111111111111111111111111111" ), got .ReturnData .ProgramId )
173+ if assert .NotNil (t , got .ComputeUnitsConsumed ) {
174+ assert .Equal (t , uint64 (150 ), * got .ComputeUnitsConsumed )
175+ }
176+ }
0 commit comments