2023-11-08 13:36:55 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFrostfsIDConfig(t *testing.T) {
|
|
|
|
pks := make([]*keys.PrivateKey, 4)
|
|
|
|
for i := range pks {
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
pks[i] = pk
|
|
|
|
}
|
|
|
|
|
2023-12-04 13:12:59 +00:00
|
|
|
fmts := []string{
|
2023-11-08 13:36:55 +00:00
|
|
|
pks[0].GetScriptHash().StringLE(),
|
|
|
|
address.Uint160ToString(pks[1].GetScriptHash()),
|
|
|
|
hex.EncodeToString(pks[2].PublicKey().UncompressedBytes()),
|
|
|
|
hex.EncodeToString(pks[3].PublicKey().Bytes()),
|
2023-12-04 13:12:59 +00:00
|
|
|
}
|
2023-11-08 13:36:55 +00:00
|
|
|
|
2023-12-04 13:12:59 +00:00
|
|
|
for i := range fmts {
|
|
|
|
v := viper.New()
|
|
|
|
v.Set("frostfsid.admin", fmts[i])
|
|
|
|
|
|
|
|
actual, found, err := getFrostfsIDAdmin(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, found)
|
|
|
|
require.Equal(t, pks[i].GetScriptHash(), actual)
|
2023-11-08 13:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("bad key", func(t *testing.T) {
|
|
|
|
v := viper.New()
|
2023-12-04 13:12:59 +00:00
|
|
|
v.Set("frostfsid.admin", "abc")
|
2023-11-08 13:36:55 +00:00
|
|
|
|
2023-12-04 13:12:59 +00:00
|
|
|
_, found, err := getFrostfsIDAdmin(v)
|
2023-11-08 13:36:55 +00:00
|
|
|
require.Error(t, err)
|
2023-12-04 13:12:59 +00:00
|
|
|
require.True(t, found)
|
|
|
|
})
|
|
|
|
t.Run("missing key", func(t *testing.T) {
|
|
|
|
v := viper.New()
|
|
|
|
|
|
|
|
_, found, err := getFrostfsIDAdmin(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, found)
|
2023-11-08 13:36:55 +00:00
|
|
|
})
|
|
|
|
}
|