Skip to content
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
8 changes: 0 additions & 8 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ type TransactionWitnessRedeemers interface {
Iter() iter.Seq2[RedeemerKey, RedeemerValue]
}

// TxReference provides a reference to a transaction which includes a hash of the full transaction
// body bytes and the total transaction size in bytes
type TxReference struct {
cbor.StructAsArray
TxHash Blake2b256
TxSize uint16
}

type Utxo struct {
cbor.StructAsArray
Id TransactionInput
Expand Down
2 changes: 1 addition & 1 deletion ledger/leios/leios.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type LeiosEndorserBlock struct {
cbor.StructAsArray
hash *common.Blake2b256
transactions []common.Transaction
TxReferences []common.TxReference
TxReferences map[common.Blake2b256]uint16
}

func (h *LeiosBlockHeader) UnmarshalCBOR(cborData []byte) error {
Expand Down
200 changes: 200 additions & 0 deletions ledger/leios/leios_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// 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 leios

import (
"testing"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/babbage"
"github.com/blinklabs-io/gouroboros/ledger/common"
)

func TestLeiosEra(t *testing.T) {
if EraLeios.Id != EraIdLeios {
t.Errorf(
"Era ID mismatch: expected %d, got %d",
EraIdLeios,
EraLeios.Id,
)
}
if EraLeios.Name != EraNameLeios {
t.Errorf(
"Era name mismatch: expected %s, got %s",
EraNameLeios,
EraLeios.Name,
)
}
}

func TestLeiosBlockTypes(t *testing.T) {
if BlockTypeLeiosRanking != 8 {
t.Errorf(
"BlockTypeLeiosRanking mismatch: expected 8, got %d",
BlockTypeLeiosRanking,
)
}
if BlockTypeLeiosEndorser != 9 {
t.Errorf(
"BlockTypeLeiosEndorser mismatch: expected 9, got %d",
BlockTypeLeiosEndorser,
)
}
if BlockHeaderTypeLeios != 7 {
t.Errorf(
"BlockHeaderTypeLeios mismatch: expected 7, got %d",
BlockHeaderTypeLeios,
)
}
if TxTypeLeios != 7 {
t.Errorf("TxTypeLeios mismatch: expected 7, got %d", TxTypeLeios)
}
}

func TestLeiosEndorserBlock_Type(t *testing.T) {
block := &LeiosEndorserBlock{}
if block.Type() != BlockTypeLeiosEndorser {
t.Errorf(
"LeiosEndorserBlock.Type() mismatch: expected %d, got %d",
BlockTypeLeiosEndorser,
block.Type(),
)
}
}

func TestLeiosRankingBlock_Type(t *testing.T) {
block := &LeiosRankingBlock{}
if block.Type() != BlockTypeLeiosRanking {
t.Errorf(
"LeiosRankingBlock.Type() mismatch: expected %d, got %d",
BlockTypeLeiosRanking,
block.Type(),
)
}
}

func TestLeiosBlockHeader_Era(t *testing.T) {
header := &LeiosBlockHeader{}
if header.Era() != EraLeios {
t.Errorf(
"LeiosBlockHeader.Era() mismatch: expected %v, got %v",
EraLeios,
header.Era(),
)
}
}

func TestLeiosEndorserBlock_Era(t *testing.T) {
block := &LeiosEndorserBlock{}
if block.Era() != EraLeios {
t.Errorf(
"LeiosEndorserBlock.Era() mismatch: expected %v, got %v",
EraLeios,
block.Era(),
)
}
}

func TestLeiosRankingBlock_Era(t *testing.T) {
block := &LeiosRankingBlock{}
if block.Era() != EraLeios {
t.Errorf(
"LeiosRankingBlock.Era() mismatch: expected %v, got %v",
EraLeios,
block.Era(),
)
}
}

func TestLeiosEndorserBlock_Hash(t *testing.T) {
block := &LeiosEndorserBlock{
TxReferences: map[common.Blake2b256]uint16{
{0x01, 0x02}: 100,
{0x03, 0x04}: 200,
},
}
hash := block.Hash()
if hash == (common.Blake2b256{}) {
t.Error("LeiosEndorserBlock.Hash() returned zero hash")
}
// Hash should be consistent
hash2 := block.Hash()
if hash != hash2 {
t.Error("LeiosEndorserBlock.Hash() not consistent")
}
}

func TestLeiosBlockHeader_Hash(t *testing.T) {
header := &LeiosBlockHeader{
Body: LeiosBlockHeaderBody{
BabbageBlockHeaderBody: babbage.BabbageBlockHeaderBody{
BlockNumber: 1,
Slot: 100,
PrevHash: common.Blake2b256{0x01},
BlockBodySize: 1000,
BlockBodyHash: common.Blake2b256{0x02},
},
},
}
hash := header.Hash()
if hash == (common.Blake2b256{}) {
t.Error("LeiosBlockHeader.Hash() returned zero hash")
}
// Hash should be consistent
hash2 := header.Hash()
if hash != hash2 {
t.Error("LeiosBlockHeader.Hash() not consistent")
}
}

func TestLeiosEndorserBlock_CborRoundTrip(t *testing.T) {
original := &LeiosEndorserBlock{
TxReferences: map[common.Blake2b256]uint16{
{0x01, 0x02}: 100,
{0x03, 0x04}: 200,
},
}

// Encode to CBOR
cborData, err := cbor.Encode(original)
if err != nil {
t.Fatalf("Failed to encode LeiosEndorserBlock: %v", err)
}

// Decode back
var decoded LeiosEndorserBlock
if _, err := cbor.Decode(cborData, &decoded); err != nil {
t.Fatalf("Failed to decode LeiosEndorserBlock: %v", err)
}

// Check TxReferences
if len(decoded.TxReferences) != len(original.TxReferences) {
t.Errorf(
"TxReferences length mismatch: expected %d, got %d",
len(original.TxReferences),
len(decoded.TxReferences),
)
}
for hash, size := range original.TxReferences {
if decoded.TxReferences[hash] != size {
t.Errorf(
"TxReference mismatch for hash %x: expected %d, got %d",
hash,
size,
decoded.TxReferences[hash],
)
}
}
}
Loading