Пример #1
0
func TestMustDecodeBase58Address(t *testing.T) {
	p, _ := GenerateKeyPair()
	a := AddressFromPubKey(p)
	assert.Nil(t, a.Verify(p))

	assert.Panics(t, func() { MustDecodeBase58Address("") })
	assert.Panics(t, func() { MustDecodeBase58Address("cascs") })
	b := a.Bytes()
	h := string(base58.Hex2Base58(b[:len(b)/2]))
	assert.Panics(t, func() { MustDecodeBase58Address(h) })
	h = string(base58.Hex2Base58(b))
	assert.NotPanics(t, func() { MustDecodeBase58Address(h) })
	a2 := MustDecodeBase58Address(h)
	assert.Equal(t, a, a2)
}
Пример #2
0
func TestDecodeBase58Address(t *testing.T) {
	p, _ := GenerateKeyPair()
	a := AddressFromPubKey(p)
	assert.Nil(t, a.Verify(p))

	a2, err := DecodeBase58Address("")
	assert.NotNil(t, err)
	a2, err = DecodeBase58Address("cascs")
	assert.NotNil(t, err)
	b := a.Bytes()
	h := string(base58.Hex2Base58(b[:len(b)/2]))
	a2, err = DecodeBase58Address(h)
	assert.NotNil(t, err)
	h = string(base58.Hex2Base58(b))
	a2, err = DecodeBase58Address(h)
	assert.Nil(t, err)
	assert.Equal(t, a, a2)
}
Пример #3
0
// Address as Base58 encoded string
func (self *Address) String() string {
	return string(base58.Hex2Base58(self.Bytes()))
}