Skip to content

Commit

Permalink
PR(TEST): Add a unit test for gen. command
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Jun 24, 2024
1 parent d181d00 commit 2946835
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions acp/identity/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,37 @@ func Test_DIDFromPublicKey_ReturnsErrorWhenProducerFails(t *testing.T) {
require.Empty(t, did)
require.ErrorIs(t, err, ErrDIDCreation)
}

func Test_RawIdentityGeneration_ReturnsNewRawIdentity(t *testing.T) {
newIdentity, err := Generate()
require.NoError(t, err)

// Check that both private and public key are not empty.
require.NotEmpty(t, newIdentity.PrivateKey)
require.NotEmpty(t, newIdentity.PublicKey)

// Check leading `did:key` prefix.
require.Equal(t, newIdentity.DID[:7], "did:key")
}

func Test_RawIdentityGenerationIsNotFixed_ReturnsUniqueRawIdentites(t *testing.T) {
newIdentity1, err1 := Generate()
newIdentity2, err2 := Generate()
require.NoError(t, err1)
require.NoError(t, err2)

// Check that both private and public key are not empty.
require.NotEmpty(t, newIdentity1.PrivateKey)
require.NotEmpty(t, newIdentity1.PublicKey)
require.NotEmpty(t, newIdentity2.PrivateKey)
require.NotEmpty(t, newIdentity2.PublicKey)

// Check leading `did:key` prefix.
require.Equal(t, newIdentity1.DID[:7], "did:key")
require.Equal(t, newIdentity2.DID[:7], "did:key")

// Check both are different.
require.NotEqual(t, newIdentity1.PrivateKey, newIdentity2.PrivateKey)
require.NotEqual(t, newIdentity1.PublicKey, newIdentity2.PublicKey)
require.NotEqual(t, newIdentity1.DID, newIdentity2.DID)
}

0 comments on commit 2946835

Please sign in to comment.