// Copyright 2024 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 babbage

import (
	"math/big"
	"reflect"
	"testing"

	"github.com/blinklabs-io/gouroboros/cbor"
	"github.com/blinklabs-io/gouroboros/internal/test"
	"github.com/blinklabs-io/gouroboros/ledger/common"
	"github.com/blinklabs-io/gouroboros/ledger/mary"
	"github.com/blinklabs-io/plutigo/data"
	"github.com/stretchr/testify/assert"
)

func TestBabbageBlockTransactions(t *testing.T) {
	b := &BabbageBlock{}

	t.Run("empty", func(t *testing.T) {
		if lenTxs := len(b.Transactions()); lenTxs != 0 {
			t.Fatalf(
				"expected number of transactions is 0 but it was %d",
				lenTxs,
			)
		}
	})

	txsCount := 7
	b.TransactionBodies = make([]BabbageTransactionBody, txsCount)
	b.TransactionWitnessSets = make([]BabbageTransactionWitnessSet, txsCount)

	for i := range txsCount {
		b.TransactionBodies[i] = BabbageTransactionBody{
			TxTotalCollateral: 1 << i,
		}
		b.TransactionWitnessSets[i] = BabbageTransactionWitnessSet{
			VkeyWitnesses: []common.VkeyWitness{
				{
					Vkey:      append(make([]byte, 31), 1<<i)[:],
					Signature: append(make([]byte, 63), 1<<i)[:],
				},
			},
		}
	}

	t.Run("no invalid", func(t *testing.T) {
		txs := b.Transactions()

		if lenTxs := len(txs); lenTxs != txsCount {
			t.Fatalf(
				"expected number of transactions is %d but it was %d",
				txsCount,
				lenTxs,
			)
		}

		for i, tx := range txs {
			if btx := tx.(*BabbageTransaction); !btx.IsValid() {
				t.Fatalf(
					"expected transaction number %d IsValid is %v but is was %v",
					i,
					true,
					btx.IsValid(),
				)
			}
		}
	})

	t.Run("with invalid", func(t *testing.T) {
		b.InvalidTransactions = []uint{2, 4, 5}
		txs := b.Transactions()

		if lenTxs := len(txs); lenTxs != txsCount {
			t.Fatalf(
				"expected number of transactions is %d but it was %d",
				txsCount,
				lenTxs,
			)
		}

		for i, tx := range txs {
			expected := i != 2 && i != 4 && i != 5
			if btx := tx.(*BabbageTransaction); btx.IsValid() != expected {
				t.Fatalf(
					"expected transaction number %d IsValid is %v but is was %v",
					i,
					expected,
					btx.IsValid(),
				)
			}
		}
	})
}

