Skip to content

Commit 9d634fb

Browse files
authored
test: fix error checking for utxorpc tx output (#1033)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 2cab307 commit 9d634fb

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

ledger/alonzo/pparams_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -29,8 +29,8 @@ import (
2929
"github.com/blinklabs-io/gouroboros/ledger/common"
3030
"github.com/blinklabs-io/gouroboros/ledger/mary"
3131
"github.com/blinklabs-io/gouroboros/ledger/shelley"
32-
cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
33-
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
32+
"github.com/stretchr/testify/assert"
33+
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
3434
)
3535

3636
func newBaseProtocolParams() alonzo.AlonzoProtocolParameters {
@@ -463,12 +463,15 @@ func TestAlonzoTransactionOutput_Utxorpc(t *testing.T) {
463463
TxOutputDatumHash: &datumHash,
464464
}
465465

466-
got := output.Utxorpc()
467-
want := &utxorpc.TxOutput{
468-
Address: address.Bytes(),
466+
got, err := output.Utxorpc()
467+
assert.NoError(t, err)
468+
addr, err := address.Bytes()
469+
assert.NoError(t, err)
470+
want := &cardano.TxOutput{
471+
Address: addr,
469472
Coin: amount,
470473
Assets: nil,
471-
Datum: &utxorpc.Datum{
474+
Datum: &cardano.Datum{
472475
Hash: datumHash.Bytes(),
473476
},
474477
}

ledger/babbage/pparams_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import (
2525
"github.com/blinklabs-io/gouroboros/ledger/common"
2626
"github.com/blinklabs-io/gouroboros/ledger/mary"
2727
"github.com/blinklabs-io/gouroboros/ledger/shelley"
28+
"github.com/stretchr/testify/assert"
2829
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
29-
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
3030
)
3131

3232
func TestBabbageProtocolParamsUpdate(t *testing.T) {
@@ -581,11 +581,14 @@ func TestBabbageTransactionOutput_Utxorpc(t *testing.T) {
581581
OutputAmount: mary.MaryTransactionOutputValue{Amount: amount},
582582
}
583583

584-
got := output.Utxorpc()
585-
want := &utxorpc.TxOutput{
586-
Address: address.Bytes(),
584+
got, err := output.Utxorpc()
585+
assert.NoError(t, err)
586+
addr, err := address.Bytes()
587+
assert.NoError(t, err)
588+
want := &cardano.TxOutput{
589+
Address: addr,
587590
Coin: amount,
588-
Datum: &utxorpc.Datum{
591+
Datum: &cardano.Datum{
589592
Hash: make([]byte, 32),
590593
},
591594
}

ledger/byron/byron_test.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package byron_test
216

317
import (
@@ -6,15 +20,16 @@ import (
620

721
"github.com/blinklabs-io/gouroboros/ledger/byron"
822
"github.com/blinklabs-io/gouroboros/ledger/common"
9-
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
1025
)
1126

1227
// Unit test for ByronTransactionInput.Utxorpc()
1328
func TestByronTransactionInput_Utxorpc(t *testing.T) {
1429
input := byron.NewByronTransactionInput("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1)
1530

1631
got := input.Utxorpc()
17-
want := &utxorpc.TxInput{
32+
want := &cardano.TxInput{
1833
TxHash: input.Id().Bytes(),
1934
OutputIndex: input.Index(),
2035
}
@@ -32,9 +47,12 @@ func TestByronTransactionOutput_Utxorpc(t *testing.T) {
3247
OutputAmount: 5000,
3348
}
3449

35-
got := output.Utxorpc()
36-
want := &utxorpc.TxOutput{
37-
Address: address.Bytes(),
50+
got, err := output.Utxorpc()
51+
assert.NoError(t, err)
52+
addr, err := address.Bytes()
53+
assert.NoError(t, err)
54+
want := &cardano.TxOutput{
55+
Address: addr,
3856
Coin: output.OutputAmount,
3957
}
4058

@@ -53,7 +71,7 @@ func TestByronTransaction_Utxorpc_Empty(t *testing.T) {
5371

5472
// Validate it's not nil
5573
if result == nil {
56-
t.Fatal("ByronTransaction.Utxorpc() returned nil; expected empty utxorpc.Tx object")
74+
t.Fatal("ByronTransaction.Utxorpc() returned nil; expected empty cardano.Tx object")
5775
}
5876

5977
// Validate that it's the zero value

ledger/mary/pparams_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import (
2424
"github.com/blinklabs-io/gouroboros/ledger/common"
2525
"github.com/blinklabs-io/gouroboros/ledger/mary"
2626
"github.com/blinklabs-io/gouroboros/ledger/shelley"
27+
"github.com/stretchr/testify/assert"
2728
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2829
)
2930

@@ -158,9 +159,12 @@ func TestMaryTransactionOutput_Utxorpc(t *testing.T) {
158159
OutputAmount: mary.MaryTransactionOutputValue{Amount: amount},
159160
}
160161

161-
got := output.Utxorpc()
162+
got, err := output.Utxorpc()
163+
assert.NoError(t, err)
164+
addr, err := address.Bytes()
165+
assert.NoError(t, err)
162166
want := &cardano.TxOutput{
163-
Address: address.Bytes(),
167+
Address: addr,
164168
Coin: amount,
165169
}
166170

0 commit comments

Comments
 (0)