diff --git a/ledger/common/address.go b/ledger/common/address.go index a6d9439a..e85470b0 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -16,6 +16,7 @@ package common import ( "fmt" + "strings" "github.com/blinklabs-io/gouroboros/base58" "github.com/blinklabs-io/gouroboros/bech32" @@ -55,6 +56,7 @@ type Address struct { // NewAddress returns an Address based on the provided bech32 address string func NewAddress(addr string) (Address, error) { + addr = strings.ToLower(addr) _, data, err := bech32.DecodeNoLimit(addr) if err != nil { return Address{}, err diff --git a/ledger/common/address_test.go b/ledger/common/address_test.go index 99649038..3e5220fc 100644 --- a/ledger/common/address_test.go +++ b/ledger/common/address_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/blinklabs-io/gouroboros/internal/test" + "github.com/stretchr/testify/assert" ) func TestAddressFromBytes(t *testing.T) { @@ -225,3 +226,16 @@ func TestAddressStakeAddress(t *testing.T) { } } } + +func TestAddressPaymentAddress_MixedCase(t *testing.T) { + + lowerCaseAddress := "addr_test1qqawz5hm2tchtmarkfn2tamzvd2spatl89gtutgra6zwc3ktqj7p944ckc9lq7u36jrq99znwhzlq6jfv2j4ql92m4rq07hp8t" + laddr, err := NewAddress(lowerCaseAddress) + assert.Nil(t, err, "Expected no error when decoding a lowercase address") + // address with mixed case + mixedCaseAddress := "addr_test1QQawz5hm2tchtmarkfn2tamzvd2spatl89gtutgra6zwc3ktqj7p944ckc9lq7u36jrq99znwhzlq6jfv2j4ql92m4rq07hp8t" + addr, err := NewAddress(mixedCaseAddress) + assert.Nil(t, err, "Expected no error when decoding a mixed-case address") + assert.NotNil(t, addr, "Expected a valid address object after decoding") + assert.Equal(t, laddr.String(), addr.String(), "Expected the mixed-case address to be equal to lowercase") +}