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

Function TestKeystoreDeleteKeyWithOpts

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

Source from the content-addressed store, hash-verified

64}
65
66func TestKeystoreDeleteKeyWithOpts(t *testing.T) {
67 password := "password"
68 // pre-create a new private key
69 private, err := NewBLS12381PrivateKey()
70 require.NoError(t, err)
71 // get the address
72 address := private.PublicKey().Address().Bytes()
73 // create a new in-memory keystore
74 ks := NewKeystoreInMemory()
75 // execute the function call
76 gotAddress, err := ks.ImportRaw(private.Bytes(), password, ImportRawOpts{
77 Nickname: "pablito",
78 })
79 require.NoError(t, err)
80 // validate got address vs expected
81 require.Equal(t, hex.EncodeToString(address), gotAddress)
82 // delete the key
83 ks.DeleteKey(DeleteOpts{
84 Address: address,
85 })
86 // check the key was imported with address
87 _, err = ks.GetKey(address, password)
88 require.ErrorContains(t, err, "key not found")
89 // check the key was imported with nickname
90 _, err = ks.GetKeyGroup(password, GetKeyGroupOpts{
91 Nickname: "pablito",
92 })
93 require.ErrorContains(t, err, "key not found")
94
95 // execute the function call
96 gotAddress, err = ks.ImportRaw(private.Bytes(), password, ImportRawOpts{
97 Nickname: "pablito",
98 })
99 require.NoError(t, err)
100 // validate got address vs expected
101 require.Equal(t, hex.EncodeToString(address), gotAddress)
102 // delete the key
103 ks.DeleteKey(DeleteOpts{
104 Nickname: "pablito",
105 })
106 // check the key was imported with address
107 _, err = ks.GetKey(address, password)
108 require.ErrorContains(t, err, "key not found")
109 // check the key was imported with nickname
110 _, err = ks.GetKeyGroup(password, GetKeyGroupOpts{
111 Nickname: "pablito",
112 })
113 require.ErrorContains(t, err, "key not found")
114}

Callers

nothing calls this directly

Calls 11

PublicKeyMethod · 0.95
BytesMethod · 0.95
NewBLS12381PrivateKeyFunction · 0.85
NewKeystoreInMemoryFunction · 0.85
ImportRawMethod · 0.80
EqualMethod · 0.80
DeleteKeyMethod · 0.80
GetKeyGroupMethod · 0.80
BytesMethod · 0.65
AddressMethod · 0.65
GetKeyMethod · 0.45

Tested by

no test coverage detected