2018-03-28 05:23:43 -06:00
|
|
|
package eth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEthParser_GetAddrIDFromAddress(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
address string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "with 0x prefix",
|
|
|
|
args: args{address: "0x81b7e08f65bdf5648606c89998a9cc8164397647"},
|
|
|
|
want: "81b7e08f65bdf5648606c89998a9cc8164397647",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without 0x prefix",
|
|
|
|
args: args{address: "47526228d673e9f079630d6cdaff5a2ed13e0e60"},
|
|
|
|
want: "47526228d673e9f079630d6cdaff5a2ed13e0e60",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "odd address",
|
|
|
|
args: args{address: "7526228d673e9f079630d6cdaff5a2ed13e0e60"},
|
|
|
|
want: "07526228d673e9f079630d6cdaff5a2ed13e0e60",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ErrAddressMissing",
|
|
|
|
args: args{address: ""},
|
|
|
|
want: "",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "error - not eth address",
|
|
|
|
args: args{address: "1JKgN43B9SyLuZH19H5ECvr4KcfrbVHzZ6"},
|
|
|
|
want: "",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2018-04-03 14:24:23 -06:00
|
|
|
p := &EthereumParser{}
|
2018-03-28 05:23:43 -06:00
|
|
|
got, err := p.GetAddrIDFromAddress(tt.args.address)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("EthParser.GetAddrIDFromAddress() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := hex.EncodeToString(got)
|
|
|
|
if !reflect.DeepEqual(h, tt.want) {
|
|
|
|
t.Errorf("EthParser.GetAddrIDFromAddress() = %v, want %v", h, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|