JoshOrndorff / recipes

A Hands-On Cookbook for Aspiring Blockchain Chefs
GNU General Public License v3.0
379 stars 187 forks source link

New (Sub)Recipe: show users how to use keystore in tests. #211

Closed nczhu closed 4 years ago

nczhu commented 4 years ago

Basically this:

Writing to keystore:

// a key storage to store new key pairs during testing
let keystore = KeyStore::new(); 
let alice_pub_key = keystore.write().sr25519_generate_new(SR25519, Some(ALICE_PHRASE)).unwrap();

...
// Print the values to get GENESIS_UTXO
let mut ext = sp_io::TestExternalities::from(t);
ext.register_extension(KeystoreExt(keystore));

Getting / using from keystore:

let alice_pub_key = sp_io::crypto::sr25519_public_keys(SR25519)[0];

nczhu commented 4 years ago

nvm, I see this is already done in off-chain workers reciple