Skip to content

Commit 6c14c80

Browse files
authored
fix: address nilaway issues (#1189)
1 parent 6336fed commit 6c14c80

File tree

14 files changed

+34
-27
lines changed

14 files changed

+34
-27
lines changed

ledger/allegra/allegra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (b *AllegraTransactionBody) AuxDataHash() *common.Blake2b256 {
230230
}
231231

232232
func (b *AllegraTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
233-
return common.TransactionBodyToUtxorpc(b), nil
233+
return common.TransactionBodyToUtxorpc(b)
234234
}
235235

236236
type AllegraTransaction struct {

ledger/allegra/pparams_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestAllegraTransactionBody_Utxorpc(t *testing.T) {
164164
// Run Utxorpc conversion
165165
actual, err := txBody.Utxorpc()
166166
if err != nil {
167-
t.Errorf("Failed to convert the transaction")
167+
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
168168
}
169169

170170
// Check that the fee matches
@@ -227,7 +227,7 @@ func TestAllegraTransaction_Utxorpc(t *testing.T) {
227227
// Run Utxorpc conversion
228228
actual, err := tx.Utxorpc()
229229
if err != nil {
230-
t.Errorf("Failed to convert the transaction")
230+
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
231231
}
232232
// Assertion checks
233233
if actual.Fee != tx.Fee() {

ledger/alonzo/alonzo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (b *AlonzoTransactionBody) ScriptDataHash() *common.Blake2b256 {
268268
}
269269

270270
func (b *AlonzoTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
271-
return common.TransactionBodyToUtxorpc(b), nil
271+
return common.TransactionBodyToUtxorpc(b)
272272
}
273273

274274
type AlonzoTransactionOutput struct {

ledger/alonzo/pparams_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ func TestScientificNotationInCostModels(t *testing.T) {
261261
}
262262

263263
expected := []int64{2477736, 1500000, 1000000}
264+
if params.CostModels == nil || params.CostModels[alonzo.PlutusV1Key] == nil {
265+
t.Fatal("CostModels not properly initialized")
266+
}
264267
for i := range 3 {
265268
if params.CostModels[alonzo.PlutusV1Key][i] != expected[i] {
266269
t.Errorf("parameter %d conversion failed: got %d, want %d",
@@ -517,7 +520,7 @@ func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
517520
// Run Utxorpc conversion
518521
got, err := body.Utxorpc()
519522
if err != nil {
520-
t.Errorf("Failed to convert the transaction")
523+
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
521524
}
522525

523526
// Assertion checks
@@ -580,7 +583,7 @@ func TestAlonzoTransaction_Utxorpc(t *testing.T) {
580583
// Run Utxorpc conversion
581584
got, err := tx.Utxorpc()
582585
if err != nil {
583-
t.Errorf("Failed to convert the transaction")
586+
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
584587
}
585588

586589
// Assertion checks

ledger/babbage/babbage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (b *BabbageTransactionBody) TotalCollateral() uint64 {
364364
}
365365

366366
func (b *BabbageTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
367-
return common.TransactionBodyToUtxorpc(b), nil
367+
return common.TransactionBodyToUtxorpc(b)
368368
}
369369

370370
const (

ledger/babbage/pparams_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func TestBabbageTransactionBody_Utxorpc(t *testing.T) {
637637

638638
got, err := body.Utxorpc()
639639
if err != nil {
640-
t.Fatalf("Utxorpc() conversion failed: %v", err)
640+
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
641641
}
642642
if got.Fee != 100 {
643643
t.Errorf("Fee mismatch: got %d, want 100", got.Fee)
@@ -682,7 +682,7 @@ func TestBabbageTransaction_Utxorpc(t *testing.T) {
682682

683683
got, err := tx.Utxorpc()
684684
if err != nil {
685-
t.Fatalf("Utxorpc() failed: %v", err)
685+
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
686686
}
687687
if got.Fee != 150 {
688688
t.Errorf("Fee mismatch: got %d, want 150", got.Fee)

ledger/common/script_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ func TestScriptRefDecodeEncode(t *testing.T) {
5454
}
5555

5656
func TestNativeScriptHash(t *testing.T) {
57-
testScriptBytes, _ := hex.DecodeString(
57+
testScriptBytes, err := hex.DecodeString(
5858
"820181830301838200581c058a5ab0c66647dcce82d7244f80bfea41ba76c7c9ccaf86a41b00fe8200581c45cbc234959cb619ef54e36c16e7719318592e627cdf1a39bd3d64398200581c85fd53e110449649b709ef0fa93e86d99535bdce5db306ce0e7418fc",
5959
)
60+
// Make nilaway happy
61+
if err != nil {
62+
t.Fatalf("failed to decode hex string: %v", err)
63+
}
6064
expectedScriptHash := "1c0053ec18e2c0f7bd4d007fe14243ca220563f9c124381f75c43704"
6165
var testScript common.NativeScript
6266
if err := testScript.UnmarshalCBOR(testScriptBytes); err != nil {

ledger/common/tx.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,25 @@ func (b *TransactionBodyBase) Donation() uint64 {
195195
return 0
196196
}
197197

198-
func (b *TransactionBodyBase) Utxorpc() *utxorpc.Tx {
199-
return nil
198+
func (b *TransactionBodyBase) Utxorpc() (*utxorpc.Tx, error) {
199+
return nil, nil
200200
}
201201

202202
// TransactionBodyToUtxorpc is a common helper for converting TransactionBody to utxorpc.Tx
203-
func TransactionBodyToUtxorpc(tx TransactionBody) *utxorpc.Tx {
203+
func TransactionBodyToUtxorpc(tx TransactionBody) (*utxorpc.Tx, error) {
204204
txi := []*utxorpc.TxInput{}
205205
txo := []*utxorpc.TxOutput{}
206206
for _, i := range tx.Inputs() {
207207
input, err := i.Utxorpc()
208208
if err != nil {
209-
return nil
209+
return nil, err
210210
}
211211
txi = append(txi, input)
212212
}
213213
for _, o := range tx.Outputs() {
214214
output, err := o.Utxorpc()
215215
if err != nil {
216-
return nil
216+
return nil, err
217217
}
218218
txo = append(txo, output)
219219
}
@@ -236,17 +236,17 @@ func TransactionBodyToUtxorpc(tx TransactionBody) *utxorpc.Tx {
236236
for _, ri := range tx.ReferenceInputs() {
237237
input, err := ri.Utxorpc()
238238
if err != nil {
239-
return nil
239+
return nil, err
240240
}
241241
ret.ReferenceInputs = append(ret.ReferenceInputs, input)
242242
}
243243
for _, c := range tx.Certificates() {
244244
cert, err := c.Utxorpc()
245245
if err != nil {
246-
return nil
246+
return nil, err
247247
}
248248
ret.Certificates = append(ret.Certificates, cert)
249249
}
250250

251-
return ret
251+
return ret, nil
252252
}

ledger/conway/conway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func (b *ConwayTransactionBody) Donation() uint64 {
508508
}
509509

510510
func (b *ConwayTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
511-
return common.TransactionBodyToUtxorpc(b), nil
511+
return common.TransactionBodyToUtxorpc(b)
512512
}
513513

514514
type ConwayTransaction struct {

ledger/conway/pparams_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ func TestConwayTransactionBody_Utxorpc(t *testing.T) {
656656

657657
got, err := body.Utxorpc()
658658
if err != nil {
659-
t.Errorf("Could not get the transaction input")
659+
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
660660
}
661661

662662
if got.Fee != 1000 {
@@ -733,7 +733,7 @@ func TestConwayTransaction_Utxorpc(t *testing.T) {
733733

734734
got, err := tx.Utxorpc()
735735
if err != nil {
736-
t.Errorf("Could not get the transaction input")
736+
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
737737
}
738738

739739
if got.Fee != 1000 {

0 commit comments

Comments
 (0)