frostfs-api-go/chain/address_test.go

42 lines
732 B
Go
Raw Normal View History

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"
)
type addressTestCase struct {
name string
publicKey string
wallet string
2019-11-18 13:34:06 +00:00
}
func TestKeyToAddress(t *testing.T) {
tests := []addressTestCase{
2019-11-18 13:34:06 +00:00
{
"nil key",
"",
"",
2019-11-18 13:34:06 +00:00
},
{
"correct key",
"031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a",
"NgzuJWWGVEwFGsRrgzj8knswEYRJrTe7sm",
2019-11-18 13:34:06 +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)
key := crypto.UnmarshalPublicKey(data)
2019-11-18 13:34:06 +00:00
require.Equal(t, tests[i].wallet, KeyToAddress(key))
2019-11-18 13:34:06 +00:00
})
}
}