Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/vb-zks-331-rebuild-zk-tests-for-…
Browse files Browse the repository at this point in the history
…new-contract' into dvush-new-sc
  • Loading branch information
dvush committed Feb 2, 2021
2 parents ad1f246 + f3ddae1 commit 9406e14
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 493 deletions.
5 changes: 1 addition & 4 deletions core/bin/zksync_eth_sender/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use num::BigUint;
use zksync_basic_types::{H256, U256};
// Workspace uses
use zksync_storage::{ConnectionPool, StorageProcessor};
use zksync_types::{
ethereum::{ETHOperation, EthOpId, InsertedOperationResponse, OperationType},
Action, ActionType, Operation,
};
use zksync_types::ethereum::{ETHOperation, EthOpId, InsertedOperationResponse};
// Local uses
use super::transactions::ETHStats;
use zksync_types::aggregated_operations::{AggregatedActionType, AggregatedOperation};
Expand Down
20 changes: 11 additions & 9 deletions core/bin/zksync_eth_sender/src/gas_adjuster/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Built-in uses
use std::convert::TryFrom;
// Workspace uses
use zksync_basic_types::U256;
// Local uses
Expand Down Expand Up @@ -82,10 +84,10 @@ async fn lower_gas_limit() {
#[tokio::test]
async fn gas_price_limit_restore() {
// Price limit to set (should be obtained from the DB by GasAdjuster).
const PRICE_LIMIT: u64 = 1000;
const PRICE_LIMIT: i64 = 1000;

let (_, db) = eth_and_db_clients().await;
db.update_gas_price_limit(PRICE_LIMIT.into()).await.unwrap();
db.update_gas_price_limit(PRICE_LIMIT).await.unwrap();
let gas_adjuster: GasAdjuster<MockEthereum, MockDatabase> = GasAdjuster::new(&db).await;

assert_eq!(gas_adjuster.get_current_max_price(), PRICE_LIMIT.into());
Expand All @@ -97,11 +99,11 @@ async fn gas_price_limit_restore() {
#[tokio::test]
async fn initial_upper_gas_limit() {
// Initial price limit to set.
const PRICE_LIMIT: u64 = 1000;
const PRICE_LIMIT: i64 = 1000;

let (mut ethereum, db) = eth_and_db_clients().await;

db.update_gas_price_limit(PRICE_LIMIT.into()).await.unwrap();
db.update_gas_price_limit(PRICE_LIMIT).await.unwrap();
let mut gas_adjuster: GasAdjuster<MockEthereum, MockDatabase> = GasAdjuster::new(&db).await;

// Set the gas price in Ethereum, which is greater than the current limit.
Expand Down Expand Up @@ -130,7 +132,7 @@ async fn initial_upper_gas_limit() {
#[tokio::test]
async fn gas_price_limit_scaling() {
// Amount of times we'll call `GasAdjuster::keep_updated`.
const PRICE_UPDATES: u64 = 5;
const PRICE_UPDATES: i64 = 5;
// Amount of samples to gather statistics.
const N_SAMPLES: usize = GasStatistics::GAS_PRICE_SAMPLES_AMOUNT;
// Initial price limit to set.
Expand All @@ -139,7 +141,7 @@ async fn gas_price_limit_scaling() {
let (mut ethereum, db) = eth_and_db_clients().await;
let mut connection = db.acquire_connection().await.unwrap();

db.update_gas_price_limit(PRICE_LIMIT.into()).await.unwrap();
db.update_gas_price_limit(PRICE_LIMIT as i64).await.unwrap();

let mut gas_adjuster: GasAdjuster<MockEthereum, MockDatabase> = GasAdjuster::new(&db).await;

Expand All @@ -165,7 +167,7 @@ async fn gas_price_limit_scaling() {
}

// Stats are gathered. Now they're based on the Ethereum price.
expected_price = ethereum.gas_price.as_u64();
expected_price = u64::try_from(ethereum.gas_price).expect("Can't convert U256 to i64");
for _ in 0..PRICE_UPDATES {
// Request the gas price N times to gather statistics in GasAdjuster.
// Each time the limit will be changed, so it's not checked. Instead, we check
Expand Down Expand Up @@ -207,7 +209,7 @@ async fn gas_price_limit_average_basis() {

let (mut ethereum, db) = eth_and_db_clients().await;
let mut connection = db.acquire_connection().await.unwrap();
db.update_gas_price_limit(PRICE_LIMIT.into()).await.unwrap();
db.update_gas_price_limit(PRICE_LIMIT as i64).await.unwrap();
let mut gas_adjuster: GasAdjuster<MockEthereum, MockDatabase> = GasAdjuster::new(&db).await;

// Set the client price way beyond the limit.
Expand Down Expand Up @@ -267,7 +269,7 @@ async fn gas_price_limit_preservation() {

let (mut ethereum, db) = eth_and_db_clients().await;
let mut connection = db.acquire_connection().await.unwrap();
db.update_gas_price_limit(price_limit.into()).await.unwrap();
db.update_gas_price_limit(price_limit as i64).await.unwrap();
let mut gas_adjuster: GasAdjuster<MockEthereum, MockDatabase> = GasAdjuster::new(&db).await;

// Set the client price way beyond the limit.
Expand Down
Loading

0 comments on commit 9406e14

Please sign in to comment.