2019-08-15 17:59:22 +02:00
|
|
|
// 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};
|
2019-10-23 13:03:46 +02:00
|
|
|
use ethkey::Password;
|
|
|
|
use parity_crypto::publickey::{Signature, Error};
|
2019-08-15 17:59:22 +02:00
|
|
|
use log::warn;
|
|
|
|
use accounts::{self, AccountProvider, SignError};
|
|
|
|
|
|
|
|
use crate::signer::EngineSigner;
|
|
|
|
|
|
|
|
impl EngineSigner for (Arc<AccountProvider>, Address, Password) {
|
2019-10-23 13:03:46 +02:00
|
|
|
fn sign(&self, hash: H256) -> Result<Signature, Error> {
|
2019-08-15 17:59:22 +02:00
|
|
|
match self.0.sign(self.1, Some(self.2.clone()), hash) {
|
|
|
|
Err(SignError::NotUnlocked) => unreachable!(),
|
2019-10-23 13:03:46 +02:00
|
|
|
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))) => {
|
2019-08-15 17:59:22 +02:00
|
|
|
warn!("Low level crypto error: {:?}", err);
|
2019-10-23 13:03:46 +02:00
|
|
|
Err(Error::InvalidSecretKey)
|
2019-08-15 17:59:22 +02:00
|
|
|
},
|
|
|
|
Err(SignError::SStore(err)) => {
|
|
|
|
warn!("Error signing for engine: {:?}", err);
|
2019-10-23 13:03:46 +02:00
|
|
|
Err(Error::InvalidSignature)
|
2019-08-15 17:59:22 +02:00
|
|
|
},
|
|
|
|
Ok(ok) => Ok(ok),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn address(&self) -> Address {
|
|
|
|
self.1
|
|
|
|
}
|
|
|
|
}
|