From 2275b9e4ada61c401c44ea487347cd29812dd379 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 26 Aug 2019 15:46:19 +0300 Subject: [PATCH] _pkg.dev: drop address pkg, move test into crypto address wrappers don't seem to fit well into master's code, so just drop 'em, but pick the testing function with good known input/output pair. --- _pkg.dev/wire/util/address/address.go | 43 ---------------------- _pkg.dev/wire/util/address/address_test.go | 17 --------- pkg/crypto/address_test.go | 14 ++++++- 3 files changed, 13 insertions(+), 61 deletions(-) delete mode 100644 _pkg.dev/wire/util/address/address.go delete mode 100644 _pkg.dev/wire/util/address/address_test.go diff --git a/_pkg.dev/wire/util/address/address.go b/_pkg.dev/wire/util/address/address.go deleted file mode 100644 index 08b0347af..000000000 --- a/_pkg.dev/wire/util/address/address.go +++ /dev/null @@ -1,43 +0,0 @@ -package address - -import ( - "github.com/CityOfZion/neo-go/pkg/crypto/base58" - "github.com/CityOfZion/neo-go/pkg/wire/util" -) - -// ToScriptHash converts an address to a script hash -func ToScriptHash(address string) string { - a, err := Uint160Decode(address) - if err != nil { - return "" - } - return a.String() - -} - -// ToReverseScriptHash converts an address to a reverse script hash -func ToReverseScriptHash(address string) string { - a, err := Uint160Decode(address) - if err != nil { - return "" - } - return a.ReverseString() -} - -// FromUint160 returns the "NEO address" from the given -// Uint160. -func FromUint160(u util.Uint160) (string, error) { - // Dont forget to prepend the Address version 0x17 (23) A - b := append([]byte{0x17}, u.Bytes()...) - return base58.CheckEncode(b) -} - -// Uint160Decode attempts to decode the given NEO address string -// into an Uint160. -func Uint160Decode(s string) (u util.Uint160, err error) { - b, err := base58.CheckDecode(s) - if err != nil { - return u, err - } - return util.Uint160DecodeBytes(b[1:21]) -} diff --git a/_pkg.dev/wire/util/address/address_test.go b/_pkg.dev/wire/util/address/address_test.go deleted file mode 100644 index af264a935..000000000 --- a/_pkg.dev/wire/util/address/address_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package address - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestScriptHash(t *testing.T) { - address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP" - - hash := ToScriptHash(address) - reverseHash := ToReverseScriptHash(address) - - assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", reverseHash) - assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", hash) -} diff --git a/pkg/crypto/address_test.go b/pkg/crypto/address_test.go index b325adb43..c4d54fd2c 100644 --- a/pkg/crypto/address_test.go +++ b/pkg/crypto/address_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestUint160DecodeAddress(t *testing.T) { +func TestUint160DecodeEncodeAddress(t *testing.T) { addrs := []string{ "AMLr1CpPQtbEdiJdriX1HpRNMZUwbU2Huj", "AKtwd3DRXj3nL5kHMUoNsdnsCEVjnuuTFF", @@ -20,3 +20,15 @@ func TestUint160DecodeAddress(t *testing.T) { assert.Equal(t, addr, AddressFromUint160(val)) } } + +func TestUint160DecodeKnownAddress(t *testing.T) { + address := "AJeAEsmeD6t279Dx4n2HWdUvUmmXQ4iJvP" + + val, err := Uint160DecodeAddress(address) + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, "b28427088a3729b2536d10122960394e8be6721f", val.ReverseString()) + assert.Equal(t, "1f72e68b4e39602912106d53b229378a082784b2", val.String()) +}