2019-12-25 12:22:02 +00:00
|
|
|
package address
|
2018-03-17 11:53:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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{
|
|
|
|
"AMLr1CpPQtbEdiJdriX1HpRNMZUwbU2Huj",
|
|
|
|
"AKtwd3DRXj3nL5kHMUoNsdnsCEVjnuuTFF",
|
|
|
|
"AMxkaxFVG8Q1BhnB4fjTA5ZmUTEnnTMJMa",
|
|
|
|
}
|
|
|
|
for _, addr := range addrs {
|
2019-12-25 12:22:02 +00:00
|
|
|
val, err := DecodeUint160(addr)
|
2018-03-17 11:53:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-25 12:22:02 +00:00
|
|
|
assert.Equal(t, addr, EncodeUint160(val))
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 12:46:19 +00:00
|
|
|
|
|
|
|
func TestUint160DecodeKnownAddress(t *testing.T) {
|
|
|
|
address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP"
|
|
|
|
|
2019-12-25 12:22:02 +00:00
|
|
|
val, err := DecodeUint160(address)
|
2019-08-26 12:46:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
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@"
|
|
|
|
|
|
|
|
_, err := DecodeUint160(address)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUint160DecodeBadPrefix(t *testing.T) {
|
|
|
|
// The same AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP key encoded with 0x18 prefix.
|
|
|
|
address := "AhymDz4vvHLtvaN36CMbzkki7H2U8ENb8F"
|
|
|
|
|
|
|
|
_, err := DecodeUint160(address)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|