Skip to content

style: make format golines #1035

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 11, 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
54 changes: 44 additions & 10 deletions ledger/allegra/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ func TestAllegraUtxorpc(t *testing.T) {
// Unit test for AllegraTransactionBody.Utxorpc()
func TestAllegraTransactionBody_Utxorpc(t *testing.T) {
// mock input
input := shelley.NewShelleyTransactionInput("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
input := shelley.NewShelleyTransactionInput(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
1,
)
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

address := common.Address{}

Expand All @@ -159,23 +164,40 @@ func TestAllegraTransactionBody_Utxorpc(t *testing.T) {

// Check that the fee matches
if actual.Fee != txBody.Fee() {
t.Errorf("AllegraTransactionBody.Utxorpc() fee mismatch\nGot: %d\nWant: %d", actual.Fee, txBody.Fee())
t.Errorf(
"AllegraTransactionBody.Utxorpc() fee mismatch\nGot: %d\nWant: %d",
actual.Fee,
txBody.Fee(),
)
}
// Check number of inputs
if len(actual.Inputs) != len(txBody.Inputs()) {
t.Errorf("AllegraTransactionBody.Utxorpc() input length mismatch\nGot: %d\nWant: %d", len(actual.Inputs), len(txBody.Inputs()))
t.Errorf(
"AllegraTransactionBody.Utxorpc() input length mismatch\nGot: %d\nWant: %d",
len(actual.Inputs),
len(txBody.Inputs()),
)
}
// Check number of outputs
if len(actual.Outputs) != len(txBody.Outputs()) {
t.Errorf("AllegraTransactionBody.Utxorpc() output length mismatch\nGot: %d\nWant: %d", len(actual.Outputs), len(txBody.Outputs()))
t.Errorf(
"AllegraTransactionBody.Utxorpc() output length mismatch\nGot: %d\nWant: %d",
len(actual.Outputs),
len(txBody.Outputs()),
)
}
}

// Unit test for AllegraTransaction.Utxorpc()
func TestAllegraTransaction_Utxorpc(t *testing.T) {
// Prepare mock input
input := shelley.NewShelleyTransactionInput("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 0)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
input := shelley.NewShelleyTransactionInput(
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
0,
)
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

// Prepare mock output
address := common.Address{}
Expand All @@ -202,14 +224,26 @@ func TestAllegraTransaction_Utxorpc(t *testing.T) {

// Assertion checks
if actual.Fee != tx.Fee() {
t.Errorf("AllegraTransaction.Utxorpc() fee mismatch\nGot: %d\nWant: %d", actual.Fee, tx.Fee())
t.Errorf(
"AllegraTransaction.Utxorpc() fee mismatch\nGot: %d\nWant: %d",
actual.Fee,
tx.Fee(),
)
}

if len(actual.Inputs) != len(tx.Inputs()) {
t.Errorf("AllegraTransaction.Utxorpc() input length mismatch\nGot: %d\nWant: %d", len(actual.Inputs), len(tx.Inputs()))
t.Errorf(
"AllegraTransaction.Utxorpc() input length mismatch\nGot: %d\nWant: %d",
len(actual.Inputs),
len(tx.Inputs()),
)
}

if len(actual.Outputs) != len(tx.Outputs()) {
t.Errorf("AllegraTransaction.Utxorpc() output length mismatch\nGot: %d\nWant: %d", len(actual.Outputs), len(tx.Outputs()))
t.Errorf(
"AllegraTransaction.Utxorpc() output length mismatch\nGot: %d\nWant: %d",
len(actual.Outputs),
len(tx.Outputs()),
)
}
}
36 changes: 29 additions & 7 deletions ledger/alonzo/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,24 @@ func TestAlonzoTransactionOutput_Utxorpc(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("AlonzoTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v", got, want)
t.Errorf(
"AlonzoTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v",
got,
want,
)
}
}

// Unit test for AlonzoTransactionBody.Utxorpc()
func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
// Mock input
input := shelley.NewShelleyTransactionInput("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
input := shelley.NewShelleyTransactionInput(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0,
)
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

// Mock output
address := common.Address{}
Expand Down Expand Up @@ -513,7 +522,11 @@ func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
t.Errorf("Expected 1 input, got %d", len(got.Inputs))
}
if got.Inputs[0].OutputIndex != input.Index() {
t.Errorf("Input index mismatch: got %d, want %d", got.Inputs[0].OutputIndex, input.Index())
t.Errorf(
"Input index mismatch: got %d, want %d",
got.Inputs[0].OutputIndex,
input.Index(),
)
}
if len(got.Outputs) != 1 {
t.Errorf("Expected 1 output, got %d", len(got.Outputs))
Expand All @@ -529,8 +542,13 @@ func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
// Unit test for AlonzoTransaction.Utxorpc()
func TestAlonzoTransaction_Utxorpc(t *testing.T) {
// Mock input
input := shelley.NewShelleyTransactionInput("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 1)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
input := shelley.NewShelleyTransactionInput(
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
1,
)
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

// Mock output
address := common.Address{}
Expand Down Expand Up @@ -571,7 +589,11 @@ func TestAlonzoTransaction_Utxorpc(t *testing.T) {
}
expectedDatum := datumHash.Bytes()
if !reflect.DeepEqual(got.Outputs[0].Datum.Hash, expectedDatum) {
t.Errorf("Datum hash mismatch: got %x, want %x", got.Outputs[0].Datum.Hash, expectedDatum)
t.Errorf(
"Datum hash mismatch: got %x, want %x",
got.Outputs[0].Datum.Hash,
expectedDatum,
)
}
if len(got.Hash) == 0 {
t.Error("Expected non-empty transaction hash")
Expand Down
25 changes: 20 additions & 5 deletions ledger/babbage/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ func TestBabbageUtxorpc(t *testing.T) {

// Unit test for BabbageTransactionInput.Utxorpc()
func TestBabbageTransactionInput_Utxorpc(t *testing.T) {
input := shelley.NewShelleyTransactionInput("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", 2)
input := shelley.NewShelleyTransactionInput(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
2,
)

got := input.Utxorpc()
want := &cardano.TxInput{
Expand All @@ -567,7 +570,11 @@ func TestBabbageTransactionInput_Utxorpc(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("BabbageTransactionInput.Utxorpc() mismatch\\nGot: %+v\\nWant: %+v", got, want)
t.Errorf(
"BabbageTransactionInput.Utxorpc() mismatch\\nGot: %+v\\nWant: %+v",
got,
want,
)
}
}

Expand All @@ -594,15 +601,21 @@ func TestBabbageTransactionOutput_Utxorpc(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("BabbageTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v", got, want)
t.Errorf(
"BabbageTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v",
got,
want,
)
}
}

// Unit test for BabbageTransactionBody.Utxorpc()
func TestBabbageTransactionBody_Utxorpc(t *testing.T) {
input := shelley.NewShelleyTransactionInput(
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 1)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

address := common.Address{}
output := babbage.BabbageTransactionOutput{
Expand Down Expand Up @@ -639,7 +652,9 @@ func TestBabbageTransactionBody_Utxorpc(t *testing.T) {
func TestBabbageTransaction_Utxorpc(t *testing.T) {
input := shelley.NewShelleyTransactionInput(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", 2)
inputSet := shelley.NewShelleyTransactionInputSet([]shelley.ShelleyTransactionInput{input})
inputSet := shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{input},
)

address := common.Address{}
output := babbage.BabbageTransactionOutput{
Expand Down
46 changes: 26 additions & 20 deletions ledger/babbage/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,26 +1450,32 @@ func TestUtxoValidateCollateralEqBalance(t *testing.T) {
},
)
// no valid collateral UTxO, should skip and not underflow
t.Run("no valid collateral UTxO, should skip and not underflow", func(t *testing.T) {
// Ledger state with NO matching UTxO
missingUtxoLedgerState := test.MockLedgerState{
MockUtxos: []common.Utxo{}, // empty
}
testTx.Body.TxCollateralReturn = &babbage.BabbageTransactionOutput{
OutputAmount: mary.MaryTransactionOutputValue{
Amount: testCollateralReturnAmountBad,
},
}
err := babbage.UtxoValidateCollateralEqBalance(
testTx,
testSlot,
missingUtxoLedgerState,
testProtocolParams,
)
if err != nil {
t.Errorf("Should skip collateral return validation if collBalance == 0. Got error: %v", err)
}
})
t.Run(
"no valid collateral UTxO, should skip and not underflow",
func(t *testing.T) {
// Ledger state with NO matching UTxO
missingUtxoLedgerState := test.MockLedgerState{
MockUtxos: []common.Utxo{}, // empty
}
testTx.Body.TxCollateralReturn = &babbage.BabbageTransactionOutput{
OutputAmount: mary.MaryTransactionOutputValue{
Amount: testCollateralReturnAmountBad,
},
}
err := babbage.UtxoValidateCollateralEqBalance(
testTx,
testSlot,
missingUtxoLedgerState,
testProtocolParams,
)
if err != nil {
t.Errorf(
"Should skip collateral return validation if collBalance == 0. Got error: %v",
err,
)
}
},
)
}

func TestUtxoValidateTooManyCollateralInputs(t *testing.T) {
Expand Down
21 changes: 17 additions & 4 deletions ledger/byron/byron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (

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

got := input.Utxorpc()
want := &cardano.TxInput{
Expand All @@ -35,7 +38,11 @@ func TestByronTransactionInput_Utxorpc(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("ByronTransactionInput.Utxorpc() mismatch\nGot: %+v\nWant: %+v", got, want)
t.Errorf(
"ByronTransactionInput.Utxorpc() mismatch\nGot: %+v\nWant: %+v",
got,
want,
)
}
}

Expand All @@ -57,7 +64,11 @@ func TestByronTransactionOutput_Utxorpc(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("ByronTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v", got, want)
t.Errorf(
"ByronTransactionOutput.Utxorpc() mismatch\nGot: %+v\nWant: %+v",
got,
want,
)
}
}

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

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

// Validate that it's the zero value
Expand Down
10 changes: 8 additions & 2 deletions ledger/common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ func (a Address) Bytes() ([]byte, error) {
}
rawPayload, err := cbor.Encode(tmpPayload)
if err != nil {
return nil, fmt.Errorf("failed to encode Byron address payload: %w", err)
return nil, fmt.Errorf(
"failed to encode Byron address payload: %w",
err,
)
}
tmpData := []any{
cbor.Tag{
Expand All @@ -400,7 +403,10 @@ func (a Address) Bytes() ([]byte, error) {
}
ret, err := cbor.Encode(tmpData)
if err != nil {
return nil, fmt.Errorf("failed to encode Byron address data: %w", err)
return nil, fmt.Errorf(
"failed to encode Byron address data: %w",
err,
)
}
return ret, nil
}
Expand Down
4 changes: 3 additions & 1 deletion ledger/conway/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ func (p *ConwayProtocolParameters) Update(
}
}

func (p *ConwayProtocolParameters) UpdateFromGenesis(genesis *ConwayGenesis) error {
func (p *ConwayProtocolParameters) UpdateFromGenesis(
genesis *ConwayGenesis,
) error {
if genesis == nil {
return nil
}
Expand Down
10 changes: 8 additions & 2 deletions ledger/conway/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,10 @@ func TestUtxorpc(t *testing.T) {

// Unit test for ConwayTransactionBody.Utxorpc()
func TestConwayTransactionBody_Utxorpc(t *testing.T) {
input := shelley.NewShelleyTransactionInput("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1)
input := shelley.NewShelleyTransactionInput(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
1,
)
var inputSet conway.ConwayTransactionInputSet
inputSet.SetItems([]shelley.ShelleyTransactionInput{input})

Expand Down Expand Up @@ -660,7 +663,10 @@ func TestConwayTransactionBody_Utxorpc(t *testing.T) {

// Unit test for ConwayTransaction.Utxorpc()
func TestConwayTransaction_Utxorpc(t *testing.T) {
input := shelley.NewShelleyTransactionInput("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0)
input := shelley.NewShelleyTransactionInput(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0,
)
var inputSet conway.ConwayTransactionInputSet
inputSet.SetItems([]shelley.ShelleyTransactionInput{input})

Expand Down
Loading
Loading