mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
util: add Uint160.Reverse()
This commit is contained in:
parent
9e04e61533
commit
09b295d727
2 changed files with 18 additions and 0 deletions
|
@ -60,6 +60,15 @@ func (u Uint160) StringLE() string {
|
|||
return hex.EncodeToString(u.BytesLE())
|
||||
}
|
||||
|
||||
// Reverse returns reversed representation of u.
|
||||
func (u Uint160) Reverse() (r Uint160) {
|
||||
for i := 0; i < Uint160Size; i++ {
|
||||
r[i] = u[Uint160Size-i-1]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns true if both Uint256 values are the same.
|
||||
func (u Uint160) Equals(other Uint160) bool {
|
||||
return u == other
|
||||
|
|
|
@ -94,3 +94,12 @@ func TestUInt160String(t *testing.T) {
|
|||
assert.Equal(t, hexStr, val.String())
|
||||
assert.Equal(t, hexRevStr, val.StringLE())
|
||||
}
|
||||
|
||||
func TestUint160_Reverse(t *testing.T) {
|
||||
hexStr := "b28427088a3729b2536d10122960394e8be6721f"
|
||||
val, err := Uint160DecodeStringBE(hexStr)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, hexStr, val.Reverse().StringLE())
|
||||
assert.Equal(t, val, val.Reverse().Reverse())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue