Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 2, 2020
1 parent d595c98 commit b1b6373
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions core/lib/config/src/test_config/unit_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ pub struct CryptoPrimitiveInput {
pub struct CryptoPrimitiveOutput {
#[serde(with = "ZeroPrefixHexSerde")]
pub private_key: Vec<u8>,
// FIXME: is it really a hash?
pub pub_key_hash: String,
pub pub_key: String,
pub signature: String,
}

Expand Down
2 changes: 1 addition & 1 deletion core/tests/loadtest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false # We don't want to publish our tests.
[dependencies]
zksync_types = { path = "../../lib/types", version = "1.0" }
zksync_eth_signer = { path = "../../lib/eth_signer", version = "1.0" }
zksync = { path = "../../../sdk/zksync-rs", version = "0.1" }
zksync = { path = "../../../sdk/zksync-rs", version = "0.2" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_utils = { path = "../../lib/utils", version = "1.0" }

Expand Down
2 changes: 1 addition & 1 deletion etc/test_config/sdk/test-vectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"outputs": {
"privateKey": "0x0552a69519d1f3043611126c13489ff4a2a867a1c667b1d9d9031cd27fdcff5a",
"pubKeyHash": "17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184",
"pubKey": "17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184",
"signature": "5462c3083d92b832d540c9068eed0a0450520f6dd2e4ab169de1a46585b394a4292896a2ebca3c0378378963a6bc1710b64c573598e73de3a33d6cec2f5d7403"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface CryptoPrimitivesTestEntry extends TestVectorEntry {
// Private key to be obtained from seed.
privateKey: string;
// Hash of a public key corresponding to the generated private key.
pubKeyHash: string;
pubKey: string;
// Signature obtained using private key and message.
signature: string;
};
Expand All @@ -41,7 +41,7 @@ export async function generateCryptoTestVectors(): Promise<TestVector<CryptoPrim
},
outputs: {
privateKey: utils.hexlify(privateKey),
pubKeyHash: pubKey,
pubKey: pubKey,
signature: signature
}
};
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zksync"
version = "0.1.1"
version = "0.2.0"
authors = ["The Matter Labs Team <[email protected]>"]
edition = "2018"

Expand Down
8 changes: 6 additions & 2 deletions sdk/zksync-rs/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::time::Duration;

// External uses
use async_trait::async_trait;
use jsonrpc_core::{types::response::Output, ErrorCode};

// Workspace uses
Expand All @@ -29,7 +30,10 @@ pub fn get_rpc_addr(network: Network) -> &'static str {
}
}

#[async_trait::async_trait]
#[async_trait]
/// `Provider` used to connect to zkSync network in order to send transactions
/// and retrieve some information from the server about
/// zkSync accounts, transactions, supported tokens and the like.
pub trait Provider {
/// Requests and returns information about a ZKSync account given its address.
async fn account_info(&self, address: Address) -> Result<AccountInfo, ClientError>;
Expand Down Expand Up @@ -72,7 +76,7 @@ pub struct RpcProvider {
network: Network,
}

#[async_trait::async_trait]
#[async_trait]
impl Provider for RpcProvider {
async fn account_info(&self, address: Address) -> Result<AccountInfo, ClientError> {
let msg = JsonRpcRequest::account_info(address);
Expand Down
26 changes: 19 additions & 7 deletions sdk/zksync-rs/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod primitives_with_vectors {
);

let signature = TxSignature::sign_musig(&private_key, &inputs.message);
assert_tx_signature(&signature, &outputs.pub_key_hash, &outputs.signature);
assert_tx_signature(&signature, &outputs.pub_key, &outputs.signature);
}
}
}
Expand Down Expand Up @@ -389,11 +389,12 @@ mod signatures_with_vectors {
mod wallet_tests {
use super::*;
use num::{BigUint, ToPrimitive};
use zksync::provider::Provider;
use zksync::types::{AccountState, BlockStatus};
use zksync::{
error::ClientError,
types::{AccountInfo, ContractAddress, Fee, Tokens, TransactionInfo},
provider::Provider,
types::{
AccountInfo, AccountState, BlockStatus, ContractAddress, Fee, Tokens, TransactionInfo,
},
Network, Wallet, WalletCredentials,
};
use zksync_eth_signer::PrivateKeySigner;
Expand All @@ -404,12 +405,18 @@ mod wallet_tests {
};

#[derive(Debug, Clone)]
/// Provides some hardcoded values the `Provider` responsible to
/// without communicating with the network
struct MockProvider {
network: Network,
}

#[async_trait::async_trait]
impl Provider for MockProvider {
/// Returns the example `AccountInfo` instance:
/// - assigns the '42' value to account_id;
/// - adds single entry of "DAI" token to the committed balances;
/// - adds single entry of "USDC" token to the verified balances.
async fn account_info(&self, address: Address) -> Result<AccountInfo, ClientError> {
let mut committed_balances = HashMap::new();
committed_balances.insert("DAI".into(), BigUint::from(12345_u32).into());
Expand All @@ -436,6 +443,8 @@ mod wallet_tests {
})
}

/// Returns first three tokens from the configuration found in
/// $ZKSYNC_HOME/etc/tokens/<NETWORK>.json
async fn tokens(&self) -> Result<Tokens, ClientError> {
let genesis_tokens = get_genesis_token_list(&self.network.to_string())
.expect("Initial token list not found");
Expand All @@ -456,7 +465,7 @@ mod wallet_tests {
}

async fn tx_info(&self, _tx_hash: TxHash) -> Result<TransactionInfo, ClientError> {
unimplemented!()
unreachable!()
}

async fn get_tx_fee(
Expand All @@ -465,21 +474,24 @@ mod wallet_tests {
_address: Address,
_token: impl Into<TokenLike> + Send + 'async_trait,
) -> Result<Fee, ClientError> {
unimplemented!()
unreachable!()
}

async fn send_tx(
&self,
_tx: ZkSyncTx,
_eth_signature: Option<PackedEthSignature>,
) -> Result<TxHash, ClientError> {
unimplemented!()
unreachable!()
}

fn network(&self) -> Network {
self.network
}

/// Returns the example `ContractAddress` instance:
/// - the HEX-encoded sequence of bytes [0..20) provided as the `main_contract`;
/// - the `gov_contract` is not usable in tests and it is simply an empty string.
async fn contract_address(&self) -> Result<ContractAddress, ClientError> {
Ok(ContractAddress {
main_contract: "0x000102030405060708090a0b0c0d0e0f10111213".to_string(),
Expand Down

0 comments on commit b1b6373

Please sign in to comment.