Add helpful debug info to VerifyAddressFormat (#7016)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
3a4e608930
commit
034b478a60
|
@ -111,7 +111,7 @@ func VerifyAddressFormat(bz []byte) error {
|
||||||
return verifier(bz)
|
return verifier(bz)
|
||||||
}
|
}
|
||||||
if len(bz) != AddrLen {
|
if len(bz) != AddrLen {
|
||||||
return errors.New("incorrect address length")
|
return fmt.Errorf("incorrect address length (expected: %d, actual: %d)", AddrLen, len(bz))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,6 +325,22 @@ func TestAddressInterface(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVerifyAddressFormat(t *testing.T) {
|
||||||
|
addr0 := make([]byte, 0)
|
||||||
|
addr5 := make([]byte, 5)
|
||||||
|
addr20 := make([]byte, 20)
|
||||||
|
addr32 := make([]byte, 32)
|
||||||
|
|
||||||
|
err := types.VerifyAddressFormat(addr0)
|
||||||
|
require.EqualError(t, err, "incorrect address length (expected: 20, actual: 0)")
|
||||||
|
err = types.VerifyAddressFormat(addr5)
|
||||||
|
require.EqualError(t, err, "incorrect address length (expected: 20, actual: 5)")
|
||||||
|
err = types.VerifyAddressFormat(addr20)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = types.VerifyAddressFormat(addr32)
|
||||||
|
require.EqualError(t, err, "incorrect address length (expected: 20, actual: 32)")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCustomAddressVerifier(t *testing.T) {
|
func TestCustomAddressVerifier(t *testing.T) {
|
||||||
// Create a 10 byte address
|
// Create a 10 byte address
|
||||||
addr := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
addr := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
|
Loading…
Reference in New Issue