Skip to content

Commit

Permalink
upgraded dependencies and added trivial aaddress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
safanaj committed Nov 10, 2023
1 parent f18d320 commit 349aeeb
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 127 deletions.
8 changes: 4 additions & 4 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewAddressFromBytes(bytes []byte) (Address, error) {
switch addr.Type {
case Base:
if len(bytes) != 57 {
return addr, errors.New("base address length should be 29")
return addr, errors.New("base address length should be 57")
}
addr.Payment = StakeCredential{
Type: KeyCredential,
Expand All @@ -59,7 +59,7 @@ func NewAddressFromBytes(bytes []byte) (Address, error) {
}
case Base + 1:
if len(bytes) != 57 {
return addr, errors.New("base address length should be 29")
return addr, errors.New("base address length should be 57")
}
addr.Payment = StakeCredential{
Type: ScriptCredential,
Expand All @@ -71,7 +71,7 @@ func NewAddressFromBytes(bytes []byte) (Address, error) {
}
case Base + 2:
if len(bytes) != 57 {
return addr, errors.New("base address length should be 29")
return addr, errors.New("base address length should be 57")
}
addr.Payment = StakeCredential{
Type: KeyCredential,
Expand All @@ -83,7 +83,7 @@ func NewAddressFromBytes(bytes []byte) (Address, error) {
}
case Base + 3:
if len(bytes) != 57 {
return addr, errors.New("base address length should be 29")
return addr, errors.New("base address length should be 57")
}
addr.Payment = StakeCredential{
Type: ScriptCredential,
Expand Down
85 changes: 85 additions & 0 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
addrType5 = "addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu"
addrType6 = "addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8"
addrType7 = "addr1w8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcyjy7wx"
addrType8 = "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw"
)

var (
Expand All @@ -31,6 +32,7 @@ var (
"addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu",
"addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8",
"addr1w8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcyjy7wx",
"stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw",
}
)

Expand Down Expand Up @@ -140,6 +142,89 @@ func TestNewAddress(t *testing.T) {
if got, want := enterprise1.Bech32(), addrType7; got != want {
t.Errorf("invalid enterprise address\ngot: %s\nwant: %s", got, want)
}

stake0, err := NewStakeAddress(Mainnet, stakeAddrCred)
if err != nil {
t.Fatal(err)
}
if got, want := stake0.Bech32(), addrType8; got != want {
t.Errorf("invalid stake address\ngot: %s\nwant: %s", got, want)
}
}

func TestNewAddressFromBytesErrors(t *testing.T) {
// failing bech32 decoding
badAddr := []byte(addrType0)
badAddr[10] = 'Z'
_, err := NewAddress(string(badAddr))
if err == nil {
t.Errorf("error expected")
}

badAddr = make([]byte, 2)
for _, at := range []AddressType{Base, Ptr, Enterprise, Stake} {
badAddr[0] = byte(at) << 4
expectedErr := ""
switch at {
case Base:
expectedErr = "base address length should be 57"
case Ptr:
expectedErr = "pointer address length should be greater than 29"
case Enterprise:
expectedErr = "enterprise address length should be 29"
case Stake:
expectedErr = "stake address length should be 29"
}

if at == Base {
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}

badAddr[0] = (byte(at) + 1) << 4
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}

badAddr[0] = (byte(at) + 2) << 4
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}

badAddr[0] = (byte(at) + 3) << 4
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}
} else {
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}

badAddr[0] = (byte(at) + 1) << 4
_, err = NewAddressFromBytes(badAddr)
if err == nil {
t.Errorf("error expected")
} else if err.Error() != expectedErr {
t.Errorf("error expected is different")
}
}
}

}

func TestNat(t *testing.T) {
Expand Down
75 changes: 39 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,60 @@ go 1.18

require (
filippo.io/edwards25519 v1.0.0
github.com/blinklabs-io/gouroboros v0.38.3
github.com/blockfrost/blockfrost-go v0.1.0
github.com/blinklabs-io/gouroboros v0.62.0
github.com/blockfrost/blockfrost-go v0.1.1
github.com/cardano-community/koios-go-client/v3 v3.1.2
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/dgraph-io/badger/v3 v3.2103.5
github.com/matoous/go-nanoid/v2 v2.0.0
github.com/otiai10/copy v1.9.0
github.com/spf13/cobra v1.4.0
github.com/otiai10/copy v1.14.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/spf13/viper v1.17.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/veraison/go-cose v1.0.0
github.com/veraison/go-cose v1.1.0
github.com/x448/float16 v0.8.4
golang.org/x/crypto v0.8.0
golang.org/x/crypto v0.15.0
)

require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.2.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 349aeeb

Please sign in to comment.