github.com/aergoio/aergo@v1.3.1/types/account_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestEnDecodeAddress(t *testing.T) {
    10  	addr, err := DecodeAddress("aergo.system")
    11  	assert.NoError(t, err, "decode aergo.system")
    12  	assert.Equal(t, "aergo.system", string(addr), "decode aergo.system")
    13  
    14  	addr, err = DecodeAddress("aergo.name")
    15  	assert.NoError(t, err, "decode aergo.name")
    16  	assert.Equal(t, "aergo.name", string(addr), "decode aergo.name")
    17  
    18  	addr, err = DecodeAddress("aergo.enterprise")
    19  	assert.NoError(t, err, "decode aergo.enterprise")
    20  	assert.Equal(t, "aergo.enterprise", string(addr), "decode aergo.enterprise")
    21  
    22  	addr, err = DecodeAddress("")
    23  	assert.NoError(t, err, "decode aergo.name")
    24  	assert.Equal(t, "", string(addr), "decode \"\"")
    25  
    26  	encoded := EncodeAddress([]byte("aergo.system"))
    27  	assert.Equal(t, "aergo.system", encoded, "encode aergo.system")
    28  
    29  	encoded = EncodeAddress([]byte("aergo.name"))
    30  	assert.Equal(t, "aergo.name", encoded, "encode aergo.name")
    31  
    32  	encoded = EncodeAddress([]byte("aergo.enterprise"))
    33  	assert.Equal(t, "aergo.enterprise", encoded, "encode aergo.enterprise")
    34  
    35  	encoded = EncodeAddress(nil)
    36  	assert.Equal(t, "", encoded, "encode nil")
    37  
    38  	testAddress := []byte{3, 49, 133, 46, 196, 51, 37, 27, 66, 1, 191, 92, 224, 12, 248, 246, 21, 247, 79, 10, 164, 63, 34, 97, 238, 0, 145, 129, 206, 54, 218, 241, 84}
    39  	encoded = EncodeAddress(testAddress)
    40  	assert.Equal(t, "AmNpn7K9wg6wsn6oMkTirQSUNdqtDm94iCrrpP5ZpwCAAxxPrsU2", encoded, "encode test address")
    41  
    42  	addr, err = DecodeAddress("AmNpn7K9wg6wsn6oMkTirQSUNdqtDm94iCrrpP5ZpwCAAxxPrsU2")
    43  	assert.NoError(t, err, "decode test address")
    44  	assert.Equal(t, testAddress, addr, "decode test address")
    45  }
    46  
    47  func TestToAddress(t *testing.T) {
    48  	addr := ToAddress("")
    49  	assert.Equal(t, 0, len(addr), "nil")
    50  }