(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestNewPublicKeyFromBytes(t *testing.T) { |
| 66 | // pre-generate a secp256k1 |
| 67 | secp256k1Pk, err := NewSECP256K1PrivateKey() |
| 68 | require.NoError(t, err) |
| 69 | // pre-generate a secp256k1 |
| 70 | ethSecp256k1, err := NewETHSECP256K1PrivateKey() |
| 71 | require.NoError(t, err) |
| 72 | // pre-generate a ED25519 |
| 73 | ed25519Pk, err := NewEd25519PrivateKey() |
| 74 | require.NoError(t, err) |
| 75 | // pre-generate a BLS12381 |
| 76 | blsPrivateKey, err := NewBLS12381PrivateKey() |
| 77 | require.NoError(t, err) |
| 78 | tests := []struct { |
| 79 | name string |
| 80 | bytes []byte |
| 81 | expected PublicKeyI |
| 82 | error string |
| 83 | }{ |
| 84 | { |
| 85 | name: "not a recognized key", |
| 86 | bytes: []byte("abcd"), |
| 87 | error: "unrecognized public key format", |
| 88 | }, |
| 89 | { |
| 90 | name: "eth_secp256k1 public key", |
| 91 | bytes: ethSecp256k1.PublicKey().Bytes(), |
| 92 | expected: ethSecp256k1.PublicKey(), |
| 93 | }, |
| 94 | { |
| 95 | name: "eth_secp256k1 public key with a SEC1 prefix", |
| 96 | bytes: ethSecp256k1.PublicKey().(*ETHSECP256K1PublicKey).BytesWithPrefix(), |
| 97 | expected: ethSecp256k1.PublicKey(), |
| 98 | }, |
| 99 | { |
| 100 | name: "secp256k1 public key", |
| 101 | bytes: secp256k1Pk.PublicKey().Bytes(), |
| 102 | expected: secp256k1Pk.PublicKey(), |
| 103 | }, |
| 104 | { |
| 105 | name: "ed25519 public key", |
| 106 | bytes: ed25519Pk.PublicKey().Bytes(), |
| 107 | expected: ed25519Pk.PublicKey(), |
| 108 | }, |
| 109 | { |
| 110 | name: "bls12381 public key", |
| 111 | bytes: blsPrivateKey.PublicKey().Bytes(), |
| 112 | expected: blsPrivateKey.PublicKey(), |
| 113 | }, |
| 114 | } |
| 115 | for _, test := range tests { |
| 116 | t.Run(test.name, func(t *testing.T) { |
| 117 | // execute the function call |
| 118 | got, e := NewPublicKeyFromBytes(test.bytes) |
| 119 | // check if an error is expected or not |
| 120 | require.Equal(t, test.error != "", e != nil) |
| 121 | // check the error |
| 122 | if e != nil { |
nothing calls this directly
no test coverage detected