func TestBabbageBlock_Utxorpc(t *testing.T) {
	// Define a full Babbage block for testing
	blockData := []byte{
		0x85,
		0x82,
		0x8a,
		0x1a,
		0x0,
		0x25,
		0x85,
		0x81,
		0x1a,
		0x3,
		0xe0,
		0x17,
		0x6,
		0x58,
		0x20,
		0xc6,
		0x81,
		0xf5,
		0xee,
		0xf5,
		0x6f,
		0xbf,
		0x5d,
		0x72,
		0xd,
		0xe4,
		0x8,
		0xb4,
		0x6,
		0xf9,
		0x31,
		0x95,
		0xba,
		0xde,
		0xc8,
		0xfe,
		0x8,
		0x45,
		0xc5,
		0x4b,
		0x96,
		0xa,
		0xac,
		0xde,
		0xb6,
		0x5c,
		0xb8,
		0x58,
		0x20,
		0x11,
		0xb4,
		0x23,
		0xbd,
		0x77,
		0x18,
		0x51,
		0x5c,
		0xdf,
		0x82,
		0xf1,
		0x83,
		0x2e,
		0x72,
		0x47,
		0xa7,
		0x30,
		0x8b,
		0x21,
		0xdd,
		0x88,
		0x9d,
		0x8a,
		0x48,
		0x5a,
		0x88,
		0x56,
		0xd2,
		0x91,
		0xac,
		0xc3,
		0xee,
		0x58,
		0x20,
		0x99,
		0x60,
		0x80,
		0xea,
		0x9a,
		0x46,
		0x76,
		0xe,
		0x2c,
		0x10,
		0xe2,
		0xd1,
		0x79,
		0x4,
		0x9b,
		0xf2,
		0x2f,
		0xe8,
		0x4f,
		0x8f,
		0x76,
		0xe8,
		0x8d,
		0xde,
		0x7e,
		0xfe,
		0xe8,
		0xdd,
		0x66,
		0xed,
		0xe8,
		0x4d,
		0x82,
		0x58,
		0x40,
		0x91,
		0x98,
		0x3d,
		0x82,
		0xda,
		0x70,
		0x88,
		0xb3,
		0x62,
		0x79,
		0xc,
		0xff,
		0x41,
		0xe6,
		0x82,
		0xb0,
		0xa,
		0x92,
		0x85,
		0x7f,
		0xef,
		0x85,
		0xe,
		0x66,
		0x5d,
		0xa4,
		0x4,
		0x4d,
		0xff,
		0xc7,
		0xbd,
		0x9b,
		0x13,
		0x96,
		0x54,
		0x42,
		0x57,
		0xe5,
		0xcb,
		0xe5,
		0x70,
		0x3c,
		0x9b,
		0x11,
		0xe,
		0xc1,
		0xe6,
		0xdf,
		0x95,
		0x12,
		0xc3,
		0xbc,
		0x7c,
		0xbd,
		0x72,
		0xd3,
		0x20,
		0x64,
		0xc7,
		0xc5,
		0x55,
		0xbb,
		0x66,
		0x5e,
		0x58,
		0x50,
		0x46,
		0xb0,
		0x98,
		0x3f,
		0x35,
		0x80,
		0xd1,
		0x51,
		0x1c,
		0x91,
		0x88,
		0xcf,
		0x3b,
		0x12,
		0xe7,
		0xc2,
		0xdb,
		0x3c,
		0x60,
		0x1f,
		0xae,
		0x7a,
		0x8d,
		0xc0,
		0x6d,
		0x1a,
		0x49,
		0xd6,
		0xd1,
		0x4f,
		0x6d,
		0x9f,
		0x73,
		0xa4,
		0x98,
		0x9a,
		0xc0,
		0xa0,
		0x66,
		0xe9,
		0xef,
		0xba,
		0xc9,
		0x9c,
		0xa8,
		0x20,
		0x62,
		0x52,
		0xe0,
		0xc7,
		0xd9,
		0xd2,
		0x84,
		0xe7,
		0x9c,
		0x26,
		0x6f,
		0x4d,
		0x16,
		0x3f,
		0x57,
		0x64,
		0xbb,
		0x91,
		0x3a,
		0x3a,
		0x7e,
		0x91,
		0x55,
		0xbe,
		0x84,
		0xb0,
		0xe7,
		0xf2,
		0xe6,
		0x56,
		0xb,
		0x14,
		0xcc,
		0x0,
		0x19,
		0x6,
		0xda,
		0x58,
		0x20,
		0xcd,
		0xc2,
		0x1a,
		0x79,
		0xcf,
		0xe,
		0xcb,
		0xed,
		0xee,
		0xad,
		0x83,
		0xa0,
		0x7c,
		0xf7,
		0xab,
		0xb5,
		0x87,
		0x4e,
		0x5f,
		0x93,
		0xdc,
		0x8f,
		0xab,
		0x9a,
		0x83,
		0x6b,
		0xd6,
		0x59,
		0x17,
		0x80,
		0x8a,
		0xcc,
		0x84,
		0x58,
		0x20,
		0x7e,
		0x1c,
		0x68,
		0xad,
		0x57,
		0xa0,
		0x7a,
		0x8e,
		0xc1,
		0x1c,
		0x67,
		0xc2,
		0x7b,
		0xc1,
		0xfd,
		0x42,
		0x34,
		0x25,
		0x46,
		0xc5,
		0x64,
		0xb8,
		0xb6,
		0x3,
		0x3d,
		0x75,
		0xf8,
		0xd,
		0x9d,
		0xd5,
		0xf,
		0x5a,
		0x0,
		0x19,
		0x1,
		0xd1,
		0x58,
		0x40,
		0x48,
		0xc9,
		0x36,
		0xb8,
		0xa1,
		0xe1,
		0x78,
		0x25,
		0xc7,
		0x30,
		0x2e,
		0x2c,
		0x38,
		0x3a,
		0xa6,
		0x99,
		0xf7,
		0x5c,
		0xc6,
		0xd5,
		0x24,
		0x5c,
		0x4b,
		0xa3,
		0xe2,
		0xd6,
		0xaa,
		0xa8,
		0x2,
		0x83,
		0xf7,
		0x95,
		0x84,
		0xac,
		0xcf,
		0x76,
		0x6c,
		0x9,
		0x4f,
		0x5,
		0x37,
		0xca,
		0x13,
		0x31,
		0x63,
		0xa7,
		0x22,
		0x73,
		0x13,
		0xc1,
		0xf2,
		0x8f,
		0xb,
		0xac,
		0x5c,
		0x93,
		0xdc,
		0x26,
		0x9,
		0xe6,
		0x25,
		0x15,
		0xf3,
		0xd,
		0x82,
		0x8,
		0x0,
		0x59,
		0x1,
		0xc0,
		0xa6,
		0xff,
		0xbb,
		0xa6,
		0xbd,
		0xa8,
		0xc7,
		0x7b,
		0xe9,
		0xed,
		0x62,
		0x76,
		0xf0,
		0x73,
		0x67,
		0x3d,
		0x13,
		0x83,
		0xf8,
		0x5,
		0x31,
		0x54,
		0x98,
		0xcb,
		0xd6,
		0x7c,
		0x36,
		0x2e,
		0x8e,
		0x2b,
		0xe4,
		0x13,
		0x5b,
		0x93,
		0x48,
		0x5f,
		0x8b,
		0xf5,
		0x6d,
		0xb6,
		0x56,
		0xe7,
		0x9e,
		0x48,
		0xc0,
		0xb0,
		0x43,
		0x78,
		0x6e,
		0xa5,
		0xde,
		0x4d,
		0xc6,
		0xa7,
		0xe6,
		0x1,
		0xc,
		0x84,
		0x4a,
		0xea,
		0x34,
		0x83,
		0x12,
		0xd,
		0xec,
		0xc,
		0x63,
		0xab,
		0xbe,
		0xbd,
		0x89,
		0x68,
		0x90,
		0x31,
		0xca,
		0x4c,
		0xa1,
		0x5c,
		0x9a,
		0x50,
		0xfe,
		0xb3,
		0x64,
		0x92,
		0xd,
		0xda,
		0x26,
		0x5a,
		0xb8,
		0xcc,
		0x88,
		0x32,
		0xd9,
		0xed,
		0x99,
		0xdc,
		0x4a,
		0xf7,
		0x21,
		0xe7,
		0x0,
		0xae,
		0x11,
		0x48,
		0xa4,
		0x1a,
		0xe0,
		0xaa,
		0xa0,
		0xae,
		0x26,
		0x4e,
		0x3a,
		0xa5,
		0xd7,
		0x16,
		0x1b,
		0x4b,
		0x98,
		0xd9,
		0xa7,
		0x32,
		0x86,
		0x76,
		0x13,
		0x63,
		0xc0,
		0x4d,
		0xd1,
		0x4a,
		0xf,
		0xca,
		0x69,
		0xce,
		0x56,
		0x2c,
		0x71,
		0x6d,
		0x7b,
		0x5,
		0x38,
		0x47,
		0x4f,
		0x11,
		0xeb,
		0x4e,
		0xc1,
		0xd9,
		0x17,
		0xef,
		0xa7,
		0x14,
		0xe9,
		0x4,
		0x64,
		0x4e,
		0xa8,
		0x7c,
		0xc8,
		0x44,
		0xc4,
		0xba,
		0xc4,
		0x76,
		0xe9,
		0xe3,
		0xe7,
		0x56,
		0x89,
		0x56,
		0xe3,
		0x37,
		0x19,
		0x21,
		0x6a,
		0xa0,
		0x3,
		0x8,
		0x46,
		0xd9,
		0xe8,
		0xa6,
		0xb,
		0xde,
		0xc2,
		0x6,
		0xdb,
		0x29,
		0x7,
		0xe3,
		0xb0,
		0x12,
		0x2a,
		0x4,
		0xfb,
		0xa8,
		0xf6,
		0x3f,
		0xc0,
		0x8b,
		0x3b,
		0xb2,
		0x95,
		0xdc,
		0x9f,
		0x45,
		0xdb,
		0xae,
		0xe,
		0x80,
		0xc1,
		0xac,
		0xb7,
		0x3a,
		0x62,
		0xb8,
		0x95,
		0x24,
		0xad,
		0xb0,
		0xa8,
		0x62,
		0x31,
		0x40,
		0x3a,
		0x1c,
		0x65,
		0x3,
		0xfc,
		0x8e,
		0x11,
		0xb2,
		0x9,
		0xe1,
		0x79,
		0x57,
		0x9a,
		0x13,
		0x23,
		0x61,
		0x89,
		0x1a,
		0x16,
		0x55,
		0x5f,
		0x7e,
		0x52,
		0xb9,
		0x8a,
		0x13,
		0xb3,
		0x99,
		0x59,
		0xdb,
		0x15,
		0xc9,
		0x28,
		0xf,
		0xc7,
		0xb,
		0xb5,
		0xdd,
		0xef,
		0x19,
		0xac,
		0x7c,
		0x78,
		0x6c,
		0x5d,
		0x46,
		0x1f,
		0x1d,
		0xdf,
		0xcf,
		0x88,
		0x3,
		0xc2,
		0x87,
		0x41,
		0xaa,
		0x16,
		0x13,
		0xee,
		0xd4,
		0xe9,
		0x5d,
		0x4f,
		0xd8,
		0xd7,
		0xd7,
		0x50,
		0x37,
		0x57,
		0x55,
		0x5,
		0x4f,
		0xe,
		0xf8,
		0xa,
		0xe6,
		0x23,
		0x1e,
		0x4f,
		0xff,
		0x93,
		0x45,
		0xe6,
		0x29,
		0x9b,
		0xf7,
		0x11,
		0xb7,
		0x9e,
		0xb4,
		0x8d,
		0x5c,
		0x52,
		0x15,
		0x95,
		0x6e,
		0xd,
		0x97,
		0x5b,
		0x6f,
		0xa3,
		0xed,
		0x3e,
		0xba,
		0x20,
		0x4b,
		0xf7,
		0x88,
		0xa,
		0x90,
		0x19,
		0x90,
		0xf4,
		0xbd,
		0x94,
		0xb4,
		0xc1,
		0xc7,
		0xea,
		0x9,
		0x10,
		0xeb,
		0xc3,
		0x85,
		0xc3,
		0xf6,
		0x46,
		0x60,
		0x65,
		0xbb,
		0x97,
		0x95,
		0xb3,
		0x5b,
		0x36,
		0xc8,
		0xf8,
		0xec,
		0x30,
		0x81,
		0x14,
		0x5c,
		0x4a,
		0xc4,
		0x8f,
		0x3,
		0x95,
		0x5c,
		0x8c,
		0x85,
		0xc7,
		0xb6,
		0x87,
		0xc6,
		0x78,
		0xe,
		0xa3,
		0xd7,
		0x2,
		0x1b,
		0xa8,
		0xcd,
		0x45,
		0xe2,
		0x81,
		0xc7,
		0x9c,
		0x39,
		0x12,
		0x6,
		0x28,
		0xcd,
		0x3b,
		0xc3,
		0x33,
		0x1d,
		0xe8,
		0x36,
		0xf5,
		0x41,
		0x6,
		0xb,
		0x2c,
		0xf4,
		0xd3,
		0xf0,
		0xe9,
		0x14,
		0xff,
		0x7f,
		0x11,
		0x3a,
		0xc9,
		0x1c,
		0x9a,
		0x67,
		0x64,
		0xf,
		0x51,
		0x2a,
		0x23,
		0x2c,
		0xd7,
		0xf8,
		0xb0,
		0xa9,
		0x11,
		0xaa,
		0x6e,
		0xb7,
		0x88,
		0xd7,
		0xd4,
		0x72,
		0x21,
		0x80,
		0xad,
		0x2c,
		0x88,
		0x71,
		0xf4,
		0x79,
		0x98,
		0x54,
		0x82,
		0xab,
		0x0,
		0x83,
		0x82,
		0x58,
		0x20,
		0xb2,
		0xac,
		0x90,
		0xf0,
		0x7f,
		0xe2,
		0xf2,
		0x33,
		0x34,
		0xff,
		0x81,
		0x61,
		0xbc,
		0x49,
		0xcc,
		0x70,
		0x0,
		0x38,
		0x59,
		0x9e,
		0xe5,
		0xa8,
		0x50,
		0x80,
		0x7a,
		0x37,
		0xab,
		0x88,
		0x13,
		0x1d,
		0x37,
		0x9b,
		0x1,
		0x82,
		0x58,
		0x20,
		0xd9,
		0xb1,
		0xd2,
		0x86,
		0xa2,
		0xa7,
		0x5f,
		0x6c,
		0x9b,
		0x87,
		0xc3,
		0xe8,
		0xb4,
		0x1a,
		0x16,
		0x22,
		0xc9,
		0x3b,
		0x6a,
		0xec,
		0x3a,
		0xe3,
		0xe6,
		0xef,
		0xf7,
		0x48,
		0x3c,
		0xbd,
		0xf1,
		0xd7,
		0x16,
		0x9d,
		0x0,
		0x82,
		0x58,
		0x20,
		0xd9,
		0xb1,
		0xd2,
		0x86,
		0xa2,
		0xa7,
		0x5f,
		0x6c,
		0x9b,
		0x87,
		0xc3,
		0xe8,
		0xb4,
		0x1a,
		0x16,
		0x22,
		0xc9,
		0x3b,
		0x6a,
		0xec,
		0x3a,
		0xe3,
		0xe6,
		0xef,
		0xf7,
		0x48,
		0x3c,
		0xbd,
		0xf1,
		0xd7,
		0x16,
		0x9d,
		0x1,
		0x1,
		0x83,
		0xa3,
		0x0,
		0x58,
		0x1d,
		0x70,
		0xf5,
		0x54,
		0x2f,
		0xa9,
		0xd9,
		0xc6,
		0x1b,
		0x4d,
		0xbc,
		0xcd,
		0x71,
		0x65,
		0x4c,
		0xc5,
		0xa7,
		0x2a,
		0x9f,
		0xdd,
		0xc9,
		0xd5,
		0x63,
		0xf5,
		0x3,
		0x68,
		0x2e,
		0x77,
		0x2e,
		0xc9,
		0x1,
		0x82,
		0x1a,
		0x0,
		0x1e,
		0x84,
		0x80,
		0xa1,
		0x58,
		0x1c,
		0x5e,
		0x4a,
		0x24,
		0x31,
		0xa4,
		0x65,
		0xa0,
		0xd,
		0xc5,
		0xd8,
		0x18,
		0x1a,
		0xaf,
		0xf6,
		0x39,
		0x59,
		0xbb,
		0x23,
		0x5d,
		0x97,
		0x1,
		0x3e,
		0x7a,
		0xcb,
		0x50,
		0xb5,
		0x5b,
		0xc4,
		0xa1,
		0x48,
		0x4e,
		0x6f,
		0x64,
		0x65,
		0x46,
		0x65,
		0x65,
		0x64,
		0x1,
		0x2,
		0x82,
		0x1,
		0xd8,
		0x18,
		0x58,
		0x3c,
		0xd8,
		0x7a,
		0x9f,
		0xd8,
		0x79,
		0x9f,
		0x58,
		0x1c,
		0xf6,
		0xf6,
		0x9e,
		0x5a,
		0xf3,
		0x7c,
		0x29,
		0x78,
		0xcb,
		0x21,
		0x24,
		0xc1,
		0x22,
		0x2,
		0xf2,
		0x18,
		0x5f,
		0xd5,
		0xc1,
		0x4e,
		0xe9,
		0x3b,
		0xb8,
		0x32,
		0x91,
		0x1d,
		0xaf,
		0x8e,
		0xd8,
		0x79,
		0x9f,
		0xd8,
		0x79,
		0x9f,
		0x1a,
		0x0,
		0x44,
		0x88,
		0x14,
		0x1b,
		0x0,
		0x0,
		0x1,
		0x90,
		0xa1,
		0xc1,
		0x62,
		0xfa,
		0xff,
		0xff,
		0xff,
		0xff,
		0x82,
		0x58,
		0x1d,
		0x60,
		0xf6,
		0xf6,
		0x9e,
		0x5a,
		0xf3,
		0x7c,
		0x29,
		0x78,
		0xcb,
		0x21,
		0x24,
		0xc1,
		0x22,
		0x2,
		0xf2,
		0x18,
		0x5f,
		0xd5,
		0xc1,
		0x4e,
		0xe9,
		0x3b,
		0xb8,
		0x32,
		0x91,
		0x1d,
		0xaf,
		0x8e,
		0x1a,
		0x0,
		0x89,
		0x54,
		0x40,
		0x82,
		0x58,
		0x1d,
		0x60,
		0xf6,
		0xf6,
		0x9e,
		0x5a,
		0xf3,
		0x7c,
		0x29,
		0x78,
		0xcb,
		0x21,
		0x24,
		0xc1,
		0x22,
		0x2,
		0xf2,
		0x18,
		0x5f,
		0xd5,
		0xc1,
		0x4e,
		0xe9,
		0x3b,
		0xb8,
		0x32,
		0x91,
		0x1d,
		0xaf,
		0x8e,
		0x1a,
		0x0,
		0x85,
		0x5,
		0xc8,
		0x2,
		0x1a,
		0x0,
		0x4,
		0x4e,
		0x78,
		0x3,
		0x1a,
		0x3,
		0xe0,
		0x17,
		0x22,
		0x8,
		0x1a,
		0x3,
		0xe0,
		0x16,
		0xaa,
		0xb,
		0x58,
		0x20,
		0x5f,
		0x65,
		0x8f,
		0xa6,
		0x99,
		0x4c,
		0xd9,
		0x15,
		0x7a,
		0x48,
		0x83,
		0x57,
		0x60,
		0xa4,
		0x42,
		0x1d,
		0xa6,
		0xfe,
		0xc5,
		0x94,
		0x0,
		0xf6,
		0x66,
		0xb3,
		0x43,
		0xe1,
		0x14,
		0x28,
		0x3f,
		0x45,
		0x4e,
		0xea,
		0xd,
		0x81,
		0x82,
		0x58,
		0x20,
		0xd9,
		0xb1,
		0xd2,
		0x86,
		0xa2,
		0xa7,
		0x5f,
		0x6c,
		0x9b,
		0x87,
		0xc3,
		0xe8,
		0xb4,
		0x1a,
		0x16,
		0x22,
		0xc9,
		0x3b,
		0x6a,
		0xec,
		0x3a,
		0xe3,
		0xe6,
		0xef,
		0xf7,
		0x48,
		0x3c,
		0xbd,
		0xf1,
		0xd7,
		0x16,
		0x9d,
		0x1,
		0xe,
		0x81,
		0x58,
		0x1c,
		0xf6,
		0xf6,
		0x9e,
		0x5a,
		0xf3,
		0x7c,
		0x29,
		0x78,
		0xcb,
		0x21,
		0x24,
		0xc1,
		0x22,
		0x2,
		0xf2,
		0x18,
		0x5f,
		0xd5,
		0xc1,
		0x4e,
		0xe9,
		0x3b,
		0xb8,
		0x32,
		0x91,
		0x1d,
		0xaf,
		0x8e,
		0x10,
		0x82,
		0x58,
		0x1d,
		0x60,
		0xf6,
		0xf6,
		0x9e,
		0x5a,
		0xf3,
		0x7c,
		0x29,
		0x78,
		0xcb,
		0x21,
		0x24,
		0xc1,
		0x22,
		0x2,
		0xf2,
		0x18,
		0x5f,
		0xd5,
		0xc1,
		0x4e,
		0xe9,
		0x3b,
		0xb8,
		0x32,
		0x91,
		0x1d,
		0xaf,
		0x8e,
		0x1a,
		0x0,
		0x52,
		0x48,
		0x1,
		0x11,
		0x1a,
		0x0,
		0x37,
		0xc,
		0x3f,
		0x12,
		0x81,
		0x82,
		0x58,
		0x20,
		0x4b,
		0x61,
		0xac,
		0xed,
		0xca,
		0x64,
		0x26,
		0xec,
		0x98,
		0x9e,
		0xf7,
		0x8a,
		0x85,
		0xed,
		0x97,
		0xa8,
		0xb4,
		0xff,
		0xd4,
		0x7d,
		0x9c,
		0x40,
		0xd4,
		0x15,
		0x5e,
		0x45,
		0x3d,
		0x7e,
		0x6b,
		0x25,
		0xae,
		0x58,
		0x0,
		0xaa,
		0x0,
		0x82,
		0x82,
		0x58,
		0x20,
		0xe7,
		0xd2,
		0xe1,
		0xcd,
		0x4e,
		0xae,
		0xd6,
		0x4d,
		0x92,
		0xe8,
		0x4a,
		0x30,
		0x3f,
		0x3f,
		0x3d,
		0x1f,
		0xd0,
		0x84,
		0xeb,
		0x7c,
		0xaa,
		0x92,
		0x75,
		0x53,
		0xfc,
		0x58,
		0xd7,
		0xcd,
		0xfd,
		0x14,
		0xd5,
		0xac,
		0x0,
		0x82,
		0x58,
		0x20,
		0x9a,
		0xbb,
		0x6a,
		0xd3,
		0x51,
		0x2f,
		0x70,
		0x86,
		0x5,
		0x6c,
		0x85,
		0x68,
		0xb8,
		0x11,
		0x1f,
		0x12,
		0x25,
		0x45,
		0x9c,
		0x45,
		0xe,
		0x93,
		0x29,
		0x9d,
		0x76,
		0x7e,
		0xc5,
		0x26,
		0xcd,
		0x15,
		0x41,
		0x90,
		0x4,
		0x1,
		0x81,
		0x82,
		0x58,
		0x1d,
		0x60,
		0xbd,
		0x72,
		0xb8,
		0xc9,
		0x3f,
		0x8d,
		0x9b,
		0x99,
		0x5c,
		0x33,
		0x81,
		0x93,
		0x6f,
		0xbc,
		0x51,
		0x66,
		0xba,
		0x44,
		0xba,
		0xe6,
		0x85,
		0xc5,
		0x66,
		0x4f,
		0xb2,
		0x2c,
		0x40,
		0x1c,
		0x1b,
		0x0,
		0x0,
		0x0,
		0x1,
		0x5a,
		0xc5,
		0xf6,
		0xfa,
		0x2,
		0x1a,
		0x0,
		0x3,
		0x2e,
		0x4b,
		0x3,
		0x1a,
		0x3,
		0xe0,
		0x17,
		0xbe,
		0x9,
		0xa1,
		0x58,
		0x1c,
		0xc0,
		0xce,
		0x2e,
		0x57,
		0x2,
		0x99,
		0xf8,
		0xb7,
		0xc9,
		0xee,
		0xa9,
		0x89,
		0x9e,
		0x7e,
		0xe3,
		0x13,
		0x94,
		0xf2,
		0xc6,
		0x46,
		0xdf,
		0x5f,
		0x37,
		0x27,
		0x77,
		0x4d,
		0x8a,
		0x19,
		0xa1,
		0x4d,
		0x4d,
		0x79,
		0x4d,
		0x69,
		0x6e,
		0x74,
		0x65,
		0x64,
		0x54,
		0x6f,
		0x6b,
		0x65,
		0x6e,
		0x20,
		0xb,
		0x58,
		0x20,
		0xf0,
		0x58,
		0x34,
		0x13,
		0x70,
		0x8b,
		0x5c,
		0xfa,
		0xe9,
		0x80,
		0x31,
		0x53,
		0xb9,
		0xfd,
		0x86,
		0x14,
		0x1f,
		0xb0,
		0x90,
		0xcf,
		0xc4,
		0x26,
		0x71,
		0x96,
		0xaf,
		0x7e,
		0x22,
		0xa5,
		0x10,
		0x71,
		0x13,
		0xe6,
		0xd,
		0x81,
		0x82,
		0x58,
		0x20,
		0xa2,
		0xc8,
		0xfb,
		0x2d,
		0x6c,
		0x72,
		0x71,
		0x97,
		0xb,
		0xb2,
		0x97,
		0x90,
		0x67,
		0x4d,
		0x2a,
		0x11,
		0xc,
		0x46,
		0x64,
		0x89,
		0xfb,
		0x41,
		0x59,
		0x4,
		0x6f,
		0x64,
		0x5a,
		0x82,
		0x6a,
		0x90,
		0x2d,
		0x4d,
		0x2,
		0xe,
		0x81,
		0x58,
		0x1c,
		0xbd,
		0x72,
		0xb8,
		0xc9,
		0x3f,
		0x8d,
		0x9b,
		0x99,
		0x5c,
		0x33,
		0x81,
		0x93,
		0x6f,
		0xbc,
		0x51,
		0x66,
		0xba,
		0x44,
		0xba,
		0xe6,
		0x85,
		0xc5,
		0x66,
		0x4f,
		0xb2,
		0x2c,
		0x40,
		0x1c,
		0x10,
		0x82,
		0x58,
		0x1d,
		0x60,
		0xbd,
		0x72,
		0xb8,
		0xc9,
		0x3f,
		0x8d,
		0x9b,
		0x99,
		0x5c,
		0x33,
		0x81,
		0x93,
		0x6f,
		0xbc,
		0x51,
		0x66,
		0xba,
		0x44,
		0xba,
		0xe6,
		0x85,
		0xc5,
		0x66,
		0x4f,
		0xb2,
		0x2c,
		0x40,
		0x1c,
		0x1b,
		0x0,
		0x0,
		0x0,
		0x2,
		0x44,
		0x0,
		0xe2,
		0xff,
		0x11,
		0x1a,
		0x0,
		0x4,
		0xc5,
		0x71,
		0x82,
		0xa2,
		0x0,
		0x81,
		0x82,
		0x58,
		0x20,
		0x70,
		0x8e,
		0x3d,
		0x6a,
		0xf5,
		0x41,
		0x86,
		0xc7,
		0x89,
		0x25,
		0x49,
		0x2c,
		0x20,
		0xb7,
		0xe7,
		0xa6,
		0xaf,
		0x5a,
		0xa1,
		0xd9,
		0x82,
		0xe3,
		0x3,
		0x1d,
		0xac,
		0xc6,
		0xfc,
		0x8e,
		0x38,
		0xf4,
		0xd5,
		0x2,
		0x58,
		0x40,
		0x34,
		0x1b,
		0xb7,
		0xc8,
		0x94,
		0xa2,
		0x86,
		0x29,
		0x13,
		0xe1,
		0xad,
		0x4,
		0x8e,
		0x82,
		0x96,
		0x36,
		0x5b,
		0x6c,
		0xa,
		0x36,
		0x58,
		0x9a,
		0xf1,
		0x6a,
		0x5e,
		0x1,
		0xbc,
		0x51,
		0x98,
		0xcb,
		0xc3,
		0x38,
		0xf7,
		0xe,
		0x5,
		0x2c,
		0x1c,
		0x69,
		0xee,
		0xdf,
		0x63,
		0x38,
		0x4,
		0x4b,
		0xca,
		0x40,
		0x75,
		0xd0,
		0x87,
		0xa1,
		0x7e,
		0x46,
		0xd7,
		0x4a,
		0x57,
		0x9d,
		0x1d,
		0xe8,
		0x3c,
		0xc3,
		0xfa,
		0x57,
		0x31,
		0x2,
		0x5,
		0x81,
		0x84,
		0x0,
		0x1,
		0xd8,
		0x79,
		0x80,
		0x82,
		0x1a,
		0x0,
		0x12,
		0xc2,
		0xf4,
		0x1a,
		0x15,
		0xf4,
		0xbf,
		0xf0,
		0xa3,
		0x0,
		0x81,
		0x82,
		0x58,
		0x20,
		0xe0,
		0xfb,
		0x85,
		0x85,
		0xf1,
		0x1,
		0xb2,
		0x57,
		0x12,
		0x36,
		0x44,
		0xd7,
		0x64,
		0x7f,
		0xdb,
		0x45,
		0x36,
		0x74,
		0xa4,
		0xd8,
		0xe,
		0xe3,
		0xd7,
		0xb3,
		0xdd,
		0xb9,
		0x5a,
		0xba,
		0x89,
		0xfa,
		0x50,
		0x56,
		0x58,
		0x40,
		0xeb,
		0xa3,
		0x38,
		0xe8,
		0xe8,
		0x5,
		0x56,
		0x1e,
		0x45,
		0xd3,
		0xc5,
		0x30,
		0x34,
		0x9f,
		0x3f,
		0xc3,
		0xaa,
		0xe1,
		0xb2,
		0x40,
		0x20,
		0xea,
		0xc1,
		0x32,
		0xa1,
		0xdf,
		0x6c,
		0xbe,
		0x7b,
		0xe6,
		0x94,
		0xdc,
		0x26,
		0x87,
		0xb6,
		0xca,
		0xff,
		0x33,
		0xb3,
		0x44,
		0xd8,
		0x51,
		0x2f,
		0xcb,
		0x25,
		0x36,
		0xb1,
		0xf0,
		0x74,
		0x13,
		0xc0,
		0xc,
		0x1e,
		0x10,
		0x6,
		0x88,
		0xa0,
		0xc8,
		0x75,
		0x2f,
		0x1f,
		0x57,
		0xdf,
		0x3,
		0x5,
		0x81,
		0x84,
		0x1,
		0x0,
		0xd8,
		0x79,
		0x80,
		0x82,
		0x19,
		0xf1,
		0xaa,
		0x1a,
		0x1,
		0x50,
		0xfa,
		0xde,
		0x6,
		0x81,
		0x59,
		0x2,
		0x75,
		0x59,
		0x2,
		0x72,
		0x1,
		0x0,
		0x0,
		0x33,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x23,
		0x22,
		0x32,
		0x22,
		0x53,
		0x33,
		0x0,
		0xb3,
		0x25,
		0x33,
		0x30,
		0xc,
		0x33,
		0x70,
		0xe9,
		0x0,
		0x1,
		0x80,
		0x58,
		0x0,
		0x89,
		0x91,
		0x91,
		0x92,
		0x99,
		0x98,
		0x7,
		0x99,
		0x19,
		0x80,
		0x8,
		0x0,
		0x80,
		0x11,
		0x12,
		0x99,
		0x98,
		0xa,
		0x80,
		0x8,
		0xa5,
		0x1,
		0x32,
		0x32,
		0x32,
		0x32,
		0x32,
		0x53,
		0x33,
		0x1,
		0x63,
		0x37,
		0x10,
		0x90,
		0x0,
		0x0,
		0x10,
		0xa5,
		0x11,
		0x0,
		0x13,
		0x30,
		0x6,
		0x0,
		0x60,
		0x3,
		0x37,
		0x5a,
		0x60,
		0x2e,
		0x0,
		0x66,
		0xeb,
		0x8c,
		0x5,
		0x40,
		0x8,
		0xc0,
		0x64,
		0x0,
		0x8c,
		0x5,
		0xc0,
		0x4,
		0x54,
		0xcc,
		0xc0,
		0x3c,
		0xcc,
		0x88,
		0xcc,
		0x88,
		0xc8,
		0xcc,
		0x0,
		0x40,
		0x4,
		0x0,
		0xc8,
		0x94,
		0xcc,
		0xc0,
		0x64,
		0x0,
		0x45,
		0x28,
		0x9,
		0x91,
		0x92,
		0x99,
		0x98,
		0xb,
		0x99,
		0xb8,
		0xf0,
		0x2,
		0x0,
		0x51,
		0x4a,
		0x22,
		0x66,
		0x0,
		0x80,
		0x8,
		0x0,
		0x26,
		0x3,
		0xa0,
		0x4,
		0x6e,
		0xb8,
		0xc0,
		0x6c,
		0x0,
		0x4d,
		0xd6,
		0x19,
		0x80,
		0x69,
		0x80,
		0x78,
		0x1,
		0x24,
		0x2,
		0x0,
		0x2,
		0x66,
		0x1,
		0x66,
		0x1,
		0xa0,
		0xa,
		0x90,
		0x0,
		0x0,
		0x48,
		0x99,
		0x91,
		0x19,
		0x19,
		0x29,
		0x99,
		0x80,
		0x99,
		0x9b,
		0x87,
		0x48,
		0x0,
		0x80,
		0x4,
		0x4c,
		0x8c,
		0x8c,
		0xdc,
		0x48,
		0x0,
		0x80,
		0x29,
		0xba,
		0xd3,
		0x1,
		0xa0,
		0x1,
		0x30,
		0x11,
		0x0,
		0x21,
		0x4a,
		0x6,
		0x2,
		0x20,
		0x2,
		0x66,
		0x1,
		0xa6,
		0x1,
		0xe6,
		0x60,
		0x1a,
		0x60,
		0x1e,
		0x0,
		0x49,
		0x0,
		0x12,
		0x40,
		0x0,
		0x66,
		0x1,
		0x66,
		0x1,
		0xa6,
		0x60,
		0x16,
		0x60,
		0x1a,
		0x0,
		0xa9,
		0x0,
		0x2,
		0x40,
		0x1c,
		0x0,
		0xe2,
		0x94,
		0x5,
		0x28,
		0x99,
		0x91,
		0x19,
		0x19,
		0x29,
		0x99,
		0x80,
		0x91,
		0x9b,
		0x87,
		0x48,
		0x0,
		0x80,
		0x4,
		0x52,
		0xf5,
		0xbd,
		0xed,
		0x8c,
		0x2,
		0x64,
		0x6e,
		0xac,
		0xc0,
		0x64,
		0x0,
		0x4c,
		0x4,
		0x0,
		0x8,
		0xc0,
		0x40,
		0x0,
		0x4c,
		0x8c,
		0xc0,
		0x4,
		0x0,
		0x40,
		0xc,
		0x89,
		0x4c,
		0xcc,
		0x5,
		0x80,
		0x4,
		0x53,
		0x1,
		0x3,
		0xd8,
		0x7a,
		0x80,
		0x0,
		0x13,
		0x23,
		0x23,
		0x23,
		0x25,
		0x33,
		0x30,
		0x16,
		0x33,
		0x71,
		0xe0,
		0xe,
		0x0,
		0x42,
		0x66,
		0xe9,
		0x52,
		0x0,
		0x3,
		0x30,
		0x1b,
		0x37,
		0x4c,
		0x0,
		0x29,
		0x7a,
		0xe0,
		0x13,
		0x30,
		0x6,
		0x0,
		0x60,
		0x3,
		0x37,
		0x56,
		0x60,
		0x30,
		0x0,
		0x66,
		0xeb,
		0x8c,
		0x5,
		0x80,
		0x8,
		0xc0,
		0x68,
		0x0,
		0x8c,
		0x6,
		0x0,
		0x4,
		0xc8,
		0xc8,
		0xcc,
		0x0,
		0x40,
		0x4,
		0x0,
		0x88,
		0x94,
		0xcc,
		0xc0,
		0x54,
		0x0,
		0x45,
		0x2f,
		0x5b,
		0xde,
		0xd8,
		0xc0,
		0x26,
		0x46,
		0x46,
		0x46,
		0x4a,
		0x66,
		0x60,
		0x2a,
		0x66,
		0xe3,
		0xd2,
		0x21,
		0x0,
		0x0,
		0x21,
		0x0,
		0x31,
		0x33,
		0x1,
		0xa3,
		0x37,
		0x60,
		0x6e,
		0xa4,
		0x0,
		0x8d,
		0xd3,
		0x0,
		0x9,
		0x98,
		0x3,
		0x0,
		0x30,
		0x1,
		0x9b,
		0xab,
		0x30,
		0x17,
		0x0,
		0x33,
		0x75,
		0xc6,
		0x2,
		0xa0,
		0x4,
		0x60,
		0x32,
		0x0,
		0x46,
		0x2,
		0xe0,
		0x2,
		0x6e,
		0xac,
		0xcc,
		0x2,
		0x8c,
		0x3,
		0xc,
		0xc0,
		0x28,
		0xc0,
		0x30,
		0x1,
		0x12,
		0x0,
		0x4,
		0x80,
		0x20,
		0x0,
		0x4d,
		0xd7,
		0x18,
		0x9,
		0x80,
		0x9,
		0x80,
		0x50,
		0x0,
		0x8a,
		0x99,
		0x80,
		0x6a,
		0x49,
		0x2a,
		0x45,
		0x78,
		0x70,
		0x65,
		0x63,
		0x74,
		0x65,
		0x64,
		0x20,
		0x6f,
		0x6e,
		0x20,
		0x69,
		0x6e,
		0x63,
		0x6f,
		0x72,
		0x72,
		0x65,
		0x63,
		0x74,
		0x20,
		0x63,
		0x6f,
		0x6e,
		0x73,
		0x74,
		0x72,
		0x75,
		0x63,
		0x74,
		0x6f,
		0x72,
		0x20,
		0x76,
		0x61,
		0x72,
		0x69,
		0x61,
		0x6e,
		0x74,
		0x2e,
		0x0,
		0x16,
		0x33,
		0x0,
		0x73,
		0x0,
		0x90,
		0x1,
		0x48,
		0x0,
		0x85,
		0x26,
		0x16,
		0x37,
		0x5a,
		0x0,
		0x26,
		0xeb,
		0x80,
		0x4,
		0xcc,
		0x0,
		0x40,
		0x5,
		0x20,
		0x0,
		0x22,
		0x22,
		0x33,
		0x33,
		0x0,
		0x73,
		0x37,
		0xe,
		0x0,
		0x20,
		0x6,
		0x1,
		0xa4,
		0x66,
		0x66,
		0x0,
		0xa0,
		0xa,
		0x66,
		0xe0,
		0x0,
		0x11,
		0x20,
		0x2,
		0x30,
		0xf,
		0x0,
		0x10,
		0x2,
		0x0,
		0x22,
		0x30,
		0x6,
		0x37,
		0x54,
		0x0,
		0x24,
		0x60,
		0x8,
		0x6e,
		0xa8,
		0x0,
		0x55,
		0xcd,
		0x2b,
		0x9c,
		0x55,
		0x73,
		0xaa,
		0xae,
		0x79,
		0x55,
		0xcf,
		0xab,
		0xa0,
		0x57,
		0x42,
		0xae,
		0x89,
		0x30,
		0x1,
		0x1e,
		0x58,
		0x1c,
		0xbd,
		0x72,
		0xb8,
		0xc9,
		0x3f,
		0x8d,
		0x9b,
		0x99,
		0x5c,
		0x33,
		0x81,
		0x93,
		0x6f,
		0xbc,
		0x51,
		0x66,
		0xba,
		0x44,
		0xba,
		0xe6,
		0x85,
		0xc5,
		0x66,
		0x4f,
		0xb2,
		0x2c,
		0x40,
		0x1c,
		0x0,
		0x4c,
		0x1,
		0x9,
		0x1b,
		0x0,
		0x0,
		0x1,
		0x97,
		0xf9,
		0x2c,
		0x5a,
		0x78,
		0x0,
		0x1,
		0xa0,
		0x80,
	}

	// Decode the CBOR data to create a BabbageBlock
	babbageBlock := &BabbageBlock{}
	err := babbageBlock.UnmarshalCBOR(blockData)
	assert.NoError(t, err)

	// Ensure the block is correctly unmarshaled
	assert.NotNil(t, babbageBlock)
	assert.NotNil(t, babbageBlock.Header)
	assert.NotNil(t, babbageBlock.TransactionBodies)
	assert.NotNil(t, babbageBlock.TransactionWitnessSets)

	utxoBlock, err := babbageBlock.Utxorpc()
	if err != nil {
		t.Fatalf("Utxorpc() failed: %v", err)
	}

	// Validate the resulting utxorpc.Block
	assert.NotNil(t, utxoBlock)
	assert.NotNil(t, utxoBlock.Header)
	assert.NotNil(t, utxoBlock.Body)
	assert.Equal(t, len(babbageBlock.TransactionBodies), len(utxoBlock.Body.Tx))

	// Validate the header details
	assert.Equal(t, babbageBlock.Hash().Bytes(), utxoBlock.Header.Hash)
	assert.Equal(t, babbageBlock.BlockNumber(), utxoBlock.Header.Height)
	assert.Equal(t, babbageBlock.SlotNumber(), utxoBlock.Header.Slot)

	// Validate transactions
	for i, tx := range utxoBlock.Body.Tx {
		assert.NotNil(t, tx)
		assert.Equal(
			t,
			len(babbageBlock.TransactionBodies[i].Inputs()),
			len(tx.Inputs),
		)
		assert.Equal(
			t,
			len(babbageBlock.TransactionBodies[i].Outputs()),
			len(tx.Outputs),
		)
	}
}

