From b1b6373632af8afa897a545662935bd25b5ad093 Mon Sep 17 00:00:00 2001 From: Ivan Ladelshchikov Date: Wed, 2 Dec 2020 15:48:35 +0500 Subject: [PATCH] review fixes --- Cargo.lock | 2 +- .../config/src/test_config/unit_vectors.rs | 3 +-- core/tests/loadtest/Cargo.toml | 2 +- etc/test_config/sdk/test-vectors.json | 2 +- .../src/vectors/crypto-vector.ts | 4 +-- sdk/zksync-rs/Cargo.toml | 2 +- sdk/zksync-rs/src/provider.rs | 8 ++++-- sdk/zksync-rs/tests/unit.rs | 26 ++++++++++++++----- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6cd898e661..f5879e1777 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5515,7 +5515,7 @@ checksum = "05f33972566adbd2d3588b0491eb94b98b43695c4ef897903470ede4f3f5a28a" [[package]] name = "zksync" -version = "0.1.1" +version = "0.2.0" dependencies = [ "anyhow", "async-trait", diff --git a/core/lib/config/src/test_config/unit_vectors.rs b/core/lib/config/src/test_config/unit_vectors.rs index e02a9f622a..21d0401fe4 100644 --- a/core/lib/config/src/test_config/unit_vectors.rs +++ b/core/lib/config/src/test_config/unit_vectors.rs @@ -51,8 +51,7 @@ pub struct CryptoPrimitiveInput { pub struct CryptoPrimitiveOutput { #[serde(with = "ZeroPrefixHexSerde")] pub private_key: Vec, - // FIXME: is it really a hash? - pub pub_key_hash: String, + pub pub_key: String, pub signature: String, } diff --git a/core/tests/loadtest/Cargo.toml b/core/tests/loadtest/Cargo.toml index d497f4d281..3cd8e009b1 100644 --- a/core/tests/loadtest/Cargo.toml +++ b/core/tests/loadtest/Cargo.toml @@ -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" } diff --git a/etc/test_config/sdk/test-vectors.json b/etc/test_config/sdk/test-vectors.json index 2ab707fce3..a58f26e306 100644 --- a/etc/test_config/sdk/test-vectors.json +++ b/etc/test_config/sdk/test-vectors.json @@ -9,7 +9,7 @@ }, "outputs": { "privateKey": "0x0552a69519d1f3043611126c13489ff4a2a867a1c667b1d9d9031cd27fdcff5a", - "pubKeyHash": "17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184", + "pubKey": "17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184", "signature": "5462c3083d92b832d540c9068eed0a0450520f6dd2e4ab169de1a46585b394a4292896a2ebca3c0378378963a6bc1710b64c573598e73de3a33d6cec2f5d7403" } } diff --git a/infrastructure/sdk-test-vector-generator/src/vectors/crypto-vector.ts b/infrastructure/sdk-test-vector-generator/src/vectors/crypto-vector.ts index 920a21d503..08312475f2 100644 --- a/infrastructure/sdk-test-vector-generator/src/vectors/crypto-vector.ts +++ b/infrastructure/sdk-test-vector-generator/src/vectors/crypto-vector.ts @@ -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; }; @@ -41,7 +41,7 @@ export async function generateCryptoTestVectors(): Promise"] edition = "2018" diff --git a/sdk/zksync-rs/src/provider.rs b/sdk/zksync-rs/src/provider.rs index 522860c362..9b764de90e 100644 --- a/sdk/zksync-rs/src/provider.rs +++ b/sdk/zksync-rs/src/provider.rs @@ -5,6 +5,7 @@ use std::time::Duration; // External uses +use async_trait::async_trait; use jsonrpc_core::{types::response::Output, ErrorCode}; // Workspace uses @@ -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; @@ -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 { let msg = JsonRpcRequest::account_info(address); diff --git a/sdk/zksync-rs/tests/unit.rs b/sdk/zksync-rs/tests/unit.rs index be5111960e..22802ac0c5 100644 --- a/sdk/zksync-rs/tests/unit.rs +++ b/sdk/zksync-rs/tests/unit.rs @@ -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); } } } @@ -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; @@ -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 { let mut committed_balances = HashMap::new(); committed_balances.insert("DAI".into(), BigUint::from(12345_u32).into()); @@ -436,6 +443,8 @@ mod wallet_tests { }) } + /// Returns first three tokens from the configuration found in + /// $ZKSYNC_HOME/etc/tokens/.json async fn tokens(&self) -> Result { let genesis_tokens = get_genesis_token_list(&self.network.to_string()) .expect("Initial token list not found"); @@ -456,7 +465,7 @@ mod wallet_tests { } async fn tx_info(&self, _tx_hash: TxHash) -> Result { - unimplemented!() + unreachable!() } async fn get_tx_fee( @@ -465,7 +474,7 @@ mod wallet_tests { _address: Address, _token: impl Into + Send + 'async_trait, ) -> Result { - unimplemented!() + unreachable!() } async fn send_tx( @@ -473,13 +482,16 @@ mod wallet_tests { _tx: ZkSyncTx, _eth_signature: Option, ) -> Result { - 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 { Ok(ContractAddress { main_contract: "0x000102030405060708090a0b0c0d0e0f10111213".to_string(),