diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f9ef4859..71157152 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -9,8 +9,8 @@ anyhow = "1.0" maplit = "1.0" near-units = "0.2.0" near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] } -near-jsonrpc-primitives = "0.20.0" -near-primitives = "0.20.0" +near-jsonrpc-primitives = "0.23.0" +near-primitives = "0.23.0" serde = "1.0" serde_with = "3.4" serde_json = { version = "1.0" } diff --git a/examples/src/tx_status.rs b/examples/src/tx_status.rs index 5daa4a0f..98fbf960 100644 --- a/examples/src/tx_status.rs +++ b/examples/src/tx_status.rs @@ -27,7 +27,9 @@ async fn main() -> anyhow::Result<()> { }; // NOTE: this API is under the "experimental" flag and no guarantees are given. - let resp = worker.tx_status(tx_info).await?; + let resp = worker + .tx_status(tx_info, near_primitives::views::TxExecutionStatus::Final) + .await?; // Example outcome: // diff --git a/workspaces/Cargo.toml b/workspaces/Cargo.toml index c4ac2497..2eccd300 100644 --- a/workspaces/Cargo.toml +++ b/workspaces/Cargo.toml @@ -11,18 +11,18 @@ Library for automating workflows and testing NEAR smart contracts. [dependencies] async-trait = "0.1" -base64 = "0.21" +base64 = "0.22" bs58 = "0.5" cargo_metadata = { version = "0.18", optional = true } -cargo-near = { version = "0.5.2", default-features = false } +cargo-near = { version = "0.6.3", default-features = false } chrono = "0.4.19" fs2 = "0.4" rand = "0.8.4" -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.12", features = ["json"] } sha2 = "0.10" serde = "1.0" serde_json = "1.0" -json-patch = "1.0" +json-patch = "2.0" tempfile = "3.3" thiserror = "1.0" tokio = { version = "1", features = ["full"] } @@ -33,14 +33,14 @@ url = { version = "2.2.2", features = ["serde"] } near-abi-client = "0.1.1" near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] } near-token = { version = "0.2.0", features = ["serde"] } -near-sdk = { version = "5.0.0-alpha.2", optional = true } +near-sdk = { version = "5.2.0", optional = true } near-account-id = "1.0.0" -near-crypto = "0.20.0" -near-primitives = "0.20.0" -near-jsonrpc-primitives = "0.20.0" -near-jsonrpc-client = { version = "0.8", features = ["sandbox"] } -near-sandbox-utils = "0.8.0" -near-chain-configs = { version = "0.20.0", optional = true } +near-crypto = "0.23.0" +near-primitives = "0.23.0" +near-jsonrpc-primitives = "0.23.0" +near-jsonrpc-client = { version = "0.10.1", features = ["sandbox"] } +near-sandbox-utils = "0.9.0" +near-chain-configs = { version = "0.23.0", optional = true } [build-dependencies] near-sandbox-utils = "0.8.0" @@ -51,7 +51,7 @@ libc = "0.2" [dev-dependencies] anyhow = "1.0" futures = "0.3" -near-sdk = "5.0.0-alpha.2" +near-sdk = "5.2.0" test-log = { version = "0.2.8", default-features = false, features = ["trace"] } tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/workspaces/src/cargo/mod.rs b/workspaces/src/cargo/mod.rs index 75cb4f5e..58558263 100644 --- a/workspaces/src/cargo/mod.rs +++ b/workspaces/src/cargo/mod.rs @@ -6,6 +6,7 @@ use cargo_near::commands::build_command::{build, BuildCommand}; /// /// NOTE: This function does not check whether the resulting wasm file is a valid smart /// contract or not. +/// NOTE: This function builds the project using default features pub async fn compile_project(project_path: &str) -> crate::Result> { let project_path = std::fs::canonicalize(project_path).map_err(|e| match e.kind() { std::io::ErrorKind::NotFound => ErrorKind::Io.message(format!( @@ -16,9 +17,9 @@ pub async fn compile_project(project_path: &str) -> crate::Result> { })?; let cargo_near_build_command = BuildCommand { - release: true, - embed_abi: true, - doc: false, + no_release: false, + no_embed_abi: false, + no_doc: true, color: None, no_abi: true, out_dir: None, @@ -33,6 +34,8 @@ pub async fn compile_project(project_path: &str) -> crate::Result> { )) })?, ), + features: None, + no_default_features: false, }; let compile_artifact = diff --git a/workspaces/src/network/sandbox.rs b/workspaces/src/network/sandbox.rs index 4552fc5a..5f85ebab 100644 --- a/workspaces/src/network/sandbox.rs +++ b/workspaces/src/network/sandbox.rs @@ -66,9 +66,7 @@ impl Sandbox { // Check the conditions of the provided rpc_url and validator_key let mut server = match (build.rpc_addr, build.validator_key) { // Connect to a provided sandbox: - (Some(rpc_url), Some(validator_key)) => { - SandboxServer::connect(rpc_url, validator_key).await? - } + (Some(rpc_url), Some(validator_key)) => SandboxServer::new(rpc_url, validator_key)?, // Spawn a new sandbox since rpc_url and home_dir weren't specified: (None, None) => SandboxServer::run_new_with_version(version).await?, diff --git a/workspaces/src/network/server.rs b/workspaces/src/network/server.rs index f910105c..0693c3a4 100644 --- a/workspaces/src/network/server.rs +++ b/workspaces/src/network/server.rs @@ -94,7 +94,7 @@ pub struct SandboxServer { impl SandboxServer { /// Connect a sandbox server that's already been running, provided we know the rpc_addr /// and home_dir pointing to the sandbox process. - pub(crate) async fn connect(rpc_addr: String, validator_key: ValidatorKey) -> Result { + pub(crate) fn new(rpc_addr: String, validator_key: ValidatorKey) -> Result { let rpc_addr = Url::parse(&rpc_addr).map_err(|e| { SandboxErrorCode::InitFailure.full(format!("Invalid rpc_url={rpc_addr}"), e) })?; diff --git a/workspaces/src/operations.rs b/workspaces/src/operations.rs index b83ad370..55ded649 100644 --- a/workspaces/src/operations.rs +++ b/workspaces/src/operations.rs @@ -519,12 +519,17 @@ impl TransactionStatus { .tx_async_status( &self.sender_id, near_primitives::hash::CryptoHash(self.hash.0), + near_primitives::views::TxExecutionStatus::Final, ) .await - .map(ExecutionFinalResult::from_view); + .map(|o| { + o.final_execution_outcome + .map(|e| ExecutionFinalResult::from_view(e.into_outcome())) + }); match result { - Ok(result) => Ok(Poll::Ready(result)), + Ok(Some(result)) => Ok(Poll::Ready(result)), + Ok(None) => Ok(Poll::Pending), Err(err) => match err { JsonRpcError::ServerError(JsonRpcServerError::HandlerError( RpcTransactionError::UnknownTransaction { .. }, diff --git a/workspaces/src/rpc/client.rs b/workspaces/src/rpc/client.rs index a383602c..f61356fc 100644 --- a/workspaces/src/rpc/client.rs +++ b/workspaces/src/rpc/client.rs @@ -10,7 +10,7 @@ use tokio_retry::strategy::{jitter, ExponentialBackoff}; use tokio_retry::Retry; use near_jsonrpc_client::errors::{JsonRpcError, JsonRpcServerError}; -use near_jsonrpc_client::methods::tx::RpcTransactionError; +use near_jsonrpc_client::methods::tx::{RpcTransactionError, RpcTransactionResponse}; use near_jsonrpc_client::{methods, JsonRpcClient, MethodCallResult}; use near_jsonrpc_primitives::types::query::QueryResponseKind; use near_primitives::account::{AccessKey, AccessKeyPermission}; @@ -23,6 +23,7 @@ use near_primitives::transaction::{ use near_primitives::types::{BlockReference, Finality, Gas}; use near_primitives::views::{ AccessKeyView, BlockView, FinalExecutionOutcomeView, QueryRequest, StatusResponse, + TxExecutionStatus, }; #[cfg(feature = "experimental")] @@ -34,10 +35,7 @@ use { }, near_primitives::{ types::MaybeBlockId, - views::{ - validator_stake_view::ValidatorStakeView, FinalExecutionOutcomeWithReceiptView, - ReceiptView, StateChangesRequestView, - }, + views::{validator_stake_view::ValidatorStakeView, ReceiptView, StateChangesRequestView}, }, }; @@ -306,12 +304,14 @@ impl Client { &self, sender_id: &AccountId, tx_hash: CryptoHash, - ) -> Result> { + wait_until: TxExecutionStatus, + ) -> Result> { self.query(methods::tx::RpcTransactionStatusRequest { transaction_info: methods::tx::TransactionInfo::TransactionId { sender_account_id: sender_id.clone(), tx_hash, }, + wait_until, }) .await } @@ -420,10 +420,16 @@ impl Client { pub(crate) async fn tx_status( &self, transaction_info: TransactionInfo, - ) -> Result { + wait_until: TxExecutionStatus, + ) -> Result { let resp = self .rpc_client - .call(methods::EXPERIMENTAL_tx_status::RpcTransactionStatusRequest { transaction_info }) + .call( + methods::EXPERIMENTAL_tx_status::RpcTransactionStatusRequest { + transaction_info, + wait_until, + }, + ) .await .map_err(|e| RpcErrorCode::QueryFailure.custom(e))?; Ok(resp) diff --git a/workspaces/src/types/account.rs b/workspaces/src/types/account.rs index 9d96819e..afe7df00 100644 --- a/workspaces/src/types/account.rs +++ b/workspaces/src/types/account.rs @@ -1,6 +1,8 @@ use std::fmt; use std::path::Path; +use near_primitives::types::StorageUsage; +use near_primitives::version::PROTOCOL_VERSION; use near_primitives::views::AccountView; use crate::error::ErrorKind; @@ -329,7 +331,7 @@ pub struct AccountDetailsPatch { pub balance: Option, pub locked: Option, pub code_hash: Option, - pub storage_usage: Option, + pub storage_usage: Option, pub(crate) storage_paid_at: Option, } @@ -367,7 +369,7 @@ impl AccountDetailsPatch { self } - pub fn storage_usage(mut self, storage_usage: u64) -> Self { + pub fn storage_usage(mut self, storage_usage: StorageUsage) -> Self { self.storage_usage = Some(storage_usage); self } @@ -393,7 +395,7 @@ pub struct AccountDetails { pub balance: NearToken, pub locked: NearToken, pub code_hash: CryptoHash, - pub storage_usage: u64, + pub storage_usage: StorageUsage, // Deprecated value. Mainly used to be able to convert back into an AccountView pub(crate) storage_paid_at: BlockHeight, } @@ -413,8 +415,10 @@ impl AccountDetails { near_primitives::account::Account::new( self.balance.as_yoctonear(), self.locked.as_yoctonear(), + 0, near_primitives::hash::CryptoHash(self.code_hash.0), self.storage_usage, + PROTOCOL_VERSION, ) } } diff --git a/workspaces/src/worker/impls.rs b/workspaces/src/worker/impls.rs index 0a0dbf4b..e8bbb0e3 100644 --- a/workspaces/src/worker/impls.rs +++ b/workspaces/src/worker/impls.rs @@ -1,4 +1,6 @@ +use near_jsonrpc_client::methods::tx::RpcTransactionResponse; use near_primitives::views::StatusResponse; +use near_primitives::views::TxExecutionStatus; use crate::network::{AllowDevAccountCreation, NetworkClient, NetworkInfo}; use crate::network::{Info, Sandbox}; @@ -24,10 +26,7 @@ use { }, near_primitives::{ types::{BlockReference, MaybeBlockId}, - views::{ - validator_stake_view::ValidatorStakeView, FinalExecutionOutcomeWithReceiptView, - ReceiptView, StateChangesRequestView, - }, + views::{validator_stake_view::ValidatorStakeView, ReceiptView, StateChangesRequestView}, }, }; @@ -247,8 +246,9 @@ where pub async fn tx_status( &self, transaction_info: TransactionInfo, - ) -> Result { - self.client().tx_status(transaction_info).await + wait_until: TxExecutionStatus, + ) -> Result { + self.client().tx_status(transaction_info, wait_until).await } /// Provides a list of validators ordered with respect to their stake. diff --git a/workspaces/tests/account.rs b/workspaces/tests/account.rs index 6f896cb1..8de64a5d 100644 --- a/workspaces/tests/account.rs +++ b/workspaces/tests/account.rs @@ -76,10 +76,6 @@ async fn test_delete_account() -> anyhow::Result<()> { _ = alice.clone().delete_account(bob.id()).await?; - // All sandbox accounts start with a balance of 100 NEAR tokens. - // On account deletion, alice's balance is debited to bob as beneficiary. - assert!(bob.view_account().await?.balance > NearToken::from_near(100)); - // Alice's account should be deleted. let res = alice.view_account().await; @@ -92,5 +88,9 @@ async fn test_delete_account() -> anyhow::Result<()> { .to_string() .contains(&format!("{} does not exist while viewing", alice.id())),); + // All sandbox accounts start with a balance of 100 NEAR tokens. + // On account deletion, alice's balance is debited to bob as beneficiary. + assert!(bob.view_account().await?.balance > NearToken::from_near(100)); + Ok(()) }