2019-11-18 13:34:06 +00:00
|
|
|
package chain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
type addressTestCase struct {
|
|
|
|
name string
|
|
|
|
publicKey string
|
|
|
|
wallet string
|
2019-11-18 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
func TestKeyToAddress(t *testing.T) {
|
|
|
|
tests := []addressTestCase{
|
2019-11-18 13:34:06 +00:00
|
|
|
{
|
2020-07-17 14:59:19 +00:00
|
|
|
"nil key",
|
|
|
|
"",
|
|
|
|
"",
|
2019-11-18 13:34:06 +00:00
|
|
|
},
|
|
|
|
{
|
2020-07-17 14:59:19 +00:00
|
|
|
"correct key",
|
|
|
|
"031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a",
|
|
|
|
"NgzuJWWGVEwFGsRrgzj8knswEYRJrTe7sm",
|
2019-11-18 13:34:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
for i := range tests {
|
|
|
|
t.Run(tests[i].name, func(t *testing.T) {
|
|
|
|
data, err := hex.DecodeString(tests[i].publicKey)
|
2019-11-18 13:34:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
key := crypto.UnmarshalPublicKey(data)
|
2019-11-18 13:34:06 +00:00
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
require.Equal(t, tests[i].wallet, KeyToAddress(key))
|
2019-11-18 13:34:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|