diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 992d54ea..6239adc1 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -6,12 +6,11 @@ edition = "2018" [dev-dependencies] anyhow = "1.0" -borsh = "1.2.0" maplit = "1.0" near-units = "0.2.0" -near-gas = { version = "0.2.3", features = ["serde", "borsh", "schemars"] } -near-jsonrpc-primitives = "0.17" -near-primitives = "0.17" +near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] } +near-jsonrpc-primitives = "0.20.0" +near-primitives = "0.20.0" serde = "1.0" serde_with = "3.4" serde_json = { version = "1.0" } diff --git a/examples/noop-contract/Cargo.toml b/examples/noop-contract/Cargo.toml index 7402c15d..923c13f1 100644 --- a/examples/noop-contract/Cargo.toml +++ b/examples/noop-contract/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.1.1" +near-sdk = "5.0.0-alpha.2" [profile.release] codegen-units = 1 @@ -18,4 +18,4 @@ lto = true debug = false panic = "abort" # Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 -overflow-checks = true \ No newline at end of file +overflow-checks = true diff --git a/examples/noop-contract/src/lib.rs b/examples/noop-contract/src/lib.rs index e691d014..b9aa3c3e 100644 --- a/examples/noop-contract/src/lib.rs +++ b/examples/noop-contract/src/lib.rs @@ -1,8 +1,9 @@ -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::near_bindgen; #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_sdk::borsh")] pub struct Noop; #[near_bindgen] diff --git a/examples/simple-contract/Cargo.toml b/examples/simple-contract/Cargo.toml index 7a782a3d..5bac8a4f 100644 --- a/examples/simple-contract/Cargo.toml +++ b/examples/simple-contract/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.1.1" +near-sdk = "5.0.0-alpha.2" [profile.release] codegen-units = 1 diff --git a/examples/simple-contract/src/lib.rs b/examples/simple-contract/src/lib.rs index 18e799cd..0aace4af 100644 --- a/examples/simple-contract/src/lib.rs +++ b/examples/simple-contract/src/lib.rs @@ -1,8 +1,9 @@ -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::{env, log, near_bindgen}; #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_sdk::borsh")] pub struct Simple {} #[near_bindgen] diff --git a/examples/src/spooning.rs b/examples/src/spooning.rs index dfe5ee63..adf0452f 100644 --- a/examples/src/spooning.rs +++ b/examples/src/spooning.rs @@ -1,6 +1,6 @@ use std::env; -use borsh::{self, BorshDeserialize, BorshSerialize}; +use near_primitives::borsh::{BorshDeserialize, BorshSerialize}; use near_workspaces::{AccountId, Contract, DevNetwork, Worker}; use serde_json::json; use tracing::info; @@ -28,12 +28,14 @@ const TESTNET_PREDEPLOYED_CONTRACT_ID: &str = "dev-20211013002148-59466083160385 // formats. Note that these will be different depending on what data structure // we use in our contract. #[derive(Clone, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_primitives::borsh")] struct Record { k: String, v: String, } #[derive(Clone, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_primitives::borsh")] struct StatusMessage { records: Vec, } diff --git a/examples/src/tx_status.rs b/examples/src/tx_status.rs index ace5791d..5daa4a0f 100644 --- a/examples/src/tx_status.rs +++ b/examples/src/tx_status.rs @@ -21,8 +21,8 @@ async fn main() -> anyhow::Result<()> { let tx_info = { let outcome = outcome.outcome(); TransactionInfo::TransactionId { - hash: CryptoHash(outcome.transaction_hash.0), - account_id: outcome.executor_id.clone(), + tx_hash: CryptoHash(outcome.transaction_hash.0), + sender_account_id: outcome.executor_id.clone(), } }; diff --git a/workspaces/Cargo.toml b/workspaces/Cargo.toml index 742b72ca..8877243e 100644 --- a/workspaces/Cargo.toml +++ b/workspaces/Cargo.toml @@ -12,7 +12,6 @@ Library for automating workflows and testing NEAR smart contracts. [dependencies] async-trait = "0.1" base64 = "0.21" -borsh = "0.10" bs58 = "0.5" cargo_metadata = { version = "0.18", optional = true } cargo-near = "0.3.1" @@ -31,16 +30,16 @@ tokio-retry = "0.3" tracing = "0.1" url = { version = "2.2.2", features = ["serde"] } -near-gas = { version = "0.2.3", features = ["serde", "borsh", "schemars"] } +near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] } near-token = { version = "0.2.0", features = ["serde"] } -near-sdk = { version = "4.1", optional = true } -near-account-id = "0.17" -near-crypto = "0.17" -near-primitives = "0.17" -near-jsonrpc-primitives = "0.17" -near-jsonrpc-client = { version = "0.6", features = ["sandbox"] } +near-sdk = { version = "5.0.0-alpha.2", 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.7.0" -near-chain-configs = { version = "0.17.0", optional = true } +near-chain-configs = { version = "0.20.0", optional = true } [build-dependencies] near-sandbox-utils = "0.7.0" @@ -50,9 +49,8 @@ libc = "0.2" [dev-dependencies] anyhow = "1.0" -borsh = "0.10" futures = "0.3" -near-sdk = "4.0.0" +near-sdk = "5.0.0-alpha.2" 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/operations.rs b/workspaces/src/operations.rs index 65b252d3..b83ad370 100644 --- a/workspaces/src/operations.rs +++ b/workspaces/src/operations.rs @@ -17,6 +17,7 @@ use near_account_id::ParseAccountError; use near_gas::NearGas; use near_jsonrpc_client::errors::{JsonRpcError, JsonRpcServerError}; use near_jsonrpc_client::methods::tx::RpcTransactionError; +use near_primitives::borsh; use near_primitives::transaction::{ Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction, DeployContractAction, FunctionCallAction, StakeAction, TransferAction, @@ -77,7 +78,7 @@ impl Function { /// Similar to `args`, specify an argument that is borsh serializable and can be /// accepted by the equivalent contract. pub fn args_borsh(mut self, args: U) -> Self { - match args.try_to_vec() { + match borsh::to_vec(&args) { Ok(args) => self.args = Ok(args), Err(e) => self.args = Err(ErrorKind::DataConversion.custom(e)), } @@ -162,12 +163,12 @@ impl Transaction { }; if let Ok(actions) = &mut self.actions { - actions.push(Action::FunctionCall(FunctionCallAction { + actions.push(Action::FunctionCall(Box::new(FunctionCallAction { method_name: function.name.to_string(), args, deposit: function.deposit.as_yoctonear(), gas: function.gas.as_gas(), - })); + }))); } self diff --git a/workspaces/src/result.rs b/workspaces/src/result.rs index 286c05c1..1bfe1150 100644 --- a/workspaces/src/result.rs +++ b/workspaces/src/result.rs @@ -4,6 +4,7 @@ use std::fmt; use near_account_id::AccountId; use near_gas::NearGas; +use near_primitives::borsh; use near_primitives::errors::TxExecutionError; use near_primitives::views::{ CallResult, ExecutionOutcomeWithIdView, ExecutionStatusView, FinalExecutionOutcomeView, diff --git a/workspaces/src/rpc/client.rs b/workspaces/src/rpc/client.rs index 50d978de..ac090776 100644 --- a/workspaces/src/rpc/client.rs +++ b/workspaces/src/rpc/client.rs @@ -311,12 +311,12 @@ impl Client { pub(crate) async fn tx_async_status( &self, sender_id: &AccountId, - hash: CryptoHash, + tx_hash: CryptoHash, ) -> Result> { self.query(methods::tx::RpcTransactionStatusRequest { transaction_info: methods::tx::TransactionInfo::TransactionId { - account_id: sender_id.clone(), - hash, + sender_account_id: sender_id.clone(), + tx_hash, }, }) .await diff --git a/workspaces/src/rpc/query.rs b/workspaces/src/rpc/query.rs index 59b192b8..7467591f 100644 --- a/workspaces/src/rpc/query.rs +++ b/workspaces/src/rpc/query.rs @@ -228,7 +228,7 @@ impl Query<'_, ViewFunction> { /// Similar to `args`, specify an argument that is borsh serializable and can be /// accepted by the equivalent contract. - pub fn args_borsh(mut self, args: U) -> Self { + pub fn args_borsh(mut self, args: U) -> Self { self.method.function = self.method.function.args_borsh(args); self } diff --git a/workspaces/src/types/mod.rs b/workspaces/src/types/mod.rs index e791f1ca..192ff5bc 100644 --- a/workspaces/src/types/mod.rs +++ b/workspaces/src/types/mod.rs @@ -16,8 +16,8 @@ use std::io; use std::path::Path; use std::str::FromStr; -use borsh::{BorshDeserialize, BorshSerialize}; pub use near_account_id::AccountId; +use near_primitives::borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use sha2::Digest; diff --git a/workspaces/tests/patch_state.rs b/workspaces/tests/patch_state.rs index 3927f20b..b7a27336 100644 --- a/workspaces/tests/patch_state.rs +++ b/workspaces/tests/patch_state.rs @@ -1,7 +1,7 @@ // Required since `test_log` adds more recursion than the standard recursion limit of 128 #![recursion_limit = "256"] -use borsh::{self, BorshDeserialize, BorshSerialize}; +use near_primitives::borsh::{self, BorshDeserialize, BorshSerialize}; use near_token::NearToken; use serde_json::json; use test_log::test; @@ -12,12 +12,14 @@ use near_workspaces::{AccessKey, AccountDetailsPatch, AccountId, Contract, DevNe const STATUS_MSG_WASM_FILEPATH: &str = "../examples/res/status_message.wasm"; #[derive(Clone, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_primitives::borsh")] struct Record { k: String, v: String, } #[derive(Clone, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_primitives::borsh")] struct StatusMessage { records: Vec, } @@ -74,7 +76,7 @@ async fn test_patch_state() -> anyhow::Result<()> { }); worker - .patch_state(&contract_id, b"STATE", &status_msg.try_to_vec()?) + .patch_state(&contract_id, b"STATE", &borsh::to_vec(&status_msg)?) .await?; let status: String = worker @@ -101,7 +103,7 @@ async fn test_patch() -> anyhow::Result<()> { worker .patch(&contract_id) - .state(b"STATE", &status_msg.try_to_vec()?) + .state(b"STATE", &borsh::to_vec(&status_msg)?) .transact() .await?; @@ -140,7 +142,7 @@ async fn test_patch_full() -> anyhow::Result<()> { ) .access_key(sk.public_key(), AccessKey::full_access()) .code(&status_msg_code) - .state(b"STATE", &status_msg.try_to_vec()?) + .state(b"STATE", &borsh::to_vec(&status_msg)?) .transact() .await?; diff --git a/workspaces/tests/test-contracts/status-message/Cargo.toml b/workspaces/tests/test-contracts/status-message/Cargo.toml index 1e9dc4e0..28c24cec 100644 --- a/workspaces/tests/test-contracts/status-message/Cargo.toml +++ b/workspaces/tests/test-contracts/status-message/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.1.1" +near-sdk = "5.0.0-alpha.2" [profile.release] codegen-units = 1 diff --git a/workspaces/tests/test-contracts/status-message/src/lib.rs b/workspaces/tests/test-contracts/status-message/src/lib.rs index c1b7aa8d..c6926bc0 100644 --- a/workspaces/tests/test-contracts/status-message/src/lib.rs +++ b/workspaces/tests/test-contracts/status-message/src/lib.rs @@ -1,9 +1,10 @@ -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::{env, log, near_bindgen, AccountId}; use std::collections::HashMap; #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_sdk::borsh")] pub struct StatusMessage { records: HashMap, } diff --git a/workspaces/tests/test-contracts/type-serialize/Cargo.toml b/workspaces/tests/test-contracts/type-serialize/Cargo.toml index aaf37e99..5389347f 100644 --- a/workspaces/tests/test-contracts/type-serialize/Cargo.toml +++ b/workspaces/tests/test-contracts/type-serialize/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] bs58 = "0.5" -near-sdk = "4.1" +near-sdk = "5.0.0-alpha.2" [profile.release] codegen-units = 1 diff --git a/workspaces/tests/test-contracts/type-serialize/src/lib.rs b/workspaces/tests/test-contracts/type-serialize/src/lib.rs index 3cc9e542..7a070af4 100644 --- a/workspaces/tests/test-contracts/type-serialize/src/lib.rs +++ b/workspaces/tests/test-contracts/type-serialize/src/lib.rs @@ -1,10 +1,11 @@ -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::near_bindgen; use near_sdk::{CurveType, PublicKey}; use std::convert::TryFrom; #[derive(Default, BorshSerialize, BorshDeserialize)] +#[borsh(crate = "near_sdk::borsh")] #[near_bindgen] struct Contract {} diff --git a/workspaces/tests/types.rs b/workspaces/tests/types.rs index d90e54e3..6d363072 100644 --- a/workspaces/tests/types.rs +++ b/workspaces/tests/types.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use borsh::{BorshDeserialize, BorshSerialize}; +use near_primitives::borsh::{self, BorshDeserialize}; use near_workspaces::types::{KeyType, PublicKey, SecretKey}; use near_workspaces::AccountId; @@ -45,7 +45,7 @@ fn test_pubkey_serialization() -> anyhow::Result<()> { for key_type in [KeyType::ED25519, KeyType::SECP256K1] { let sk = SecretKey::from_seed(key_type, "test"); let pk = sk.public_key(); - let bytes = pk.try_to_vec()?; + let bytes = borsh::to_vec(&pk)?; // Borsh Deserialization should equate to the original public key: assert_eq!(PublicKey::try_from_slice(&bytes)?, pk); @@ -91,7 +91,7 @@ async fn test_pubkey_from_sdk_ser() -> anyhow::Result<()> { fn test_pubkey_borsh_format_change() -> anyhow::Result<()> { let pk = default_workspaces_pubkey()?; assert_eq!( - pk.try_to_vec()?, + borsh::to_vec(&pk)?, bs58::decode("279Zpep9MBBg4nKsVmTQE7NbXZkWdxti6HS1yzhp8qnc1ExS7gU").into_vec()? );