openethereum/ethcore/engine/src/test_helpers.rs
Anton Gavrilov 834585d61b
Crypto primitives removed from ethkey (#11174)
* Crypto utils removed from ethkey

* Fix ethkey lib

* Switch ethsore to new crypto

* Accounts crate fixed

* Secret store crate switched to new crypto

* Ethcore builtin fixed

* Accounts crate fixed

* Ethcore crate fixed

* Util network fixed

* Util network-devp2p fixed

* Private tx fixed

* Ethcore sync fixed

* Secret store fixed

* Rpc fixed

* Parity fixed

* Ethkey cli fixed

* Local store fixed

* Ethcore blockchain fixed

* Cargo.lock pushed; doc comment added for reversed nonce

* Ethstore tests fixed

* Ethstore cli fixed

* Miner fixed

* Snapshot tests are fixed

* Single brackets removed

* Machine fixed

* Verification fixed

* Executive state fixed

* More single brackets removed

* Update version of parity-crypto

* Use published version 0.4.2 of parity-crypto

* New test in tx_filter fixed
2019-10-23 13:03:46 +02:00

51 lines
1.7 KiB
Rust

// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Test helpers for engine related tests
use std::sync::Arc;
use ethereum_types::{Address, H256};
use ethkey::Password;
use parity_crypto::publickey::{Signature, Error};
use log::warn;
use accounts::{self, AccountProvider, SignError};
use crate::signer::EngineSigner;
impl EngineSigner for (Arc<AccountProvider>, Address, Password) {
fn sign(&self, hash: H256) -> Result<Signature, Error> {
match self.0.sign(self.1, Some(self.2.clone()), hash) {
Err(SignError::NotUnlocked) => unreachable!(),
Err(SignError::NotFound) => Err(Error::InvalidAddress),
Err(SignError::SStore(accounts::Error::EthCrypto(err))) => Err(Error::Custom(err.to_string())),
Err(SignError::SStore(accounts::Error::EthPublicKeyCrypto(err))) => {
warn!("Low level crypto error: {:?}", err);
Err(Error::InvalidSecretKey)
},
Err(SignError::SStore(err)) => {
warn!("Error signing for engine: {:?}", err);
Err(Error::InvalidSignature)
},
Ok(ok) => Ok(ok),
}
}
fn address(&self) -> Address {
self.1
}
}