Skip to content

Commit

Permalink
go-ipfs-config: add test validating that createIdentity follows algor…
Browse files Browse the repository at this point in the history
…ithm preference
  • Loading branch information
willscott committed Apr 28, 2020
1 parent b3a6ec5 commit 8c12429
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions config/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package config

import (
"bytes"
"testing"

"github.com/ipfs/interface-go-ipfs-core/options"
crypto_pb "github.com/libp2p/go-libp2p-core/crypto/pb"
)

func TestCreateIdentity(t *testing.T) {
writer := bytes.NewBuffer(nil)
id, err := CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.Ed25519Key)})
if err != nil {
t.Fatal(err)
}
pk, err := id.DecodePrivateKey("")
if err != nil {
t.Fatal(err)
}
if pk.Type() != crypto_pb.KeyType_Ed25519 {
t.Fatal("unexpected type:", pk.Type())
}

id, err = CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.RSAKey)})
if err != nil {
t.Fatal(err)
}
pk, err = id.DecodePrivateKey("")
if err != nil {
t.Fatal(err)
}
if pk.Type() != crypto_pb.KeyType_RSA {
t.Fatal("unexpected type:", pk.Type())
}
}

0 comments on commit 8c12429

Please sign in to comment.