type TxOutput struct {
	Address   []byte
	Coin      uint64
	DatumHash []byte
}

func TestBabbageTransactionOutput_Utxorpc_DatumOptionNil(t *testing.T) {
	output := BabbageTransactionOutput{
		OutputAddress: common.Address{},
		OutputAmount: mary.MaryTransactionOutputValue{
			Amount: 1000,
		},
		DatumOption: &BabbageTransactionOutputDatumOption{},
	}

	txOutput, err := output.Utxorpc()
	if err != nil {
		t.Fatalf("Utxorpc() failed: %v", err) // Fail and stop the test
	}

	assert.NotNil(t, txOutput)
	assert.Equal(t, []byte{}, txOutput.Datum.Hash)
	assert.Equal(t, []byte{0x0}, txOutput.Address)
	assert.Equal(t, uint64(1000), txOutput.Coin)
}

func TestBabbageTransactionOutput_DatumHashReturnsNil(t *testing.T) {
	output := BabbageTransactionOutput{
		OutputAddress: common.Address{},
		OutputAmount: mary.MaryTransactionOutputValue{
			Amount: 1000,
		},
		DatumOption: &BabbageTransactionOutputDatumOption{},
	}

	datumHash := output.DatumHash()

	assert.Nil(t, datumHash)
}

