Skip to content

Commit

Permalink
refactor: Upgraded NEAR crates to 0.20.0 release (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Jan 25, 2024
1 parent 51e0ead commit f59dd3e
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 42 deletions.
7 changes: 3 additions & 4 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions examples/noop-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
overflow-checks = true
3 changes: 2 additions & 1 deletion examples/noop-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/simple-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 3 additions & 1 deletion examples/src/spooning.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Record>,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/tx_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
};

Expand Down
20 changes: 9 additions & 11 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"] }

Expand Down
7 changes: 4 additions & 3 deletions workspaces/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<U: borsh::BorshSerialize>(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)),
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions workspaces/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions workspaces/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ impl Client {
pub(crate) async fn tx_async_status(
&self,
sender_id: &AccountId,
hash: CryptoHash,
tx_hash: CryptoHash,
) -> Result<FinalExecutionOutcomeView, JsonRpcError<RpcTransactionError>> {
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
Expand Down
2 changes: 1 addition & 1 deletion workspaces/src/rpc/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U: borsh::BorshSerialize>(mut self, args: U) -> Self {
pub fn args_borsh<U: near_primitives::borsh::BorshSerialize>(mut self, args: U) -> Self {
self.method.function = self.method.function.args_borsh(args);
self
}
Expand Down
2 changes: 1 addition & 1 deletion workspaces/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions workspaces/tests/patch_state.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Record>,
}
Expand Down Expand Up @@ -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
Expand All @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down
2 changes: 1 addition & 1 deletion workspaces/tests/test-contracts/status-message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion workspaces/tests/test-contracts/status-message/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<AccountId, String>,
}
Expand Down
2 changes: 1 addition & 1 deletion workspaces/tests/test-contracts/type-serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion workspaces/tests/test-contracts/type-serialize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down
6 changes: 3 additions & 3 deletions workspaces/tests/types.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()?
);

Expand Down

0 comments on commit f59dd3e

Please sign in to comment.