Skip to content

Commit be52da6

Browse files
committed
feat(ledger): Modifed Check part in all the tests for the exact expected string instead of using a regex
Signed-off-by: Akhil Repala <[email protected]>
1 parent 33aed59 commit be52da6

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

ledger/alonzo/alonzo_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package alonzo
1717
import (
1818
"math/big"
1919
"reflect"
20-
"regexp"
2120
"testing"
2221

2322
"github.com/blinklabs-io/gouroboros/cbor"
@@ -293,8 +292,8 @@ func TestAlonzoTransactionOutputString(t *testing.T) {
293292
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma},
294293
}
295294
s := out.String()
296-
re := regexp.MustCompile(`^\(AlonzoTransactionOutput address=addr1[0-9a-z]+ amount=456 assets=\.\.\.\)$`)
297-
if !re.MatchString(s) {
295+
expected := "(AlonzoTransactionOutput address=" + addr.String() + " amount=456 assets=...)"
296+
if s != expected {
298297
t.Fatalf("unexpected string: %s", s)
299298
}
300299
}

ledger/babbage/babbage_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package babbage
1717
import (
1818
"math/big"
1919
"reflect"
20-
"regexp"
2120
"testing"
2221

2322
"github.com/blinklabs-io/gouroboros/cbor"
@@ -2986,8 +2985,8 @@ func TestBabbageTransactionOutputString(t *testing.T) {
29862985
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma},
29872986
}
29882987
s := out.String()
2989-
re := regexp.MustCompile(`^\(BabbageTransactionOutput address=addr1[0-9a-z]+ amount=456 assets=\.\.\.\)$`)
2990-
if !re.MatchString(s) {
2988+
expected := "(BabbageTransactionOutput address=" + addr.String() + " amount=456 assets=...)"
2989+
if s != expected {
29912990
t.Fatalf("unexpected string: %s", s)
29922991
}
29932992
}

ledger/byron/byron_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package byron_test
1616

1717
import (
1818
"reflect"
19-
"regexp"
2019
"testing"
2120

2221
"github.com/blinklabs-io/gouroboros/ledger/byron"
@@ -120,8 +119,8 @@ func TestByronTransactionOutputString(t *testing.T) {
120119
OutputAmount: 456,
121120
}
122121
s := out.String()
123-
re := regexp.MustCompile(`^\(ByronTransactionOutput address=[1-9A-HJ-NP-Za-km-z]+ amount=456\)$`)
124-
if !re.MatchString(s) {
122+
expected := "(ByronTransactionOutput address=" + addr.String() + " amount=456)"
123+
if s != expected {
125124
t.Fatalf("unexpected string: %s", s)
126125
}
127126
}

ledger/mary/mary_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ package mary
1616

1717
import (
1818
"encoding/hex"
19+
"fmt"
1920
"reflect"
20-
"regexp"
2121
"testing"
2222

2323
"github.com/blinklabs-io/gouroboros/cbor"
@@ -129,8 +129,8 @@ func TestMaryTransactionOutputString(t *testing.T) {
129129
OutputAmount: MaryTransactionOutputValue{Amount: 456, Assets: &ma},
130130
}
131131
s := out.String()
132-
re := regexp.MustCompile(`^\(MaryTransactionOutput address=addr1[0-9a-z]+ amount=456 assets=\.\.\.\)$`)
133-
if !re.MatchString(s) {
132+
expected := fmt.Sprintf("(MaryTransactionOutput address=%s amount=456 assets=...)", addr.String())
133+
if s != expected {
134134
t.Fatalf("unexpected string: %s", s)
135135
}
136136
}
@@ -142,8 +142,8 @@ func TestMaryOutputTooBigErrorFormatting(t *testing.T) {
142142
OutputAmount: MaryTransactionOutputValue{Amount: 456},
143143
}
144144
errStr := OutputTooBigUtxoError{Outputs: []common.TransactionOutput{out}}.Error()
145-
re := regexp.MustCompile(`^output value too large: \(MaryTransactionOutput address=addr1[0-9a-z]+ amount=456\)$`)
146-
if !re.MatchString(errStr) {
145+
expected := fmt.Sprintf("output value too large: (MaryTransactionOutput address=%s amount=456)", addr.String())
146+
if errStr != expected {
147147
t.Fatalf("unexpected error: %s", errStr)
148148
}
149149
}

ledger/shelley/shelley_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package shelley_test
22

33
import (
4-
"regexp"
4+
"fmt"
55
"testing"
66

77
"github.com/blinklabs-io/gouroboros/ledger/common"
@@ -15,8 +15,8 @@ func TestShelleyTransactionOutputString(t *testing.T) {
1515
OutputAmount: 456,
1616
}
1717
s := out.String()
18-
re := regexp.MustCompile(`^\(ShelleyTransactionOutput address=addr1[0-9a-z]+ amount=456\)$`)
19-
if !re.MatchString(s) {
18+
expected := fmt.Sprintf("(ShelleyTransactionOutput address=%s amount=456)", addr.String())
19+
if s != expected {
2020
t.Fatalf("unexpected string: %s", s)
2121
}
2222
}
@@ -28,7 +28,8 @@ func TestShelleyOutputTooSmallErrorFormatting(t *testing.T) {
2828
OutputAmount: 456,
2929
}
3030
errStr := shelley.OutputTooSmallUtxoError{Outputs: []common.TransactionOutput{out}}.Error()
31-
if matched, _ := regexp.MatchString(`^output too small: \(ShelleyTransactionOutput address=addr1[0-9a-z]+ amount=456\)$`, errStr); !matched {
31+
expected := fmt.Sprintf("output too small: (ShelleyTransactionOutput address=%s amount=456)", addr.String())
32+
if errStr != expected {
3233
t.Fatalf("unexpected error: %s", errStr)
3334
}
3435
}

0 commit comments

Comments
 (0)