From 59be77266f07704799026814423fe4cace48406a Mon Sep 17 00:00:00 2001 From: Antonina Norair Date: Thu, 29 Apr 2021 13:09:50 -0700 Subject: [PATCH] Fix parallelism --- gateway-crypto/src/std.rs | 2 +- pallets/cash/src/tests/mod.rs | 36 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/gateway-crypto/src/std.rs b/gateway-crypto/src/std.rs index 3f78b09b3..14d84d157 100644 --- a/gateway-crypto/src/std.rs +++ b/gateway-crypto/src/std.rs @@ -106,7 +106,7 @@ pub(crate) fn combine_sig_and_recovery( /// /// Reference implementation https://github.com/MaiaVictor/eth-lib/blob/d959c54faa1e1ac8d474028ed1568c5dce27cc7a/src/account.js#L55 /// This is called by web3.js https://github.com/ethereum/web3.js/blob/27c9679766bb4a965843e9bdaea575ea706202f1/packages/web3-eth-accounts/package.json#L18 -fn eth_sign(message: &[u8], private_key: &SecretKey, prepend_preamble: bool) -> SignatureBytes { +pub fn eth_sign(message: &[u8], private_key: &SecretKey, prepend_preamble: bool) -> SignatureBytes { let hashed = eth_keccak_for_signature(message, prepend_preamble); // todo: there is something in this function that says "it is ok for the message to overflow.." that seems bad. let message = secp256k1::Message::parse(&hashed); diff --git a/pallets/cash/src/tests/mod.rs b/pallets/cash/src/tests/mod.rs index 273c32441..4337d5fec 100644 --- a/pallets/cash/src/tests/mod.rs +++ b/pallets/cash/src/tests/mod.rs @@ -1,15 +1,19 @@ #![allow(non_upper_case_globals)] pub use codec::{Decode, Encode}; -use ethereum_client::encode_block_hex; pub use frame_support::{assert_err, assert_ok, dispatch::DispatchError}; pub use hex_literal::hex; -pub use our_std::convert::TryInto; -pub use our_std::{iter::FromIterator, str::FromStr}; -use parking_lot::RwLock; +pub use our_std::{ + sync::Arc, + convert::TryInto, + iter::FromIterator, str::FromStr, +}; pub use sp_core::crypto::AccountId32; +use parking_lot::RwLock; +use secp256k1::SecretKey; use sp_core::offchain::testing; -use std::sync::Arc; + +use ethereum_client::encode_block_hex; pub mod assets; pub mod common; @@ -165,11 +169,12 @@ pub fn initialize_storage() { } pub fn validator_a_sign(data: &[u8]) -> Result { - std::env::set_var( - "ETH_KEY", - "6bc5ea78f041146e38233f5bc29c703c1cec8eaaa2214353ee8adf7fc598f23d", - ); - validator_sign::(data) + let private_key = + hex::decode("6bc5ea78f041146e38233f5bc29c703c1cec8eaaa2214353ee8adf7fc598f23d").unwrap(); + let secret_key = SecretKey::parse_slice(&private_key).unwrap(); + let signature_raw = gateway_crypto::eth_sign(data, &secret_key, false); + let signature = ChainSignature::Eth(signature_raw); + Ok(signature) } pub fn a_receive_chain_blocks(blocks: &ChainBlocks) -> Result<(), DispatchError> { @@ -183,11 +188,12 @@ pub fn a_receive_chain_reorg(reorg: &ChainReorg) -> Result<(), DispatchError> { } pub fn validator_b_sign(data: &[u8]) -> Result { - std::env::set_var( - "ETH_KEY", - "50f05592dc31bfc65a77c4cc80f2764ba8f9a7cce29c94a51fe2d70cb5599374", - ); - validator_sign::(data) + let private_key = + hex::decode("50f05592dc31bfc65a77c4cc80f2764ba8f9a7cce29c94a51fe2d70cb5599374").unwrap(); + let secret_key = SecretKey::parse_slice(&private_key).unwrap(); + let signature_raw = gateway_crypto::eth_sign(data, &secret_key, false); + let signature = ChainSignature::Eth(signature_raw); + Ok(signature) } pub fn b_receive_chain_blocks(blocks: &ChainBlocks) -> Result<(), DispatchError> {