Skip to content

Commit cd1aba7

Browse files
committed
fix(address): normalize mixed-case Bech32 address before decoding
Signed-off-by: Ales Verbic <[email protected]>
1 parent c442124 commit cd1aba7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ledger/common/address.go

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

1717
import (
1818
"fmt"
19+
"strings"
1920

2021
"github.com/blinklabs-io/gouroboros/base58"
2122
"github.com/blinklabs-io/gouroboros/bech32"
@@ -55,6 +56,7 @@ type Address struct {
5556

5657
// NewAddress returns an Address based on the provided bech32 address string
5758
func NewAddress(addr string) (Address, error) {
59+
addr = strings.ToLower(addr)
5860
_, data, err := bech32.DecodeNoLimit(addr)
5961
if err != nil {
6062
return Address{}, err

ledger/common/address_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/blinklabs-io/gouroboros/internal/test"
21+
"github.com/stretchr/testify/assert"
2122
)
2223

2324
func TestAddressFromBytes(t *testing.T) {
@@ -225,3 +226,13 @@ func TestAddressStakeAddress(t *testing.T) {
225226
}
226227
}
227228
}
229+
230+
func TestAddressPaymentAddress_MixedCase(t *testing.T) {
231+
232+
// address: "addr_test1qqawz5hm2tchtmarkfn2tamzvd2spatl89gtutgra6zwc3ktqj7p944ckc9lq7u36jrq99znwhzlq6jfv2j4ql92m4rq07hp8t",
233+
// address with mixed case
234+
mixedCaseAddress := "addr_test1QQawz5hm2tchtmarkfn2tamzvd2spatl89gtutgra6zwc3ktqj7p944ckc9lq7u36jrq99znwhzlq6jfv2j4ql92m4rq07hp8t"
235+
addr, err := NewAddress(mixedCaseAddress)
236+
assert.Nil(t, err, "Expected no error when decoding a mixed-case address")
237+
assert.NotNil(t, addr, "Expected a valid address object after decoding")
238+
}

0 commit comments

Comments
 (0)