func TestBabbageTransactionOutputToPlutusDataCoinOnly(t *testing.T) {
	testAddr := "addr_test1vqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygxrcya6"
	var testAmount uint64 = 123_456_789
	testTxOut := BabbageTransactionOutput{
		OutputAddress: func() common.Address { foo, _ := common.NewAddress(testAddr); return foo }(),
		OutputAmount: mary.MaryTransactionOutputValue{
			Amount: testAmount,
		},
	}
	expectedData := data.NewConstr(
		0,
		// Address
		data.NewConstr(
			0,
			data.NewConstr(
				0,
				data.NewByteString(
					[]byte{
						0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
					},
				),
			),
			data.NewConstr(
				1,
			),
		),
		// Value
		data.NewMap(
			[][2]data.PlutusData{
				{
					data.NewByteString(nil),
					data.NewMap(
						[][2]data.PlutusData{
							{
								data.NewByteString(nil),
								data.NewInteger(big.NewInt(int64(testAmount))),
							},
						},
					),
				},
			},
		),
		// TODO: empty datum option
		data.NewConstr(0),
		// TODO: empty script ref
		data.NewConstr(1),
	)
	tmpData := testTxOut.ToPlutusData()
	if !reflect.DeepEqual(tmpData, expectedData) {
		t.Fatalf(
			"did not get expected PlutusData\n     got: %#v\n  wanted: %#v",
			tmpData,
			expectedData,
		)
	}
}

