From 2946835fb6de8bb2b5bc98eb0824dcc73ba57de0 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Mon, 24 Jun 2024 12:51:31 -0400 Subject: [PATCH] PR(TEST): Add a unit test for gen. command --- acp/identity/identity_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/acp/identity/identity_test.go b/acp/identity/identity_test.go index 4d6d4814cf..bcef99005b 100644 --- a/acp/identity/identity_test.go +++ b/acp/identity/identity_test.go @@ -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) +}