Skip to content

test: fix error checking for utxorpc tx output #1033

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

Merged
merged 1 commit into from
Jun 10, 2025
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ledger/alonzo/pparams_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,8 +29,8 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
"github.com/stretchr/testify/assert"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

func newBaseProtocolParams() alonzo.AlonzoProtocolParameters {
Expand Down Expand Up @@ -463,12 +463,15 @@ func TestAlonzoTransactionOutput_Utxorpc(t *testing.T) {
TxOutputDatumHash: &datumHash,
}

got := output.Utxorpc()
want := &utxorpc.TxOutput{
Address: address.Bytes(),
got, err := output.Utxorpc()
assert.NoError(t, err)
addr, err := address.Bytes()
assert.NoError(t, err)
want := &cardano.TxOutput{
Address: addr,
Coin: amount,
Assets: nil,
Datum: &utxorpc.Datum{
Datum: &cardano.Datum{
Hash: datumHash.Bytes(),
},
}
Expand Down
15 changes: 9 additions & 6 deletions ledger/babbage/pparams_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,8 +25,8 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/stretchr/testify/assert"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

func TestBabbageProtocolParamsUpdate(t *testing.T) {
Expand Down Expand Up @@ -581,11 +581,14 @@ func TestBabbageTransactionOutput_Utxorpc(t *testing.T) {
OutputAmount: mary.MaryTransactionOutputValue{Amount: amount},
}

got := output.Utxorpc()
want := &utxorpc.TxOutput{
Address: address.Bytes(),
got, err := output.Utxorpc()
assert.NoError(t, err)
addr, err := address.Bytes()
assert.NoError(t, err)
want := &cardano.TxOutput{
Address: addr,
Coin: amount,
Datum: &utxorpc.Datum{
Datum: &cardano.Datum{
Hash: make([]byte, 32),
},
}
Expand Down
30 changes: 24 additions & 6 deletions ledger/byron/byron_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package byron_test

import (
Expand All @@ -6,15 +20,16 @@ import (

"github.com/blinklabs-io/gouroboros/ledger/byron"
"github.com/blinklabs-io/gouroboros/ledger/common"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
"github.com/stretchr/testify/assert"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

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

got := input.Utxorpc()
want := &utxorpc.TxInput{
want := &cardano.TxInput{
TxHash: input.Id().Bytes(),
OutputIndex: input.Index(),
}
Expand All @@ -32,9 +47,12 @@ func TestByronTransactionOutput_Utxorpc(t *testing.T) {
OutputAmount: 5000,
}

got := output.Utxorpc()
want := &utxorpc.TxOutput{
Address: address.Bytes(),
got, err := output.Utxorpc()
assert.NoError(t, err)
addr, err := address.Bytes()
assert.NoError(t, err)
want := &cardano.TxOutput{
Address: addr,
Coin: output.OutputAmount,
}

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

// Validate it's not nil
if result == nil {
t.Fatal("ByronTransaction.Utxorpc() returned nil; expected empty utxorpc.Tx object")
t.Fatal("ByronTransaction.Utxorpc() returned nil; expected empty cardano.Tx object")
}

// Validate that it's the zero value
Expand Down
10 changes: 7 additions & 3 deletions ledger/mary/pparams_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/stretchr/testify/assert"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

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

got := output.Utxorpc()
got, err := output.Utxorpc()
assert.NoError(t, err)
addr, err := address.Bytes()
assert.NoError(t, err)
want := &cardano.TxOutput{
Address: address.Bytes(),
Address: addr,
Coin: amount,
}

Expand Down
Loading