MCPcopy
hub / github.com/canopy-network/canopy / TestKeystoreImportWithOpts

Function TestKeystoreImportWithOpts

lib/crypto/keystore_test.go:10–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestKeystoreImportWithOpts(t *testing.T) {
11 password := []byte("password")
12 // pre-create a new private key
13 private, err := NewBLS12381PrivateKey()
14 require.NoError(t, err)
15 // get the address
16 address := private.PublicKey().Address().Bytes()
17 // encrypt the private key
18 encrypted, err := EncryptPrivateKey(private.PublicKey().Bytes(), private.Bytes(), password, private.PublicKey().Address().String())
19 require.NoError(t, err)
20 // create a new in-memory keystore
21 ks := NewKeystoreInMemory()
22 // execute the function call
23 require.NoError(t, ks.Import(encrypted, ImportOpts{
24 Address: address,
25 Nickname: "pablito",
26 }))
27 // check the key was imported
28 got, err := ks.GetKey(address, string(password))
29 require.NoError(t, err)
30 // validate got vs expected
31 require.EqualExportedValues(t, private, got)
32 // check the key was imported by nickname
33 pKey, err := ks.GetKeyGroup(string(password), GetKeyGroupOpts{
34 Nickname: "pablito",
35 })
36 require.NoError(t, err)
37 // validate got vs expected
38 require.EqualExportedValues(t, private, pKey.PrivateKey)
39}
40
41func TestKeystoreImportRawWithOpts(t *testing.T) {
42 password := "password"

Callers

nothing calls this directly

Calls 11

PublicKeyMethod · 0.95
BytesMethod · 0.95
NewBLS12381PrivateKeyFunction · 0.85
EncryptPrivateKeyFunction · 0.85
NewKeystoreInMemoryFunction · 0.85
ImportMethod · 0.80
GetKeyGroupMethod · 0.80
BytesMethod · 0.65
AddressMethod · 0.65
StringMethod · 0.65
GetKeyMethod · 0.45

Tested by

no test coverage detected