From 9832ec7d5df95cb85050296f71774a6bb38867c1 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Tue, 10 Jun 2025 09:58:52 -0400 Subject: [PATCH] test: fix error checking for utxorpc tx output Signed-off-by: Chris Gianelloni --- ledger/alonzo/pparams_test.go | 17 ++++++++++------- ledger/babbage/pparams_test.go | 15 +++++++++------ ledger/byron/byron_test.go | 30 ++++++++++++++++++++++++------ ledger/mary/pparams_test.go | 10 +++++++--- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/ledger/alonzo/pparams_test.go b/ledger/alonzo/pparams_test.go index 0726f72e..220e4bdb 100644 --- a/ledger/alonzo/pparams_test.go +++ b/ledger/alonzo/pparams_test.go @@ -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. @@ -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 { @@ -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(), }, } diff --git a/ledger/babbage/pparams_test.go b/ledger/babbage/pparams_test.go index c772a163..6015f83b 100644 --- a/ledger/babbage/pparams_test.go +++ b/ledger/babbage/pparams_test.go @@ -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. @@ -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) { @@ -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), }, } diff --git a/ledger/byron/byron_test.go b/ledger/byron/byron_test.go index 51e0f967..f801becd 100644 --- a/ledger/byron/byron_test.go +++ b/ledger/byron/byron_test.go @@ -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 ( @@ -6,7 +20,8 @@ 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() @@ -14,7 +29,7 @@ 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(), } @@ -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, } @@ -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 diff --git a/ledger/mary/pparams_test.go b/ledger/mary/pparams_test.go index 327c0b76..99df823f 100644 --- a/ledger/mary/pparams_test.go +++ b/ledger/mary/pparams_test.go @@ -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. @@ -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" ) @@ -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, }