2019-12-25 12:22:02 +00:00
|
|
|
package address
|
2018-03-17 11:53:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-06-16 10:47:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2018-03-17 11:53:21 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-12-25 12:55:39 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-03-17 11:53:21 +00:00
|
|
|
)
|
|
|
|
|
2019-08-26 12:46:19 +00:00
|
|
|
func TestUint160DecodeEncodeAddress(t *testing.T) {
|
2018-03-17 11:53:21 +00:00
|
|
|
addrs := []string{
|
2020-06-16 10:47:29 +00:00
|
|
|
"NRHkiY2hLy5ypD32CKZtL6pNwhbFMqDEhR",
|
|
|
|
"NPCD6gAxNuuJqssZY1eCJabuaz4BjBUHab",
|
|
|
|
"NUJUhgvvQyp6AmDBg3QRQ1cmRkMRhaXqZP",
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|
|
|
|
for _, addr := range addrs {
|
2019-12-25 14:34:18 +00:00
|
|
|
val, err := StringToUint160(addr)
|
2020-02-29 15:55:16 +00:00
|
|
|
require.NoError(t, err)
|
2019-12-25 14:34:18 +00:00
|
|
|
assert.Equal(t, addr, Uint160ToString(val))
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 12:46:19 +00:00
|
|
|
|
|
|
|
func TestUint160DecodeKnownAddress(t *testing.T) {
|
2020-06-16 10:47:29 +00:00
|
|
|
address := "NNnFn8iHWWnJe9QYoN1r4PeXMuVpfLVRS7"
|
2019-08-26 12:46:19 +00:00
|
|
|
|
2019-12-25 14:34:18 +00:00
|
|
|
val, err := StringToUint160(address)
|
2020-02-29 15:55:16 +00:00
|
|
|
require.NoError(t, err)
|
2019-08-26 12:46:19 +00:00
|
|
|
|
2019-11-27 09:20:31 +00:00
|
|
|
assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", val.StringLE())
|
2019-08-26 12:46:19 +00:00
|
|
|
assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", val.String())
|
|
|
|
}
|
2019-12-25 12:55:39 +00:00
|
|
|
|
|
|
|
func TestUint160DecodeBadBase58(t *testing.T) {
|
|
|
|
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJv@"
|
|
|
|
|
2019-12-25 14:34:18 +00:00
|
|
|
_, err := StringToUint160(address)
|
2019-12-25 12:55:39 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUint160DecodeBadPrefix(t *testing.T) {
|
|
|
|
// The same AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP key encoded with 0x18 prefix.
|
|
|
|
address := "AhymDz4vvHLtvaN36CMbzkki7H2U8ENb8F"
|
|
|
|
|
2019-12-25 14:34:18 +00:00
|
|
|
_, err := StringToUint160(address)
|
2019-12-25 12:55:39 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|
2020-06-16 10:47:29 +00:00
|
|
|
|
|
|
|
func TestPrefixFirstLetter(t *testing.T) {
|
|
|
|
u := util.Uint160{}
|
|
|
|
require.EqualValues(t, 'N', Uint160ToString(u)[0])
|
|
|
|
|
|
|
|
for i := range u {
|
|
|
|
u[i] = 0xFF
|
|
|
|
}
|
|
|
|
require.EqualValues(t, 'N', Uint160ToString(u)[0])
|
|
|
|
}
|