Skip to content

Commit

Permalink
fix signature tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 1, 2020
1 parent 0531a5d commit 0f19fc2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
11 changes: 11 additions & 0 deletions sdk/zksync-rs/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use num::BigUint;
use zksync_crypto::PrivateKey;
use zksync_types::tx::{ChangePubKey, PackedEthSignature};
use zksync_types::{AccountId, Address, ForcedExit, Nonce, PubKeyHash, Token, Transfer, Withdraw};
// Local imports
use crate::WalletCredentials;

fn signing_failed_error(err: impl ToString) -> SignerError {
SignerError::SigningFailed(err.to_string())
Expand Down Expand Up @@ -48,6 +50,15 @@ impl<S: EthereumSigner> Signer<S> {
}
}

/// Construct a `Signer` with the given credentials
pub fn with_credentials(credentials: WalletCredentials<S>) -> Self {
Self::new(
credentials.zksync_private_key,
credentials.eth_address,
credentials.eth_signer,
)
}

pub fn pubkey_hash(&self) -> &PubKeyHash {
&self.pubkey_hash
}
Expand Down
8 changes: 2 additions & 6 deletions sdk/zksync-rs/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ impl<S: EthereumSigner + Clone> Wallet<S> {
provider: Provider,
credentials: WalletCredentials<S>,
) -> Result<Self, ClientError> {
let mut signer = Signer::new(
credentials.zksync_private_key,
credentials.eth_address,
credentials.eth_signer,
);

let account_info = provider.account_info(credentials.eth_address).await?;

let mut signer = Signer::with_credentials(credentials);
signer.set_account_id(account_info.id);

let tokens = TokensCache::new(provider.tokens().await?);
Expand Down
22 changes: 8 additions & 14 deletions sdk/zksync-rs/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,28 @@ mod utils_with_vectors {
#[cfg(test)]
mod signatures_with_vectors {
use super::*;
use zksync::{signer::Signer, Provider, Wallet, WalletCredentials};
use zksync::{signer::Signer, WalletCredentials};
use zksync_config::test_config::unit_vectors::{EthSignature, Tx};
use zksync_eth_signer::PrivateKeySigner;
use zksync_types::{network::Network, AccountId, Address, H256};

async fn get_signer(
private_key_raw: &[u8],
eth_private_key_raw: &[u8],
from_address: Address,
account_id: AccountId,
) -> Signer<PrivateKeySigner> {
let eth_signer = PrivateKeySigner::new(H256::from_slice(private_key_raw));
let eth_private_key = H256::from_slice(eth_private_key_raw);
let eth_signer = PrivateKeySigner::new(eth_private_key);

let creds =
WalletCredentials::from_eth_signer(from_address, eth_signer, Network::Localhost)
.await
.unwrap();
let creds = WalletCredentials::from_eth_signer(from_address, eth_signer, Network::Mainnet)
.await
.unwrap();

let provider = Provider::new(Network::Localhost);
let wallet = Wallet::new(provider, creds).await.unwrap();
let Wallet { mut signer, .. } = wallet;
let mut signer = Signer::with_credentials(creds);
signer.set_account_id(Some(account_id));
signer
}

#[ignore]
#[tokio::test]
async fn test_transfer_signature() {
let test_vectors = TestVectorsConfig::load();
Expand Down Expand Up @@ -231,7 +228,6 @@ mod signatures_with_vectors {
}
}

#[ignore]
#[tokio::test]
async fn test_withdraw_signature() {
let test_vectors = TestVectorsConfig::load();
Expand Down Expand Up @@ -287,7 +283,6 @@ mod signatures_with_vectors {
}
}

#[ignore]
#[tokio::test]
async fn test_change_pubkey_signature() {
let test_vectors = TestVectorsConfig::load();
Expand Down Expand Up @@ -344,7 +339,6 @@ mod signatures_with_vectors {
}
}

#[ignore]
#[tokio::test]
async fn test_forced_exit_signature() {
let test_vectors = TestVectorsConfig::load();
Expand Down

0 comments on commit 0f19fc2

Please sign in to comment.