func TestBabbageTransactionOutputToPlutusDataCoinAssets(t *testing.T) {
	testAddr := "addr_test1vqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygxrcya6"
	var testAmount uint64 = 123_456_789
	testAssets := common.NewMultiAsset[common.MultiAssetTypeOutput](
		map[common.Blake2b224]map[cbor.ByteString]common.MultiAssetTypeOutput{
			common.NewBlake2b224(test.DecodeHexString("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61")): {
				cbor.NewByteString(test.DecodeHexString("6675726e697368613239686e")): 123456,
			},
			common.NewBlake2b224(test.DecodeHexString("eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5")): {
				cbor.NewByteString(test.DecodeHexString("426f7764757261436f6e63657074733638")): 234567,
			},
		},
	)
	testTxOut := BabbageTransactionOutput{
		OutputAddress: func() common.Address { foo, _ := common.NewAddress(testAddr); return foo }(),
		OutputAmount: mary.MaryTransactionOutputValue{
			Amount: testAmount,
			Assets: &testAssets,
		},
	}
	expectedData := data.NewConstr(
		0,
		// Address
		data.NewConstr(
			0,
			data.NewConstr(
				0,
				data.NewByteString(
					[]byte{
						0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
					},
				),
			),
			data.NewConstr(
				1,
			),
		),
		// Value
		data.NewMap(
			[][2]data.PlutusData{
				{
					data.NewByteString(nil),
					data.NewMap(
						[][2]data.PlutusData{
							{
								data.NewByteString(nil),
								data.NewInteger(big.NewInt(int64(testAmount))),
							},
						},
					),
				},
				{
					data.NewByteString(
						test.DecodeHexString(
							"29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61",
						),
					),
					data.NewMap(
						[][2]data.PlutusData{
							{
								data.NewByteString(
									test.DecodeHexString(
										"6675726e697368613239686e",
									),
								),
								data.NewInteger(big.NewInt(123456)),
							},
						},
					),
				},
				{
					data.NewByteString(
						test.DecodeHexString(
							"eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5",
						),
					),
					data.NewMap(
						[][2]data.PlutusData{
							{
								data.NewByteString(
									test.DecodeHexString(
										"426f7764757261436f6e63657074733638",
									),
								),
								data.NewInteger(big.NewInt(234567)),
							},
						},
					),
				},
			},
		),
		// Empty datum option
		data.NewConstr(0),
		// Empty script ref
		data.NewConstr(1),
	)
	tmpData := testTxOut.ToPlutusData()
	if !reflect.DeepEqual(tmpData, expectedData) {
		t.Fatalf(
			"did not get expected PlutusData\n     got: %#v\n  wanted: %#v",
			tmpData,
			expectedData,
		)
	}
}

func TestBabbageTransactionOutputString(t *testing.T) {
	addrStr := "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd"
	addr, _ := common.NewAddress(addrStr)
	ma := common.NewMultiAsset[common.MultiAssetTypeOutput](
		map[common.Blake2b224]map[cbor.ByteString]uint64{
			common.NewBlake2b224(make([]byte, 28)): {
				cbor.NewByteString([]byte("x")): 2,
			},
		},
	)
	out := BabbageTransactionOutput{
		OutputAddress: addr,
		OutputAmount: mary.MaryTransactionOutputValue{
			Amount: 456,
			Assets: &ma,
		},
	}
	s := out.String()
	expected := "(BabbageTransactionOutput address=" + addrStr + " amount=456 assets=" + ma.String() + ")"
	if s != expected {
		t.Fatalf("unexpected string: %s", s)
	}
}
