2

I'm trying to add a test case for my function which is extracting key from the local Keystore.

This is how I'm creating an instance of a local Keystore and setting a key inside it in my test environment:

let keystore = LocalKeystore::in_memory();
SyncCryptoStore::insert_unknown(&keystore, KeyTypeId::try_from("test").unwrap(), "test", public_key);

Here the problem I'm facing is, I'm unable to extract the stored key from the keystone. This is how I'm extracting it:

SyncCryptoStore::sr25519_public_keys(&keystore, KeyTypeId::try_from("test").unwrap())

This function is returning an empty vector.

1 Answer 1

2

You can check the key existance with has_key method and list all available keys with keys. the sr25519_public_keys method forces to retrieve just the sr25519 ones.

3
  • I'm getting sr25519 in my list but still, this function is returning an empty vector. – Apr 11, 2022 at 11:24
  • you have created public_key somewhere that maybe is not true sr25519 please use sr25519_generate_new instead and iterate over all sr25519 keys by sr25519_public_keys Apr 11, 2022 at 21:09
  • I was converting the public key into bytes using .as_bytes(), but after converting it using sp_core::sr25519::Public:: from_ss58check(), the problem got resolved. Converting a string of public key into bytes using .as_bytes() is the wrong approach, in substrate we should convert the keys into bytes using the substrate's internal components only. Thanks for your help. Apr 12, 2022 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.