@@ -22,6 +22,7 @@ import (
22
22
"testing"
23
23
24
24
"github.com/blinklabs-io/gouroboros/cbor"
25
+ "github.com/blinklabs-io/gouroboros/ledger/common"
25
26
"github.com/blinklabs-io/gouroboros/ledger/shelley"
26
27
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
27
28
)
@@ -161,3 +162,142 @@ func TestShelleyUtxorpc(t *testing.T) {
161
162
)
162
163
}
163
164
}
165
+
166
+ // Tests conversion of a ShelleyTransactionInput to its utxorpc-compatible representation.
167
+ func TestShelleyTransactionInput_Utxorpc (t * testing.T ) {
168
+ // Create a mock transaction input with dummy transaction hash and index
169
+ input := shelley .NewShelleyTransactionInput ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" , 1 )
170
+
171
+ // Convert it to utxorpc TxInput
172
+ got := input .Utxorpc ()
173
+
174
+ // Expected value with same hash and index
175
+ want := & cardano.TxInput {
176
+ TxHash : input .Id ().Bytes (),
177
+ OutputIndex : input .Index (),
178
+ }
179
+
180
+ // Compare actual and expected results
181
+ if ! reflect .DeepEqual (got , want ) {
182
+ t .Errorf ("TxInput.Utxorpc() mismatch\n Got: %+v\n Want: %+v" , got , want )
183
+ }
184
+ }
185
+
186
+ // Test the conversion of a ShelleyTransactionOutput to its utxorpc-compatible representation.
187
+ func TestShelleyTransactionOutput_Utxorpc (t * testing.T ) {
188
+ // Use a zero-value common.Address as a placeholder
189
+ address := common.Address {}
190
+
191
+ // Create a transaction output
192
+ output := shelley.ShelleyTransactionOutput {
193
+ OutputAddress : address ,
194
+ OutputAmount : 1000 ,
195
+ }
196
+
197
+ // Convert it to utxorpc format
198
+ actual := output .Utxorpc ()
199
+
200
+ // expected output in utxorpc format
201
+ expected := & cardano.TxOutput {
202
+ Address : address .Bytes (),
203
+ Coin : 1000 ,
204
+ }
205
+
206
+ // Debug prints
207
+ t .Logf ("DEBUG got.Address=%#v want.Address=%#v\n " , actual .Address , expected .Address )
208
+
209
+ // Compare actual and expected results
210
+ if ! reflect .DeepEqual (actual , expected ) {
211
+ t .Errorf ("TxOutput.Utxorpc() mismatch\n Got: %+v\n Want: %+v" , actual , expected )
212
+ }
213
+ }
214
+
215
+ // Test the conversion of a full ShelleyTransactionBody to utxorpc format, verifying fee, input count, and output count.
216
+ func TestShelleyTransactionBody_Utxorpc (t * testing.T ) {
217
+ // Create input set with one mock input
218
+ input := shelley .NewShelleyTransactionInput ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" , 0 )
219
+ inputSet := shelley .NewShelleyTransactionInputSet ([]shelley.ShelleyTransactionInput {input })
220
+
221
+ // Use mock address
222
+ address := common.Address {}
223
+
224
+ // Define a transaction output
225
+ output := shelley.ShelleyTransactionOutput {
226
+ OutputAddress : address ,
227
+ OutputAmount : 2000 ,
228
+ }
229
+
230
+ // Create the transaction body
231
+ txBody := & shelley.ShelleyTransactionBody {
232
+ TxInputs : inputSet ,
233
+ TxOutputs : []shelley.ShelleyTransactionOutput {output },
234
+ TxFee : 150 ,
235
+ Ttl : 1000 ,
236
+ }
237
+
238
+ // Convert the transaction body to utxorpc format
239
+ actual := txBody .Utxorpc ()
240
+
241
+ // Check that the fee matches
242
+ if actual .Fee != txBody .Fee () {
243
+ t .Errorf ("TxBody.Utxorpc() fee mismatch\n Got: %d\n Want: %d" , actual .Fee , txBody .Fee ())
244
+ }
245
+
246
+ // Check number of inputs
247
+ if len (actual .Inputs ) != len (txBody .Inputs ()) {
248
+ t .Errorf ("TxBody.Utxorpc() input length mismatch\n Got: %d\n Want: %d" , len (actual .Inputs ), len (txBody .Inputs ()))
249
+ }
250
+
251
+ // Check number of outputs
252
+ if len (actual .Outputs ) != len (txBody .Outputs ()) {
253
+ t .Errorf ("TxBody.Utxorpc() output length mismatch\n Got: %d\n Want: %d" , len (actual .Outputs ), len (txBody .Outputs ()))
254
+ }
255
+ }
256
+
257
+ // Test the conversion of a full ShelleyTransaction to utxorpc format, verifying fee, input count, and output count.
258
+ func TestShelleyTransaction_Utxorpc (t * testing.T ) {
259
+ // Create input set with one mock input
260
+ input := shelley .NewShelleyTransactionInput ("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" , 0 )
261
+ inputSet := shelley .NewShelleyTransactionInputSet ([]shelley.ShelleyTransactionInput {input })
262
+
263
+ // Use mock address
264
+ address := common.Address {}
265
+
266
+ // Define a transaction output
267
+ output := shelley.ShelleyTransactionOutput {
268
+ OutputAddress : address ,
269
+ OutputAmount : 5000 ,
270
+ }
271
+
272
+ // Build the transaction body
273
+ txBody := shelley.ShelleyTransactionBody {
274
+ TxInputs : inputSet ,
275
+ TxOutputs : []shelley.ShelleyTransactionOutput {output },
276
+ TxFee : 250 ,
277
+ Ttl : 800 ,
278
+ }
279
+
280
+ // Create full transaction with body and empty witness set
281
+ tx := shelley.ShelleyTransaction {
282
+ Body : txBody ,
283
+ WitnessSet : shelley.ShelleyTransactionWitnessSet {},
284
+ }
285
+
286
+ // Invoke Utxorpc conversion
287
+ got := tx .Utxorpc ()
288
+
289
+ // Verify the fee
290
+ if got .Fee != tx .Body .Fee () {
291
+ t .Errorf ("ShelleyTransaction.Utxorpc() fee mismatch\n Got: %d\n Want: %d" , got .Fee , tx .Body .Fee ())
292
+ }
293
+
294
+ // Verify input count
295
+ if len (got .Inputs ) != len (tx .Body .Inputs ()) {
296
+ t .Errorf ("ShelleyTransaction.Utxorpc() input count mismatch\n Got: %d\n Want: %d" , len (got .Inputs ), len (tx .Body .Inputs ()))
297
+ }
298
+
299
+ // Verify output count
300
+ if len (got .Outputs ) != len (tx .Body .Outputs ()) {
301
+ t .Errorf ("ShelleyTransaction.Utxorpc() output count mismatch\n Got: %d\n Want: %d" , len (got .Outputs ), len (tx .Body .Outputs ()))
302
+ }
303
+ }
0 commit comments