Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Fix parallelism #373

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gateway-crypto/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 21 additions & 15 deletions pallets/cash/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -165,11 +169,12 @@ pub fn initialize_storage() {
}

pub fn validator_a_sign(data: &[u8]) -> Result<ChainSignature, Reason> {
std::env::set_var(
"ETH_KEY",
"6bc5ea78f041146e38233f5bc29c703c1cec8eaaa2214353ee8adf7fc598f23d",
);
validator_sign::<Test>(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> {
Expand All @@ -183,11 +188,12 @@ pub fn a_receive_chain_reorg(reorg: &ChainReorg) -> Result<(), DispatchError> {
}

pub fn validator_b_sign(data: &[u8]) -> Result<ChainSignature, Reason> {
std::env::set_var(
"ETH_KEY",
"50f05592dc31bfc65a77c4cc80f2764ba8f9a7cce29c94a51fe2d70cb5599374",
);
validator_sign::<Test>(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> {
Expand Down