Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch prints to tracing #55

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = "1.0"
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
tokio-retry = "0.3"
tracing = "0.1.29"
itegulov marked this conversation as resolved.
Show resolved Hide resolved
url = { version = "2.2.2", features = ["serde"] }

near-account-id = "0.5"
Expand All @@ -40,3 +41,6 @@ libc = "0.2"

[dev-dependencies]
borsh = "0.9"
env_logger = "0.9.0"
test-log = { version = "0.2.8", default-features = false, features = ["trace"] }
tracing-subscriber = {version = "0.3.5", default-features = false, features = ["env-filter", "fmt"]}
14 changes: 7 additions & 7 deletions workspaces/src/network/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::process::Child;

use portpicker::pick_unused_port;

use crate::network::Sandbox;
use portpicker::pick_unused_port;
use std::process::Child;
use tracing::info;

pub struct SandboxServer {
pub(crate) rpc_port: u16,
Expand All @@ -20,15 +19,15 @@ impl SandboxServer {
}

pub fn start(&mut self) -> anyhow::Result<()> {
println!("Starting up sandbox at localhost:{}", self.rpc_port);
info!(target: "workspaces", "Starting up sandbox at localhost:{}", self.rpc_port);
let home_dir = Sandbox::home_dir(self.rpc_port);

// Remove dir if it already exists:
let _ = std::fs::remove_dir_all(&home_dir);
near_sandbox_utils::init(&home_dir)?.wait()?;

let child = near_sandbox_utils::run(&home_dir, self.rpc_port, self.net_port)?;
println!("Started sandbox: pid={:?}", child.id());
info!(target: "workspaces", "Started sandbox: pid={:?}", child.id());
self.process = Some(child);

Ok(())
Expand All @@ -55,7 +54,8 @@ impl Drop for SandboxServer {

let child = self.process.as_mut().unwrap();

eprintln!(
info!(
target: "workspaces",
"Cleaning up sandbox: port={}, pid={}",
self.rpc_port,
child.id()
Expand Down
3 changes: 2 additions & 1 deletion workspaces/tests/create_account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use test_log::test;
use workspaces::prelude::*;

#[tokio::test]
#[test(tokio::test)]
async fn test_subaccount_creation() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let account = worker.dev_create_account().await?;
Expand Down
4 changes: 2 additions & 2 deletions workspaces/tests/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};

use test_log::test;
use workspaces::prelude::*;

const NFT_WASM_FILEPATH: &str = "../examples/res/non_fungible_token.wasm";
Expand Down Expand Up @@ -28,7 +28,7 @@ fn expected() -> NftMetadata {
serde_json::from_str(EXPECTED_NFT_METADATA).unwrap()
}

#[tokio::test]
#[test(tokio::test)]
async fn test_dev_deploy() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let wasm = std::fs::read(NFT_WASM_FILEPATH)?;
Expand Down
6 changes: 3 additions & 3 deletions workspaces/tests/patch_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use borsh::{self, BorshDeserialize, BorshSerialize};
use serde_json::json;

use test_log::test;
use workspaces::prelude::*;
use workspaces::{AccountId, DevNetwork, Worker};

Expand Down Expand Up @@ -40,7 +40,7 @@ async fn view_status_state(
Ok((contract.id().clone(), status_msg))
}

#[tokio::test]
#[test(tokio::test)]
async fn test_view_state() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let (contract_id, status_msg) = view_status_state(worker).await?;
Expand All @@ -58,7 +58,7 @@ async fn test_view_state() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn test_patch_state() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let (contract_id, mut status_msg) = view_status_state(worker.clone()).await?;
Expand Down