From a68907315c5b288084b4f5ca6f46a41c9444eaa9 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 21 Apr 2020 16:25:21 +0300 Subject: [PATCH 01/12] fix: extract actix dependency from near-primitives --- Cargo.lock | 20 +- Cargo.toml | 2 + chain/chain/Cargo.toml | 1 + chain/chain/tests/challenges.rs | 2 +- chain/chain/tests/simple_chain.rs | 2 +- chain/chain/tests/sync_chain.rs | 2 +- chain/client/Cargo.toml | 2 + chain/client/tests/bug_repros.rs | 2 +- chain/client/tests/catching_up.rs | 2 +- chain/client/tests/challenges.rs | 2 +- chain/client/tests/chunks_management.rs | 4 +- chain/client/tests/cross_shard_tx.rs | 4 +- chain/client/tests/process_blocks.rs | 2 +- chain/client/tests/query_client.rs | 2 +- chain/jsonrpc/Cargo.toml | 1 + chain/jsonrpc/tests/http_query.rs | 2 +- chain/jsonrpc/tests/rpc_query.rs | 2 +- chain/jsonrpc/tests/rpc_transactions.rs | 2 +- chain/network/Cargo.toml | 1 + chain/network/tests/infinite_loop.rs | 2 +- chain/network/tests/peer_handshake.rs | 2 +- chain/network/tests/runner/mod.rs | 2 +- chain/network/tests/stress_network.rs | 2 +- core/primitives/Cargo.toml | 2 - core/primitives/src/account.rs | 6 + core/primitives/src/block.rs | 76 +++++++ core/primitives/src/lib.rs | 1 - core/primitives/src/test_utils.rs | 267 ------------------------ core/primitives/src/transaction.rs | 92 +++++++- env/Cargo.toml | 9 + env/src/lib.rs | 61 ++++++ neard/Cargo.toml | 1 + neard/src/lib.rs | 2 +- neard/src/runtime.rs | 2 +- neard/tests/rpc_nodes.rs | 4 +- neard/tests/run_nodes.rs | 3 +- neard/tests/stake_nodes.rs | 4 +- neard/tests/sync_nodes.rs | 4 +- neard/tests/sync_state_nodes.rs | 3 +- neard/tests/track_shards.rs | 4 +- runtime/runtime/src/verifier.rs | 4 +- test-utils/state-viewer/Cargo.toml | 2 + test-utils/state-viewer/src/main.rs | 2 +- test-utils/testlib/Cargo.toml | 1 + test-utils/testlib/src/lib.rs | 2 +- test-utils/testlib/src/run_nodes.rs | 2 +- tests/test_errors.rs | 2 +- 47 files changed, 309 insertions(+), 312 deletions(-) delete mode 100644 core/primitives/src/test_utils.rs create mode 100644 env/Cargo.toml create mode 100644 env/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ac4b3260fac..902e443d4b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1923,6 +1923,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "near-chain-configs 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-metrics 0.1.0", "near-pool 0.1.0", "near-primitives 0.1.0", @@ -1988,6 +1989,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-chunks 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-metrics 0.1.0", "near-network 0.1.0", "near-pool 0.1.0", @@ -2003,6 +2005,7 @@ dependencies = [ "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "sysinfo 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", + "testlib 0.1.0", ] [[package]] @@ -2030,6 +2033,14 @@ dependencies = [ "subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "near-env" +version = "0.1.0" +dependencies = [ + "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-subscriber 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "near-epoch-manager" version = "0.0.1" @@ -2069,6 +2080,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-jsonrpc-client 0.1.0", "near-metrics 0.1.0", "near-network 0.1.0", @@ -2124,6 +2136,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-metrics 0.1.0", "near-primitives 0.1.0", "near-store 0.1.0", @@ -2179,8 +2192,6 @@ dependencies = [ "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smart-default 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "validator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "validator_derive 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2329,6 +2340,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "near-chain-configs 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-jsonrpc 0.1.0", "near-network 0.1.0", "near-primitives 0.1.0", @@ -2362,6 +2374,7 @@ dependencies = [ "near-chunks 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-epoch-manager 0.0.1", "near-jsonrpc 0.1.0", "near-network 0.1.0", @@ -3433,12 +3446,14 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-network 0.1.0", "near-primitives 0.1.0", "near-store 0.1.0", "neard 0.4.13", "node-runtime 0.0.1", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "testlib 0.1.0", ] [[package]] @@ -3577,6 +3592,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", + "near-env 0.1.0", "near-jsonrpc 0.1.0", "near-jsonrpc-client 0.1.0", "near-network 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index f516ce4eb29..a817ef14e61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "core/runtime-configs", "core/store", "core/metrics", + "env", "runtime/runtime", "runtime/near-runtime-fees", "runtime/near-vm-logic", @@ -47,6 +48,7 @@ serde_json = "1.0.0" reqwest = "0.10" futures = "0.3" +near-env = { path = "./env" } near-chain-configs = { path = "./core/chain-configs" } near-crypto = { path = "./core/crypto" } near-primitives = { path = "./core/primitives" } diff --git a/chain/chain/Cargo.toml b/chain/chain/Cargo.toml index 3dbd522bc88..fea37db66cc 100644 --- a/chain/chain/Cargo.toml +++ b/chain/chain/Cargo.toml @@ -27,6 +27,7 @@ near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } near-metrics = { path = "../../core/metrics" } near-pool = { path = "../pool" } +near-env = {path = "../../env"} [features] # if enabled, we assert in most situations that are impossible unless some byzantine behavior is observed. diff --git a/chain/chain/tests/challenges.rs b/chain/chain/tests/challenges.rs index ad727892435..045ade2e0c5 100644 --- a/chain/chain/tests/challenges.rs +++ b/chain/chain/tests/challenges.rs @@ -1,6 +1,6 @@ use near_chain::test_utils::setup; use near_chain::{Block, ErrorKind, Provenance}; -use near_primitives::test_utils::init_test_logger; +use near_env::init_test_logger; #[test] fn challenges_new_head_prev() { diff --git a/chain/chain/tests/simple_chain.rs b/chain/chain/tests/simple_chain.rs index 3cca8123b0e..31e607f24bc 100644 --- a/chain/chain/tests/simple_chain.rs +++ b/chain/chain/tests/simple_chain.rs @@ -1,7 +1,7 @@ use near_chain::test_utils::setup; use near_chain::{Block, ChainStoreAccess, ErrorKind, Provenance}; +use near_env::init_test_logger; use near_primitives::hash::CryptoHash; -use near_primitives::test_utils::init_test_logger; use num_rational::Rational; #[test] diff --git a/chain/chain/tests/sync_chain.rs b/chain/chain/tests/sync_chain.rs index 4456e641699..ef5c892471d 100644 --- a/chain/chain/tests/sync_chain.rs +++ b/chain/chain/tests/sync_chain.rs @@ -1,6 +1,6 @@ use near_chain::test_utils::setup; use near_chain::Block; -use near_primitives::test_utils::init_test_logger; +use near_env::init_test_logger; #[test] fn chain_sync_headers() { diff --git a/chain/client/Cargo.toml b/chain/client/Cargo.toml index f8ffd7db5bb..acf98d16bee 100644 --- a/chain/client/Cargo.toml +++ b/chain/client/Cargo.toml @@ -34,6 +34,8 @@ near-chunks = { path = "../chunks" } near-telemetry = { path = "../telemetry" } [dev-dependencies] +near-env = { path = "../../env" } +testlib = { path = "../../test-utils/testlib" } neard = { path = "../../neard" } [features] diff --git a/chain/client/tests/bug_repros.rs b/chain/client/tests/bug_repros.rs index c82b39fde32..a02a3d0edcd 100644 --- a/chain/client/tests/bug_repros.rs +++ b/chain/client/tests/bug_repros.rs @@ -10,10 +10,10 @@ use near_chain::test_utils::account_id_to_shard_id; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; +use near_env::init_test_logger; use near_network::types::NetworkRequests::PartialEncodedChunkMessage; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::Block; -use near_primitives::test_utils::init_test_logger; use near_primitives::transaction::SignedTransaction; use std::cmp::max; use std::collections::HashMap; diff --git a/chain/client/tests/catching_up.rs b/chain/client/tests/catching_up.rs index 9ec87849008..5ff718df9c0 100644 --- a/chain/client/tests/catching_up.rs +++ b/chain/client/tests/catching_up.rs @@ -14,13 +14,13 @@ mod tests { use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; + use near_env::init_integration_logger; use near_network::types::AccountOrPeerIdOrHash; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::hash::hash as hash_func; use near_primitives::hash::CryptoHash; use near_primitives::receipt::Receipt; use near_primitives::sharding::ChunkHash; - use near_primitives::test_utils::init_integration_logger; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{BlockHeight, BlockHeightDelta, BlockIdOrFinality}; use near_primitives::views::{QueryRequest, QueryResponseKind::ViewAccount}; diff --git a/chain/client/tests/challenges.rs b/chain/client/tests/challenges.rs index aa4b27f4020..9c5d28b4c58 100644 --- a/chain/client/tests/challenges.rs +++ b/chain/client/tests/challenges.rs @@ -15,6 +15,7 @@ use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; use near_client::Client; use near_crypto::{InMemorySigner, KeyType, Signer}; +use near_env::init_test_logger; use near_network::test_utils::MockNetworkAdapter; use near_network::NetworkRequests; use near_primitives::challenge::{ @@ -25,7 +26,6 @@ use near_primitives::merkle::{merklize, MerklePath}; use near_primitives::receipt::Receipt; use near_primitives::serialize::BaseDecode; use near_primitives::sharding::{EncodedShardChunk, ReedSolomonWrapper}; -use near_primitives::test_utils::init_test_logger; use near_primitives::transaction::SignedTransaction; use near_primitives::types::StateRoot; use near_primitives::validator_signer::InMemoryValidatorSigner; diff --git a/chain/client/tests/chunks_management.rs b/chain/client/tests/chunks_management.rs index 7a1a35ac309..b0c79b7de9f 100644 --- a/chain/client/tests/chunks_management.rs +++ b/chain/client/tests/chunks_management.rs @@ -11,15 +11,15 @@ use near_chain::ChainGenesis; use near_client::test_utils::{setup_mock_all_validators, TestEnv}; use near_client::{ClientActor, GetBlock, ViewClientActor}; use near_crypto::KeyType; +use near_env::{init_integration_logger, init_test_logger}; use near_network::types::PartialEncodedChunkRequestMsg; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::BlockHeader; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::sharding::{PartialEncodedChunk, ShardChunkHeader}; -use near_primitives::test_utils::init_integration_logger; -use near_primitives::test_utils::{heavy_test, init_test_logger}; use near_primitives::transaction::SignedTransaction; use near_primitives::validator_signer::InMemoryValidatorSigner; +use testlib::test_helpers::heavy_test; #[test] fn chunks_produced_and_distributed_all_in_all_shards() { diff --git a/chain/client/tests/cross_shard_tx.rs b/chain/client/tests/cross_shard_tx.rs index c7b9f36ba40..5d41124df18 100644 --- a/chain/client/tests/cross_shard_tx.rs +++ b/chain/client/tests/cross_shard_tx.rs @@ -6,8 +6,8 @@ use futures::{future, FutureExt}; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; +use near_env::init_test_logger; use near_network::{NetworkRequests, NetworkResponses, PeerInfo}; -use near_primitives::test_utils::init_test_logger; use near_primitives::types::BlockIdOrFinality; use near_primitives::views::{QueryRequest, QueryResponseKind::ViewAccount}; @@ -87,11 +87,11 @@ mod tests { use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; + use near_env::init_test_logger; use near_network::{ NetworkClientMessages, NetworkClientResponses, NetworkRequests, NetworkResponses, PeerInfo, }; use near_primitives::hash::CryptoHash; - use near_primitives::test_utils::init_test_logger; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{AccountId, BlockIdOrFinality}; use near_primitives::views::{QueryRequest, QueryResponse, QueryResponseKind::ViewAccount}; diff --git a/chain/client/tests/process_blocks.rs b/chain/client/tests/process_blocks.rs index 79729d11cc0..7fe3d016b23 100644 --- a/chain/client/tests/process_blocks.rs +++ b/chain/client/tests/process_blocks.rs @@ -13,6 +13,7 @@ use near_client::test_utils::setup_mock_all_validators; use near_client::test_utils::{setup_client, setup_mock, TestEnv}; use near_client::{Client, GetBlock}; use near_crypto::{InMemorySigner, KeyType, Signature, Signer}; +use near_env::init_test_logger; #[cfg(feature = "metric_recorder")] use near_network::recorder::MetricRecorder; use near_network::routing::EdgeInfo; @@ -27,7 +28,6 @@ use near_primitives::errors::InvalidTxError; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::merkle::merklize; use near_primitives::sharding::{EncodedShardChunk, ReedSolomonWrapper}; -use near_primitives::test_utils::init_test_logger; use near_primitives::transaction::{SignedTransaction, Transaction}; use near_primitives::types::{BlockHeight, EpochId, MerkleHash, NumBlocks}; use near_primitives::utils::to_timestamp; diff --git a/chain/client/tests/query_client.rs b/chain/client/tests/query_client.rs index 13f7acde8d6..a70c104017c 100644 --- a/chain/client/tests/query_client.rs +++ b/chain/client/tests/query_client.rs @@ -3,7 +3,7 @@ use futures::{future, FutureExt}; use near_client::test_utils::setup_no_network; use near_client::Query; -use near_primitives::test_utils::init_test_logger; +use near_env::init_test_logger; use near_primitives::types::BlockIdOrFinality; use near_primitives::views::{QueryRequest, QueryResponseKind}; diff --git a/chain/jsonrpc/Cargo.toml b/chain/jsonrpc/Cargo.toml index 28d1967f470..afd17d1079d 100644 --- a/chain/jsonrpc/Cargo.toml +++ b/chain/jsonrpc/Cargo.toml @@ -25,6 +25,7 @@ borsh = "0.6.1" near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } +near-env = { path = "../../env" } near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } near-metrics = { path = "../../core/metrics" } diff --git a/chain/jsonrpc/tests/http_query.rs b/chain/jsonrpc/tests/http_query.rs index 9e95c3ae2a0..0fe60b2090c 100644 --- a/chain/jsonrpc/tests/http_query.rs +++ b/chain/jsonrpc/tests/http_query.rs @@ -1,8 +1,8 @@ use actix::System; use futures::{future, FutureExt}; +use near_env::init_test_logger; use near_jsonrpc::client::new_http_client; -use near_primitives::test_utils::init_test_logger; mod test_utils; diff --git a/chain/jsonrpc/tests/rpc_query.rs b/chain/jsonrpc/tests/rpc_query.rs index 1696b0c2528..fbc574c31a5 100644 --- a/chain/jsonrpc/tests/rpc_query.rs +++ b/chain/jsonrpc/tests/rpc_query.rs @@ -5,13 +5,13 @@ use futures::{future, FutureExt}; use near_chain_configs::PROTOCOL_VERSION; use near_crypto::{KeyType, PublicKey, Signature}; +use near_env::init_test_logger; use near_jsonrpc::client::new_client; use near_jsonrpc_client::ChunkId; use near_network::test_utils::WaitOrTimeout; use near_primitives::account::{AccessKey, AccessKeyPermission}; use near_primitives::hash::CryptoHash; use near_primitives::rpc::{RpcGenesisRecordsRequest, RpcPagination, RpcQueryRequest}; -use near_primitives::test_utils::init_test_logger; use near_primitives::types::{BlockId, BlockIdOrFinality, Finality, ShardId}; use near_primitives::views::{QueryRequest, QueryResponseKind}; diff --git a/chain/jsonrpc/tests/rpc_transactions.rs b/chain/jsonrpc/tests/rpc_transactions.rs index cf44034df3e..1c8ecf3436c 100644 --- a/chain/jsonrpc/tests/rpc_transactions.rs +++ b/chain/jsonrpc/tests/rpc_transactions.rs @@ -5,11 +5,11 @@ use borsh::BorshSerialize; use futures::{future, FutureExt, TryFutureExt}; use near_crypto::{InMemorySigner, KeyType}; +use near_env::{init_integration_logger, init_test_logger}; use near_jsonrpc::client::new_client; use near_network::test_utils::WaitOrTimeout; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::serialize::{to_base, to_base64}; -use near_primitives::test_utils::{init_integration_logger, init_test_logger}; use near_primitives::transaction::SignedTransaction; use near_primitives::types::BlockIdOrFinality; use near_primitives::views::FinalExecutionStatus; diff --git a/chain/network/Cargo.toml b/chain/network/Cargo.toml index cca62ba7762..5eaa943e60e 100644 --- a/chain/network/Cargo.toml +++ b/chain/network/Cargo.toml @@ -31,6 +31,7 @@ near-metrics = { path = "../../core/metrics" } near-chain = { path = "../chain" } [dev-dependencies] +near-env = {path = "../../env"} tempdir = "0.3.7" bencher = "0.1.5" num-rational = "0.2.4" diff --git a/chain/network/tests/infinite_loop.rs b/chain/network/tests/infinite_loop.rs index 6407694f529..f367e43e8cc 100644 --- a/chain/network/tests/infinite_loop.rs +++ b/chain/network/tests/infinite_loop.rs @@ -7,12 +7,12 @@ use actix::{Actor, System}; use futures::{future, FutureExt}; use near_client::ClientActor; +use near_env::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses, SyncData}; use near_network::{NetworkClientResponses, NetworkConfig, NetworkRequests, PeerManagerActor}; use near_primitives::block::GenesisId; use near_primitives::network::{AnnounceAccount, PeerId}; -use near_primitives::test_utils::init_integration_logger; use near_store::test_utils::create_test_store; /// Make Peer Manager with mocked client ready to accept any announce account. diff --git a/chain/network/tests/peer_handshake.rs b/chain/network/tests/peer_handshake.rs index ec125edc9d6..56cc476806d 100644 --- a/chain/network/tests/peer_handshake.rs +++ b/chain/network/tests/peer_handshake.rs @@ -9,10 +9,10 @@ use actix::System; use futures::{future, FutureExt}; use near_client::{ClientActor, ViewClientActor}; +use near_env::init_test_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses}; use near_network::{NetworkClientResponses, NetworkConfig, PeerManagerActor}; -use near_primitives::test_utils::init_test_logger; use near_store::test_utils::create_test_store; type ClientMock = Mocker; diff --git a/chain/network/tests/runner/mod.rs b/chain/network/tests/runner/mod.rs index 18f771ac05a..6967de026f3 100644 --- a/chain/network/tests/runner/mod.rs +++ b/chain/network/tests/runner/mod.rs @@ -13,6 +13,7 @@ use near_chain::ChainGenesis; use near_chain_configs::ClientConfig; use near_client::{ClientActor, ViewClientActor}; use near_crypto::KeyType; +use near_env::init_test_logger; use near_network::test_utils::{ convert_boot_nodes, expected_routing_tables, open_port, peer_id_from_seed, BanPeerSignal, GetInfo, StopSignal, WaitOrTimeout, @@ -22,7 +23,6 @@ use near_network::utils::blacklist_from_vec; use near_network::{ NetworkConfig, NetworkRecipient, NetworkRequests, NetworkResponses, PeerInfo, PeerManagerActor, }; -use near_primitives::test_utils::init_test_logger; use near_primitives::types::{AccountId, ValidatorId}; use near_primitives::validator_signer::InMemoryValidatorSigner; use near_store::test_utils::create_test_store; diff --git a/chain/network/tests/stress_network.rs b/chain/network/tests/stress_network.rs index a7cc4c7e339..df1e027c7aa 100644 --- a/chain/network/tests/stress_network.rs +++ b/chain/network/tests/stress_network.rs @@ -8,10 +8,10 @@ use futures::FutureExt; use tracing::info; use near_client::{ClientActor, ViewClientActor}; +use near_env::init_test_logger_allow_panic; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses}; use near_network::{NetworkClientResponses, NetworkConfig, PeerManagerActor}; -use near_primitives::test_utils::init_test_logger_allow_panic; use near_store::test_utils::create_test_store; type ClientMock = Mocker; diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 401bf0255bf..38d3bce4831 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -27,8 +27,6 @@ jemallocator = { version = "0.3.0", optional = true } actix = "0.9.0" hex = "0.4" num-rational = "0.2.4" -tracing = "0.1.13" -tracing-subscriber = "0.2.4" borsh = "0.6.1" diff --git a/core/primitives/src/account.rs b/core/primitives/src/account.rs index 75dde90e1ab..48bb7b479d7 100644 --- a/core/primitives/src/account.rs +++ b/core/primitives/src/account.rs @@ -20,6 +20,12 @@ pub struct Account { pub storage_usage: StorageUsage, } +impl Account { + pub fn new(amount: Balance, code_hash: CryptoHash) -> Self { + Account { amount, locked: 0, code_hash, storage_usage: std::mem::size_of::() as u64 } + } +} + /// Access key provides limited access to an account. Each access key belongs to some account and /// is identified by a unique (within the account) public key. One account may have large number of /// access keys. Access keys allow to act on behalf of the account by restricting transactions diff --git a/core/primitives/src/block.rs b/core/primitives/src/block.rs index 4895c06bc20..7bf03135689 100644 --- a/core/primitives/src/block.rs +++ b/core/primitives/src/block.rs @@ -721,6 +721,82 @@ impl Block { } } +impl Block { + pub fn empty_with_epoch( + prev: &Block, + height: BlockHeight, + epoch_id: EpochId, + next_epoch_id: EpochId, + next_bp_hash: CryptoHash, + signer: &dyn ValidatorSigner, + ) -> Self { + Self::empty_with_approvals( + prev, + height, + epoch_id, + next_epoch_id, + vec![], + signer, + next_bp_hash, + ) + } + + pub fn empty_with_height( + prev: &Block, + height: BlockHeight, + signer: &dyn ValidatorSigner, + ) -> Self { + Self::empty_with_epoch( + prev, + height, + prev.header.inner_lite.epoch_id.clone(), + if prev.header.prev_hash == CryptoHash::default() { + EpochId(prev.hash()) + } else { + prev.header.inner_lite.next_epoch_id.clone() + }, + prev.header.inner_lite.next_bp_hash, + signer, + ) + } + + pub fn empty(prev: &Block, signer: &dyn ValidatorSigner) -> Self { + Self::empty_with_height(prev, prev.header.inner_lite.height + 1, signer) + } + + /// This is not suppose to be used outside of chain tests, because this doesn't refer to correct chunks. + /// Done because chain tests don't have a good way to store chunks right now. + pub fn empty_with_approvals( + prev: &Block, + height: BlockHeight, + epoch_id: EpochId, + next_epoch_id: EpochId, + approvals: Vec, + signer: &dyn ValidatorSigner, + next_bp_hash: CryptoHash, + ) -> Self { + Block::produce( + &prev.header, + height, + prev.chunks.clone(), + epoch_id, + next_epoch_id, + approvals, + Rational::from_integer(0), + 0, + Some(0), + vec![], + vec![], + signer, + 0.into(), + CryptoHash::default(), + CryptoHash::default(), + CryptoHash::default(), + next_bp_hash, + ) + } +} + /// The score is defined as the height of the last block with quorum pre-vote /// We have a separate type to ensure that the height is never assigned to score and vice versa #[derive( diff --git a/core/primitives/src/lib.rs b/core/primitives/src/lib.rs index 338df9e82ef..125110569f4 100644 --- a/core/primitives/src/lib.rs +++ b/core/primitives/src/lib.rs @@ -20,7 +20,6 @@ pub mod serialize; pub mod sharding; pub mod state_record; pub mod telemetry; -pub mod test_utils; pub mod transaction; pub mod trie_key; pub mod types; diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs deleted file mode 100644 index 8905c84a276..00000000000 --- a/core/primitives/src/test_utils.rs +++ /dev/null @@ -1,267 +0,0 @@ -use std::env; -use std::sync::{Mutex, Once}; - -use tracing_subscriber::EnvFilter; - -use lazy_static::lazy_static; -use near_crypto::{EmptySigner, PublicKey, Signer}; - -use crate::account::{AccessKey, AccessKeyPermission, Account}; -use crate::block::{Approval, Block}; -use crate::hash::CryptoHash; -use crate::transaction::{ - Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, SignedTransaction, StakeAction, - Transaction, TransferAction, -}; -use crate::types::{AccountId, Balance, BlockHeight, EpochId, Nonce}; -use crate::validator_signer::ValidatorSigner; -use num_rational::Rational; - -lazy_static! { - static ref HEAVY_TESTS_LOCK: Mutex<()> = Mutex::new(()); -} - -pub fn heavy_test(f: F) -where - F: FnOnce() -> (), -{ - let _guard = HEAVY_TESTS_LOCK.lock(); - f(); -} - -fn setup_subscriber_from_filter(mut env_filter: EnvFilter) { - if let Ok(rust_log) = env::var("RUST_LOG") { - for directive in rust_log.split(',').filter_map(|s| match s.parse() { - Ok(directive) => Some(directive), - Err(err) => { - eprintln!("Ignoring directive `{}`: {}", s, err); - None - } - }) { - env_filter = env_filter.add_directive(directive); - } - } - - let _ = tracing_subscriber::fmt::Subscriber::builder() - .with_env_filter(env_filter) - .with_writer(std::io::stderr) - .try_init(); -} - -pub fn init_test_logger() { - let env_filter = EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,debug"); - setup_subscriber_from_filter(env_filter); - init_stop_on_panic(); -} - -pub fn init_test_logger_allow_panic() { - let env_filter = EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,debug"); - setup_subscriber_from_filter(env_filter); -} - -pub fn init_test_module_logger(module: &str) { - let env_filter = - EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,cranelift_wasm=warn,info") - .add_directive(format!("{}=info", module).parse().unwrap()); - setup_subscriber_from_filter(env_filter); - init_stop_on_panic(); -} - -pub fn init_integration_logger() { - let env_filter = EnvFilter::new("actix_web=warn,info"); - setup_subscriber_from_filter(env_filter); - init_stop_on_panic(); -} - -static SET_PANIC_HOOK: Once = Once::new(); - -/// This is a workaround to make actix/tokio runtime stop when a task panics. -pub fn init_stop_on_panic() { - SET_PANIC_HOOK.call_once(|| { - let default_hook = std::panic::take_hook(); - std::panic::set_hook(Box::new(move |info| { - default_hook(info); - if actix::System::is_set() { - actix::System::with_current(|sys| sys.stop_with_code(1)); - } - })); - }) -} - -impl Transaction { - pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { - let signature = signer.sign(self.get_hash().as_ref()); - SignedTransaction::new(signature, self) - } -} - -impl SignedTransaction { - pub fn send_money( - nonce: Nonce, - signer_id: AccountId, - receiver_id: AccountId, - signer: &dyn Signer, - deposit: Balance, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id, - receiver_id, - signer, - vec![Action::Transfer(TransferAction { deposit })], - block_hash, - ) - } - - pub fn stake( - nonce: Nonce, - signer_id: AccountId, - signer: &dyn Signer, - stake: Balance, - public_key: PublicKey, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id.clone(), - signer_id, - signer, - vec![Action::Stake(StakeAction { stake, public_key })], - block_hash, - ) - } - - pub fn create_account( - nonce: Nonce, - originator: AccountId, - new_account_id: AccountId, - amount: Balance, - public_key: PublicKey, - signer: &dyn Signer, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - originator, - new_account_id, - signer, - vec![ - Action::CreateAccount(CreateAccountAction {}), - Action::AddKey(AddKeyAction { - public_key, - access_key: AccessKey { nonce: 0, permission: AccessKeyPermission::FullAccess }, - }), - Action::Transfer(TransferAction { deposit: amount }), - ], - block_hash, - ) - } - - pub fn delete_account( - nonce: Nonce, - signer_id: AccountId, - receiver_id: AccountId, - beneficiary_id: AccountId, - signer: &dyn Signer, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id, - receiver_id, - signer, - vec![Action::DeleteAccount(DeleteAccountAction { beneficiary_id })], - block_hash, - ) - } - - pub fn empty(block_hash: CryptoHash) -> Self { - Self::from_actions(0, "".to_string(), "".to_string(), &EmptySigner {}, vec![], block_hash) - } -} - -impl Block { - pub fn empty_with_epoch( - prev: &Block, - height: BlockHeight, - epoch_id: EpochId, - next_epoch_id: EpochId, - next_bp_hash: CryptoHash, - signer: &dyn ValidatorSigner, - ) -> Self { - Self::empty_with_approvals( - prev, - height, - epoch_id, - next_epoch_id, - vec![], - signer, - next_bp_hash, - ) - } - - pub fn empty_with_height( - prev: &Block, - height: BlockHeight, - signer: &dyn ValidatorSigner, - ) -> Self { - Self::empty_with_epoch( - prev, - height, - prev.header.inner_lite.epoch_id.clone(), - if prev.header.prev_hash == CryptoHash::default() { - EpochId(prev.hash()) - } else { - prev.header.inner_lite.next_epoch_id.clone() - }, - prev.header.inner_lite.next_bp_hash, - signer, - ) - } - - pub fn empty(prev: &Block, signer: &dyn ValidatorSigner) -> Self { - Self::empty_with_height(prev, prev.header.inner_lite.height + 1, signer) - } - - /// This is not suppose to be used outside of chain tests, because this doesn't refer to correct chunks. - /// Done because chain tests don't have a good way to store chunks right now. - pub fn empty_with_approvals( - prev: &Block, - height: BlockHeight, - epoch_id: EpochId, - next_epoch_id: EpochId, - approvals: Vec, - signer: &dyn ValidatorSigner, - next_bp_hash: CryptoHash, - ) -> Self { - Block::produce( - &prev.header, - height, - prev.chunks.clone(), - epoch_id, - next_epoch_id, - approvals, - Rational::from_integer(0), - 0, - Some(0), - vec![], - vec![], - signer, - 0.into(), - CryptoHash::default(), - CryptoHash::default(), - CryptoHash::default(), - next_bp_hash, - ) - } -} - -/// Size of account struct in bytes. -pub const ACCOUNT_SIZE_BYTES: u64 = std::mem::size_of::() as u64; - -impl Account { - pub fn new(amount: Balance, code_hash: CryptoHash) -> Self { - Account { amount, locked: 0, code_hash, storage_usage: ACCOUNT_SIZE_BYTES } - } -} diff --git a/core/primitives/src/transaction.rs b/core/primitives/src/transaction.rs index 212430dd85c..815590b6fd3 100644 --- a/core/primitives/src/transaction.rs +++ b/core/primitives/src/transaction.rs @@ -5,9 +5,9 @@ use std::hash::{Hash, Hasher}; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use near_crypto::{PublicKey, Signature, Signer}; +use near_crypto::{EmptySigner, PublicKey, Signature, Signer}; -use crate::account::AccessKey; +use crate::account::{AccessKey, AccessKeyPermission}; use crate::errors::TxExecutionError; use crate::hash::{hash, CryptoHash}; use crate::logging; @@ -41,6 +41,11 @@ impl Transaction { let bytes = self.try_to_vec().expect("Failed to deserialize"); hash(&bytes) } + + pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { + let signature = signer.sign(self.get_hash().as_ref()); + SignedTransaction::new(signature, self) + } } #[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] @@ -192,6 +197,89 @@ impl SignedTransaction { } .sign(signer) } + pub fn send_money( + nonce: Nonce, + signer_id: AccountId, + receiver_id: AccountId, + signer: &dyn Signer, + deposit: Balance, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id, + receiver_id, + signer, + vec![Action::Transfer(TransferAction { deposit })], + block_hash, + ) + } + + pub fn stake( + nonce: Nonce, + signer_id: AccountId, + signer: &dyn Signer, + stake: Balance, + public_key: PublicKey, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id.clone(), + signer_id, + signer, + vec![Action::Stake(StakeAction { stake, public_key })], + block_hash, + ) + } + + pub fn create_account( + nonce: Nonce, + originator: AccountId, + new_account_id: AccountId, + amount: Balance, + public_key: PublicKey, + signer: &dyn Signer, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + originator, + new_account_id, + signer, + vec![ + Action::CreateAccount(CreateAccountAction {}), + Action::AddKey(AddKeyAction { + public_key, + access_key: AccessKey { nonce: 0, permission: AccessKeyPermission::FullAccess }, + }), + Action::Transfer(TransferAction { deposit: amount }), + ], + block_hash, + ) + } + + pub fn delete_account( + nonce: Nonce, + signer_id: AccountId, + receiver_id: AccountId, + beneficiary_id: AccountId, + signer: &dyn Signer, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id, + receiver_id, + signer, + vec![Action::DeleteAccount(DeleteAccountAction { beneficiary_id })], + block_hash, + ) + } + + pub fn empty(block_hash: CryptoHash) -> Self { + Self::from_actions(0, "".to_string(), "".to_string(), &EmptySigner {}, vec![], block_hash) + } } impl Hash for SignedTransaction { diff --git a/env/Cargo.toml b/env/Cargo.toml new file mode 100644 index 00000000000..8eefefd38f4 --- /dev/null +++ b/env/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "near-env" +version = "0.1.0" +authors = ["Near Inc "] +edition = "2018" + +[dependencies] +actix = "0.9.0" +tracing-subscriber = "0.2.4" \ No newline at end of file diff --git a/env/src/lib.rs b/env/src/lib.rs new file mode 100644 index 00000000000..a914b23b658 --- /dev/null +++ b/env/src/lib.rs @@ -0,0 +1,61 @@ +use std::sync::Once; +use tracing_subscriber::EnvFilter; + +static SET_PANIC_HOOK: Once = Once::new(); + +/// This is a workaround to make actix/tokio runtime stop when a task panics. +pub fn init_stop_on_panic() { + SET_PANIC_HOOK.call_once(|| { + let default_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + default_hook(info); + if actix::System::is_set() { + actix::System::with_current(|sys| sys.stop_with_code(1)); + } + })); + }) +} + +fn setup_subscriber_from_filter(mut env_filter: EnvFilter) { + if let Ok(rust_log) = std::env::var("RUST_LOG") { + for directive in rust_log.split(',').filter_map(|s| match s.parse() { + Ok(directive) => Some(directive), + Err(err) => { + eprintln!("Ignoring directive `{}`: {}", s, err); + None + } + }) { + env_filter = env_filter.add_directive(directive); + } + } + + let _ = tracing_subscriber::fmt::Subscriber::builder() + .with_env_filter(env_filter) + .with_writer(std::io::stderr) + .try_init(); +} + +pub fn init_test_logger() { + let env_filter = EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,debug"); + setup_subscriber_from_filter(env_filter); + init_stop_on_panic(); +} + +pub fn init_test_logger_allow_panic() { + let env_filter = EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,debug"); + setup_subscriber_from_filter(env_filter); +} + +pub fn init_test_module_logger(module: &str) { + let env_filter = + EnvFilter::new("tokio_reactor=info,tokio_core=info,hyper=info,cranelift_wasm=warn,info") + .add_directive(format!("{}=info", module).parse().unwrap()); + setup_subscriber_from_filter(env_filter); + init_stop_on_panic(); +} + +pub fn init_integration_logger() { + let env_filter = EnvFilter::new("actix_web=warn,info"); + setup_subscriber_from_filter(env_filter); + init_stop_on_panic(); +} diff --git a/neard/Cargo.toml b/neard/Cargo.toml index afede28dcb6..0ebadc2df86 100644 --- a/neard/Cargo.toml +++ b/neard/Cargo.toml @@ -26,6 +26,7 @@ tracing = "0.1.13" tracing-subscriber = "0.2.4" num-rational = { version = "0.2.4", features = ["serde"] } +near-env = { path = "../env" } near-crypto = { path = "../core/crypto" } near-primitives = { path = "../core/primitives" } near-chain-configs = { path = "../core/chain-configs" } diff --git a/neard/src/lib.rs b/neard/src/lib.rs index c8d2b6dc6d0..62438a12cec 100644 --- a/neard/src/lib.rs +++ b/neard/src/lib.rs @@ -53,7 +53,7 @@ pub fn start_with_config( config: NearConfig, ) -> (Addr, Addr) { let store = create_store(&get_store_path(home_dir)); - near_primitives::test_utils::init_stop_on_panic(); + near_env::init_stop_on_panic(); let runtime = Arc::new(NightshadeRuntime::new( home_dir, Arc::clone(&store), diff --git a/neard/src/runtime.rs b/neard/src/runtime.rs index be16eaa1fe4..e99b83c70aa 100644 --- a/neard/src/runtime.rs +++ b/neard/src/runtime.rs @@ -1215,7 +1215,7 @@ mod test { use near_chain::{ReceiptResult, Tip}; use near_crypto::{InMemorySigner, KeyType, Signer}; - use near_primitives::test_utils::init_test_logger; + use near_env::init_test_logger; use near_primitives::transaction::{Action, CreateAccountAction, StakeAction}; use near_primitives::types::{BlockHeightDelta, Nonce, ValidatorId, ValidatorKickoutReason}; use near_primitives::validator_signer::{InMemoryValidatorSigner, ValidatorSigner}; diff --git a/neard/tests/rpc_nodes.rs b/neard/tests/rpc_nodes.rs index 3e94a9fa6a1..2c91a0552a8 100644 --- a/neard/tests/rpc_nodes.rs +++ b/neard/tests/rpc_nodes.rs @@ -5,15 +5,15 @@ use tempdir::TempDir; use near_client::{GetBlock, TxStatus}; use near_crypto::{InMemorySigner, KeyType}; +use near_env::init_integration_logger; use near_jsonrpc::client::new_client; use near_network::test_utils::WaitOrTimeout; use near_primitives::serialize::to_base64; -use near_primitives::test_utils::{heavy_test, init_integration_logger}; use near_primitives::transaction::SignedTransaction; use near_primitives::types::BlockId; use near_primitives::views::{FinalExecutionStatus, QueryResponseKind}; use neard::config::TESTING_INIT_BALANCE; -use testlib::{genesis_block, start_nodes}; +use testlib::{genesis_block, start_nodes, test_helpers::heavy_test}; /// Starts 2 validators and 2 light clients (not tracking anything). /// Sends tx to first light client and checks that a node can return tx status. diff --git a/neard/tests/run_nodes.rs b/neard/tests/run_nodes.rs index c1bb0da9c6f..5892aa65e82 100644 --- a/neard/tests/run_nodes.rs +++ b/neard/tests/run_nodes.rs @@ -4,10 +4,9 @@ use tempdir::TempDir; use near_client::GetBlock; use near_network::test_utils::WaitOrTimeout; -use near_primitives::test_utils::heavy_test; use near_primitives::types::{BlockHeightDelta, NumSeats, NumShards}; use rand::{thread_rng, Rng}; -use testlib::start_nodes; +use testlib::{start_nodes, test_helpers::heavy_test}; fn run_nodes( num_shards: NumShards, diff --git a/neard/tests/stake_nodes.rs b/neard/tests/stake_nodes.rs index 2b54b165081..aa88a6c230c 100644 --- a/neard/tests/stake_nodes.rs +++ b/neard/tests/stake_nodes.rs @@ -11,16 +11,16 @@ use tempdir::TempDir; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock, Query, Status, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; +use near_env::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; use near_network::NetworkClientMessages; use near_primitives::hash::CryptoHash; -use near_primitives::test_utils::{heavy_test, init_integration_logger}; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{AccountId, BlockHeightDelta, BlockIdOrFinality, NumSeats}; use near_primitives::views::{QueryRequest, QueryResponseKind, ValidatorInfo}; use neard::config::{GenesisExt, TESTING_INIT_BALANCE, TESTING_INIT_STAKE}; use neard::{load_test_config, start_with_config, NearConfig}; -use testlib::genesis_hash; +use testlib::{genesis_hash, test_helpers::heavy_test}; #[derive(Clone)] struct TestNode { diff --git a/neard/tests/sync_nodes.rs b/neard/tests/sync_nodes.rs index a810af50cfd..88a3ab457f7 100644 --- a/neard/tests/sync_nodes.rs +++ b/neard/tests/sync_nodes.rs @@ -10,18 +10,18 @@ use near_chain::{Block, Chain}; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock}; use near_crypto::{InMemorySigner, KeyType}; +use near_env::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; use near_network::{NetworkClientMessages, PeerInfo}; use near_primitives::block::Approval; use near_primitives::hash::CryptoHash; -use near_primitives::test_utils::{heavy_test, init_integration_logger}; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{BlockHeightDelta, EpochId, ValidatorStake}; use near_primitives::validator_signer::{InMemoryValidatorSigner, ValidatorSigner}; use neard::config::{GenesisExt, TESTING_INIT_STAKE}; use neard::{load_test_config, start_with_config}; use num_rational::Rational; -use testlib::genesis_block; +use testlib::{genesis_block, test_helpers::heavy_test}; // This assumes that there is no height skipped. Otherwise epoch hash calculation will be wrong. fn add_blocks( diff --git a/neard/tests/sync_state_nodes.rs b/neard/tests/sync_state_nodes.rs index 353b5614be4..5a9debcd2f1 100644 --- a/neard/tests/sync_state_nodes.rs +++ b/neard/tests/sync_state_nodes.rs @@ -7,9 +7,10 @@ use tempdir::TempDir; use near_chain_configs::Genesis; use near_client::GetBlock; +use near_env::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; -use near_primitives::test_utils::{heavy_test, init_integration_logger}; use neard::{config::GenesisExt, load_test_config, start_with_config}; +use testlib::test_helpers::heavy_test; /// One client is in front, another must sync to it using state (fast) sync. #[test] diff --git a/neard/tests/track_shards.rs b/neard/tests/track_shards.rs index 45a1a330c18..02425514559 100644 --- a/neard/tests/track_shards.rs +++ b/neard/tests/track_shards.rs @@ -5,10 +5,10 @@ use futures::{future, FutureExt}; use tempdir::TempDir; use near_client::{GetBlock, GetChunk}; +use near_env::init_integration_logger; use near_network::test_utils::WaitOrTimeout; use near_primitives::hash::CryptoHash; -use near_primitives::test_utils::{heavy_test, init_integration_logger}; -use testlib::start_nodes; +use testlib::{start_nodes, test_helpers::heavy_test}; #[test] fn track_shards() { diff --git a/runtime/runtime/src/verifier.rs b/runtime/runtime/src/verifier.rs index a3b4f00ca6e..df55c7253dc 100644 --- a/runtime/runtime/src/verifier.rs +++ b/runtime/runtime/src/verifier.rs @@ -380,7 +380,6 @@ mod tests { use near_primitives::account::{AccessKey, Account, FunctionCallPermission}; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::receipt::DataReceiver; - use near_primitives::test_utils::ACCOUNT_SIZE_BYTES; use near_primitives::transaction::{ CreateAccountAction, DeleteKeyAction, StakeAction, TransferAction, }; @@ -817,7 +816,8 @@ mod tests { .expect_err("expected an error"), RuntimeError::InvalidTxError(InvalidTxError::LackBalanceForState { signer_id: alice_account(), - amount: Balance::from(ACCOUNT_SIZE_BYTES) * config.storage_amount_per_byte + amount: Balance::from(std::mem::size_of::() as u64) + * config.storage_amount_per_byte - (initial_balance - transfer_amount) }) ); diff --git a/test-utils/state-viewer/Cargo.toml b/test-utils/state-viewer/Cargo.toml index 38d40a7afae..025e06f5bbd 100644 --- a/test-utils/state-viewer/Cargo.toml +++ b/test-utils/state-viewer/Cargo.toml @@ -19,6 +19,8 @@ near-network = { path = "../../chain/network" } neard = { path = "../../neard" } [dev-dependencies] +near-env = {path = "../../env"} +testlib = { path = "../../test-utils/testlib" } near-client = { path = "../../chain/client" } serde_json = "1.0" diff --git a/test-utils/state-viewer/src/main.rs b/test-utils/state-viewer/src/main.rs index 48898ec6c4a..197d161f88a 100644 --- a/test-utils/state-viewer/src/main.rs +++ b/test-utils/state-viewer/src/main.rs @@ -6,12 +6,12 @@ use ansi_term::Color::Red; use clap::{App, Arg, SubCommand}; use near_chain::{ChainStore, ChainStoreAccess, RuntimeAdapter}; +use near_env::init_integration_logger; use near_network::peer_store::PeerStore; use near_primitives::block::BlockHeader; use near_primitives::hash::CryptoHash; use near_primitives::serialize::to_base; use near_primitives::state_record::StateRecord; -use near_primitives::test_utils::init_integration_logger; use near_primitives::types::{BlockHeight, StateRoot}; use near_store::test_utils::create_test_store; use near_store::{create_store, Store, TrieIterator}; diff --git a/test-utils/testlib/Cargo.toml b/test-utils/testlib/Cargo.toml index 292868d5c9d..2e544cf88e0 100644 --- a/test-utils/testlib/Cargo.toml +++ b/test-utils/testlib/Cargo.toml @@ -23,6 +23,7 @@ num-rational = "0.2.4" borsh = "0.6.1" +near-env = { path = "../../env" } near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } near-primitives = { path = "../../core/primitives" } diff --git a/test-utils/testlib/src/lib.rs b/test-utils/testlib/src/lib.rs index f88cd35ae0c..81c6ba0e010 100644 --- a/test-utils/testlib/src/lib.rs +++ b/test-utils/testlib/src/lib.rs @@ -6,10 +6,10 @@ use tempdir::TempDir; use near_chain::{Chain, ChainGenesis, DoomslugThresholdMode}; use near_chain_configs::Genesis; use near_client::{ClientActor, ViewClientActor}; +use near_env::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port}; use near_primitives::block::{Block, BlockHeader}; use near_primitives::hash::CryptoHash; -use near_primitives::test_utils::init_integration_logger; use near_primitives::types::{BlockHeight, BlockHeightDelta, NumSeats, NumShards, ShardId}; use near_store::test_utils::create_test_store; use neard::{config::GenesisExt, load_test_config, start_with_config, NightshadeRuntime}; diff --git a/test-utils/testlib/src/run_nodes.rs b/test-utils/testlib/src/run_nodes.rs index cd8ca173bdf..d5cb5253f18 100644 --- a/test-utils/testlib/src/run_nodes.rs +++ b/test-utils/testlib/src/run_nodes.rs @@ -4,7 +4,7 @@ use std::time::Duration; use clap::{App, Arg}; -use near_primitives::test_utils::init_integration_logger; +use near_env::init_integration_logger; use testlib::node::{create_nodes, Node, NodeConfig}; fn main() { diff --git a/tests/test_errors.rs b/tests/test_errors.rs index c2b2c3e0347..41991436f8e 100644 --- a/tests/test_errors.rs +++ b/tests/test_errors.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use near_chain_configs::Genesis; use near_crypto::{InMemorySigner, KeyType}; +use near_env::init_integration_logger; use near_network::test_utils::open_port; use near_primitives::account::AccessKey; use near_primitives::errors::{InvalidAccessKeyError, InvalidTxError}; -use near_primitives::test_utils::init_integration_logger; use near_primitives::transaction::{ Action, AddKeyAction, CreateAccountAction, SignedTransaction, TransferAction, }; From 130ebbc008773b028868a885c3be7504ab960a36 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 21 Apr 2020 20:53:54 +0300 Subject: [PATCH 02/12] fix near-env in state-viewer --- core/primitives/src/account.rs | 7 ++++++- test-utils/state-viewer/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/primitives/src/account.rs b/core/primitives/src/account.rs index 48bb7b479d7..629984e4cd5 100644 --- a/core/primitives/src/account.rs +++ b/core/primitives/src/account.rs @@ -22,7 +22,12 @@ pub struct Account { impl Account { pub fn new(amount: Balance, code_hash: CryptoHash) -> Self { - Account { amount, locked: 0, code_hash, storage_usage: std::mem::size_of::() as u64 } + Account { + amount, + locked: 0, + code_hash, + storage_usage: std::mem::size_of::() as u64, + } } } diff --git a/test-utils/state-viewer/Cargo.toml b/test-utils/state-viewer/Cargo.toml index 025e06f5bbd..4efb68778d3 100644 --- a/test-utils/state-viewer/Cargo.toml +++ b/test-utils/state-viewer/Cargo.toml @@ -11,6 +11,7 @@ borsh = "0.6.1" near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } +near-env = {path = "../../env"} near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } node-runtime = { path = "../../runtime/runtime" } @@ -19,7 +20,6 @@ near-network = { path = "../../chain/network" } neard = { path = "../../neard" } [dev-dependencies] -near-env = {path = "../../env"} testlib = { path = "../../test-utils/testlib" } near-client = { path = "../../chain/client" } serde_json = "1.0" From 8ce012bdfd56f7bedc9594d01bfa3b1079fad900 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 22 Apr 2020 00:19:18 +0300 Subject: [PATCH 03/12] fix test --- tests/test_cases_testnet_rpc.rs | 2 +- tests/test_simple.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cases_testnet_rpc.rs b/tests/test_cases_testnet_rpc.rs index 48232f50f52..2d8e8264047 100644 --- a/tests/test_cases_testnet_rpc.rs +++ b/tests/test_cases_testnet_rpc.rs @@ -6,7 +6,7 @@ mod test { use std::thread; use std::time::Duration; - use near_primitives::test_utils::init_test_module_logger; + use near_env::init_test_module_logger; use testlib::node::{create_nodes_from_seeds, Node, NodeConfig, ThreadNode}; use testlib::runtime_utils::alice_account; use testlib::standard_test_cases::*; diff --git a/tests/test_simple.rs b/tests/test_simple.rs index 285fd58df10..aa3bcec7d91 100644 --- a/tests/test_simple.rs +++ b/tests/test_simple.rs @@ -2,7 +2,7 @@ #[cfg(test)] #[cfg(feature = "expensive_tests")] mod test { - use near_primitives::test_utils::init_integration_logger; + use near_env::init_integration_logger; use near_primitives::transaction::SignedTransaction; use testlib::node::{create_nodes, sample_two_nodes, Node}; use testlib::test_helpers::{heavy_test, wait}; From fdf96336a024e2b87f744a9c9de52ac192f11f11 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 23 Apr 2020 16:30:36 +0300 Subject: [PATCH 04/12] dubstiuted near-env with near-actix-utils and near-logger-utils --- Cargo.lock | 39 +++++++++++++++---------- Cargo.toml | 4 +-- chain/chain/Cargo.toml | 2 +- chain/chain/tests/challenges.rs | 2 +- chain/chain/tests/simple_chain.rs | 2 +- chain/chain/tests/sync_chain.rs | 2 +- chain/client/Cargo.toml | 2 +- chain/client/tests/bug_repros.rs | 2 +- chain/client/tests/catching_up.rs | 2 +- chain/client/tests/challenges.rs | 2 +- chain/client/tests/chunks_management.rs | 2 +- chain/client/tests/cross_shard_tx.rs | 4 +-- chain/client/tests/process_blocks.rs | 2 +- chain/client/tests/query_client.rs | 2 +- chain/jsonrpc/Cargo.toml | 2 +- chain/jsonrpc/tests/http_query.rs | 2 +- chain/jsonrpc/tests/rpc_query.rs | 2 +- chain/jsonrpc/tests/rpc_transactions.rs | 2 +- chain/network/Cargo.toml | 2 +- chain/network/tests/infinite_loop.rs | 2 +- chain/network/tests/peer_handshake.rs | 2 +- chain/network/tests/runner/mod.rs | 2 +- chain/network/tests/stress_network.rs | 2 +- neard/Cargo.toml | 2 +- neard/src/lib.rs | 2 +- neard/src/runtime.rs | 2 +- neard/tests/rpc_nodes.rs | 2 +- neard/tests/stake_nodes.rs | 2 +- neard/tests/sync_nodes.rs | 2 +- neard/tests/sync_state_nodes.rs | 2 +- neard/tests/track_shards.rs | 2 +- {env => test-utils/logger}/Cargo.toml | 4 +-- {env => test-utils/logger}/src/lib.rs | 17 +---------- test-utils/state-viewer/Cargo.toml | 2 +- test-utils/state-viewer/src/main.rs | 2 +- test-utils/testlib/Cargo.toml | 2 +- test-utils/testlib/src/lib.rs | 2 +- test-utils/testlib/src/run_nodes.rs | 2 +- tests/test_cases_testnet_rpc.rs | 2 +- tests/test_errors.rs | 2 +- tests/test_simple.rs | 2 +- utils/actix/Cargo.toml | 8 +++++ utils/actix/src/lib.rs | 16 ++++++++++ 43 files changed, 90 insertions(+), 74 deletions(-) rename {env => test-utils/logger}/Cargo.toml (64%) rename {env => test-utils/logger}/src/lib.rs (75%) create mode 100644 utils/actix/Cargo.toml create mode 100644 utils/actix/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b6c2c09d1ac..cd5a14ee70b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1917,6 +1917,13 @@ dependencies = [ "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "near-actix-utils" +version = "0.1.0" +dependencies = [ + "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "near-chain" version = "0.1.0" @@ -1931,7 +1938,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "near-chain-configs 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", + "near-logger-utils 0.1.0", "near-metrics 0.1.0", "near-pool 0.1.0", "near-primitives 0.1.0", @@ -1997,7 +2004,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-chunks 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", + "near-logger-utils 0.1.0", "near-metrics 0.1.0", "near-network 0.1.0", "near-pool 0.1.0", @@ -2041,14 +2048,6 @@ dependencies = [ "subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "near-env" -version = "0.1.0" -dependencies = [ - "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-subscriber 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "near-epoch-manager" version = "0.0.1" @@ -2088,8 +2087,8 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", "near-jsonrpc-client 0.1.0", + "near-logger-utils 0.1.0", "near-metrics 0.1.0", "near-network 0.1.0", "near-pool 0.1.0", @@ -2117,6 +2116,14 @@ dependencies = [ "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "near-logger-utils" +version = "0.1.0" +dependencies = [ + "near-actix-utils 0.1.0", + "tracing-subscriber 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "near-metrics" version = "0.1.0" @@ -2144,7 +2151,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", + "near-logger-utils 0.1.0", "near-metrics 0.1.0", "near-primitives 0.1.0", "near-store 0.1.0", @@ -2348,8 +2355,8 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "near-chain-configs 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", "near-jsonrpc 0.1.0", + "near-logger-utils 0.1.0", "near-network 0.1.0", "near-primitives 0.1.0", "near-store 0.1.0", @@ -2377,12 +2384,12 @@ dependencies = [ "git-version 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "near-actix-utils 0.1.0", "near-chain 0.1.0", "near-chain-configs 0.1.0", "near-chunks 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", "near-epoch-manager 0.0.1", "near-jsonrpc 0.1.0", "near-network 0.1.0", @@ -3430,7 +3437,7 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", + "near-logger-utils 0.1.0", "near-network 0.1.0", "near-primitives 0.1.0", "near-store 0.1.0", @@ -3581,9 +3588,9 @@ dependencies = [ "near-chain-configs 0.1.0", "near-client 0.1.0", "near-crypto 0.1.0", - "near-env 0.1.0", "near-jsonrpc 0.1.0", "near-jsonrpc-client 0.1.0", + "near-logger-utils 0.1.0", "near-network 0.1.0", "near-primitives 0.1.0", "near-runtime-fees 0.8.0", diff --git a/Cargo.toml b/Cargo.toml index a817ef14e61..2f14e583696 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "core/runtime-configs", "core/store", "core/metrics", - "env", + "utils/actix", "runtime/runtime", "runtime/near-runtime-fees", "runtime/near-vm-logic", @@ -48,7 +48,7 @@ serde_json = "1.0.0" reqwest = "0.10" futures = "0.3" -near-env = { path = "./env" } +near-logger-utils = { path = "./test-utils/logger" } near-chain-configs = { path = "./core/chain-configs" } near-crypto = { path = "./core/crypto" } near-primitives = { path = "./core/primitives" } diff --git a/chain/chain/Cargo.toml b/chain/chain/Cargo.toml index fea37db66cc..1fd54e87935 100644 --- a/chain/chain/Cargo.toml +++ b/chain/chain/Cargo.toml @@ -27,7 +27,7 @@ near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } near-metrics = { path = "../../core/metrics" } near-pool = { path = "../pool" } -near-env = {path = "../../env"} +near-logger-utils = {path = "../../test-utils/logger"} [features] # if enabled, we assert in most situations that are impossible unless some byzantine behavior is observed. diff --git a/chain/chain/tests/challenges.rs b/chain/chain/tests/challenges.rs index 045ade2e0c5..7cac85d0d62 100644 --- a/chain/chain/tests/challenges.rs +++ b/chain/chain/tests/challenges.rs @@ -1,6 +1,6 @@ use near_chain::test_utils::setup; use near_chain::{Block, ErrorKind, Provenance}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; #[test] fn challenges_new_head_prev() { diff --git a/chain/chain/tests/simple_chain.rs b/chain/chain/tests/simple_chain.rs index 31e607f24bc..9738194c89f 100644 --- a/chain/chain/tests/simple_chain.rs +++ b/chain/chain/tests/simple_chain.rs @@ -1,6 +1,6 @@ use near_chain::test_utils::setup; use near_chain::{Block, ChainStoreAccess, ErrorKind, Provenance}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_primitives::hash::CryptoHash; use num_rational::Rational; diff --git a/chain/chain/tests/sync_chain.rs b/chain/chain/tests/sync_chain.rs index ef5c892471d..413a303419b 100644 --- a/chain/chain/tests/sync_chain.rs +++ b/chain/chain/tests/sync_chain.rs @@ -1,6 +1,6 @@ use near_chain::test_utils::setup; use near_chain::Block; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; #[test] fn chain_sync_headers() { diff --git a/chain/client/Cargo.toml b/chain/client/Cargo.toml index acf98d16bee..c1099a5200d 100644 --- a/chain/client/Cargo.toml +++ b/chain/client/Cargo.toml @@ -34,7 +34,7 @@ near-chunks = { path = "../chunks" } near-telemetry = { path = "../telemetry" } [dev-dependencies] -near-env = { path = "../../env" } +near-logger-utils = { path = "../../test-utils/logger" } testlib = { path = "../../test-utils/testlib" } neard = { path = "../../neard" } diff --git a/chain/client/tests/bug_repros.rs b/chain/client/tests/bug_repros.rs index a02a3d0edcd..7a45241c478 100644 --- a/chain/client/tests/bug_repros.rs +++ b/chain/client/tests/bug_repros.rs @@ -10,7 +10,7 @@ use near_chain::test_utils::account_id_to_shard_id; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_network::types::NetworkRequests::PartialEncodedChunkMessage; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::Block; diff --git a/chain/client/tests/catching_up.rs b/chain/client/tests/catching_up.rs index 5ff718df9c0..73408501205 100644 --- a/chain/client/tests/catching_up.rs +++ b/chain/client/tests/catching_up.rs @@ -14,7 +14,7 @@ mod tests { use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; - use near_env::init_integration_logger; + use near_logger_utils::init_integration_logger; use near_network::types::AccountOrPeerIdOrHash; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::hash::hash as hash_func; diff --git a/chain/client/tests/challenges.rs b/chain/client/tests/challenges.rs index 9c5d28b4c58..424ad5d8f5b 100644 --- a/chain/client/tests/challenges.rs +++ b/chain/client/tests/challenges.rs @@ -15,7 +15,7 @@ use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; use near_client::Client; use near_crypto::{InMemorySigner, KeyType, Signer}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_network::test_utils::MockNetworkAdapter; use near_network::NetworkRequests; use near_primitives::challenge::{ diff --git a/chain/client/tests/chunks_management.rs b/chain/client/tests/chunks_management.rs index b0c79b7de9f..999091bc3fd 100644 --- a/chain/client/tests/chunks_management.rs +++ b/chain/client/tests/chunks_management.rs @@ -11,7 +11,7 @@ use near_chain::ChainGenesis; use near_client::test_utils::{setup_mock_all_validators, TestEnv}; use near_client::{ClientActor, GetBlock, ViewClientActor}; use near_crypto::KeyType; -use near_env::{init_integration_logger, init_test_logger}; +use near_logger_utils::{init_integration_logger, init_test_logger}; use near_network::types::PartialEncodedChunkRequestMsg; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::BlockHeader; diff --git a/chain/client/tests/cross_shard_tx.rs b/chain/client/tests/cross_shard_tx.rs index 5d41124df18..2cb27d4afe6 100644 --- a/chain/client/tests/cross_shard_tx.rs +++ b/chain/client/tests/cross_shard_tx.rs @@ -6,7 +6,7 @@ use futures::{future, FutureExt}; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_network::{NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::types::BlockIdOrFinality; use near_primitives::views::{QueryRequest, QueryResponseKind::ViewAccount}; @@ -87,7 +87,7 @@ mod tests { use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; - use near_env::init_test_logger; + use near_logger_utils::init_test_logger; use near_network::{ NetworkClientMessages, NetworkClientResponses, NetworkRequests, NetworkResponses, PeerInfo, }; diff --git a/chain/client/tests/process_blocks.rs b/chain/client/tests/process_blocks.rs index 7fe3d016b23..0b4fe297a6c 100644 --- a/chain/client/tests/process_blocks.rs +++ b/chain/client/tests/process_blocks.rs @@ -13,7 +13,7 @@ use near_client::test_utils::setup_mock_all_validators; use near_client::test_utils::{setup_client, setup_mock, TestEnv}; use near_client::{Client, GetBlock}; use near_crypto::{InMemorySigner, KeyType, Signature, Signer}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; #[cfg(feature = "metric_recorder")] use near_network::recorder::MetricRecorder; use near_network::routing::EdgeInfo; diff --git a/chain/client/tests/query_client.rs b/chain/client/tests/query_client.rs index a70c104017c..f73812c6705 100644 --- a/chain/client/tests/query_client.rs +++ b/chain/client/tests/query_client.rs @@ -3,7 +3,7 @@ use futures::{future, FutureExt}; use near_client::test_utils::setup_no_network; use near_client::Query; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_primitives::types::BlockIdOrFinality; use near_primitives::views::{QueryRequest, QueryResponseKind}; diff --git a/chain/jsonrpc/Cargo.toml b/chain/jsonrpc/Cargo.toml index afd17d1079d..620c06a53a6 100644 --- a/chain/jsonrpc/Cargo.toml +++ b/chain/jsonrpc/Cargo.toml @@ -25,7 +25,7 @@ borsh = "0.6.1" near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } -near-env = { path = "../../env" } +near-logger-utils = { path = "../../test-utils/logger" } near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } near-metrics = { path = "../../core/metrics" } diff --git a/chain/jsonrpc/tests/http_query.rs b/chain/jsonrpc/tests/http_query.rs index 0fe60b2090c..68ca0524c3e 100644 --- a/chain/jsonrpc/tests/http_query.rs +++ b/chain/jsonrpc/tests/http_query.rs @@ -1,8 +1,8 @@ use actix::System; use futures::{future, FutureExt}; -use near_env::init_test_logger; use near_jsonrpc::client::new_http_client; +use near_logger_utils::init_test_logger; mod test_utils; diff --git a/chain/jsonrpc/tests/rpc_query.rs b/chain/jsonrpc/tests/rpc_query.rs index fbc574c31a5..c5c242f1c53 100644 --- a/chain/jsonrpc/tests/rpc_query.rs +++ b/chain/jsonrpc/tests/rpc_query.rs @@ -5,9 +5,9 @@ use futures::{future, FutureExt}; use near_chain_configs::PROTOCOL_VERSION; use near_crypto::{KeyType, PublicKey, Signature}; -use near_env::init_test_logger; use near_jsonrpc::client::new_client; use near_jsonrpc_client::ChunkId; +use near_logger_utils::init_test_logger; use near_network::test_utils::WaitOrTimeout; use near_primitives::account::{AccessKey, AccessKeyPermission}; use near_primitives::hash::CryptoHash; diff --git a/chain/jsonrpc/tests/rpc_transactions.rs b/chain/jsonrpc/tests/rpc_transactions.rs index 1c8ecf3436c..72beea750fe 100644 --- a/chain/jsonrpc/tests/rpc_transactions.rs +++ b/chain/jsonrpc/tests/rpc_transactions.rs @@ -5,8 +5,8 @@ use borsh::BorshSerialize; use futures::{future, FutureExt, TryFutureExt}; use near_crypto::{InMemorySigner, KeyType}; -use near_env::{init_integration_logger, init_test_logger}; use near_jsonrpc::client::new_client; +use near_logger_utils::{init_integration_logger, init_test_logger}; use near_network::test_utils::WaitOrTimeout; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::serialize::{to_base, to_base64}; diff --git a/chain/network/Cargo.toml b/chain/network/Cargo.toml index 5eaa943e60e..b441c52023d 100644 --- a/chain/network/Cargo.toml +++ b/chain/network/Cargo.toml @@ -31,7 +31,7 @@ near-metrics = { path = "../../core/metrics" } near-chain = { path = "../chain" } [dev-dependencies] -near-env = {path = "../../env"} +near-logger-utils = {path = "../../test-utils/logger"} tempdir = "0.3.7" bencher = "0.1.5" num-rational = "0.2.4" diff --git a/chain/network/tests/infinite_loop.rs b/chain/network/tests/infinite_loop.rs index f367e43e8cc..01b23814070 100644 --- a/chain/network/tests/infinite_loop.rs +++ b/chain/network/tests/infinite_loop.rs @@ -7,7 +7,7 @@ use actix::{Actor, System}; use futures::{future, FutureExt}; use near_client::ClientActor; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses, SyncData}; use near_network::{NetworkClientResponses, NetworkConfig, NetworkRequests, PeerManagerActor}; diff --git a/chain/network/tests/peer_handshake.rs b/chain/network/tests/peer_handshake.rs index 56cc476806d..67a19c73c61 100644 --- a/chain/network/tests/peer_handshake.rs +++ b/chain/network/tests/peer_handshake.rs @@ -9,7 +9,7 @@ use actix::System; use futures::{future, FutureExt}; use near_client::{ClientActor, ViewClientActor}; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses}; use near_network::{NetworkClientResponses, NetworkConfig, PeerManagerActor}; diff --git a/chain/network/tests/runner/mod.rs b/chain/network/tests/runner/mod.rs index 6967de026f3..5d970728af5 100644 --- a/chain/network/tests/runner/mod.rs +++ b/chain/network/tests/runner/mod.rs @@ -13,7 +13,7 @@ use near_chain::ChainGenesis; use near_chain_configs::ClientConfig; use near_client::{ClientActor, ViewClientActor}; use near_crypto::KeyType; -use near_env::init_test_logger; +use near_logger_utils::init_test_logger; use near_network::test_utils::{ convert_boot_nodes, expected_routing_tables, open_port, peer_id_from_seed, BanPeerSignal, GetInfo, StopSignal, WaitOrTimeout, diff --git a/chain/network/tests/stress_network.rs b/chain/network/tests/stress_network.rs index df1e027c7aa..972fc8580c1 100644 --- a/chain/network/tests/stress_network.rs +++ b/chain/network/tests/stress_network.rs @@ -8,7 +8,7 @@ use futures::FutureExt; use tracing::info; use near_client::{ClientActor, ViewClientActor}; -use near_env::init_test_logger_allow_panic; +use near_logger_utils::init_test_logger_allow_panic; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; use near_network::types::{NetworkViewClientMessages, NetworkViewClientResponses}; use near_network::{NetworkClientResponses, NetworkConfig, PeerManagerActor}; diff --git a/neard/Cargo.toml b/neard/Cargo.toml index 0ebadc2df86..d2216c3019d 100644 --- a/neard/Cargo.toml +++ b/neard/Cargo.toml @@ -26,7 +26,7 @@ tracing = "0.1.13" tracing-subscriber = "0.2.4" num-rational = { version = "0.2.4", features = ["serde"] } -near-env = { path = "../env" } +near-actix-utils = { path = "../utils/actix" } near-crypto = { path = "../core/crypto" } near-primitives = { path = "../core/primitives" } near-chain-configs = { path = "../core/chain-configs" } diff --git a/neard/src/lib.rs b/neard/src/lib.rs index 62438a12cec..0b0a90111fa 100644 --- a/neard/src/lib.rs +++ b/neard/src/lib.rs @@ -53,7 +53,7 @@ pub fn start_with_config( config: NearConfig, ) -> (Addr, Addr) { let store = create_store(&get_store_path(home_dir)); - near_env::init_stop_on_panic(); + near_actix_utils::init_stop_on_panic(); let runtime = Arc::new(NightshadeRuntime::new( home_dir, Arc::clone(&store), diff --git a/neard/src/runtime.rs b/neard/src/runtime.rs index e99b83c70aa..6d34d167d10 100644 --- a/neard/src/runtime.rs +++ b/neard/src/runtime.rs @@ -1215,7 +1215,7 @@ mod test { use near_chain::{ReceiptResult, Tip}; use near_crypto::{InMemorySigner, KeyType, Signer}; - use near_env::init_test_logger; + use near_logger_utils::init_test_logger; use near_primitives::transaction::{Action, CreateAccountAction, StakeAction}; use near_primitives::types::{BlockHeightDelta, Nonce, ValidatorId, ValidatorKickoutReason}; use near_primitives::validator_signer::{InMemoryValidatorSigner, ValidatorSigner}; diff --git a/neard/tests/rpc_nodes.rs b/neard/tests/rpc_nodes.rs index 2c91a0552a8..e9c1bf4b49d 100644 --- a/neard/tests/rpc_nodes.rs +++ b/neard/tests/rpc_nodes.rs @@ -5,8 +5,8 @@ use tempdir::TempDir; use near_client::{GetBlock, TxStatus}; use near_crypto::{InMemorySigner, KeyType}; -use near_env::init_integration_logger; use near_jsonrpc::client::new_client; +use near_logger_utils::init_integration_logger; use near_network::test_utils::WaitOrTimeout; use near_primitives::serialize::to_base64; use near_primitives::transaction::SignedTransaction; diff --git a/neard/tests/stake_nodes.rs b/neard/tests/stake_nodes.rs index aa88a6c230c..89dc6954811 100644 --- a/neard/tests/stake_nodes.rs +++ b/neard/tests/stake_nodes.rs @@ -11,7 +11,7 @@ use tempdir::TempDir; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock, Query, Status, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; use near_network::NetworkClientMessages; use near_primitives::hash::CryptoHash; diff --git a/neard/tests/sync_nodes.rs b/neard/tests/sync_nodes.rs index 88a3ab457f7..fbc55a89a1e 100644 --- a/neard/tests/sync_nodes.rs +++ b/neard/tests/sync_nodes.rs @@ -10,7 +10,7 @@ use near_chain::{Block, Chain}; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock}; use near_crypto::{InMemorySigner, KeyType}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; use near_network::{NetworkClientMessages, PeerInfo}; use near_primitives::block::Approval; diff --git a/neard/tests/sync_state_nodes.rs b/neard/tests/sync_state_nodes.rs index 5a9debcd2f1..bb58b0ac787 100644 --- a/neard/tests/sync_state_nodes.rs +++ b/neard/tests/sync_state_nodes.rs @@ -7,7 +7,7 @@ use tempdir::TempDir; use near_chain_configs::Genesis; use near_client::GetBlock; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, WaitOrTimeout}; use neard::{config::GenesisExt, load_test_config, start_with_config}; use testlib::test_helpers::heavy_test; diff --git a/neard/tests/track_shards.rs b/neard/tests/track_shards.rs index 02425514559..167adcb25f8 100644 --- a/neard/tests/track_shards.rs +++ b/neard/tests/track_shards.rs @@ -5,7 +5,7 @@ use futures::{future, FutureExt}; use tempdir::TempDir; use near_client::{GetBlock, GetChunk}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::WaitOrTimeout; use near_primitives::hash::CryptoHash; use testlib::{start_nodes, test_helpers::heavy_test}; diff --git a/env/Cargo.toml b/test-utils/logger/Cargo.toml similarity index 64% rename from env/Cargo.toml rename to test-utils/logger/Cargo.toml index 8eefefd38f4..07682c8c41a 100644 --- a/env/Cargo.toml +++ b/test-utils/logger/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "near-env" +name = "near-logger-utils" version = "0.1.0" authors = ["Near Inc "] edition = "2018" [dependencies] -actix = "0.9.0" +near-actix-utils = { path = "../../utils/actix" } tracing-subscriber = "0.2.4" \ No newline at end of file diff --git a/env/src/lib.rs b/test-utils/logger/src/lib.rs similarity index 75% rename from env/src/lib.rs rename to test-utils/logger/src/lib.rs index a914b23b658..c4e5327100f 100644 --- a/env/src/lib.rs +++ b/test-utils/logger/src/lib.rs @@ -1,21 +1,6 @@ -use std::sync::Once; +use near_actix_utils::init_stop_on_panic; use tracing_subscriber::EnvFilter; -static SET_PANIC_HOOK: Once = Once::new(); - -/// This is a workaround to make actix/tokio runtime stop when a task panics. -pub fn init_stop_on_panic() { - SET_PANIC_HOOK.call_once(|| { - let default_hook = std::panic::take_hook(); - std::panic::set_hook(Box::new(move |info| { - default_hook(info); - if actix::System::is_set() { - actix::System::with_current(|sys| sys.stop_with_code(1)); - } - })); - }) -} - fn setup_subscriber_from_filter(mut env_filter: EnvFilter) { if let Ok(rust_log) = std::env::var("RUST_LOG") { for directive in rust_log.split(',').filter_map(|s| match s.parse() { diff --git a/test-utils/state-viewer/Cargo.toml b/test-utils/state-viewer/Cargo.toml index 4efb68778d3..d2d3a63ca72 100644 --- a/test-utils/state-viewer/Cargo.toml +++ b/test-utils/state-viewer/Cargo.toml @@ -11,7 +11,7 @@ borsh = "0.6.1" near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } -near-env = {path = "../../env"} +near-logger-utils = {path = "../../test-utils/logger"} near-primitives = { path = "../../core/primitives" } near-store = { path = "../../core/store" } node-runtime = { path = "../../runtime/runtime" } diff --git a/test-utils/state-viewer/src/main.rs b/test-utils/state-viewer/src/main.rs index 197d161f88a..14bd3cc8f70 100644 --- a/test-utils/state-viewer/src/main.rs +++ b/test-utils/state-viewer/src/main.rs @@ -6,7 +6,7 @@ use ansi_term::Color::Red; use clap::{App, Arg, SubCommand}; use near_chain::{ChainStore, ChainStoreAccess, RuntimeAdapter}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::peer_store::PeerStore; use near_primitives::block::BlockHeader; use near_primitives::hash::CryptoHash; diff --git a/test-utils/testlib/Cargo.toml b/test-utils/testlib/Cargo.toml index 2e544cf88e0..41fe37cd34e 100644 --- a/test-utils/testlib/Cargo.toml +++ b/test-utils/testlib/Cargo.toml @@ -23,7 +23,7 @@ num-rational = "0.2.4" borsh = "0.6.1" -near-env = { path = "../../env" } +near-logger-utils = { path = "../../test-utils/logger" } near-chain-configs = { path = "../../core/chain-configs" } near-crypto = { path = "../../core/crypto" } near-primitives = { path = "../../core/primitives" } diff --git a/test-utils/testlib/src/lib.rs b/test-utils/testlib/src/lib.rs index 81c6ba0e010..c6626b09d67 100644 --- a/test-utils/testlib/src/lib.rs +++ b/test-utils/testlib/src/lib.rs @@ -6,7 +6,7 @@ use tempdir::TempDir; use near_chain::{Chain, ChainGenesis, DoomslugThresholdMode}; use near_chain_configs::Genesis; use near_client::{ClientActor, ViewClientActor}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port}; use near_primitives::block::{Block, BlockHeader}; use near_primitives::hash::CryptoHash; diff --git a/test-utils/testlib/src/run_nodes.rs b/test-utils/testlib/src/run_nodes.rs index d5cb5253f18..0cb7d81c906 100644 --- a/test-utils/testlib/src/run_nodes.rs +++ b/test-utils/testlib/src/run_nodes.rs @@ -4,7 +4,7 @@ use std::time::Duration; use clap::{App, Arg}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use testlib::node::{create_nodes, Node, NodeConfig}; fn main() { diff --git a/tests/test_cases_testnet_rpc.rs b/tests/test_cases_testnet_rpc.rs index 2d8e8264047..724c06dbb8b 100644 --- a/tests/test_cases_testnet_rpc.rs +++ b/tests/test_cases_testnet_rpc.rs @@ -6,7 +6,7 @@ mod test { use std::thread; use std::time::Duration; - use near_env::init_test_module_logger; + use near_logger_utils::init_test_module_logger; use testlib::node::{create_nodes_from_seeds, Node, NodeConfig, ThreadNode}; use testlib::runtime_utils::alice_account; use testlib::standard_test_cases::*; diff --git a/tests/test_errors.rs b/tests/test_errors.rs index 41991436f8e..e1f944d6c69 100644 --- a/tests/test_errors.rs +++ b/tests/test_errors.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use near_chain_configs::Genesis; use near_crypto::{InMemorySigner, KeyType}; -use near_env::init_integration_logger; +use near_logger_utils::init_integration_logger; use near_network::test_utils::open_port; use near_primitives::account::AccessKey; use near_primitives::errors::{InvalidAccessKeyError, InvalidTxError}; diff --git a/tests/test_simple.rs b/tests/test_simple.rs index aa3bcec7d91..177384868e6 100644 --- a/tests/test_simple.rs +++ b/tests/test_simple.rs @@ -2,7 +2,7 @@ #[cfg(test)] #[cfg(feature = "expensive_tests")] mod test { - use near_env::init_integration_logger; + use near_logger_utils::init_integration_logger; use near_primitives::transaction::SignedTransaction; use testlib::node::{create_nodes, sample_two_nodes, Node}; use testlib::test_helpers::{heavy_test, wait}; diff --git a/utils/actix/Cargo.toml b/utils/actix/Cargo.toml new file mode 100644 index 00000000000..26c81841475 --- /dev/null +++ b/utils/actix/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "near-actix-utils" +version = "0.1.0" +authors = ["Near Inc "] +edition = "2018" + +[dependencies] +actix = "0.9.0" \ No newline at end of file diff --git a/utils/actix/src/lib.rs b/utils/actix/src/lib.rs new file mode 100644 index 00000000000..db969022652 --- /dev/null +++ b/utils/actix/src/lib.rs @@ -0,0 +1,16 @@ +use std::sync::Once; + +static SET_PANIC_HOOK: Once = Once::new(); + +/// This is a workaround to make actix/tokio runtime stop when a task panics. +pub fn init_stop_on_panic() { + SET_PANIC_HOOK.call_once(|| { + let default_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + default_hook(info); + if actix::System::is_set() { + actix::System::with_current(|sys| sys.stop_with_code(1)); + } + })); + }) +} From 0382fbde9b1bafca61ee8d27a4c9fe417ac5f05a Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 23 Apr 2020 16:30:36 +0300 Subject: [PATCH 05/12] substituted near-env with near-actix-utils and near-logger-utils --- neard/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/neard/Cargo.toml b/neard/Cargo.toml index d2216c3019d..7249efebe21 100644 --- a/neard/Cargo.toml +++ b/neard/Cargo.toml @@ -44,6 +44,7 @@ near-epoch-manager = { path = "../chain/epoch_manager" } [dev-dependencies] tempdir = "0.3" +near-logger-utils = { path = "../test-utils/logger" } testlib = { path = "../test-utils/testlib" } [features] From 1f81e8cb1554055a2eb7306c97d2a64dea92c4a7 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 00:26:39 +0300 Subject: [PATCH 06/12] remove Account::new and account_new function added --- Cargo.lock | 1 + core/primitives/benches/serialization.rs | 2 +- core/primitives/src/account.rs | 11 ----------- runtime/runtime/src/balance_checker.rs | 14 +++++++------- runtime/runtime/src/lib.rs | 8 ++++---- runtime/runtime/src/verifier.rs | 4 ++-- test-utils/testlib/src/runtime_utils.rs | 6 +++++- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd5a14ee70b..cf5096ee66d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2392,6 +2392,7 @@ dependencies = [ "near-crypto 0.1.0", "near-epoch-manager 0.0.1", "near-jsonrpc 0.1.0", + "near-logger-utils 0.1.0", "near-network 0.1.0", "near-pool 0.1.0", "near-primitives 0.1.0", diff --git a/core/primitives/benches/serialization.rs b/core/primitives/benches/serialization.rs index 69b92f6eb0a..e3305db277a 100644 --- a/core/primitives/benches/serialization.rs +++ b/core/primitives/benches/serialization.rs @@ -65,7 +65,7 @@ fn create_block() -> Block { } fn create_account() -> Account { - Account::new(0, CryptoHash::default()) + account_new(0, CryptoHash::default()) } fn serialize_tx(bench: &mut Bencher) { diff --git a/core/primitives/src/account.rs b/core/primitives/src/account.rs index 629984e4cd5..75dde90e1ab 100644 --- a/core/primitives/src/account.rs +++ b/core/primitives/src/account.rs @@ -20,17 +20,6 @@ pub struct Account { pub storage_usage: StorageUsage, } -impl Account { - pub fn new(amount: Balance, code_hash: CryptoHash) -> Self { - Account { - amount, - locked: 0, - code_hash, - storage_usage: std::mem::size_of::() as u64, - } - } -} - /// Access key provides limited access to an account. Each access key belongs to some account and /// is identified by a unique (within the account) public key. One account may have large number of /// access keys. Access keys allow to act on behalf of the account by restricting transactions diff --git a/runtime/runtime/src/balance_checker.rs b/runtime/runtime/src/balance_checker.rs index 35084555610..a04dbbdb6b5 100644 --- a/runtime/runtime/src/balance_checker.rs +++ b/runtime/runtime/src/balance_checker.rs @@ -227,7 +227,7 @@ mod tests { use near_runtime_fees::RuntimeFeesConfig; use near_store::test_utils::create_trie; use near_store::{set_account, TrieUpdate}; - use testlib::runtime_utils::{alice_account, bob_account}; + use testlib::runtime_utils::{account_new, alice_account, bob_account}; use assert_matches::assert_matches; @@ -288,12 +288,12 @@ mod tests { let refund_balance = 1000; let mut initial_state = TrieUpdate::new(trie.clone(), root); - let initial_account = Account::new(initial_balance, hash(&[])); + let initial_account = account_new(initial_balance, hash(&[])); set_account(&mut initial_state, account_id.clone(), &initial_account); initial_state.commit(StateChangeCause::NotWritableToDisk); let mut final_state = TrieUpdate::new(trie.clone(), root); - let final_account = Account::new(initial_balance + refund_balance, hash(&[])); + let final_account = account_new(initial_balance + refund_balance, hash(&[])); set_account(&mut final_state, account_id.clone(), &final_account); final_state.commit(StateChangeCause::NotWritableToDisk); @@ -329,12 +329,12 @@ mod tests { / (*cfg.burnt_gas_reward.denom() as u128); let total_validator_reward = send_gas as Balance * gas_price - contract_reward; let mut initial_state = TrieUpdate::new(trie.clone(), root); - let initial_account = Account::new(initial_balance, hash(&[])); + let initial_account = account_new(initial_balance, hash(&[])); set_account(&mut initial_state, account_id.clone(), &initial_account); initial_state.commit(StateChangeCause::NotWritableToDisk); let mut final_state = TrieUpdate::new(trie.clone(), root); - let final_account = Account::new( + let final_account = account_new( initial_balance - (exec_gas + send_gas) as Balance * gas_price - deposit + contract_reward, hash(&[]), @@ -392,8 +392,8 @@ mod tests { let deposit = 1000; let mut initial_state = TrieUpdate::new(trie.clone(), root); - let alice = Account::new(std::u128::MAX, hash(&[])); - let bob = Account::new(1u128, hash(&[])); + let alice = account_new(std::u128::MAX, hash(&[])); + let bob = account_new(1u128, hash(&[])); set_account(&mut initial_state, alice_id.clone(), &alice); set_account(&mut initial_state, bob_id.clone(), &bob); diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index a0cf03e57ff..1caca3c6264 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -1275,7 +1275,7 @@ mod tests { use near_primitives::transaction::TransferAction; use near_primitives::types::MerkleHash; use near_store::test_utils::create_trie; - use testlib::runtime_utils::{alice_account, bob_account}; + use testlib::runtime_utils::{account_new, alice_account, bob_account}; const GAS_PRICE: Balance = 5000; @@ -1287,7 +1287,7 @@ mod tests { fn test_get_and_set_accounts() { let trie = create_trie(); let mut state_update = TrieUpdate::new(trie, MerkleHash::default()); - let test_account = Account::new(to_yocto(10), hash(&[])); + let test_account = account_new(to_yocto(10), hash(&[])); let account_id = bob_account(); set_account(&mut state_update, account_id.clone(), &test_account); let get_res = get_account(&state_update, &account_id).unwrap().unwrap(); @@ -1299,7 +1299,7 @@ mod tests { let trie = create_trie(); let root = MerkleHash::default(); let mut state_update = TrieUpdate::new(trie.clone(), root); - let test_account = Account::new(to_yocto(10), hash(&[])); + let test_account = account_new(to_yocto(10), hash(&[])); let account_id = bob_account(); set_account(&mut state_update, account_id.clone(), &test_account); state_update.commit(StateChangeCause::InitialState); @@ -1329,7 +1329,7 @@ mod tests { Arc::new(InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id)); let mut initial_state = TrieUpdate::new(trie.clone(), root); - let mut initial_account = Account::new(initial_balance, hash(&[])); + let mut initial_account = account_new(initial_balance, hash(&[])); initial_account.locked = initial_locked; set_account(&mut initial_state, account_id.clone(), &initial_account); set_access_key( diff --git a/runtime/runtime/src/verifier.rs b/runtime/runtime/src/verifier.rs index df55c7253dc..8e14cfd774e 100644 --- a/runtime/runtime/src/verifier.rs +++ b/runtime/runtime/src/verifier.rs @@ -386,7 +386,7 @@ mod tests { use near_primitives::types::{AccountId, Balance, MerkleHash, StateChangeCause}; use near_store::test_utils::create_trie; use std::sync::Arc; - use testlib::runtime_utils::{alice_account, bob_account, eve_dot_alice_account}; + use testlib::runtime_utils::{account_new, alice_account, bob_account, eve_dot_alice_account}; /// Initial balance used in tests. const TESTING_INIT_BALANCE: Balance = 1_000_000_000 * NEAR_BASE; @@ -414,7 +414,7 @@ mod tests { let mut initial_state = TrieUpdate::new(trie.clone(), root); for (account_id, initial_balance, initial_locked, access_key) in accounts { - let mut initial_account = Account::new(initial_balance, hash(&[])); + let mut initial_account = account_new(initial_balance, hash(&[])); initial_account.locked = initial_locked; set_account(&mut initial_state, account_id.clone(), &initial_account); if let Some(access_key) = access_key { diff --git a/test-utils/testlib/src/runtime_utils.rs b/test-utils/testlib/src/runtime_utils.rs index aae56e0672b..3109eef2ed9 100644 --- a/test-utils/testlib/src/runtime_utils.rs +++ b/test-utils/testlib/src/runtime_utils.rs @@ -8,12 +8,16 @@ use near_chain_configs::Genesis; use near_primitives::account::Account; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::state_record::StateRecord; -use near_primitives::types::{AccountId, MerkleHash, StateRoot}; +use near_primitives::types::{AccountId, Balance, MerkleHash, StateRoot}; use near_store::test_utils::create_trie; use near_store::{Trie, TrieUpdate}; use neard::config::GenesisExt; use node_runtime::{state_viewer::TrieViewer, Runtime}; +pub fn account_new(amount: Balance, code_hash: CryptoHash) -> Account { + Account { amount, locked: 0, code_hash, storage_usage: std::mem::size_of::() as u64 } +} + pub fn alice_account() -> AccountId { "alice.near".to_string() } From c26ecc76dee3ba858b45c7f4b9cce9b1f81ab8d5 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 02:02:33 +0300 Subject: [PATCH 07/12] core/primitives/src/test_utils.rs ressurected --- core/primitives/src/block.rs | 76 ---------- core/primitives/src/lib.rs | 1 + core/primitives/src/test_utils.rs | 200 +++++++++++++++++++++++++ core/primitives/src/transaction.rs | 113 +------------- runtime/runtime/src/balance_checker.rs | 1 - 5 files changed, 204 insertions(+), 187 deletions(-) create mode 100644 core/primitives/src/test_utils.rs diff --git a/core/primitives/src/block.rs b/core/primitives/src/block.rs index 7bf03135689..4895c06bc20 100644 --- a/core/primitives/src/block.rs +++ b/core/primitives/src/block.rs @@ -721,82 +721,6 @@ impl Block { } } -impl Block { - pub fn empty_with_epoch( - prev: &Block, - height: BlockHeight, - epoch_id: EpochId, - next_epoch_id: EpochId, - next_bp_hash: CryptoHash, - signer: &dyn ValidatorSigner, - ) -> Self { - Self::empty_with_approvals( - prev, - height, - epoch_id, - next_epoch_id, - vec![], - signer, - next_bp_hash, - ) - } - - pub fn empty_with_height( - prev: &Block, - height: BlockHeight, - signer: &dyn ValidatorSigner, - ) -> Self { - Self::empty_with_epoch( - prev, - height, - prev.header.inner_lite.epoch_id.clone(), - if prev.header.prev_hash == CryptoHash::default() { - EpochId(prev.hash()) - } else { - prev.header.inner_lite.next_epoch_id.clone() - }, - prev.header.inner_lite.next_bp_hash, - signer, - ) - } - - pub fn empty(prev: &Block, signer: &dyn ValidatorSigner) -> Self { - Self::empty_with_height(prev, prev.header.inner_lite.height + 1, signer) - } - - /// This is not suppose to be used outside of chain tests, because this doesn't refer to correct chunks. - /// Done because chain tests don't have a good way to store chunks right now. - pub fn empty_with_approvals( - prev: &Block, - height: BlockHeight, - epoch_id: EpochId, - next_epoch_id: EpochId, - approvals: Vec, - signer: &dyn ValidatorSigner, - next_bp_hash: CryptoHash, - ) -> Self { - Block::produce( - &prev.header, - height, - prev.chunks.clone(), - epoch_id, - next_epoch_id, - approvals, - Rational::from_integer(0), - 0, - Some(0), - vec![], - vec![], - signer, - 0.into(), - CryptoHash::default(), - CryptoHash::default(), - CryptoHash::default(), - next_bp_hash, - ) - } -} - /// The score is defined as the height of the last block with quorum pre-vote /// We have a separate type to ensure that the height is never assigned to score and vice versa #[derive( diff --git a/core/primitives/src/lib.rs b/core/primitives/src/lib.rs index 125110569f4..338df9e82ef 100644 --- a/core/primitives/src/lib.rs +++ b/core/primitives/src/lib.rs @@ -20,6 +20,7 @@ pub mod serialize; pub mod sharding; pub mod state_record; pub mod telemetry; +pub mod test_utils; pub mod transaction; pub mod trie_key; pub mod types; diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs new file mode 100644 index 00000000000..0b77fbe6715 --- /dev/null +++ b/core/primitives/src/test_utils.rs @@ -0,0 +1,200 @@ +use near_crypto::{EmptySigner, PublicKey, Signer}; + +use crate::account::{AccessKey, AccessKeyPermission}; +use crate::block::{Approval, Block}; +use crate::hash::CryptoHash; +use crate::transaction::{ + Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, SignedTransaction, StakeAction, + Transaction, TransferAction, +}; +use crate::types::{AccountId, Balance, BlockHeight, EpochId, Nonce}; +use crate::validator_signer::ValidatorSigner; +use num_rational::Rational; + +impl Transaction { + pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { + let signature = signer.sign(self.get_hash().as_ref()); + SignedTransaction::new(signature, self) + } +} + +impl SignedTransaction { + pub fn from_actions( + nonce: Nonce, + signer_id: AccountId, + receiver_id: AccountId, + signer: &dyn Signer, + actions: Vec, + block_hash: CryptoHash, + ) -> Self { + Transaction { + nonce, + signer_id, + public_key: signer.public_key(), + receiver_id, + block_hash, + actions, + } + .sign(signer) + } + + pub fn send_money( + nonce: Nonce, + signer_id: AccountId, + receiver_id: AccountId, + signer: &dyn Signer, + deposit: Balance, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id, + receiver_id, + signer, + vec![Action::Transfer(TransferAction { deposit })], + block_hash, + ) + } + + pub fn stake( + nonce: Nonce, + signer_id: AccountId, + signer: &dyn Signer, + stake: Balance, + public_key: PublicKey, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id.clone(), + signer_id, + signer, + vec![Action::Stake(StakeAction { stake, public_key })], + block_hash, + ) + } + + pub fn create_account( + nonce: Nonce, + originator: AccountId, + new_account_id: AccountId, + amount: Balance, + public_key: PublicKey, + signer: &dyn Signer, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + originator, + new_account_id, + signer, + vec![ + Action::CreateAccount(CreateAccountAction {}), + Action::AddKey(AddKeyAction { + public_key, + access_key: AccessKey { nonce: 0, permission: AccessKeyPermission::FullAccess }, + }), + Action::Transfer(TransferAction { deposit: amount }), + ], + block_hash, + ) + } + + pub fn delete_account( + nonce: Nonce, + signer_id: AccountId, + receiver_id: AccountId, + beneficiary_id: AccountId, + signer: &dyn Signer, + block_hash: CryptoHash, + ) -> Self { + Self::from_actions( + nonce, + signer_id, + receiver_id, + signer, + vec![Action::DeleteAccount(DeleteAccountAction { beneficiary_id })], + block_hash, + ) + } + + pub fn empty(block_hash: CryptoHash) -> Self { + Self::from_actions(0, "".to_string(), "".to_string(), &EmptySigner {}, vec![], block_hash) + } +} + +impl Block { + pub fn empty_with_epoch( + prev: &Block, + height: BlockHeight, + epoch_id: EpochId, + next_epoch_id: EpochId, + next_bp_hash: CryptoHash, + signer: &dyn ValidatorSigner, + ) -> Self { + Self::empty_with_approvals( + prev, + height, + epoch_id, + next_epoch_id, + vec![], + signer, + next_bp_hash, + ) + } + + pub fn empty_with_height( + prev: &Block, + height: BlockHeight, + signer: &dyn ValidatorSigner, + ) -> Self { + Self::empty_with_epoch( + prev, + height, + prev.header.inner_lite.epoch_id.clone(), + if prev.header.prev_hash == CryptoHash::default() { + EpochId(prev.hash()) + } else { + prev.header.inner_lite.next_epoch_id.clone() + }, + prev.header.inner_lite.next_bp_hash, + signer, + ) + } + + pub fn empty(prev: &Block, signer: &dyn ValidatorSigner) -> Self { + Self::empty_with_height(prev, prev.header.inner_lite.height + 1, signer) + } + + /// This is not suppose to be used outside of chain tests, because this doesn't refer to correct chunks. + /// Done because chain tests don't have a good way to store chunks right now. + pub fn empty_with_approvals( + prev: &Block, + height: BlockHeight, + epoch_id: EpochId, + next_epoch_id: EpochId, + approvals: Vec, + signer: &dyn ValidatorSigner, + next_bp_hash: CryptoHash, + ) -> Self { + Block::produce( + &prev.header, + height, + prev.chunks.clone(), + epoch_id, + next_epoch_id, + approvals, + Rational::from_integer(0), + 0, + Some(0), + vec![], + vec![], + signer, + 0.into(), + CryptoHash::default(), + CryptoHash::default(), + CryptoHash::default(), + next_bp_hash, + ) + } +} diff --git a/core/primitives/src/transaction.rs b/core/primitives/src/transaction.rs index 815590b6fd3..7b2b1a46399 100644 --- a/core/primitives/src/transaction.rs +++ b/core/primitives/src/transaction.rs @@ -5,9 +5,9 @@ use std::hash::{Hash, Hasher}; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use near_crypto::{EmptySigner, PublicKey, Signature, Signer}; +use near_crypto::{PublicKey, Signature}; -use crate::account::{AccessKey, AccessKeyPermission}; +use crate::account::AccessKey; use crate::errors::TxExecutionError; use crate::hash::{hash, CryptoHash}; use crate::logging; @@ -41,11 +41,6 @@ impl Transaction { let bytes = self.try_to_vec().expect("Failed to deserialize"); hash(&bytes) } - - pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { - let signature = signer.sign(self.get_hash().as_ref()); - SignedTransaction::new(signature, self) - } } #[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] @@ -178,108 +173,6 @@ impl SignedTransaction { pub fn get_hash(&self) -> CryptoHash { self.hash } - - pub fn from_actions( - nonce: Nonce, - signer_id: AccountId, - receiver_id: AccountId, - signer: &dyn Signer, - actions: Vec, - block_hash: CryptoHash, - ) -> Self { - Transaction { - nonce, - signer_id, - public_key: signer.public_key(), - receiver_id, - block_hash, - actions, - } - .sign(signer) - } - pub fn send_money( - nonce: Nonce, - signer_id: AccountId, - receiver_id: AccountId, - signer: &dyn Signer, - deposit: Balance, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id, - receiver_id, - signer, - vec![Action::Transfer(TransferAction { deposit })], - block_hash, - ) - } - - pub fn stake( - nonce: Nonce, - signer_id: AccountId, - signer: &dyn Signer, - stake: Balance, - public_key: PublicKey, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id.clone(), - signer_id, - signer, - vec![Action::Stake(StakeAction { stake, public_key })], - block_hash, - ) - } - - pub fn create_account( - nonce: Nonce, - originator: AccountId, - new_account_id: AccountId, - amount: Balance, - public_key: PublicKey, - signer: &dyn Signer, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - originator, - new_account_id, - signer, - vec![ - Action::CreateAccount(CreateAccountAction {}), - Action::AddKey(AddKeyAction { - public_key, - access_key: AccessKey { nonce: 0, permission: AccessKeyPermission::FullAccess }, - }), - Action::Transfer(TransferAction { deposit: amount }), - ], - block_hash, - ) - } - - pub fn delete_account( - nonce: Nonce, - signer_id: AccountId, - receiver_id: AccountId, - beneficiary_id: AccountId, - signer: &dyn Signer, - block_hash: CryptoHash, - ) -> Self { - Self::from_actions( - nonce, - signer_id, - receiver_id, - signer, - vec![Action::DeleteAccount(DeleteAccountAction { beneficiary_id })], - block_hash, - ) - } - - pub fn empty(block_hash: CryptoHash) -> Self { - Self::from_actions(0, "".to_string(), "".to_string(), &EmptySigner {}, vec![], block_hash) - } } impl Hash for SignedTransaction { @@ -434,7 +327,7 @@ mod tests { use borsh::BorshDeserialize; - use near_crypto::{InMemorySigner, KeyType, Signature}; + use near_crypto::{InMemorySigner, KeyType, Signature, Signer}; use crate::account::{AccessKeyPermission, FunctionCallPermission}; use crate::serialize::to_base; diff --git a/runtime/runtime/src/balance_checker.rs b/runtime/runtime/src/balance_checker.rs index a04dbbdb6b5..50e798fc8dd 100644 --- a/runtime/runtime/src/balance_checker.rs +++ b/runtime/runtime/src/balance_checker.rs @@ -219,7 +219,6 @@ mod tests { use super::*; use crate::ApplyStats; use near_crypto::{InMemorySigner, KeyType}; - use near_primitives::account::Account; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::receipt::ActionReceipt; use near_primitives::transaction::{Action, TransferAction}; From b69d61dab4ad99e6c4a8797d44dd39b03cea3829 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 02:33:57 +0300 Subject: [PATCH 08/12] move account_new to near_primitives::test_utils::account_new --- core/primitives/src/test_utils.rs | 4 ++++ runtime/runtime/src/balance_checker.rs | 3 ++- runtime/runtime/src/lib.rs | 3 ++- runtime/runtime/src/verifier.rs | 3 ++- test-utils/testlib/src/runtime_utils.rs | 4 ---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs index 0b77fbe6715..533be2e5087 100644 --- a/core/primitives/src/test_utils.rs +++ b/core/primitives/src/test_utils.rs @@ -11,6 +11,10 @@ use crate::types::{AccountId, Balance, BlockHeight, EpochId, Nonce}; use crate::validator_signer::ValidatorSigner; use num_rational::Rational; +pub fn account_new(amount: Balance, code_hash: CryptoHash) -> Account { + Account { amount, locked: 0, code_hash, storage_usage: std::mem::size_of::() as u64 } +} + impl Transaction { pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { let signature = signer.sign(self.get_hash().as_ref()); diff --git a/runtime/runtime/src/balance_checker.rs b/runtime/runtime/src/balance_checker.rs index 50e798fc8dd..e6ede56c79b 100644 --- a/runtime/runtime/src/balance_checker.rs +++ b/runtime/runtime/src/balance_checker.rs @@ -221,12 +221,13 @@ mod tests { use near_crypto::{InMemorySigner, KeyType}; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::receipt::ActionReceipt; + use near_primitives::test_utils::account_new; use near_primitives::transaction::{Action, TransferAction}; use near_primitives::types::{MerkleHash, StateChangeCause}; use near_runtime_fees::RuntimeFeesConfig; use near_store::test_utils::create_trie; use near_store::{set_account, TrieUpdate}; - use testlib::runtime_utils::{account_new, alice_account, bob_account}; + use testlib::runtime_utils::{alice_account, bob_account}; use assert_matches::assert_matches; diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 1caca3c6264..d9bd2a30204 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -1272,10 +1272,11 @@ mod tests { use near_crypto::{InMemorySigner, KeyType, Signer}; use near_primitives::errors::ReceiptValidationError; use near_primitives::hash::hash; + use near_primitives::test_utils::account_new; use near_primitives::transaction::TransferAction; use near_primitives::types::MerkleHash; use near_store::test_utils::create_trie; - use testlib::runtime_utils::{account_new, alice_account, bob_account}; + use testlib::runtime_utils::{alice_account, bob_account}; const GAS_PRICE: Balance = 5000; diff --git a/runtime/runtime/src/verifier.rs b/runtime/runtime/src/verifier.rs index 8e14cfd774e..20eb4bdf050 100644 --- a/runtime/runtime/src/verifier.rs +++ b/runtime/runtime/src/verifier.rs @@ -380,13 +380,14 @@ mod tests { use near_primitives::account::{AccessKey, Account, FunctionCallPermission}; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::receipt::DataReceiver; + use near_primitives::test_utils::account_new; use near_primitives::transaction::{ CreateAccountAction, DeleteKeyAction, StakeAction, TransferAction, }; use near_primitives::types::{AccountId, Balance, MerkleHash, StateChangeCause}; use near_store::test_utils::create_trie; use std::sync::Arc; - use testlib::runtime_utils::{account_new, alice_account, bob_account, eve_dot_alice_account}; + use testlib::runtime_utils::{alice_account, bob_account, eve_dot_alice_account}; /// Initial balance used in tests. const TESTING_INIT_BALANCE: Balance = 1_000_000_000 * NEAR_BASE; diff --git a/test-utils/testlib/src/runtime_utils.rs b/test-utils/testlib/src/runtime_utils.rs index 3109eef2ed9..4dff0172c20 100644 --- a/test-utils/testlib/src/runtime_utils.rs +++ b/test-utils/testlib/src/runtime_utils.rs @@ -14,10 +14,6 @@ use near_store::{Trie, TrieUpdate}; use neard::config::GenesisExt; use node_runtime::{state_viewer::TrieViewer, Runtime}; -pub fn account_new(amount: Balance, code_hash: CryptoHash) -> Account { - Account { amount, locked: 0, code_hash, storage_usage: std::mem::size_of::() as u64 } -} - pub fn alice_account() -> AccountId { "alice.near".to_string() } From d96428983fa5c60dd0671d7d0313598a6385d8b5 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 02:33:57 +0300 Subject: [PATCH 09/12] move account_new to near_primitives::test_utils::account_new --- core/primitives/benches/serialization.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/primitives/benches/serialization.rs b/core/primitives/benches/serialization.rs index 11ce8b9e0d4..5b3c97231fe 100644 --- a/core/primitives/benches/serialization.rs +++ b/core/primitives/benches/serialization.rs @@ -9,6 +9,7 @@ use near_crypto::{KeyType, PublicKey, Signature}; use near_primitives::account::Account; use near_primitives::block::{genesis_chunks, Block}; use near_primitives::hash::CryptoHash; +use near_primitives::test_utils::account_new; use near_primitives::transaction::{Action, SignedTransaction, Transaction, TransferAction}; use near_primitives::types::{EpochId, StateRoot}; use near_primitives::validator_signer::InMemoryValidatorSigner; From 04ca2671b075b7a5aca32a0ed0d1e1b8c404e9f4 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 03:22:22 +0300 Subject: [PATCH 10/12] fix warning --- Cargo.lock | 4 ++-- test-utils/testlib/src/runtime_utils.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3bbcd733f0a..b39fc217f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1953,11 +1953,11 @@ dependencies = [ "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "reed-solomon-erasure 4.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "testlib 0.1.0", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "testlib 0.1.0", ] [[package]] @@ -2047,7 +2047,7 @@ name = "near-logger-utils" version = "0.1.0" dependencies = [ "near-actix-utils 0.1.0", - "tracing-subscriber 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-subscriber 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/test-utils/testlib/src/runtime_utils.rs b/test-utils/testlib/src/runtime_utils.rs index 4dff0172c20..aae56e0672b 100644 --- a/test-utils/testlib/src/runtime_utils.rs +++ b/test-utils/testlib/src/runtime_utils.rs @@ -8,7 +8,7 @@ use near_chain_configs::Genesis; use near_primitives::account::Account; use near_primitives::hash::{hash, CryptoHash}; use near_primitives::state_record::StateRecord; -use near_primitives::types::{AccountId, Balance, MerkleHash, StateRoot}; +use near_primitives::types::{AccountId, MerkleHash, StateRoot}; use near_store::test_utils::create_trie; use near_store::{Trie, TrieUpdate}; use neard::config::GenesisExt; From 9309fd742812f83dc1db567d4691b4d3cb6290d7 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 03:40:08 +0300 Subject: [PATCH 11/12] fix consensus.rs tests --- chain/client/tests/consensus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/client/tests/consensus.rs b/chain/client/tests/consensus.rs index c9bf6ece86f..a0ec66e450a 100644 --- a/chain/client/tests/consensus.rs +++ b/chain/client/tests/consensus.rs @@ -5,9 +5,9 @@ mod tests { use near_chain::Block; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, ViewClientActor}; + use near_logger_utils::init_test_logger; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::{Approval, ApprovalInner}; - use near_primitives::test_utils::init_integration_logger; use near_primitives::types::BlockHeight; use rand::{thread_rng, Rng}; use std::collections::{BTreeMap, HashMap, HashSet}; From b951c71bf5445eaabb2815a807904d4b94a4f76f Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Apr 2020 14:23:19 +0300 Subject: [PATCH 12/12] fix test_consensus_with_epoch_switches test --- chain/client/tests/consensus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/client/tests/consensus.rs b/chain/client/tests/consensus.rs index a0ec66e450a..1fb5654b124 100644 --- a/chain/client/tests/consensus.rs +++ b/chain/client/tests/consensus.rs @@ -5,7 +5,7 @@ mod tests { use near_chain::Block; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, ViewClientActor}; - use near_logger_utils::init_test_logger; + use near_logger_utils::init_integration_logger; use near_network::{NetworkClientMessages, NetworkRequests, NetworkResponses, PeerInfo}; use near_primitives::block::{Approval, ApprovalInner}; use near_primitives::types::BlockHeight;